node icon indicating copy to clipboard operation
node copied to clipboard

tools: migrate to ESLint flat config and update ESLint to v9.2.0

Open targos opened this issue 10 months ago • 28 comments

Closes: https://github.com/nodejs/node/issues/52567

Not completely ready. I have to double check some things because there are reported errors.

I'm opening the PR to ask a question: For now, I put the entire config in one file. I would like to split it into multiple files to make it more readable but I'm not sure what approach to take. My current idea is to create a new folder, probably somewhere in tools.

targos avatar May 01 '24 15:05 targos

Review requested:

  • [ ] @nodejs/web-standards

nodejs-github-bot avatar May 01 '24 15:05 nodejs-github-bot

@nodejs/linting

targos avatar May 02 '24 06:05 targos

For now, I put the entire config in one file. I would like to split it into multiple files to make it more readable but I'm not sure what approach to take. My current idea is to create a new folder, probably somewhere in tools.

To me, the most obvious choice would be to have them in each directory (e.g. lib/eslint.config.mjs, test/eslint.config.mjs)

aduh95 avatar May 02 '24 08:05 aduh95

For now, I put the entire config in one file. I would like to split it into multiple files to make it more readable but I'm not sure what approach to take. My current idea is to create a new folder, probably somewhere in tools.

To me, the most obvious choice would be to have them in each directory (e.g. lib/eslint.config.mjs, test/eslint.config.mjs)

I think this would be confusing, because they would not be ESLint config files, just partials for the real config, and it would make people think they work like the old config system.

targos avatar May 02 '24 08:05 targos

Maybe we can use an non-confusing name, lib/eslint.partialconfig.mjs or whatnot.

aduh95 avatar May 02 '24 08:05 aduh95

SGTM. I'll wait a few days to see if there are other suggestions.

targos avatar May 02 '24 08:05 targos

Done! I went with eslint.config_partial.mjs so I could colocate it with eslint.config_utils.mjs in tools.

targos avatar May 06 '24 10:05 targos

Looks like lib/eslint.config_partial.mjs is picked up by js2c.cc. Not sure what's the best way to ignore it. /cc @joyeecheung

targos avatar May 06 '24 10:05 targos

@targos Can we also enable indentation rule for "Makefile" file?

anonrig avatar May 06 '24 23:05 anonrig

You can hard-code to exclude it from the JS2C like this:

diff --git a/tools/js2c.cc b/tools/js2c.cc
index e0f3d88447..a536b5dcd8 100644
--- a/tools/js2c.cc
+++ b/tools/js2c.cc
@@ -928,6 +928,13 @@ int Main(int argc, char* argv[]) {
   auto mjs_it = file_map.find(".mjs");
   assert(js_it != file_map.end() && mjs_it != file_map.end());

+  auto it = std::find(mjs_it->second.begin(),
+                      mjs_it->second.end(),
+                      "lib/eslint.config_partial.mjs");
+  if (it != mjs_it->second.end()) {
+    mjs_it->second.erase(it);
+  }
+
   std::sort(js_it->second.begin(), js_it->second.end());
   std::sort(mjs_it->second.begin(), mjs_it->second.end());

(Or make it more flexible as another vector to ignore, or make it an argument, or prefix it with a dot and ignore all files beginning with a dot in SearchFiles, if you want)

joyeecheung avatar May 07 '24 02:05 joyeecheung

If you want to ignore all files beginning with a dot, probably just do this (not sure if we have any files starting with a dot that we actually want to include in the binary, I am guessing we don't):

diff --git a/tools/js2c.cc b/tools/js2c.cc
index e0f3d88447..d94fd33a0d 100644
--- a/tools/js2c.cc
+++ b/tools/js2c.cc
@@ -123,6 +123,10 @@ bool SearchFiles(const std::string& dir,
         break;
       }

+      if (StartsWith(dent.name, ".")) {
+        continue;
+      }
+
       std::string path = dir + '/' + dent.name;
       if (EndsWith(path, extension)) {
         files.emplace_back(path);

joyeecheung avatar May 07 '24 02:05 joyeecheung

@targos Can we also enable indentation rule for "Makefile" file?

@anonrig Maybe, but it doesn't seem related to what I'm doing here?

targos avatar May 07 '24 15:05 targos

This is ready for reviews.

targos avatar May 08 '24 04:05 targos

CI: https://ci.nodejs.org/job/node-test-pull-request/59027/

nodejs-github-bot avatar May 08 '24 07:05 nodejs-github-bot

09:25:44 Running JS linter...
09:25:46 
09:25:46 Oops! Something went wrong! :(
09:25:46 
09:25:46 ESLint: 8.57.0
09:25:46 
09:25:46 Error: EMFILE: too many open files, open '/home/iojs/build/workspace/node-test-linter/test/parallel/test-timers-immediate-unref-nested-once.js'

🤔

targos avatar May 08 '24 07:05 targos

Also worth running on a windows machine before landing

MoLow avatar May 08 '24 08:05 MoLow

I developed it on Windows.

targos avatar May 08 '24 08:05 targos

Note that .\vcbuild.bat lint-js is already broken on Windows on the main branch because of this file: https://github.com/nodejs/node/blob/main/tools/node_modules/eslint/node_modules/eslint

targos avatar May 08 '24 08:05 targos

Proof it works after deleting the symlink:

PS D:\Git\nodejs\node> .\vcbuild.bat lint-js nobuild noprojgen
Looking for Python
Python found in C:\Users\Targos\AppData\Local\Microsoft\WindowsApps\\python.exe
Python 3.12.3
Looking for NASM
Jonction créée pour Release <<===>> out\Release
running lint-js
PS D:\Git\nodejs\node>

targos avatar May 08 '24 08:05 targos

Retrying node-test-linter: https://ci.nodejs.org/job/node-test-linter/54555/

targos avatar May 08 '24 08:05 targos

It's probably https://github.com/eslint/eslint/issues/18301, only fixed in ESLint v9. I'll add the ESLint update to this PR.

targos avatar May 08 '24 09:05 targos

Blocked on https://github.com/nodejs/node/pull/52889

targos avatar May 08 '24 11:05 targos

Added the update to ESLint v9

targos avatar May 09 '24 17:05 targos

Triggered https://ci.nodejs.org/job/node-test-linter/54577/console and it failed :(

20:19:04 Running JS linter...
20:19:04 
20:19:04 Oops! Something went wrong! :(
20:19:04 
20:19:04 ESLint: 9.2.0
20:19:04 
20:19:04 ConfigError: Config (unnamed): Key "rules": Key "constructor-super": structuredClone is not defined
20:19:04     at rethrowConfigError (/home/iojs/build/workspace/node-test-linter/tools/node_modules/eslint/node_modules/@humanwhocodes/config-array/api.js:230:8)
20:19:04     at /home/iojs/build/workspace/node-test-linter/tools/node_modules/eslint/node_modules/@humanwhocodes/config-array/api.js:1032:5
20:19:04     at Array.reduce (<anonymous>)
20:19:04     at FlatConfigArray.getConfig (/home/iojs/build/workspace/node-test-linter/tools/node_modules/eslint/node_modules/@humanwhocodes/config-array/api.js:1028:39)
20:19:04     at FlatConfigArray.isFileIgnored (/home/iojs/build/workspace/node-test-linter/tools/node_modules/eslint/node_modules/@humanwhocodes/config-array/api.js:1060:15)
20:19:04     at /home/iojs/build/workspace/node-test-linter/tools/node_modules/eslint/lib/eslint/eslint-helpers.js:548:38
20:19:04     at Array.forEach (<anonymous>)
20:19:04     at findFiles (/home/iojs/build/workspace/node-test-linter/tools/node_modules/eslint/lib/eslint/eslint-helpers.js:537:11)
20:19:04     at async ESLint.lintFiles (/home/iojs/build/workspace/node-test-linter/tools/node_modules/eslint/lib/eslint/eslint.js:847:27)
20:19:04     at async Object.execute (/home/iojs/build/workspace/node-test-linter/tools/node_modules/eslint/lib/cli.js:500:23)

MoLow avatar May 09 '24 17:05 MoLow

It must be running a very old version of node !

targos avatar May 09 '24 21:05 targos

19:19:01 + node --version
19:19:01 v16.20.2

targos avatar May 09 '24 22:05 targos

19:19:01 + node --version
19:19:01 v16.20.2

FYI https://github.com/nodejs/build/blob/102f630f31a33cf9762e98bfd10da416d472010c/ansible/roles/jenkins-workspace/tasks/main.yml#L131-L134

richardlau avatar May 09 '24 22:05 richardlau

We need to upgrade the host. Node.js 18+ can't run on Ubuntu 18.

Opened https://github.com/nodejs/build/issues/3713

targos avatar May 10 '24 05:05 targos

Rebased, reworded the first commit so the PR can be squashed, and separated additional fixes from the ESLint update to ease reviews.

(this is still blocked on updates of the build machines)

targos avatar May 10 '24 21:05 targos

Unblocked now that https://github.com/nodejs/node/pull/53070 landed and linter CI workers have Node.js 20 installed.

targos avatar May 22 '24 05:05 targos