Skip to content

[eslint-patch] Allow for extended shareable ESLint configurations to use any name #3020

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

Closed

Conversation

D4N14L
Copy link
Member

@D4N14L D4N14L commented Nov 12, 2021

Summary

Allows resolution of extended shareable configurations even when the package they are sourced from is not prefixed with eslint-config-.

Details

In order to allow use of ESLint configurations provided via Heft rigs, we need to allow consumption of configurations from packages not prefixed with eslint-config-, since Heft rigs obviously do not have the same naming restrictions.

The solution first attempts to resolve using the default logic, and falls back to attempting to resolve using the provided extended config name directly, without modification. This is done to allow for backwards-compatibility with intentionally short-named extended configs (cases where the prefix is intentionally omitted), since ESLint prefixes the eslint-config- to the package name during normalization if it was not found. For example, if @rushstack was specified as an extends configuration, then it would normally resolve to @rushstack/eslint-config.

How it was tested

Tested using resolution logic in Rushstack by moving the ESLint configuration into the rig. A future change will transition Rushstack to use the @rushstack/eslint-config package via @rushstack/heft-node-rig and @rushstack/heft-web-rig.

@octogonz
Copy link
Collaborator

In order to allow use of ESLint configurations provided via Heft rigs, we need to allow consumption of configurations from packages not prefixed with eslint-config-, since Heft rigs obviously do not have the same naming restrictions.

This doesn't seem true to me. We can chat about it offline and then follow up.

@D4N14L D4N14L force-pushed the user/danade/EslintResolverTweaks branch from 1efa4aa to 6f30379 Compare January 7, 2022 22:38
Copy link
Contributor

@dmichon-msft dmichon-msft left a comment

Choose a reason for hiding this comment

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

Few questions about the resolution logic, though it looks like you mostly just moved it from another file.


// Make sure we actually resolved the module in our call path
// and not some other spurious dependency.
if (path.join(eslintrcFolder, 'dist/eslintrc.cjs') === currentModule.filename) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be more efficient to verify currentModule.filename ends with dist/eslintrc.cjs before calling require.resolve, then verify that the output of path.dirname matches the remainder of currentModule.filename?


// Make sure we actually resolved the module in our call path
// and not some other spurious dependency.
if (path.join(eslintCandidateFolder, 'lib/cli-engine/cli-engine.js') === currentModule.filename) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Some concept here

})
);

if (path.join(eslintrcFolder, '/lib/config-array-factory.js') == currentModule.filename) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the switch to == from ===?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, same question

}

// Detect the ESLint package version
const eslintPackageJson = fs.readFileSync(path.join(eslintFolder, 'package.json')).toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Does calling toString() provide some advantage over specifying the encoding in the readFileSync call? I'd expect the latter to potentially optimize internally for different buffering behavior.

@iclanton
Copy link
Member

iclanton commented Apr 9, 2022

Note: PR #3337 has renamed our GitHub master branch to main. This should not affect your pull request, but we recommend to redo your git clone to avoid confusion with the old branch name.

@D4N14L
Copy link
Member Author

D4N14L commented Sep 25, 2023

Superseded by #4353

@D4N14L D4N14L closed this Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants