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

Bug: ESLint API cannot find eslint-recommended.js #15575

Closed
1 task
daidodo opened this issue Feb 4, 2022 · 7 comments · Fixed by eslint/eslintrc#71 or #15616
Closed
1 task

Bug: ESLint API cannot find eslint-recommended.js #15575

daidodo opened this issue Feb 4, 2022 · 7 comments · Fixed by eslint/eslintrc#71 or #15616
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly repro:needed
Projects

Comments

@daidodo
Copy link
Contributor

daidodo commented Feb 4, 2022

Environment

Node version: v16.10.0
npm version: 7.24.0
Local ESLint version: 8.8.0
Global ESLint version: N/A
Operating System: macOS Big Sur

What parser are you using?

Default (Espree)

What did you do?

To reproduce the issue:

  • git clone https://github.com/daidodo/eslint-api-issue.git
  • cd eslint-api-issue && npm i && npx webpack
  • node dist/main.js src/index.ts

What did you expect to happen?

I expect the output is the ESLint resolved config for the given file.
If you run npx tsc && node dist/main.js src/index.ts, you can get:

ESLint version: 8.8.0
eslint object: ESLint {}
Resolving ESLint config:
{
  env: {},
  globals: {},
  noInlineConfig: undefined,
  parser: null,
  parserOptions: {},
  plugins: [],
  reportUnusedDisableDirectives: undefined,
  rules: {
    'no-unused-vars': [ 'warn', [Object] ],
    'constructor-super': [ 'error' ],
    'for-direction': [ 'error' ],
    'getter-return': [ 'error' ],
    'no-async-promise-executor': [ 'error' ],
    'no-case-declarations': [ 'error' ],
    'no-class-assign': [ 'error' ],
    'no-compare-neg-zero': [ 'error' ],
    'no-cond-assign': [ 'error' ],
    'no-const-assign': [ 'error' ],
    'no-constant-condition': [ 'error' ],
    'no-control-regex': [ 'error' ],
    'no-debugger': [ 'error' ],
    'no-delete-var': [ 'error' ],
    'no-dupe-args': [ 'error' ],
    'no-dupe-class-members': [ 'error' ],
    'no-dupe-else-if': [ 'error' ],
    'no-dupe-keys': [ 'error' ],
    'no-duplicate-case': [ 'error' ],
    'no-empty': [ 'error' ],
    'no-empty-character-class': [ 'error' ],
    'no-empty-pattern': [ 'error' ],
    'no-ex-assign': [ 'error' ],
    'no-extra-boolean-cast': [ 'error' ],
    'no-extra-semi': [ 'error' ],
    'no-fallthrough': [ 'error' ],
    'no-func-assign': [ 'error' ],
    'no-global-assign': [ 'error' ],
    'no-import-assign': [ 'error' ],
    'no-inner-declarations': [ 'error' ],
    'no-invalid-regexp': [ 'error' ],
    'no-irregular-whitespace': [ 'error' ],
    'no-loss-of-precision': [ 'error' ],
    'no-misleading-character-class': [ 'error' ],
    'no-mixed-spaces-and-tabs': [ 'error' ],
    'no-new-symbol': [ 'error' ],
    'no-nonoctal-decimal-escape': [ 'error' ],
    'no-obj-calls': [ 'error' ],
    'no-octal': [ 'error' ],
    'no-prototype-builtins': [ 'error' ],
    'no-redeclare': [ 'error' ],
    'no-regex-spaces': [ 'error' ],
    'no-self-assign': [ 'error' ],
    'no-setter-return': [ 'error' ],
    'no-shadow-restricted-names': [ 'error' ],
    'no-sparse-arrays': [ 'error' ],
    'no-this-before-super': [ 'error' ],
    'no-undef': [ 'error' ],
    'no-unexpected-multiline': [ 'error' ],
    'no-unreachable': [ 'error' ],
    'no-unsafe-finally': [ 'error' ],
    'no-unsafe-negation': [ 'error' ],
    'no-unsafe-optional-chaining': [ 'error' ],
    'no-unused-labels': [ 'error' ],
    'no-useless-backreference': [ 'error' ],
    'no-useless-catch': [ 'error' ],
    'no-useless-escape': [ 'error' ],
    'no-with': [ 'error' ],
    'require-yield': [ 'error' ],
    'use-isnan': [ 'error' ],
    'valid-typeof': [ 'error' ]
  },
  settings: {},
  ignorePatterns: [ '**/xxx.js' ]
}

What actually happened?

If webpacked, the output would be:

ESLint version: 8.8.0
eslint object: ESLint {}

Error: Cannot read config file: /Users/xxx/Desktop/private/projects/conf/eslint-recommended.js
Error: Cannot find module '/Users/xxx/Desktop/private/projects/conf/eslint-recommended.js'
Require stack:
- /Users/xxx/Desktop/private/projects/eslint-api-issue/dist/noop.js
Referenced from: /Users/xxx/Desktop/private/projects/eslint-api-issue/package.json

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

I've submitted a similar issue (#13974) but got aged.
My guess is the __dirname in lib/cli-engine/cli-engine.js causes the issue. But I don't have enough context to confirm or fix it.

Thanks!

@daidodo daidodo added bug ESLint is working incorrectly repro:needed labels Feb 4, 2022
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Feb 4, 2022
@nzakas
Copy link
Member

nzakas commented Feb 5, 2022

As we discussed in the original issue, ESLint isn’t designed to be bundled with Webpack, so this isn’t something the team can prioritize. If you want to experiment with fixing the problem and submit a pull request, we can review it.

@nzakas nzakas moved this from Needs Triage to Triaging in Triage Feb 5, 2022
@daidodo
Copy link
Contributor Author

daidodo commented Feb 5, 2022

@nzakas, thanks for the response!

Could you share your thoughts about how it should be fixed?
I'm new to internal of ESLint so any guidance would help.

@daidodo
Copy link
Contributor Author

daidodo commented Feb 7, 2022

I've dived a bit and found this function which loads config extends.
I think one solution is to cache the internal extend objects (eslint:recommended and eslint:all) instead of their file paths. Both ways the CLI (e.g. eslint) will get the same result.
What do you think? Thanks!

@nzakas
Copy link
Member

nzakas commented Feb 8, 2022

The problem is that all config data is loaded via filepaths, so we can’t just swap in an object without changing a lot of the complex plumbing of the config cascade.

@daidodo
Copy link
Contributor Author

daidodo commented Feb 8, 2022

Correct me if I'm wrong.

There are two parts of the changes:

  1. Setting extend objects to the cache. That can be done by changing all the places that extend file paths are set. At a glance, those places are:
  2. Changing the way extend config is calculated. That's to update _loadExtendedBuiltInConfig as follow:
    // ...
        if (extendName === "eslint:recommended") {
            return this._normalizeConfigData(this.eslintRecommendedConfig, {
                ...ctx,
                name: `${ctx.name} » ${extendName}`
            });
        }
    // ...

Plus there are changes to class ConfigArrayFactory constructor, of course.

Do you think if it would work? Thanks!

@nzakas
Copy link
Member

nzakas commented Feb 10, 2022

I don’t know. Why don’t you try it and see what happens?

daidodo pushed a commit to daidodo/eslintrc that referenced this issue Feb 13, 2022
Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint/eslint#15575
daidodo pushed a commit to daidodo/eslint that referenced this issue Feb 13, 2022
Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint#15575
daidodo pushed a commit to daidodo/eslintrc that referenced this issue Feb 16, 2022
Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint/eslint#15575
daidodo pushed a commit to daidodo/eslint that referenced this issue Feb 16, 2022
Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint#15575
daidodo pushed a commit to daidodo/eslintrc that referenced this issue Feb 16, 2022
Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint/eslint#15575
daidodo added a commit to daidodo/eslintrc that referenced this issue Feb 16, 2022
Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint/eslint#15575
daidodo added a commit to daidodo/eslint that referenced this issue Feb 16, 2022
Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint#15575
daidodo added a commit to daidodo/eslintrc that referenced this issue Feb 17, 2022
Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint/eslint#15575
daidodo added a commit to daidodo/eslintrc that referenced this issue Feb 18, 2022
Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint/eslint#15575
daidodo added a commit to daidodo/eslintrc that referenced this issue Feb 18, 2022
Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint/eslint#15575
@nzakas nzakas moved this from Triaging to Pull Request Opened in Triage Feb 19, 2022
mdjermanovic pushed a commit to mdjermanovic/eslint that referenced this issue Feb 25, 2022
Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint#15575
Triage automation moved this from Pull Request Opened to Complete Feb 25, 2022
mdjermanovic pushed a commit to eslint/eslintrc that referenced this issue Feb 25, 2022
Load eslint:recommended and eslint:all configs via import instead file paths.

Refs eslint/eslint#15575
@mdjermanovic
Copy link
Member

Reopening as this isn't fixed until #15616 gets merged.

@mdjermanovic mdjermanovic reopened this Feb 25, 2022
Triage automation moved this from Complete to Evaluating Feb 25, 2022
Triage automation moved this from Evaluating to Complete Feb 25, 2022
mdjermanovic pushed a commit that referenced this issue Feb 25, 2022
Load eslint:recommended and eslint:all configs via require instead file paths.

Fixes: #15575
srijan-deepsource pushed a commit to DeepSourceCorp/eslint that referenced this issue May 30, 2022
Load eslint:recommended and eslint:all configs via require instead file paths.

Fixes: eslint#15575
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Aug 25, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Aug 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly repro:needed
Projects
Archived in project
Triage
Complete
3 participants