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

Migrates to Eslint's flat config #6276

Merged
merged 7 commits into from
Jun 8, 2024
Merged

Migrates to Eslint's flat config #6276

merged 7 commits into from
Jun 8, 2024

Conversation

arcanis
Copy link
Member

@arcanis arcanis commented May 6, 2024

What's the problem this PR addresses?

This lets us remove the Rushstack fix, and dogfood the VSCode SDK with the flat config (which is the only available config in Eslint 9). I would have migrated us to Eslint 9, but eslint-plugin-react isn't compatible yet.

How did you fix it?

Migrate to eslint.config.mjs.

Checklist

  • 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 marked this pull request as draft May 6, 2024 12:52
@arcanis
Copy link
Member Author

arcanis commented May 6, 2024

Draft until #6219 is fixed.

Comment on lines 9 to 41
ignores: [
`.yarn`,

`packages/docusaurus/.docusaurus`,

`packages/yarnpkg-pnp/sources/hook.js`,
`packages/yarnpkg-pnp/sources/esm-loader/built-loader.js`,

`packages/yarnpkg-libzip/sources/libzipAsync.js`,
`packages/yarnpkg-libzip/sources/libzipSync.js`,

// The parsers are auto-generated
`packages/yarnpkg-parsers/sources/grammars/*.js`,

`packages/yarnpkg-core/sources/worker-zip/index.js`,
`packages/yarnpkg-cli/bundles/yarn.js`,

`packages/*/lib`,
`packages/*/bin`,
`packages/*/build`,
`packages/**/*fixtures*`,
`packages/yarnpkg-libzip/artifacts`,
`packages/plugin-compat/extra/fsevents/fsevents-*.js`,

// Files generated by Gatsby
`packages/gatsby/public`,
// Files generated by TypeDoc`,
`packages/gatsby/static/api`,

// Minimize the diff with upstream`,
`packages/yarnpkg-pnp/sources/node`,
`packages/yarnpkg-pnp/sources/loader/node-options*`
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The gatsby rules should be safe to remove
  2. Is yarnpkg-cli the only workspace to generate a bundle directory? Because other places just ignores packages/*/bundle
  3. Should the yarnpkg-libui artifacts also be here?
  4. Should the these be grouped by package?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed Gatsby, but other changes will be for another PR (I'd like to keep the changes here as minimal as possible).

@clemyan
Copy link
Member

clemyan commented May 10, 2024

FYI, ESLint recently released the @eslint/compat package that patches v8 plugins for v9.

## What's the problem this PR addresses?

ESM loaders aren't supported by the sdks because we only
`require().setup()` but we don't `register()` the ESM loader hook.

Fixes #6219

## How did you fix it?

- Add support for ESM loaders to the SDK.

- Check whether the `findPnpApi` function could be found in the `module`
builtin. If not, tries to setup the environment accordingly. This is
because in the case of the SDK, the subprocesses have been created
without the `--require .pnp.loader.mjs` flag, so the PnP runtime won't
be setup.

## 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.
@arcanis arcanis marked this pull request as ready for review June 7, 2024 11:00
@arcanis arcanis merged commit d3695b1 into master Jun 8, 2024
22 of 26 checks passed
@arcanis arcanis deleted the mael/eslint-flat-config branch June 8, 2024 20:50
@merceyz
Copy link
Member

merceyz commented Jun 8, 2024

@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.

3 participants