⚡ Sangsakala Proxy 🏠 Home
Skip to content

Update the ESLint section to flat config (eslint.config.js) - #3995

Open
1t1sCooL wants to merge 1 commit into
javascript-tutorial:masterfrom
1t1sCooL:coding-style-eslint-flat-config
Open

1t1sCooL wants to merge 1 commit into
javascript-tutorial:masterfrom
1t1sCooL:coding-style-eslint-flat-config

Conversation

@1t1sCooL

Copy link
Copy Markdown

The "Code style" chapter tells the reader to create an .eslintrc file. That format is no longer the way ESLint is configured: flat config (eslint.config.js) has been the default since ESLint 9, and .eslintrc support was removed in ESLint 10, so following the chapter today leaves beginners with a config that ESLint ignores.

This updates that part of the section:

  • install ESLint into the project (npm install --save-dev eslint) instead of globally, and mention npm init @eslint/config@latest, which generates the config;
  • replace the .eslintrc example with an equivalent eslint.config.js one (same idea: start from the recommended rules, declare browser/node globals, then override a couple of rules);
  • point the installation link at the current page, https://eslint.org/docs/latest/use/getting-started (the old docs/user-guide/getting-started URL now redirects).

The wording and the structure of the section are otherwise untouched.

Reported for the Russian translation in javascript-tutorial/ru.javascript.info#2187; fixing it here first so the change is not overwritten by the next upstream sync.

@AKzar1el AKzar1el left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two concrete setup pitfalls in the new ESLint flat-config instructions, noted inline. This is a source/documentation review; I did not run ESLint or the repository's tests.

1. Install [Node.js](https://nodejs.org/).
2. Install ESLint with the command `npm install -g eslint` (npm is a JavaScript package installer).
3. Create a config file named `.eslintrc` in the root of your JavaScript project (in the folder that contains all your files).
2. Install ESLint in your project with the command `npm install --save-dev eslint` (npm is a JavaScript package installer).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The manual install command only declares eslint, but the sample at lines 322–323 imports @eslint/js and globals. Those should be explicit project dev dependencies rather than depending on how transitive packages happen to be hoisted. Could this step say npm install --save-dev eslint @eslint/js globals (and mention npm init -y first if there is no package.json)? ESLint's manual setup explicitly installs @eslint/js. The npm init @eslint/config@latest generator is an alternative path, but readers copying the manual example otherwise lack the declared dependencies.

4. Install/enable the plugin for your editor that integrates with ESLint. The majority of editors have one.

Here's an example of an `.eslintrc` file:
Here's an example of an `eslint.config.js` file:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example uses ESM import/export in eslint.config.js. That file will not parse as an ES module in an existing project with "type": "commonjs" in package.json. Could the tutorial use eslint.config.mjs for the ESM example, or explain that eslint.config.js needs an ESM project (and that CommonJS projects can use require/module.exports)? ESLint documents this distinction in Configuration Files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review needed Review needed, please approve or request changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants