Skip to content

Commit

Permalink
squash: add hack to load tap formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed May 22, 2024
1 parent 5a6f987 commit 86bae6f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Module from 'node:module';
import { fileURLToPath, URL } from 'node:url';

import benchmarkConfig from './benchmark/eslint.config_partial.mjs';
Expand All @@ -10,6 +11,7 @@ import {
noRestrictedSyntaxCommonLib,
noRestrictedSyntaxCommonTest,
requireEslintTool,
resolveEslintTool,
} from './tools/eslint.config_utils.mjs';

const js = requireEslintTool('@eslint/js');
Expand All @@ -22,6 +24,19 @@ 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
// dynamically load extra modules that we install with it.
const ModuleResolveFilename = Module._resolveFilename;
const hacks = [
'eslint-formatter-tap',
];
Module._resolveFilename = (request, parent, isMain, options) => {
if (hacks.includes(request) && parent.id.endsWith('__placeholder__.js')) {
return resolveEslintTool(request);
}
return ModuleResolveFilename(request, parent, isMain, options);
};

export default [
// #region ignores
{
Expand Down
1 change: 1 addition & 0 deletions tools/eslint.config_utils.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createRequire } from 'node:module';

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 86bae6f

Please sign in to comment.