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 сreates a non-working installation #93

Closed
1 task
Psychosynthesis opened this issue Apr 10, 2024 · 9 comments
Closed
1 task
Labels
bug Something isn't working repro:needed

Comments

@Psychosynthesis
Copy link

Psychosynthesis commented Apr 10, 2024

Environment

Node version: v18.19.1
npm version: v10.5.1
Local ESLint version: 8.57.0
Global ESLint version: --
Operating System: Ubuntu 23.10

What parser are you using?

Default (Espree)

What did you do?

First of all, I want to note that for some reason npm init @eslint/config is installing version 8 of ESLint, not 9, although my version of the Node is supported, according to your guide ("Node.js < v18.18, v19 are no longer supported").

But that’s okay (i really don’t care what to use, 8th or 9th, linter of any version is ****, but unfortunately this is my company’s choice). What's worse is that config command creates a non-working eslint.config.js:

Configuration

import globals from "globals";
import tseslint from "typescript-eslint";
import pluginReactConfig from "eslint-plugin-react/configs/recommended.js";

import path from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";
import pluginJs from "@eslint/js";

// mimic CommonJS variables -- not needed if using CommonJS
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended});

export default [
  {languageOptions: { globals: globals.browser }},
  ...compat.extends("standard-with-typescript"),
  ...tseslint.configs.recommended,
  pluginReactConfig,
];

If we try to run npx lint we get the following error:

Error: Key "plugins": Cannot redefine plugin "@typescript-eslint".

Okay it's look like tseslint.configs.recommended is redefine some fields of compat.extends("standard-with-typescript")... But if we just comment one of these rules, still nothing works, the linter just exits without messages.

What did you expect to happen?

I would like the linter to work after the config, and the guides to have correct, up-to-date information

What actually happened?

Linter doesn't work, and the guides are a mess

Link to Minimal Reproducible Example

https://eslint.org/play/#eyJ0ZXh0IjoiaW1wb3J0IGdsb2JhbHMgZ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m8tdXNlbGVzcy1iYWNrcmVmZXJlbmNlIjpbImVycm9yIl0sIm5vLXVzZWxlc3MtY2F0Y2giOlsiZXJyb3IiXSwibm8tdXNlbGVzcy1lc2NhcGUiOlsiZXJyb3IiXSwibm8td2l0aCI6WyJlcnJvciJdLCJyZXF1aXJlLXlpZWxkIjpbImVycm9yIl0sInVzZS1pc25hbiI6WyJlcnJvciJdLCJ2YWxpZC10eXBlb2YiOlsiZXJyb3IiXX0sImxhbmd1YWdlT3B0aW9ucyI6eyJwYXJzZXJPcHRpb25zIjp7ImVjbWFGZWF0dXJlcyI6e319fX19

Participation

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

Additional comments

Why is there no detail in the guide on how to configure the config after npm init @eslint/config? User's have to figure it out for themselfs?

Well, why it was need to update the version until everything was tested? Are you in a hurry somewhere?

@Psychosynthesis Psychosynthesis added bug Something isn't working repro:needed labels Apr 10, 2024
@WhisperingWhite
Copy link

WhisperingWhite commented Apr 10, 2024

Hi, I have the same proglem. Do you know how to fix it. And something more. eslint creates .mjs file for me. and it cannot be even detected. i change the suffix to .js and then have this error.

@aladdin-add
Copy link
Member

seems eslint-config-standard-with-typescript has not been upgraded to the latest. I'll make a fix soon.

as of now, you can use:

$ npm init @eslint/config -- --eslintrc  --config eslint-config-standard-with-typescript

@Psychosynthesis
Copy link
Author

@aladdin-add ok, now my config looklike:

const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended});

export default [
  ...compat.extends("standard-with-typescript"),
];

How to customize these rules?

@Psychosynthesis
Copy link
Author

In fact, I had to add another “files” field:

export default [
  {
    files: [ 'src/**.tsx' ]
  },
  ...compat.extends("standard-with-typescript"),
];

and run the linter as follows:
npx eslint 'src/**/*.{ts,tsx}' --no-ignore

Otherwise he didn't check anything...

@aladdin-add
Copy link
Member

export default [
  ...(compat.extends("standard-with-typescript").map(config => ({files: ["**/*.tsx"], ...config}))),
];

@aladdin-add aladdin-add transferred this issue from eslint/eslint Apr 10, 2024
aladdin-add added a commit that referenced this issue Apr 10, 2024
@Psychosynthesis
Copy link
Author

Ok, seems like it work for me, thank's

@jeffrson
Copy link

seems eslint-config-standard-with-typescript has not been upgraded to the latest. I'll make a fix soon.

as of now, you can use:

$ npm init @eslint/config -- --eslintrc  --config eslint-config-standard-with-typescript

This is installing eslint ^8.0.1 - is this intentional?

❯ npm init @eslint/config -- --eslintrc  --config eslint-config-standard-with-typescript
The config that you've selected requires the following dependencies:

eslint, eslint-config-standard-with-typescript, @typescript-eslint/eslint-plugin@^6.4.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@*, @eslint/eslintrc, @eslint/js

@aladdin-add
Copy link
Member

This is the strategy of the package manager: some of these dependencies require eslint v8, and do not support eslint v9 yet.

@aladdin-add
Copy link
Member

https://github.com/mightyiam/eslint-config-love/blob/8d8d17aa836b48772ff14e95f7401e76718649ae/package.json#L57

and seems the package has been deprecated, related #95

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

4 participants