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: npm init @eslint/config with "Standard" style generates incorrect setup #71

Closed
1 task
OnkelTem opened this issue Aug 20, 2023 · 8 comments
Closed
1 task
Labels
bug Something isn't working repro:needed

Comments

@OnkelTem
Copy link

OnkelTem commented Aug 20, 2023

Environment

Node version: 16.17
npm version: 8.15
Local ESLint version: 8.47
Global ESLint version:
Operating System: Linux Ubuntu 22.04

What parser are you using?

Default (Espree)

What did you do?

I'm running the configuration wizard like this:

npm init @eslint/config
✔ How would you like to use ESLint? · style
✔ What type of modules does your project use? · esm
✔ Which framework does your project use? · none
✔ Does your project use TypeScript? · No / Yes
✔ Where does your code run? · browser
✔ How would you like to define a style for your project? · guide
✔ Which style guide do you want to follow? · standard-with-typescript
✔ What format do you want your config file to be in? · JavaScript
Checking peerDependencies of eslint-config-standard-with-typescript@latest
Local ESLint installation not found.
The config that you've selected requires the following dependencies:

eslint-config-standard-with-typescript@latest @typescript-eslint/eslint-plugin@^5.52.0 eslint@^8.0.1 eslint-plugin-import@^2.25.2 eslint-plugin-n@^15.0.0 || ^16.0.0  eslint-plugin-promise@^6.0.0 typescript@*
✔ Would you like to install them now? · No / Yes
✔ Which package manager do you want to use? · npm
Installing eslint-config-standard-with-typescript@latest, @typescript-eslint/eslint-plugin@^5.52.0, eslint@^8.0.1, eslint-plugin-import@^2.25.2, eslint-plugin-n@^15.0.0 || ^16.0.0 , eslint-plugin-promise@^6.0.0, typescript@*

That results to this configuration file:

module.exports = {
  env: {
    browser: true,
    es2021: true,
  },
  extends: ['standard-with-typescript', 'plugin:react/recommended'],
  overrides: [
    {
      env: {
        node: true,
      },
      files: ['.eslintrc.{js,cjs}'],
      parserOptions: {
        sourceType: 'script',
      },
    },
  ],
  parserOptions: {
    ecmaVersion: 'latest',
    sourceType: 'module',
  },
  plugins: ['react'],
  rules: {},
};

As you can see, @typescript-eslint/parser was not installed during the setup process. This looks a little suspicious, taking into account, that other typescript-including wizard paths end up with @typescript-eslint/parser installed and mentioned in the config.

What did you expect to happen?

Working linting

What actually happened?

After it finishes, running eslint results to this error:

$ $npx eslint './src/**/*.ts'

Oops! Something went wrong! :(

ESLint: 8.47.0

Error: Error while loading rule '@typescript-eslint/dot-notation': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
Occurred while linting /projects/custom/eslint/tts/src/index.ts
    at getParserServices (/projects/custom/eslint/tts/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:22:15)
    at create (/projects/custom/eslint/tts/node_modules/@typescript-eslint/eslint-plugin/dist/rules/dot-notation.js:85:81)
    at Object.create (/projects/custom/eslint/tts/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:41:20)
    at createRuleListeners (/projects/custom/eslint/tts/node_modules/eslint/lib/linter/linter.js:870:21)
    at /projects/custom/eslint/tts/node_modules/eslint/lib/linter/linter.js:1040:110
    at Array.forEach (<anonymous>)
    at runRules (/projects/custom/eslint/tts/node_modules/eslint/lib/linter/linter.js:977:34)
    at Linter._verifyWithoutProcessors (/projects/custom/eslint/tts/node_modules/eslint/lib/linter/linter.js:1330:31)
    at Linter._verifyWithConfigArray (/projects/custom/eslint/tts/node_modules/eslint/lib/linter/linter.js:1706:21)
    at Linter.verify (/projects/custom/eslint/tts/node_modules/eslint/lib/linter/linter.js:1412:65)

Link to Minimal Reproducible Example

none

Participation

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

Additional comments

No response

@OnkelTem
Copy link
Author

OnkelTem commented Aug 20, 2023

Before creating this ticket, I created a similar issue in the eslint-config-standard-with-typescript repository, assuming that its maintainers would know better what to do. And in fact, this is how to fix the problem:

image

which is covered in the docs here: https://typescript-eslint.io/linting/typed-linting/

I believe that the rule @typescript-eslint/dot-notation makes this error trigger.

I'm not familiar with the internals of configuration wizard so I'm not ready to provide a PR now.

Also, I find it doubtful to not see the proper parser value in the user config.

@mdjermanovic mdjermanovic transferred this issue from eslint/eslint Aug 20, 2023
@mdjermanovic
Copy link
Member

Transferred to the eslint/create-config repo.

@mdjermanovic
Copy link
Member

As you can see, @typescript-eslint/parser was not installed during the setup process. This looks a little suspicious, taking into account, that other typescript-including wizard paths end up with @typescript-eslint/parser installed and mentioned in the config.

@typescript-eslint/parser is installed as a dependency of eslint-config-standard-with-typescript. @eslint/config only asks about installing peer dependencies, because dependencies are automatically installed by package managers.

Also, I find it doubtful to not see the proper parser value in the user config.

When you choose a shareable config (a style guide), @eslint/config lets that config to specify parser as there may be different parsers for different file paths. In this case, parser is specified here.

@OnkelTem
Copy link
Author

OnkelTem commented Aug 20, 2023

Thanks @mdjermanovic, I see the reasoning. ESlint configs have always been tough tho :)

I've cloned the repo, investigating the issue now.

@mdjermanovic
Copy link
Member

What actually happened?

After it finishes, running eslint results to this error:

$ $npx eslint './src/**/*.ts'

Oops! Something went wrong! :(

ESLint: 8.47.0

Error: Error while loading rule '@typescript-eslint/dot-notation': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
Occurred while linting /projects/custom/eslint/tts/src/index.ts
    at getParserServices (/projects/custom/eslint/tts/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:22:15)
    at create (/projects/custom/eslint/tts/node_modules/@typescript-eslint/eslint-plugin/dist/rules/dot-notation.js:85:81)
    at Object.create (/projects/custom/eslint/tts/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:41:20)
    at createRuleListeners (/projects/custom/eslint/tts/node_modules/eslint/lib/linter/linter.js:870:21)
    at /projects/custom/eslint/tts/node_modules/eslint/lib/linter/linter.js:1040:110
    at Array.forEach (<anonymous>)
    at runRules (/projects/custom/eslint/tts/node_modules/eslint/lib/linter/linter.js:977:34)
    at Linter._verifyWithoutProcessors (/projects/custom/eslint/tts/node_modules/eslint/lib/linter/linter.js:1330:31)
    at Linter._verifyWithConfigArray (/projects/custom/eslint/tts/node_modules/eslint/lib/linter/linter.js:1706:21)
    at Linter.verify (/projects/custom/eslint/tts/node_modules/eslint/lib/linter/linter.js:1412:65)

Since eslint-config-standard-with-typescript enables type-aware rules, which require specifying parserOptions.project, given the advice on https://typescript-eslint.io/linting/typed-linting/, perhaps eslint-config-standard-with-typescript could specify parserOptions: { project: true } so that the config can work without requiring an additional setup?

@OnkelTem
Copy link
Author

@mdjermanovic #72

@mightyiam
Copy link

perhaps eslint-config-standard-with-typescript could specify parserOptions: { project: true } so that the config can work without requiring an additional setup?

That's brilliant.

mightyiam/eslint-config-love#1230

@mdjermanovic
Copy link
Member

Closing as this issue is going to be fixed in the eslint-config-standard-with-typescript package.

In the meantime, you'll need to add parserOptions.project in your config file manually.

@mdjermanovic mdjermanovic closed this as not planned Won't fix, can't repro, duplicate, stale Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working repro:needed
Projects
Archived in project
Development

No branches or pull requests

3 participants