eslint-stylistic / eslint-stylistic

Monorepo for ESLint Stylistic plugins and configs
https://eslint.style
MIT License
1.37k stars 93 forks source link

feat(js/array-element-newline): options multiline and consistent combination #445

Closed Zamralik closed 3 months ago

Zamralik commented 3 months ago

Description

The rule array-element-newline doesn't allow combining the "consistent" and { "multiline": true } options.

The { "multiline": true } is excellent for readability.

But with singleline values, it entirely forbid having newlines between elements. Yet it's also quite helpful for readability with long values or some nested arrays.

With { "multiline": true }, this is invalid.

const urls = [
    "https://www.example.com/path/to/something",
    "https://www.example.com/path/to/something/else",
    "https://www.example.com/path/to/an/other/thing",
];

const matrix = [
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8],
];

Linked Issues

None here, but I opened this very issue on the eslint github back in 2020 before the split occured. At the time, stylistic rules were frozen. https://github.com/eslint/eslint/issues/13818

Additional context

This change was made to be entirely backward compatible for ease. It was just a matter of adding the possibility to put a boolean property named "consistent" to the option object.

{ "consistent": true, "multiline": true } has the meaning "if there is a multiline element, then the rule is "always" else the rule is "consistent"".

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.79%. Comparing base (e1898af) to head (7552b97).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #445 +/- ## ======================================= Coverage 99.79% 99.79% ======================================= Files 118 118 Lines 27743 27747 +4 Branches 4717 4717 ======================================= + Hits 27686 27690 +4 Misses 57 57 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.