Eslint
规则 | Rules

no-trailing-spaces

disallow trailing whitespace at the end of lines (no-trailing-spaces)

--fix命令行上的选项可以自动修复一些被这条规则反映的问题。

有时在编辑文件的过程中,最后可能会在行尾添加空格。这些空白区别可以被源代码控制系统拾取并标记为差异,从而给开发人员带来挫败感。虽然这些额外的空白不会导致功能问题,但许多代码约定要求在签入之前删除尾部空格。

规则细节

此规则不允许在行尾添加尾随空白(空格,制表符和其他Unicode空白字符)。

此规则的错误代码示例:

/*eslint no-trailing-spaces: "error"*/ var foo = 0;//••••• var baz = 5;//•• //•••••

此规则的正确代码示例:

/*eslint no-trailing-spaces: "error"*/ var foo = 0; var baz = 5;

选项

该规则有一个对象选项:

  • "skipBlankLines": false (默认)不允许空行上的尾随空白

  • "skipBlankLines": true 允许在空行上结尾空白

  • "ignoreComments": false (默认)不允许注释块中的尾随空白

  • "ignoreComments": true 允许评论块中的尾部空白

skipBlankLines

此规则的正确代码示例包含以下{ "skipBlankLines": true }选项:

/*eslint no-trailing-spaces: ["error", { "skipBlankLines": true }]*/ var foo = 0; var baz = 5; //•••••

ignoreComments

此规则的正确代码示例包含以下{ "ignoreComments": true }选项:

/*eslint no-trailing-spaces: ["error", { "ignoreComments": true }]*/ //foo• //••••• /** *•baz *•• *•bar */

版本

这条规则是在 ESLint 0.7.1 中引入的。

资源