Skip to content

[eslint-patch] Improve performance of eslint-bulk-suppressions #5055

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
38 changes: 32 additions & 6 deletions build-tests/eslint-bulk-suppressions-test-legacy/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
const { FileSystem, Executable, Text, Import } = require('@rushstack/node-core-library');
const path = require('path');
const {
ESLINT_PACKAGE_NAME_ENV_VAR_NAME
ESLINT_PACKAGE_NAME_ENV_VAR_NAME,
ESLINT_BULK_ESLINTRC_FOLDER_PATH_ENV_VAR_NAME,
ESLINT_BULK_FORCE_REGENERATE_PATCH_ENV_VAR_NAME
} = require('@rushstack/eslint-patch/lib/eslint-bulk-suppressions/constants');

const eslintBulkStartPath = Import.resolveModule({
Expand Down Expand Up @@ -65,25 +67,26 @@ for (const runFolderPath of RUN_FOLDER_PATHS) {
);
const shellPathWithEslint = `${dependencyBinFolder}${path.delimiter}${process.env['PATH']}`;

const executableResult = Executable.spawnSync(
const suppressResult = Executable.spawnSync(
process.argv0,
[eslintBulkStartPath, 'suppress', '--all', 'src'],
{
currentWorkingDirectory: folderPath,
environment: {
...process.env,
PATH: shellPathWithEslint,
[ESLINT_PACKAGE_NAME_ENV_VAR_NAME]: eslintPackageName
[ESLINT_PACKAGE_NAME_ENV_VAR_NAME]: eslintPackageName,
[ESLINT_BULK_FORCE_REGENERATE_PATCH_ENV_VAR_NAME]: 'true'
}
}
);

if (executableResult.status !== 0) {
if (suppressResult.status !== 0) {
console.error('The eslint-bulk-suppressions command failed.');
console.error('STDOUT:');
console.error(executableResult.stdout.toString());
console.error(suppressResult.stdout.toString());
console.error('STDERR:');
console.error(executableResult.stderr.toString());
console.error(suppressResult.stderr.toString());
process.exit(1);
}

Expand All @@ -94,6 +97,29 @@ for (const runFolderPath of RUN_FOLDER_PATHS) {
updateFilePaths.add(referenceSuppressionsJsonPath);
FileSystem.writeFile(referenceSuppressionsJsonPath, newSuppressions);
}
const eslintLoggingMessage = `-- Running eslint@${eslintVersion} in ${runFolderPath} --`;
console.log(eslintLoggingMessage);

const eslintBinPath = path.resolve(__dirname, `node_modules/${eslintPackageName}/bin/eslint.js`);

const executableResult = Executable.spawnSync(process.argv0, [eslintBinPath, 'src'], {
currentWorkingDirectory: folderPath,
environment: {
...process.env,
PATH: shellPathWithEslint,
[ESLINT_PACKAGE_NAME_ENV_VAR_NAME]: eslintPackageName,
[ESLINT_BULK_ESLINTRC_FOLDER_PATH_ENV_VAR_NAME]: folderPath
}
});

if (executableResult.status !== 0) {
console.error('The eslint command failed.');
console.error('STDOUT:');
console.error(executableResult.stdout.toString());
console.error('STDERR:');
console.error(executableResult.stderr.toString());
process.exit(1);
}

FileSystem.deleteFile(suppressionsJsonPath);
}
Expand Down
38 changes: 32 additions & 6 deletions build-tests/eslint-bulk-suppressions-test/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
const { FileSystem, Executable, Text, Import } = require('@rushstack/node-core-library');
const path = require('path');
const {
ESLINT_PACKAGE_NAME_ENV_VAR_NAME
ESLINT_PACKAGE_NAME_ENV_VAR_NAME,
ESLINT_BULK_ESLINTRC_FOLDER_PATH_ENV_VAR_NAME,
ESLINT_BULK_FORCE_REGENERATE_PATCH_ENV_VAR_NAME
} = require('@rushstack/eslint-patch/lib/eslint-bulk-suppressions/constants');

const eslintBulkStartPath = Import.resolveModule({
Expand Down Expand Up @@ -65,25 +67,26 @@ for (const runFolderPath of RUN_FOLDER_PATHS) {
);
const shellPathWithEslint = `${dependencyBinFolder}${path.delimiter}${process.env['PATH']}`;

const executableResult = Executable.spawnSync(
const suppressResult = Executable.spawnSync(
process.argv0,
[eslintBulkStartPath, 'suppress', '--all', 'src'],
{
currentWorkingDirectory: folderPath,
environment: {
...process.env,
PATH: shellPathWithEslint,
[ESLINT_PACKAGE_NAME_ENV_VAR_NAME]: eslintPackageName
[ESLINT_PACKAGE_NAME_ENV_VAR_NAME]: eslintPackageName,
[ESLINT_BULK_FORCE_REGENERATE_PATCH_ENV_VAR_NAME]: 'true'
}
}
);

if (executableResult.status !== 0) {
if (suppressResult.status !== 0) {
console.error('The eslint-bulk-suppressions command failed.');
console.error('STDOUT:');
console.error(executableResult.stdout.toString());
console.error(suppressResult.stdout.toString());
console.error('STDERR:');
console.error(executableResult.stderr.toString());
console.error(suppressResult.stderr.toString());
process.exit(1);
}

Expand All @@ -94,6 +97,29 @@ for (const runFolderPath of RUN_FOLDER_PATHS) {
updateFilePaths.add(referenceSuppressionsJsonPath);
FileSystem.writeFile(referenceSuppressionsJsonPath, newSuppressions);
}
const eslintLoggingMessage = `-- Running eslint@${eslintVersion} in ${runFolderPath} --`;
console.log(eslintLoggingMessage);

const eslintBinPath = path.resolve(__dirname, `node_modules/${eslintPackageName}/bin/eslint.js`);

const executableResult = Executable.spawnSync(process.argv0, [eslintBinPath, 'src'], {
currentWorkingDirectory: folderPath,
environment: {
...process.env,
PATH: shellPathWithEslint,
[ESLINT_PACKAGE_NAME_ENV_VAR_NAME]: eslintPackageName,
[ESLINT_BULK_ESLINTRC_FOLDER_PATH_ENV_VAR_NAME]: folderPath
}
});

if (executableResult.status !== 0) {
console.error('The eslint command failed.');
console.error('STDOUT:');
console.error(executableResult.stdout.toString());
console.error('STDERR:');
console.error(executableResult.stderr.toString());
process.exit(1);
}

FileSystem.deleteFile(suppressionsJsonPath);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/eslint-patch",
"comment": "Ensure that lint problems suppressed by eslint-bulk-suppressions are available in the `getSuppressedMessages()` function on the linter. Defer evaluation of bulk suppressions until after inline suppressions.",
"type": "minor"
}
],
"packageName": "@rushstack/eslint-patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/heft-lint-plugin",
"comment": "Speed up heft-lint-plugin by telling eslint-bulk-suppressions exactly where to find the config file.",
"type": "patch"
}
],
"packageName": "@rushstack/heft-lint-plugin"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/heft-lint-plugin",
"comment": "Add a config option \"disableLintConfigSearch\" to turn off the linter's built-in scanning for config files relative to the linted files, and only use the config defined in the root of the current package.",
"type": "minor"
}
],
"packageName": "@rushstack/heft-lint-plugin"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See LICENSE in the project root for license information.

import fs from 'fs';
import { VSCODE_PID_ENV_VAR_NAME } from './constants';
import { VSCODE_PID_ENV_VAR_NAME, SUPPRESSIONS_JSON_FILENAME } from './constants';

export interface ISuppression {
file: string;
Expand All @@ -23,7 +23,6 @@ export interface IBulkSuppressionsJson {

const IS_RUNNING_IN_VSCODE: boolean = process.env[VSCODE_PID_ENV_VAR_NAME] !== undefined;
const TEN_SECONDS_MS: number = 10 * 1000;
const SUPPRESSIONS_JSON_FILENAME: string = '.eslint-bulk-suppressions.json';

function throwIfAnythingOtherThanNotExistError(e: NodeJS.ErrnoException): void | never {
if (e?.code !== 'ENOENT') {
Expand Down Expand Up @@ -56,7 +55,8 @@ export function getSuppressionsConfigForEslintrcFolderPath(
const suppressionsPath: string = `${eslintrcFolderPath}/${SUPPRESSIONS_JSON_FILENAME}`;
let rawJsonFile: string | undefined;
try {
rawJsonFile = fs.readFileSync(suppressionsPath).toString();
// Decoding during read hits an optimized fast path in NodeJS >= 22.
rawJsonFile = fs.readFileSync(suppressionsPath, 'utf8');
} catch (e) {
throwIfAnythingOtherThanNotExistError(e);
}
Expand Down
Loading
Loading