Skip to content

Commit

Permalink
tools: move ESLint tools to tools/eslint
Browse files Browse the repository at this point in the history
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: #53393
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
  • Loading branch information
targos committed Jun 20, 2024
1 parent fa113b8 commit ab20214
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion benchmark/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
@@ -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');

Expand Down
2 changes: 1 addition & 1 deletion doc/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
@@ -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');

Expand Down
6 changes: 3 additions & 3 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {
noRestrictedSyntaxCommonAll,
noRestrictedSyntaxCommonLib,
} from '../tools/eslint.config_utils.mjs';
} from '../tools/eslint/eslint.config_utils.mjs';

export default [
{
Expand Down
2 changes: 1 addition & 1 deletion test/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {
noRestrictedSyntaxCommonAll,
requireEslintTool,
} from '../tools/eslint.config_utils.mjs';
} from '../tools/eslint/eslint.config_utils.mjs';

const globals = requireEslintTool('globals');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down

0 comments on commit ab20214

Please sign in to comment.