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

Adding support for eslint.config.mjs and eslint.config.cjs files. #1707

Closed
yittoo opened this issue Sep 13, 2023 · 15 comments
Closed

Adding support for eslint.config.mjs and eslint.config.cjs files. #1707

yittoo opened this issue Sep 13, 2023 · 15 comments
Labels
info-needed Issue requires more information from poster

Comments

@yittoo
Copy link

yittoo commented Sep 13, 2023

I am not sure if it is something that you do want to do until FlatConfig is final. But for cases where we want to use eslint.config.mjs we are adding a workspace overwrite as follows. I think this could be extended in the extension source code.

"eslint.options": {
  "overrideConfigFile": "eslint.config.mjs"
}

I can help with the code adjustment if this feature is desired. Cheers.

@dbaeumer
Copy link
Member

How does that work when using ESLint on the command line?

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Sep 13, 2023
@yittoo
Copy link
Author

yittoo commented Sep 14, 2023

@dbaeumer with ESLINT_USE_FLAT_CONFIG=true eslint -c eslint.config.mjs cli flag

edit: also there is a workaround which is briefly mentioned here #1518 (comment)

@dbaeumer
Copy link
Member

Since this is a command line option you need to use eslint.options to point to a different config file than the default one. I am reluctant to add any code to detect and choose config files besides that standard behavior of eslint npm package.

I will close the issue since this is the expected behavior.

@itpropro
Copy link

itpropro commented Oct 7, 2023

@dbaeumer eslint.config.js is considered the new standard and the .eslint options as legacy reference. I would definitely see it as a bug in this VSCode extension, if the default way of writing eslint configs would not be detected by default. Especially as I have not worked on a JS/TS project for months that still used the legacy syntax.

@dbaeumer
Copy link
Member

dbaeumer commented Oct 9, 2023

The extension detects by default anything that the eslint npm module (https://www.npmjs.com/package/eslint) uses as default. I don't have any special code that detects the config file. This is why I said if you need to pass -c on the command line you need to let the extension know the same via eslint.options

@jamielaw-jellyfish
Copy link

I'm encountering a related issue.

Steps to reproduce:

Start a new blank project with the following package.json

{
  "scripts": {
    "lint": "eslint ."
  },
  "devDependencies": {
    "eslint": "^8.51.0"
  },
  "type": "module"
}

eslint.config.js

export default [
  {
    rules: {
      semi: "error",
    }
  }
];

and index.js

const foo = 42

VS Code gives no red underlines inside of index.js but running npm run lint will output the following errors in the console:

/Users/jamielaw/projects/linting/index.js
  1:15  error  Missing semicolon  semi

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

Switching eslint.config.js to the following .eslintrc.js

module.exports = {
  env: {
    es6: true
  },
  rules: {
    semi: 'error'
  }
};

and VS Code will highlight code errors automatically as expected. So, ESLint seems to understand the new config file format, but VS Code isn't picking it up.

@yittoo
Copy link
Author

yittoo commented Oct 9, 2023

@jamielaw-jellyfish If i am not mistaken this feature is experimental still (or perhaps recently moved to stable?). Maybe the following will help fix it.

.vscode/settings.json

{
  "eslint.experimental.useFlatConfig": true
}

@jamielaw-jellyfish
Copy link

@yittoo It did not work in this case, at least not for me.

However, just knowing that in time it will be available is good enough. For the time being, I will keep using the old config format, but keep an eye out for when support for the new format becomes publicly available. :-)

@dbaeumer
Copy link
Member

@jamielaw-jellyfish can you please provide me with a Github repository I can clone that demos this. This ensures we are looking at the same problem since things like this depend on many variables.

@jamielaw-jellyfish
Copy link

@dbaeumer
Copy link
Member

Could it be that you have something globally installed. Running npm run lint fails for me like this:

image

@jamielaw-jellyfish
Copy link

I realise the error I made in the repo: .eslint.config.js should not have a leading dot. Remove that and the command line should find the config file.

@dbaeumer
Copy link
Member

Works for me as expected in VS Code

image

Anything special in the ESLint otuput log?

@jamielaw-jellyfish
Copy link

So, I have been able to get it working, I think. Here was my process:

  1. I updated VS Code. I was on 1.83.0 before and now I am on 1.83.1
  2. I restarted the ESLInt Server. Without .vscode/settings.json I got errors in the ESLint output log that no config file could be found. Adding the file was enough to get it working.

So, I think the solution was to add the file, but also to restart ESLint and/or VS Code.

Sorry for taking you down this rabbit hole.

@dbaeumer
Copy link
Member

No problem. Happy to hear you could solve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

4 participants