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

Getting Started guide causes ESLint complaints in .eslintrc.(c)js #6825

Closed
2 tasks done
JoshuaKGoldberg opened this issue Apr 2, 2023 · 2 comments · Fixed by #6918
Closed
2 tasks done

Getting Started guide causes ESLint complaints in .eslintrc.(c)js #6825

JoshuaKGoldberg opened this issue Apr 2, 2023 · 2 comments · Fixed by #6918
Assignees
Labels
accepting prs Go ahead, send a pull request that resolves this issue documentation Documentation ("docs") that needs adding/updating

Comments

@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Apr 2, 2023

Before You File a Documentation Request Please Confirm You Have Done The Following...

Suggested Changes

When starting a TypeScript repository from scratch using our docs, we tell folks to use this as their .eslintrc.cjs config:

module.exports = {
  extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint'],
  root: true,
};

However, that results in an ESLint error on the .eslintrc.cjs file when viewed in VS Code!

'module' is not defined. eslint [no-undef](https://eslint.org/docs/rules/no-undef)

Screenshot of the above lint error in VS Code

This is confusing. We should fix the code and/or docs so that our first run experience doesn't include ESLint errors for problems that don't exist. I'm not sure what the correct solution is, though. A few options:

  • Use env: { node: true } for specifically this file or files like it?
  • Explicitly disable the rule
  • Don't change the config, and add a warning to the docs

...I don't love any of those 🤔. How are users "supposed" to fix this?

(using the flat config system is not a viable solution yet, as flat configs are still considered experimental)

This issue came out of a Twitch stream with @Jutanium. 👋

Affected URL(s)

https://typescript-eslint.io/getting-started

@JoshuaKGoldberg JoshuaKGoldberg added triage Waiting for maintainers to take a look documentation Documentation ("docs") that needs adding/updating labels Apr 2, 2023
@armano2
Copy link
Member

armano2 commented Apr 2, 2023

to be precise you actually want to enable eaither /* eslint-env commonjs */ or /* eslint-env node */

this is described in https://eslint.org/docs/latest/use/configure/language-options


in teory we could add override to config that enables it for cjs and cts, but i don't think this is a good idea


node - Node.js global variables and Node.js scoping.
commonjs - CommonJS global variables and CommonJS scoping (use this for browser-only code that uses Browserify/WebPack).

@JoshuaKGoldberg
Copy link
Member Author

Related: eslint/create-config#59

@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Apr 16, 2023
@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Apr 16, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue documentation Documentation ("docs") that needs adding/updating
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants