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

eslint config: Fix modern module resolution #9562

Merged
merged 6 commits into from Mar 25, 2022

Conversation

tylerbutler
Copy link
Member

@tylerbutler tylerbutler commented Mar 23, 2022

Eslint's plugin behavior is to load the plugin relative to the current project. This means that if you have a shared config that depends on plugins, like we do, then each project using the shared config has to have the plugins defined as part of their own dependencies. The issue tracking this on the Eslint side is eslint/eslint#3458.

It's more convenient if the plugins are loaded relative to the shared config itself, rather than the project being linted. The Rush team provides a module that works around this behavior by patching eslint.

When I originally added the workaround package, I didn't understand how to use it properly. Now I do. Each inheriting config needs to have the following line at the beginning of their .eslintrc.js file:

// This is a workaround for https://github.com/eslint/eslint/issues/3458
require("@fluidframework/eslint-config-fluid/patch/modern-module-resolution");

That will load the patch module from the shared eslint config, which will make eslint load the plugins from the shared eslint config package. These changes will be in a future PR. This PR just updates the shared config itself.

Updating the config and publishing a new version is necessary to address this error that arises when adding the workaround:

ESLint couldn't determine the plugin "@typescript-eslint" uniquely.

- /workspaces/FluidFramework/common/lib/driver-definitions/node_modules/@rushstack/eslint-config/node_modules/@typescript-eslint/eslint-plugin/dist/index.js (loaded in ".eslintrc.js » @fluidframework/eslint-config-fluid » @rushstack/eslint-config/profile/web-app")
- /workspaces/FluidFramework/common/lib/driver-definitions/node_modules/@typescript-eslint/eslint-plugin/dist/index.js (loaded in ".eslintrc.js » @fluidframework/eslint-config-fluid » ./eslint7")

Please remove the "plugins" setting from either config or remove either plugin installation.

The error happens because the minimal config inherits from two configs that both use @typescript-eslint. This change stops extending the rushstack config, and instead depends directly on the plugins that the rushstack config itself uses.

@tylerbutler tylerbutler marked this pull request as ready for review March 24, 2022 21:12
@tylerbutler tylerbutler requested review from msfluid-bot and a team as code owners March 24, 2022 21:12
Copy link
Contributor

@heliocliu heliocliu left a comment

Choose a reason for hiding this comment

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

ooo i like this

@github-actions github-actions bot added the base: main PRs targeted against main branch label Mar 25, 2022
@tylerbutler tylerbutler merged commit 7ad8f7b into microsoft:main Mar 25, 2022
@tylerbutler tylerbutler deleted the lint/config-fix branch March 25, 2022 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
base: main PRs targeted against main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants