Skip to content

Latest commit

 

History

History
96 lines (59 loc) · 1.79 KB

dot-location.md

File metadata and controls

96 lines (59 loc) · 1.79 KB
规则名 规则类型 关联规则
dot-location
layout
newline-after-var
dot-notation

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;

规则详解

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.

配置项

The rule takes one option, a string:

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

object

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

选项 default "object"错误 代码示例:

/*eslint dot-location: ["error", "object"]*/

var foo = object
.property;

选项 default "object"正确 代码示例:

::: correct

/*eslint dot-location: ["error", "object"]*/

var foo = object.
property;

var bar = (
    object
).
property;

var baz = object.property;

property

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

选项 "property"错误 代码示例:

/*eslint dot-location: ["error", "property"]*/

var foo = object.
property;

选项 "property"正确 代码示例:

::: correct

/*eslint dot-location: ["error", "property"]*/

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

禁用建议

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