Index

dot-location

在点前后强制换行一致

🔧 Fixable

此规则报告的一些问题可通过 --fix 命令行 选项自动修复

Important

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.

Learn more

JavaScript 允许你在成员表达式中的点之前或之后放置换行符。

🌐 JavaScript allows you to place newlines before or after a dot in a member expression.

在点之前或之后放置换行符的一致性可以大大提高可读性。

🌐 Consistency in placing a newline before or after the dot can greatly increase readability.

var a = universe.
        galaxy;

var b = universe
       .galaxy;

规则详情

🌐 Rule Details

此规则旨在强制成员表达式中的换行一致性。此规则防止在成员表达式中的点周围使用混合换行。

🌐 This rule aims to enforce newline consistency in member expressions. This rule prevents the use of mixed newlines around the dot in a member expression.

选项

🌐 Options

该规则采用一个选项,一个字符串:

🌐 The rule takes one option, a string:

  • 如果是 "object"(默认),成员表达式中的点应该与对象部分在同一行上。
  • 如果是 "property",成员表达式中的点应该与属性部分在同一行。

object

默认的 "object" 选项要求点号与对象在同一行。

🌐 The default "object" option requires the dot to be on the same line as the object.

默认 "object" 选项的错误代码示例:

🌐 Examples of incorrect code for the default "object" option:

在线运行
/*eslint dot-location: ["error", "object"]*/

var foo = object
.property;

默认 "object" 选项的正确代码示例:

🌐 Examples of correct code for the default "object" option:

在线运行
/*eslint dot-location: ["error", "object"]*/

var foo = object.
property;

var bar = (
    object
).
property;

var baz = object.property;

property

"property" 选项要求点号与属性位于同一行。

🌐 The "property" option requires the dot to be on the same line as the property.

针对 "property" 选项的错误代码示例:

🌐 Examples of incorrect code for the "property" option:

在线运行
/*eslint dot-location: ["error", "property"]*/

var foo = object.
property;

适用于 "property" 选项的正确代码示例:

🌐 Examples of correct code for the "property" option:

在线运行
/*eslint dot-location: ["error", "property"]*/

var foo = object
.property;
var bar = object.property;

何时不使用

🌐 When Not To Use It

如果你不关心成员表达式中的点前后换行符的一致性,你可以关闭此规则。

🌐 You can turn this rule off if you are not concerned with the consistency of newlines before or after dots in member expressions.

版本

此规则是在 ESLint v0.21.0 中引入。

资源