Enforces a newline before each chained method call after reaching a configurable maximum depth.
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.
{
"@croct/newline-per-chained-call": [
"error",
{
"ignoreChainWithDepth": 2
}
]
}
These are examples of how the rule might apply.
this.foo.block.bar.qux();
foo().bar().baz().qux();
foo.bar.baz.qux();
this.foo
.block
.bar
.qux();
foo()
.bar()
.baz()
.qux();
await expect(callback).resolves.toHaveBeenCalledWith();
foo.bar.baz.qux;
These are the available options:
Specifies the maximum depth of chained allowed, default is 2.
/*eslint newline-per-chained-call: ["error", {"ignoreChainWithDepth": 1}]*/
foo().bar().baz();
/*eslint newline-per-chained-call: ["error", {"ignoreChainWithDepth": 1}]*/
foo()
.bar()
.baz();
- ✅ Recommended
- 🔧 Fixable
- 💭 Requires type information