eslint / eslint

Find and fix problems in your JavaScript code.
https://eslint.org
MIT License
24.39k stars 4.4k forks source link

Init wizard not generating flat config #18369

Closed elygeo closed 3 weeks ago

elygeo commented 4 weeks ago

Environment

Node version: v21.7.3 npm version: 10.5.2 Global ESLint version: v9.1.0 Operating System: MacOS

What parser are you using?

Default (Espree)

What did you do?

npm init @eslint/config

What did you expect to happen?

Generate eslint.config.js

What actually happened?

Generate .eslintrc.js

egorFiNE commented 3 weeks ago

Same here and it's 100% repeatable.

I have read docs through and through to try to figure out who's wrong here but no matter how I read the docs, I only get .eslintrc.js generated. They have released 9.1.0 and had docs updated regarding filename (#18298) but it's still false.

  1. Create empty folder.
  2. Run npm init, default values for everything
  3. Run npm init @eslint/config, answer as follows:
✔ 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 
✔ Where does your code run? · browser
✔ How would you like to define a style for your project? · prompt
✔ What format do you want your config file to be in? · JavaScript
✔ What style of indentation do you use? · tab
✔ What quotes do you use for strings? · double
✔ What line endings do you use? · unix
✔ Do you require semicolons? · Yes
Local ESLint installation not found.
The config that you've selected requires the following dependencies:

eslint@latest
✔ Would you like to install them now? · Yes
✔ Which package manager do you want to use? · npm
Installing eslint@latest

added 89 packages, and audited 90 packages in 2s

22 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Expected result: generated eslint.config.js.

Actual result:

A config file was generated, but the config file itself may not follow your linting rules.
Successfully created .eslintrc.js file in /Users/egor/workspace/www

Additional information: selecting predefined code style instead of answering questions leads to even more errors as two of the predefined styles and outright incompatible with 9.x. Still a .eslintrc.js is generated.

aladdin-add commented 3 weeks ago

it's mostly a caching issue. can you try npm init @eslint/config@latest?

krichter722 commented 3 weeks ago

fyi, this also happens when using yarn run eslint --init when only eslint 9.1.0 is installed. Since this is the only way to run the init routine with yarn afaik it's probably necessary to fix something in eslint.

egorFiNE commented 3 weeks ago

npm init @eslint/config@latest?

It is "fixed" now by breaking the "Where does your code run?" prompt in a way that prevents further execution of the script. I have opened eslint/create-config#104.

elygeo commented 3 weeks ago

it's mostly a caching issue. can you try npm init @eslint/config@latest?

Somewhat better for generating flat config, but still broken.

Accepting the defaults install the old version as well, and is pick-up by the CLI:

$ npx eslint --version v8.57.0

nzakas commented 3 weeks ago

To summarize what's probably going on here: npx aggressively caches dependencies, so if you ever ran --init before, it's probably still using that old version. We should always be using the latest version inside of ESLint, so we can fix that.

fyi, this also happens when using yarn run eslint --init when only eslint 9.1.0 is installed. Since this is the only way to run the init routine with yarn afaik it's probably necessary to fix something in eslint.

@krichter722 I believe you can use yarn create @eslint/config@latest.

it's mostly a caching issue. can you try npm init @eslint/config@latest?

Somewhat better for generating flat config, but still broken.

Accepting the defaults install the old version as well, and is pick-up by the CLI:

$ npx eslint --version v8.57.0

@elygeo we need to see what you're seeing and any reproduction steps. "still broken" doesn't give us any useful information.

elygeo commented 3 weeks ago

It seems there are two issues. The issue of using a cached version of create-config is avoided by "latest":

npm init @eslint/config@latest

The second issue is that create-config installs two versions of eslint, and the CLI seems to favor the old version as far as I can tell. Noted here https://github.com/eslint/eslint/discussions/18361 https://github.com/eslint/create-config/issues/106. This is why I filed a separate issue. Perhaps a duplicate as you say, I don't know.

Reproduction steps:

$ npm init @eslint/config@latest $ npx eslint --version

Result:

v8.57.0

package.json now contains:

  "devDependencies": {
    "@eslint/js": "^9.1.1",
    "eslint": "^8.57.0",
    "eslint-plugin-react": "^7.34.1",
    "globals": "^15.0.0"
  }

Expected result:

v9.1.1

nzakas commented 3 weeks ago

Got it, I agree this seems like two different issues. I'll reopen eslint/create-config#106

egorFiNE commented 1 week ago

Still failing. I have opened #114 for it.