In the next release we will be enabling the prefer-arrow-callback
rule by default: https://github.com/wikimedia/eslint-config-wikimedia/issues/572
Topic on Manual talk:Coding conventions/JavaScript
Is it possible to enforce this only when doing so would not also break other eslint rules? I often find myself having to craft a one-liner that satisfies both prefer-arrow-callback
and max-len
, for example.
prefer-arrow-callback
shouldn't affect how many lines you can use in a callback. Can you give an example?
Sure. Consider:
// eslint-disable-next-line arrow-body-style
provide: ( stateField ) => {
// eslint-disable-next-line arrow-body-style
return showPanel.from( stateField, ( on ) => {
return on ? () => this.panel : null;
} );
}
And if prefer-arrow-callback
had its way:
// eslint-disable-next-line max-len
provide: ( stateField ) => showPanel.from( stateField, ( on ) => on ? () => this.panel : null )
Clearly the first example is more legible. Worse, the second is considered acceptable given max-len
is only a warning. Or is there a third variant I'm missing here?
I think prefer-arrow-callback
is great practice, but ideally it would only apply if what would follow =>
does not then cause it to break max-len
. Hopefully that makes sense.
Rather than max-len disables, why not just write it out with an indent like normal, i.e.:
provide: ( stateField ) => showPanel.from(
stateField, ( on ) => on ? () => this.panel : null
)
As James shows, long expressions can usually be split elsewhere.
Is it possible to enforce this only when doing so would not also break other eslint rules?
To answer your original question, I don't think it is. Rules run independently.