no-trailing-spaces
禁止行尾空格
🔧 可修复
此规则报告的一些问题可以通过 --fix
命令行 选项自动修复
有时在编辑文件的过程中,您可能会在行尾留下额外的空格。这些空格差异可能会被源代码控制系统检测到并标记为差异,从而给开发人员带来挫败感。虽然这些额外的空格不会引起功能问题,但许多代码约定要求在提交之前删除尾随空格。
规则详情
此规则禁止行尾的尾随空格(空格、制表符和其他 Unicode 空格字符)。
此规则的错误代码示例
在 Playground 中打开
/*eslint no-trailing-spaces: "error"*/
var foo = 0;/* trailing whitespace */
var baz = 5;/* trailing whitespace */
/* trailing whitespace */
此规则的正确代码示例
在 Playground 中打开
/*eslint no-trailing-spaces: "error"*/
var foo = 0;
var baz = 5;
选项
此规则有一个对象选项
"skipBlankLines": false
(默认) 禁止空行上的尾随空格"skipBlankLines": true
允许空行上的尾随空格"ignoreComments": false
(默认) 禁止注释块中的尾随空格"ignoreComments": true
允许注释块中的尾随空格
skipBlankLines
使用 { "skipBlankLines": true }
选项时,此规则的正确代码示例
在 Playground 中打开
/*eslint no-trailing-spaces: ["error", { "skipBlankLines": true }]*/
var foo = 0;
var baz = 5;
// ↓ a line with whitespace only ↓
ignoreComments
使用 { "ignoreComments": true }
选项时,此规则的正确代码示例
在 Playground 中打开
/*eslint no-trailing-spaces: ["error", { "ignoreComments": true }]*/
// ↓ these comments have trailing whitespace →
//
/**
* baz
*
* bar
*/
版本
此规则在 ESLint v0.7.1 中引入。