Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: lint mjs files and ignore json files #6352

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

merceyz
Copy link
Member

@merceyz merceyz commented Jun 21, 2024

What's the problem this PR addresses?

.mjs files (eslint.config.mjs) aren't linted and in my IDE ESLint keeps breaking the JSON files.

How did you fix it?

Lint .mjs files and ignore JSON files.

Checklist

  • I have read the Contributing Guide.
  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@arcanis arcanis merged commit 57ed709 into master Jun 24, 2024
22 of 26 checks passed
@arcanis arcanis deleted the merceyz/chore/fix-linting branch June 24, 2024 07:22
@clemyan clemyan mentioned this pull request Jun 26, 2024
3 tasks
arcanis added a commit that referenced this pull request Jul 24, 2024
## What's the problem this PR addresses?

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

- The include patterns are unnecessary wide and causes a lot more files
to be linted by default (See #6352, which is only a partial fix)
- The ignore patterns can be simplified
(#6276 (comment))
- There are some extraneous config files and config items
- The `@typescript-eslint/naming-convention` rule config in
`@yarnpkg/eslint-config` is shadowed by the one in `eslint.config.mjs`

## 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](https://eslint.org/blog/2024/04/eslint-v9.0.0-released/#running-eslint-with-no-file-arguments)
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 #6276 (comment).
Added a few missed ignores. Also grouped them by workspace.

### Extraneous configs

See #6276 (comment).
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

<!--- Don't worry if you miss something, chores are automatically
tested. -->
<!--- This checklist exists to help you remember doing the chores when
you submit a PR. -->
<!--- Put an `x` in all the boxes that apply. -->
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).

<!-- See
https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released
for more details. -->
<!-- Check with `yarn version check` and fix with `yarn version check
-i` -->
- [x] I have set the packages that need to be released for my changes to
be effective.

<!-- The "Testing chores" workflow validates that your PR follows our
guidelines. -->
<!-- If it doesn't pass, click on it to see details as to what your PR
might be missing. -->
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.

---------

Co-authored-by: Maël Nison <nison.mael@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants