From ab2021492bd9eb00bf005e012f6923b7413741cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 11 Jun 2024 08:58:51 +0200 Subject: [PATCH] tools: move ESLint tools to tools/eslint With ESLint flat config, we don't need a hack with `node_modules` anymore to load ESLint plugins. This commit moves the node-core plugin out of `tools/node_modules` and creates a new `tools/eslint` directory to store ESLint tools. PR-URL: https://github.com/nodejs/node/pull/53393 Reviewed-By: Moshe Atlow Reviewed-By: Luigi Pinca Reviewed-By: Chemi Atlow Reviewed-By: Yagiz Nizipli Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Marco Ippolito --- Makefile | 1 + benchmark/eslint.config_partial.mjs | 2 +- doc/eslint.config_partial.mjs | 2 +- eslint.config.mjs | 6 +++--- lib/eslint.config_partial.mjs | 2 +- test/eslint.config_partial.mjs | 2 +- .../index.js => eslint/eslint-plugin-node-core.js} | 2 +- tools/{ => eslint}/eslint.config_partial.mjs | 0 tools/{ => eslint}/eslint.config_utils.mjs | 2 +- 9 files changed, 10 insertions(+), 9 deletions(-) rename tools/{node_modules/eslint-plugin-node-core/index.js => eslint/eslint-plugin-node-core.js} (89%) rename tools/{ => eslint}/eslint.config_partial.mjs (100%) rename tools/{ => eslint}/eslint.config_utils.mjs (89%) diff --git a/Makefile b/Makefile index 20500d930e9208..df08a0415f1ce5 100644 --- a/Makefile +++ b/Makefile @@ -1188,6 +1188,7 @@ $(TARBALL): release-only doc-only $(RM) -r $(TARNAME)/doc/images # too big $(RM) -r $(TARNAME)/test*.tap $(RM) -r $(TARNAME)/tools/cpplint.py + $(RM) -r $(TARNAME)/tools/eslint $(RM) -r $(TARNAME)/tools/eslint-rules $(RM) -r $(TARNAME)/tools/license-builder.sh $(RM) -r $(TARNAME)/tools/node_modules diff --git a/benchmark/eslint.config_partial.mjs b/benchmark/eslint.config_partial.mjs index b980450add2006..174d8848c99a74 100644 --- a/benchmark/eslint.config_partial.mjs +++ b/benchmark/eslint.config_partial.mjs @@ -1,4 +1,4 @@ -import { requireEslintTool } from '../tools/eslint.config_utils.mjs'; +import { requireEslintTool } from '../tools/eslint/eslint.config_utils.mjs'; const globals = requireEslintTool('globals'); diff --git a/doc/eslint.config_partial.mjs b/doc/eslint.config_partial.mjs index bb195cbe539579..add5ab3d8d6ff0 100644 --- a/doc/eslint.config_partial.mjs +++ b/doc/eslint.config_partial.mjs @@ -1,4 +1,4 @@ -import { requireEslintTool } from '../tools/eslint.config_utils.mjs'; +import { requireEslintTool } from '../tools/eslint/eslint.config_utils.mjs'; const globals = requireEslintTool('globals'); diff --git a/eslint.config.mjs b/eslint.config.mjs index e9ac911a666fd4..a2d2e5917654a7 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -5,13 +5,14 @@ import benchmarkConfig from './benchmark/eslint.config_partial.mjs'; import docConfig from './doc/eslint.config_partial.mjs'; import libConfig from './lib/eslint.config_partial.mjs'; import testConfig from './test/eslint.config_partial.mjs'; -import toolsConfig from './tools/eslint.config_partial.mjs'; +import toolsConfig from './tools/eslint/eslint.config_partial.mjs'; import { noRestrictedSyntaxCommonAll, noRestrictedSyntaxCommonLib, requireEslintTool, resolveEslintTool, -} from './tools/eslint.config_utils.mjs'; +} from './tools/eslint/eslint.config_utils.mjs'; +import nodeCore from './tools/eslint/eslint-plugin-node-core.js'; const js = requireEslintTool('@eslint/js'); const babelEslintParser = requireEslintTool('@babel/eslint-parser'); @@ -20,7 +21,6 @@ const jsdoc = requireEslintTool('eslint-plugin-jsdoc'); const markdown = requireEslintTool('eslint-plugin-markdown'); const stylisticJs = requireEslintTool('@stylistic/eslint-plugin-js'); -const nodeCore = requireEslintTool('eslint-plugin-node-core'); nodeCore.RULES_DIR = fileURLToPath(new URL('./tools/eslint-rules', import.meta.url)); // The Module._resolveFilename() monkeypatching is to make it so that ESLint is able to diff --git a/lib/eslint.config_partial.mjs b/lib/eslint.config_partial.mjs index d730b222195a73..93001eb345c0c8 100644 --- a/lib/eslint.config_partial.mjs +++ b/lib/eslint.config_partial.mjs @@ -3,7 +3,7 @@ import { noRestrictedSyntaxCommonAll, noRestrictedSyntaxCommonLib, -} from '../tools/eslint.config_utils.mjs'; +} from '../tools/eslint/eslint.config_utils.mjs'; export default [ { diff --git a/test/eslint.config_partial.mjs b/test/eslint.config_partial.mjs index b1db96b20b8a5a..4a7f200850f439 100644 --- a/test/eslint.config_partial.mjs +++ b/test/eslint.config_partial.mjs @@ -3,7 +3,7 @@ import { noRestrictedSyntaxCommonAll, requireEslintTool, -} from '../tools/eslint.config_utils.mjs'; +} from '../tools/eslint/eslint.config_utils.mjs'; const globals = requireEslintTool('globals'); diff --git a/tools/node_modules/eslint-plugin-node-core/index.js b/tools/eslint/eslint-plugin-node-core.js similarity index 89% rename from tools/node_modules/eslint-plugin-node-core/index.js rename to tools/eslint/eslint-plugin-node-core.js index e27945688ee691..4d4d2809665789 100644 --- a/tools/node_modules/eslint-plugin-node-core/index.js +++ b/tools/eslint/eslint-plugin-node-core.js @@ -13,7 +13,7 @@ module.exports = { if (!cache) { cache = {}; const files = fs.readdirSync(RULES_DIR) - .filter(filename => filename.endsWith('.js')) + .filter((filename) => filename.endsWith('.js')); for (const file of files) { const name = file.slice(0, -3); cache[name] = require(path.resolve(RULES_DIR, file)); diff --git a/tools/eslint.config_partial.mjs b/tools/eslint/eslint.config_partial.mjs similarity index 100% rename from tools/eslint.config_partial.mjs rename to tools/eslint/eslint.config_partial.mjs diff --git a/tools/eslint.config_utils.mjs b/tools/eslint/eslint.config_utils.mjs similarity index 89% rename from tools/eslint.config_utils.mjs rename to tools/eslint/eslint.config_utils.mjs index aab2cac4c32c95..8bec18d66312a5 100644 --- a/tools/eslint.config_utils.mjs +++ b/tools/eslint/eslint.config_utils.mjs @@ -1,6 +1,6 @@ import { createRequire } from 'node:module'; -export const requireEslintTool = createRequire(new URL('./node_modules/eslint/', import.meta.url)); +export const requireEslintTool = createRequire(new URL('../node_modules/eslint/', import.meta.url)); export const resolveEslintTool = (request) => requireEslintTool.resolve(request); export const noRestrictedSyntaxCommonAll = [