Skip to content

Latest commit

 

History

History
102 lines (74 loc) · 1.72 KB

min-chained-call-depth.md

File metadata and controls

102 lines (74 loc) · 1.72 KB

min-chained-call-depth

Enforces a minimum of chained method calls to allow multiline chains, except when the chain is too long to fit on a single line.

How to use

{
  "@croct/min-chained-call-depth": [
    "error",
    {
      "maxLineLength": 100
    }
  ]
}

Examples

These are examples of how the rule might apply.

❌ Incorrect

expect(screen.getElementById("very-long-identifier"))
    .toBe(true)
expect(screen.getElementById("very-long-identifier"))
    .toBe({
        foo: true
    });

✅ Correct

expect(screen.getElementById("very-long-identifier")).toBe(true);

expect(screen.getElementById("very-long-identifier"))
    // ...
    .toBe(true);
expect(screen.getElementById("very-long-identifier")).toBe({
    foo: true
});

Options

These are the available options:

maxLineLength

Specifies the maximum line length so that the rule allows breaking into multiple lines cases that otherwise would not be permitted to avoid exceeding the line length limit.

❌ Incorrect

expect(screen.getElementById("identifier"))
    .toBe(true);

✅ Correct

/*eslint min-chained-call-depth: ["error", {"maxLineLength": 63}]*/
expect(screen.getElementById("very-long-identifier"))
    .toBe(true);

ignoreChainDeeperThan

Chains that are deeper than the specified number are allowed to break line, default is 2.

❌ Incorrect

Array(10)
    .fill(0)
    .map(foo => foo);

✅ Correct

/* eslint min-chained-call-depth: ["error", {"ignoreChainDeeperThan": 1}] */
Array(10)
    .fill(0)
    .map(foo => foo);

Attributes

  • ✅ Recommended
  • 🔧 Fixable
  • 💭 Requires type information