yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.23k stars 1.07k forks source link

Enhance ESLint config #6357

Open clemyan opened 4 days ago

clemyan commented 4 days ago

What's the problem this PR addresses?

Follow up to #6276 and #6352. The ESLint config has room for improvement

How did you fix it?

Wide include

The culprit is this line https://github.com/yarnpkg/berry/blob/57ed709ceea1f45568f860729cc18ae324334289/eslint.config.mjs#L43

By only specifying a negated pattern, it matches ALL other files that are not globally ignored. Under flat config, each file matched by at least one config item (and is not globally ignored) is eligible for linting. This causes the VSCode plugin to attempt to lint pretty much every file.

The correct way to use both files and ignores to accurately specify the set of files to be linted. With that, we can simplify the test:lint command to just lint the whole repo and we have a single source of truth of what should be linted. This also aligns with the default behavior of ESLint v9 for when we migrate. I have also taken the opportunity to widen the typescript files globs to include .cts and .mts if we create those in the future.

Ignore patterns

See https://github.com/yarnpkg/berry/pull/6276#discussion_r1591850604. Added a few missed ignores. Also grouped them by workspace.

Extraneous configs

See https://github.com/yarnpkg/berry/pull/6276#issuecomment-2156189365. There are two sets of configs that specify jest globals for tests using env but that is not supported in flat config and has already been migrated in #6276.

@typescript-eslint/naming-convention

The @typescript-eslint/naming-convention is configured twice, once in @yarnpkg/eslint-config and once in eslint.config.mjs. But due to a wide include glob in the latter, the former one is actually almost entirely shadowed -- it only takes effect on sources/index.ts and sources/Plugin.ts of each workspace.

There are already ~100 violations of the rule that went unreported due to this shadowing. I have removed the shadowed config item since it isn't really being enforced. (Or is that actually intentional?)

Checklist