dot-location

在点前后强制换行一致

🔧 Fixable

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

Important

This rule was deprecated in ESLint v8.53.0. Please use the corresponding rule in @stylistic/eslint-plugin-js.

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"(默认),则成员表达式中的点应与对象部分位于同一行。

    ¥If it is "object" (default), the dot in a member expression should be on the same line as the object portion.

  • 如果是 "property",则成员表达式中的点应与属性部分位于同一行。

    ¥If it is "property", the dot in a member expression should be on the same line as the property portion.

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 中引入。

资源