Skip to content

Latest commit

 

History

History
94 lines (68 loc) · 1.49 KB

newline-per-chained-call.md

File metadata and controls

94 lines (68 loc) · 1.49 KB

newline-per-chained-call

Enforces a newline before each chained method call after reaching a configurable maximum depth.

Rule details

This rule differs from the newline-per-chained-call rule by enforcing a newline before each chained method call rather than only after the call that exceeded the maximum depth. Another difference is that this rule only applies to chained method calls, not to chained property accessors.

How to use

{
  "@croct/newline-per-chained-call": [
    "error",
    {
      "ignoreChainWithDepth": 2
    }
  ]
}

Examples

These are examples of how the rule might apply.

❌ Incorrect

this.foo.block.bar.qux();
foo().bar().baz().qux();
foo.bar.baz.qux();

✅ Correct

this.foo
    .block
    .bar
    .qux();
foo()
    .bar()
    .baz()
    .qux();
await expect(callback).resolves.toHaveBeenCalledWith();
foo.bar.baz.qux;

Options

These are the available options:

ignoreChainDeeperThan

Specifies the maximum depth of chained allowed, default is 2.

❌ Incorrect

/*eslint newline-per-chained-call: ["error", {"ignoreChainWithDepth": 1}]*/
foo().bar().baz();

✅ Correct

/*eslint newline-per-chained-call: ["error", {"ignoreChainWithDepth": 1}]*/
foo()
    .bar()
    .baz();

Attributes

  • ✅ Recommended
  • 🔧 Fixable
  • 💭 Requires type information