no-whitespace-before-property
禁止属性前有空格
此规则报告的一些问题可通过 --fix 命令行 选项自动修复
This rule was deprecated in ESLint v8.53.0. It will be removed in v11.0.0. Please use the corresponding rule in @stylistic/eslint-plugin.
JavaScript 允许对象与其属性之间有空白。然而,不一致的间距会使代码更难阅读,并可能导致错误。
🌐 JavaScript allows whitespace between objects and their properties. However, inconsistent spacing can make code harder to read and can lead to errors.
foo. bar .baz . quz
规则详情
🌐 Rule Details
此规则不允许在对象的属性前的点号周围或开括号前有空格,如果它们在同一行上。当对象和属性在不同的行上时,此规则允许空格,因为在较长的属性链中添加换行是常见的:
🌐 This rule disallows whitespace around the dot or before the opening bracket before properties of objects if they are on the same line. This rule allows whitespace when the object and property are on separate lines, as it is common to add newlines to longer chains of properties:
foo
.bar()
.baz()
.qux()
此规则的错误代码示例:
🌐 Examples of incorrect code for this rule:
/*eslint no-whitespace-before-property: "error"*/
foo [bar]
foo. bar
foo .bar
foo. bar. baz
foo. bar()
.baz()
foo
.bar(). baz()
符合此规则的正确代码示例:
🌐 Examples of correct code for this rule:
/*eslint no-whitespace-before-property: "error"*/
foo.bar
foo[bar]
foo[ bar ]
foo.bar.baz
foo
.bar().baz()
foo
.bar()
.baz()
foo.
bar().
baz()
何时不使用
🌐 When Not To Use It
如果你不关心在点周围或在对象属性之前的左括号之前允许空格(如果它们位于同一行),请关闭此规则。
🌐 Turn this rule off if you do not care about allowing whitespace around the dot or before the opening bracket before properties of objects if they are on the same line.
版本
此规则是在 ESLint v2.0.0-beta.1 中引入。