This commit is contained in:
Iliyan Angelov
2025-09-14 23:24:25 +03:00
commit c67067a2a4
71311 changed files with 6800714 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
export declare function pruneAsync(): Promise<void>;
//# sourceMappingURL=prune.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"prune.d.ts","sourceRoot":"","sources":["../../../src/eslint-bulk-suppressions/cli/prune.ts"],"names":[],"mappings":"AAaA,wBAAsB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAsBhD"}

View File

@@ -0,0 +1,60 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.pruneAsync = pruneAsync;
const fs_1 = __importDefault(require("fs"));
const print_help_1 = require("./utils/print-help");
const runEslint_1 = require("./runEslint");
const constants_1 = require("../constants");
const bulk_suppressions_file_1 = require("../bulk-suppressions-file");
async function pruneAsync() {
const args = process.argv.slice(3);
if (args.includes('--help') || args.includes('-h')) {
(0, print_help_1.printPruneHelp)();
process.exit(0);
}
if (args.length > 0) {
throw new Error(`@rushstack/eslint-bulk: Unknown arguments: ${args.join(' ')}`);
}
const normalizedCwd = process.cwd().replace(/\\/g, '/');
const allFiles = await getAllFilesWithExistingSuppressionsForCwdAsync(normalizedCwd);
if (allFiles.length > 0) {
process.env[constants_1.ESLINT_BULK_PRUNE_ENV_VAR_NAME] = '1';
console.log(`Pruning suppressions for ${allFiles.length} files...`);
await (0, runEslint_1.runEslintAsync)(allFiles, 'prune');
}
else {
console.log('No files with existing suppressions found.');
(0, bulk_suppressions_file_1.deleteBulkSuppressionsFileInEslintConfigFolder)(normalizedCwd);
}
}
async function getAllFilesWithExistingSuppressionsForCwdAsync(normalizedCwd) {
const { jsonObject: bulkSuppressionsConfigJson } = (0, bulk_suppressions_file_1.getSuppressionsConfigForEslintConfigFolderPath)(normalizedCwd);
const allFiles = new Set();
for (const { file: filePath } of bulkSuppressionsConfigJson.suppressions) {
allFiles.add(filePath);
}
const allFilesArray = Array.from(allFiles);
const allExistingFiles = [];
// TODO: limit parallelism here with something similar to `Async.forEachAsync` from `node-core-library`.
await Promise.all(allFilesArray.map(async (filePath) => {
try {
await fs_1.default.promises.access(filePath, fs_1.default.constants.F_OK);
allExistingFiles.push(filePath);
}
catch (_a) {
// Doesn't exist - ignore
}
}));
console.log(`Found ${allExistingFiles.length} files with existing suppressions.`);
const deletedCount = allFilesArray.length - allExistingFiles.length;
if (deletedCount > 0) {
console.log(`${deletedCount} files with suppressions were deleted.`);
}
return allExistingFiles;
}
//# sourceMappingURL=prune.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"prune.js","sourceRoot":"","sources":["../../../src/eslint-bulk-suppressions/cli/prune.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;AAY3D,gCAsBC;AAhCD,4CAAoB;AAEpB,mDAAoD;AACpD,2CAA6C;AAC7C,4CAA8D;AAC9D,sEAGmC;AAE5B,KAAK,UAAU,UAAU;IAC9B,MAAM,IAAI,GAAa,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE7C,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACnD,IAAA,2BAAc,GAAE,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,8CAA8C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClF,CAAC;IAED,MAAM,aAAa,GAAW,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CA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AC3B,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,SAAS,gBAAgB,CAAC,MAAM,oCAAoC,CAAC,CAAC;IAClF,MAAM,YAAY,GAAW,aAAa,CAAC,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC;IAC5E,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;QACrB,OAAO,CAAC,GAAG,CAAC,GAAG,YAAY,wCAAwC,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport fs from 'fs';\n\nimport { printPruneHelp } from './utils/print-help';\nimport { runEslintAsync } from './runEslint';\nimport { ESLINT_BULK_PRUNE_ENV_VAR_NAME } from '../constants';\nimport {\n deleteBulkSuppressionsFileInEslintConfigFolder,\n getSuppressionsConfigForEslintConfigFolderPath\n} from '../bulk-suppressions-file';\n\nexport async function pruneAsync(): Promise<void> {\n const args: string[] = process.argv.slice(3);\n\n if (args.includes('--help') || args.includes('-h')) {\n printPruneHelp();\n process.exit(0);\n }\n\n if (args.length > 0) {\n throw new Error(`@rushstack/eslint-bulk: Unknown arguments: ${args.join(' ')}`);\n }\n\n const normalizedCwd: string = process.cwd().replace(/\\\\/g, '/');\n const allFiles: string[] = await getAllFilesWithExistingSuppressionsForCwdAsync(normalizedCwd);\n if (allFiles.length > 0) {\n process.env[ESLINT_BULK_PRUNE_ENV_VAR_NAME] = '1';\n console.log(`Pruning suppressions for ${allFiles.length} files...`);\n await runEslintAsync(allFiles, 'prune');\n } else {\n console.log('No files with existing suppressions found.');\n deleteBulkSuppressionsFileInEslintConfigFolder(normalizedCwd);\n }\n}\n\nasync function getAllFilesWithExistingSuppressionsForCwdAsync(normalizedCwd: string): Promise<string[]> {\n const { jsonObject: bulkSuppressionsConfigJson } =\n getSuppressionsConfigForEslintConfigFolderPath(normalizedCwd);\n const allFiles: Set<string> = new Set();\n for (const { file: filePath } of bulkSuppressionsConfigJson.suppressions) {\n allFiles.add(filePath);\n }\n\n const allFilesArray: string[] = Array.from(allFiles);\n\n const allExistingFiles: string[] = [];\n // TODO: limit parallelism here with something similar to `Async.forEachAsync` from `node-core-library`.\n await Promise.all(\n allFilesArray.map(async (filePath: string) => {\n try {\n await fs.promises.access(filePath, fs.constants.F_OK);\n allExistingFiles.push(filePath);\n } catch {\n // Doesn't exist - ignore\n }\n })\n );\n\n console.log(`Found ${allExistingFiles.length} files with existing suppressions.`);\n const deletedCount: number = allFilesArray.length - allExistingFiles.length;\n if (deletedCount > 0) {\n console.log(`${deletedCount} files with suppressions were deleted.`);\n }\n\n return allExistingFiles;\n}\n"]}

View File

@@ -0,0 +1,2 @@
export declare function runEslintAsync(files: string[], mode: 'suppress' | 'prune'): Promise<void>;
//# sourceMappingURL=runEslint.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"runEslint.d.ts","sourceRoot":"","sources":["../../../src/eslint-bulk-suppressions/cli/runEslint.ts"],"names":[],"mappings":"AAOA,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CA4C/F"}

View File

@@ -0,0 +1,79 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.runEslintAsync = runEslintAsync;
const get_eslint_cli_1 = require("./utils/get-eslint-cli");
async function runEslintAsync(files, mode) {
const cwd = process.cwd();
const [eslintPath, eslintVersion] = (0, get_eslint_cli_1.getEslintPathAndVersion)(cwd);
const { ESLint } = require(eslintPath);
let eslint;
const majorVersion = parseInt(eslintVersion, 10);
if (majorVersion < 9) {
eslint = new ESLint({ cwd, useEslintrc: true });
}
else {
eslint = new ESLint({ cwd });
}
let results;
try {
results = await eslint.lintFiles(files);
}
catch (e) {
throw new Error(`@rushstack/eslint-bulk execution error: ${e.message}`);
}
const { write, prune } = await Promise.resolve().then(() => __importStar(require('../bulk-suppressions-patch')));
switch (mode) {
case 'suppress': {
await write();
break;
}
case 'prune': {
await prune();
break;
}
}
if (results.length > 0) {
const stylishFormatter = await eslint.loadFormatter();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const formattedResults = await Promise.resolve(stylishFormatter.format(results));
console.log(formattedResults);
}
console.log('@rushstack/eslint-bulk: Successfully pruned unused suppressions in all .eslint-bulk-suppressions.json ' +
`files under directory ${cwd}`);
}
//# sourceMappingURL=runEslint.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"runEslint.js","sourceRoot":"","sources":["../../../src/eslint-bulk-suppressions/cli/runEslint.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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D,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC;QACnG,8DAA8D;QAC9D,MAAM,gBAAgB,GAAW,MAAM,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAc,CAAC,CAAC,CAAC;QAChG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,CAAC,GAAG,CACT,wGAAwG;QACtG,yBAAyB,GAAG,EAAE,CACjC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { ESLint as TEslintLegacy } from 'eslint-8';\nimport type { ESLint as TEslint } from 'eslint-9';\nimport { getEslintPathAndVersion } from './utils/get-eslint-cli';\n\nexport async function runEslintAsync(files: string[], mode: 'suppress' | 'prune'): Promise<void> {\n const cwd: string = process.cwd();\n const [eslintPath, eslintVersion] = getEslintPathAndVersion(cwd);\n const { ESLint }: typeof import('eslint-9') | typeof import('eslint-8') = require(eslintPath);\n\n let eslint: TEslint | TEslintLegacy;\n const majorVersion: number = parseInt(eslintVersion, 10);\n if (majorVersion < 9) {\n eslint = new ESLint({ cwd, useEslintrc: true });\n } else {\n eslint = new ESLint({ cwd });\n }\n\n let results: (TEslint.LintResult | TEslintLegacy.LintResult)[];\n try {\n results = await eslint.lintFiles(files);\n } catch (e) {\n throw new Error(`@rushstack/eslint-bulk execution error: ${e.message}`);\n }\n\n const { write, prune } = await import('../bulk-suppressions-patch');\n switch (mode) {\n case 'suppress': {\n await write();\n break;\n }\n\n case 'prune': {\n await prune();\n break;\n }\n }\n\n if (results.length > 0) {\n const stylishFormatter: TEslint.Formatter | TEslintLegacy.Formatter = await eslint.loadFormatter();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const formattedResults: string = await Promise.resolve(stylishFormatter.format(results as any));\n console.log(formattedResults);\n }\n\n console.log(\n '@rushstack/eslint-bulk: Successfully pruned unused suppressions in all .eslint-bulk-suppressions.json ' +\n `files under directory ${cwd}`\n );\n}\n"]}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=start.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../../src/eslint-bulk-suppressions/cli/start.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,44 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
const prune_1 = require("./prune");
const suppress_1 = require("./suppress");
const is_correct_cwd_1 = require("./utils/is-correct-cwd");
const print_help_1 = require("./utils/print-help");
if (process.argv.includes('-h') || process.argv.includes('-H') || process.argv.includes('--help')) {
(0, print_help_1.printHelp)();
process.exit(0);
}
if (process.argv.length < 3) {
(0, print_help_1.printHelp)();
process.exit(1);
}
if (!(0, is_correct_cwd_1.isCorrectCwd)(process.cwd())) {
console.error('@rushstack/eslint-bulk: Please call this command from the directory that contains .eslintrc.js or .eslintrc.cjs');
process.exit(1);
}
const subcommand = process.argv[2];
let processPromise;
switch (subcommand) {
case 'suppress': {
processPromise = (0, suppress_1.suppressAsync)();
break;
}
case 'prune': {
processPromise = (0, prune_1.pruneAsync)();
break;
}
default: {
console.error('@rushstack/eslint-bulk: Unknown subcommand: ' + subcommand);
process.exit(1);
}
}
processPromise.catch((e) => {
if (e instanceof Error) {
console.error(e.message);
process.exit(1);
}
throw e;
});
//# sourceMappingURL=start.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../src/eslint-bulk-suppressions/cli/start.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAE3D,mCAAqC;AACrC,yCAA2C;AAC3C,2DAAsD;AACtD,mDAA+C;AAE/C,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,I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AC,CAAC;AACV,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { pruneAsync } from './prune';\nimport { suppressAsync } from './suppress';\nimport { isCorrectCwd } from './utils/is-correct-cwd';\nimport { printHelp } from './utils/print-help';\n\nif (process.argv.includes('-h') || process.argv.includes('-H') || process.argv.includes('--help')) {\n printHelp();\n process.exit(0);\n}\n\nif (process.argv.length < 3) {\n printHelp();\n process.exit(1);\n}\n\nif (!isCorrectCwd(process.cwd())) {\n console.error(\n '@rushstack/eslint-bulk: Please call this command from the directory that contains .eslintrc.js or .eslintrc.cjs'\n );\n process.exit(1);\n}\n\nconst subcommand: string = process.argv[2];\nlet processPromise: Promise<void>;\nswitch (subcommand) {\n case 'suppress': {\n processPromise = suppressAsync();\n break;\n }\n\n case 'prune': {\n processPromise = pruneAsync();\n break;\n }\n\n default: {\n console.error('@rushstack/eslint-bulk: Unknown subcommand: ' + subcommand);\n process.exit(1);\n }\n}\n\nprocessPromise.catch((e) => {\n if (e instanceof Error) {\n console.error(e.message);\n process.exit(1);\n }\n\n throw e;\n});\n"]}

View File

@@ -0,0 +1,2 @@
export declare function suppressAsync(): Promise<void>;
//# sourceMappingURL=suppress.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"suppress.d.ts","sourceRoot":"","sources":["../../../src/eslint-bulk-suppressions/cli/suppress.ts"],"names":[],"mappings":"AAaA,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAuEnD"}

View File

@@ -0,0 +1,63 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.suppressAsync = suppressAsync;
const print_help_1 = require("./utils/print-help");
const runEslint_1 = require("./runEslint");
const constants_1 = require("../constants");
async function suppressAsync() {
const args = process.argv.slice(3);
if (args.includes('--help') || args.includes('-h')) {
(0, print_help_1.printSuppressHelp)();
process.exit(0);
}
// Use reduce to create an object with all the parsed arguments
const parsedArgs = args.reduce((acc, arg, index, arr) => {
if (arg === '--rule') {
// continue because next arg should be the rule
}
else if (index > 0 && arr[index - 1] === '--rule' && arr[index + 1]) {
acc.rules.push(arg);
}
else if (arg === '--all') {
acc.all = true;
}
else if (arg.startsWith('--')) {
throw new Error(`@rushstack/eslint-bulk: Unknown option: ${arg}`);
}
else {
acc.files.push(arg);
}
return acc;
}, { rules: [], all: false, files: [] });
if (parsedArgs.files.length === 0) {
throw new Error('@rushstack/eslint-bulk: Files argument is required. Use glob patterns to specify files or use ' +
'`.` to suppress all files for the specified rules.');
}
if (parsedArgs.rules.length === 0 && !parsedArgs.all) {
throw new Error('@rushstack/eslint-bulk: Please specify at least one rule to suppress. Use --all to suppress all rules.');
}
// Find the index of the last argument that starts with '--'
const lastOptionIndex = args
.map((arg, i) => (arg.startsWith('--') ? i : -1))
.reduce((lastIndex, currentIndex) => Math.max(lastIndex, currentIndex), -1);
// Check if options come before files
if (parsedArgs.files.some((file) => args.indexOf(file) < lastOptionIndex)) {
throw new Error('@rushstack/eslint-bulk: Unable to parse command line arguments. All options should come before files argument.');
}
if (parsedArgs.all) {
process.env[constants_1.ESLINT_BULK_SUPPRESS_ENV_VAR_NAME] = '*';
}
else if (parsedArgs.rules.length > 0) {
process.env[constants_1.ESLINT_BULK_SUPPRESS_ENV_VAR_NAME] = parsedArgs.rules.join(',');
}
await (0, runEslint_1.runEslintAsync)(parsedArgs.files, 'suppress');
if (parsedArgs.all) {
console.log(`@rushstack/eslint-bulk: Successfully suppressed all rules for file(s) ${parsedArgs.files}`);
}
else if (parsedArgs.rules.length > 0) {
console.log(`@rushstack/eslint-bulk: Successfully suppressed rules ${parsedArgs.rules} for file(s) ${parsedArgs.files}`);
}
}
//# sourceMappingURL=suppress.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
export declare function getEslintPathAndVersion(packagePath: string): [string, string];
//# sourceMappingURL=get-eslint-cli.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"get-eslint-cli.d.ts","sourceRoot":"","sources":["../../../../src/eslint-bulk-suppressions/cli/utils/get-eslint-cli.ts"],"names":[],"mappings":"AAmBA,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CA8C7E"}

View File

@@ -0,0 +1,57 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEslintPathAndVersion = getEslintPathAndVersion;
const path_1 = __importDefault(require("path"));
const constants_1 = require("../../constants");
// When this list is updated, update the `eslint-bulk-suppressions-newest-test`
// and/or the `eslint-bulk-suppressions-newest-test` projects' eslint dependencies.
const TESTED_VERSIONS = new Set([
'8.6.0',
'8.7.0',
'8.21.0',
'8.22.0',
'8.23.0',
'8.23.1',
'8.57.0',
'9.25.1'
]);
function getEslintPathAndVersion(packagePath) {
// Try to find a local ESLint installation, the one that should be listed as a dev dependency in package.json
// and installed in node_modules
try {
const localEslintApiPath = require.resolve(constants_1.BULK_SUPPRESSIONS_CLI_ESLINT_PACKAGE_NAME, {
paths: [packagePath]
});
const localEslintPath = path_1.default.dirname(path_1.default.dirname(localEslintApiPath));
const { version: localEslintVersion } = require(`${localEslintPath}/package.json`);
if (!TESTED_VERSIONS.has(localEslintVersion)) {
console.warn('@rushstack/eslint-bulk: Be careful, the installed ESLint version has not been tested with eslint-bulk.');
}
return [localEslintApiPath, localEslintVersion];
}
catch (e1) {
try {
const { dependencies, devDependencies } = require(`${packagePath}/package.json`);
if (devDependencies === null || devDependencies === void 0 ? void 0 : devDependencies.eslint) {
throw new Error('@rushstack/eslint-bulk: eslint is specified as a dev dependency in package.json, ' +
'but eslint-bulk cannot find it in node_modules.');
}
else if (dependencies === null || dependencies === void 0 ? void 0 : dependencies.eslint) {
throw new Error('@rushstack/eslint-bulk: eslint is specified as a dependency in package.json, ' +
'but eslint-bulk cannot find it in node_modules.');
}
else {
throw new Error('@rushstack/eslint-bulk: eslint is not specified as a dependency in package.json.');
}
}
catch (e2) {
throw new Error("@rushstack/eslint-bulk: This command must be run in the same folder as a project's package.json file.");
}
}
}
//# sourceMappingURL=get-eslint-cli.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"get-eslint-cli.js","sourceRoot":"","sources":["../../../../src/eslint-bulk-suppressions/cli/utils/get-eslint-cli.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;AAkB3D,0DA8CC;AA9DD,gDAAwB;AACxB,+CAA4E;AAE5E,+EAA+E;AAC/E,mFAAmF;AACnF,MAAM,eAAe,GAAgB,IAAI,GAAG,CAAC;IAC3C,OAAO;IACP,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;CACT,CAAC,CAAC;AAEH,SAAgB,uBAAuB,CAAC,WAAmB;IACzD,6GAA6G;IAC7G,gCAAgC;IAChC,IAAI,CAAC;QACH,MAAM,kBAAkB,GAAW,OAAO,CAAC,OAAO,CAAC,qDAAyC,EAAE;YAC5F,KAAK,EAAE,CAAC,WAAW,CAAC;SACrB,CAAC,CAAC;QACH,MAAM,eAAe,GAAW,cAAI,CAAC,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC;QAC/E,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,GAAG,eAAe,eAAe,CAAC,CAAC;QAEnF,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAC7C,OAAO,CAAC,IAAI,CACV,wGAAwG,CACzG,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;IAClD,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,MAAM,EACJ,YAAY,EACZ,eAAe,EAChB,GAGG,OAAO,CAAC,GAAG,WAAW,eAAe,CAAC,CAAC;YAE3C,IAAI,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,MAAM,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CACb,mFAAmF;oBACjF,iDAAiD,CACpD,CAAC;YACJ,CAAC;iBAAM,IAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,EAAE,CAAC;gBAChC,MAAM,IAAI,KAAK,CACb,+EAA+E;oBAC7E,iDAAiD,CACpD,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;YACtG,CAAC;QACH,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CACb,uGAAuG,CACxG,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport path from 'path';\nimport { BULK_SUPPRESSIONS_CLI_ESLINT_PACKAGE_NAME } from '../../constants';\n\n// When this list is updated, update the `eslint-bulk-suppressions-newest-test`\n// and/or the `eslint-bulk-suppressions-newest-test` projects' eslint dependencies.\nconst TESTED_VERSIONS: Set<string> = new Set([\n '8.6.0',\n '8.7.0',\n '8.21.0',\n '8.22.0',\n '8.23.0',\n '8.23.1',\n '8.57.0',\n '9.25.1'\n]);\n\nexport function getEslintPathAndVersion(packagePath: string): [string, string] {\n // Try to find a local ESLint installation, the one that should be listed as a dev dependency in package.json\n // and installed in node_modules\n try {\n const localEslintApiPath: string = require.resolve(BULK_SUPPRESSIONS_CLI_ESLINT_PACKAGE_NAME, {\n paths: [packagePath]\n });\n const localEslintPath: string = path.dirname(path.dirname(localEslintApiPath));\n const { version: localEslintVersion } = require(`${localEslintPath}/package.json`);\n\n if (!TESTED_VERSIONS.has(localEslintVersion)) {\n console.warn(\n '@rushstack/eslint-bulk: Be careful, the installed ESLint version has not been tested with eslint-bulk.'\n );\n }\n\n return [localEslintApiPath, localEslintVersion];\n } catch (e1) {\n try {\n const {\n dependencies,\n devDependencies\n }: {\n dependencies: Record<string, string> | undefined;\n devDependencies: Record<string, string> | undefined;\n } = require(`${packagePath}/package.json`);\n\n if (devDependencies?.eslint) {\n throw new Error(\n '@rushstack/eslint-bulk: eslint is specified as a dev dependency in package.json, ' +\n 'but eslint-bulk cannot find it in node_modules.'\n );\n } else if (dependencies?.eslint) {\n throw new Error(\n '@rushstack/eslint-bulk: eslint is specified as a dependency in package.json, ' +\n 'but eslint-bulk cannot find it in node_modules.'\n );\n } else {\n throw new Error('@rushstack/eslint-bulk: eslint is not specified as a dependency in package.json.');\n }\n } catch (e2) {\n throw new Error(\n \"@rushstack/eslint-bulk: This command must be run in the same folder as a project's package.json file.\"\n );\n }\n }\n}\n"]}

View File

@@ -0,0 +1,2 @@
export declare function isCorrectCwd(cwd: string): boolean;
//# sourceMappingURL=is-correct-cwd.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"is-correct-cwd.d.ts","sourceRoot":"","sources":["../../../../src/eslint-bulk-suppressions/cli/utils/is-correct-cwd.ts"],"names":[],"mappings":"AAKA,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAQjD"}

View File

@@ -0,0 +1,17 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isCorrectCwd = isCorrectCwd;
const fs_1 = __importDefault(require("fs"));
function isCorrectCwd(cwd) {
return (fs_1.default.existsSync(`${cwd}/eslint.config.js`) ||
fs_1.default.existsSync(`${cwd}/eslint.config.cjs`) ||
fs_1.default.existsSync(`${cwd}/eslint.config.mjs`) ||
fs_1.default.existsSync(`${cwd}/.eslintrc.js`) ||
fs_1.default.existsSync(`${cwd}/.eslintrc.cjs`));
}
//# sourceMappingURL=is-correct-cwd.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"is-correct-cwd.js","sourceRoot":"","sources":["../../../../src/eslint-bulk-suppressions/cli/utils/is-correct-cwd.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;AAI3D,oCAQC;AAVD,4CAAoB;AAEpB,SAAgB,YAAY,CAAC,GAAW;IACtC,OAAO,CACL,YAAE,CAAC,UAAU,CAAC,GAAG,GAAG,mBAAmB,CAAC;QACxC,YAAE,CAAC,UAAU,CAAC,GAAG,GAAG,oBAAoB,CAAC;QACzC,YAAE,CAAC,UAAU,CAAC,GAAG,GAAG,oBAAoB,CAAC;QACzC,YAAE,CAAC,UAAU,CAAC,GAAG,GAAG,eAAe,CAAC;QACpC,YAAE,CAAC,UAAU,CAAC,GAAG,GAAG,gBAAgB,CAAC,CACtC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport fs from 'fs';\n\nexport function isCorrectCwd(cwd: string): boolean {\n return (\n fs.existsSync(`${cwd}/eslint.config.js`) ||\n fs.existsSync(`${cwd}/eslint.config.cjs`) ||\n fs.existsSync(`${cwd}/eslint.config.mjs`) ||\n fs.existsSync(`${cwd}/.eslintrc.js`) ||\n fs.existsSync(`${cwd}/.eslintrc.cjs`)\n );\n}\n"]}

View File

@@ -0,0 +1,4 @@
export declare function printPruneHelp(): void;
export declare function printHelp(): void;
export declare function printSuppressHelp(): void;
//# sourceMappingURL=print-help.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"print-help.d.ts","sourceRoot":"","sources":["../../../../src/eslint-bulk-suppressions/cli/utils/print-help.ts"],"names":[],"mappings":"AAKA,wBAAgB,cAAc,IAAI,IAAI,CAarC;AAED,wBAAgB,SAAS,IAAI,IAAI,CA8BhC;AAED,wBAAgB,iBAAiB,IAAI,IAAI,CA6BxC"}

View File

@@ -0,0 +1,81 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.printPruneHelp = printPruneHelp;
exports.printHelp = printHelp;
exports.printSuppressHelp = printSuppressHelp;
const wrap_words_to_lines_1 = require("./wrap-words-to-lines");
function printPruneHelp() {
const help = `eslint-bulk prune
Usage:
eslint-bulk prune
This command is a thin wrapper around ESLint that communicates with @rushstack/eslint-patch to delete all unused suppression entries in all .eslint-bulk-suppressions.json files under the current working directory.`;
const wrapped = (0, wrap_words_to_lines_1.wrapWordsToLines)(help);
for (const line of wrapped) {
console.log(line);
}
}
function printHelp() {
const help = `eslint-bulk <command>
Usage:
eslint-bulk suppress --rule RULENAME1 [--rule RULENAME2...] PATH1 [PATH2...]
eslint-bulk suppress --all PATH1 [PATH2...]
eslint-bulk suppress --help
eslint-bulk prune
eslint-bulk prune --help
eslint-bulk --help
This command line tool is a thin wrapper around ESLint that communicates with @rushstack/eslint-patch to suppress or prune unused suppressions in the local .eslint-bulk-suppressions.json file.
Commands:
eslint-bulk suppress [options] <path...>
Use this command to generate a new .eslint-bulk-suppressions.json file or add suppression entries to the existing file. Specify the files and rules you want to suppress.
Please run "eslint-bulk suppress --help" to learn more.
eslint-bulk prune
Use this command to delete all unused suppression entries in all .eslint-bulk-suppressions.json files under the current working directory.
Please run "eslint-bulk prune --help" to learn more.
`;
const wrapped = (0, wrap_words_to_lines_1.wrapWordsToLines)(help);
for (const line of wrapped) {
console.log(line);
}
}
function printSuppressHelp() {
const help = `eslint-bulk suppress [options] <path...>
Usage:
eslint-bulk suppress --rule RULENAME1 [--rule RULENAME2...] PATH1 [PATH2...]
eslint-bulk suppress --all PATH1 [PATH2...]
eslint-bulk suppress --help
This command is a thin wrapper around ESLint that communicates with @rushstack/eslint-patch to either generate a new .eslint-bulk-suppressions.json file or add suppression entries to the existing file. Specify the files and rules you want to suppress.
Argument:
<path...>
Glob patterns for paths to suppress, same as eslint files argument. Should be relative to the project root.
Options:
-h, -H, --help
Display this help message.
-R, --rule
The full name of the ESLint rule you want to bulk-suppress. Specify multiple rules with --rule NAME1 --rule RULENAME2.
-A, --all
Bulk-suppress all rules in the specified file patterns.`;
const wrapped = (0, wrap_words_to_lines_1.wrapWordsToLines)(help);
for (const line of wrapped) {
console.log(line);
}
}
//# sourceMappingURL=print-help.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"print-help.js","sourceRoot":"","sources":["../../../../src/eslint-bulk-suppressions/cli/utils/print-help.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAI3D,wCAaC;AAED,8BA8BC;AAED,8CA6BC;AA9ED,+DAAyD;AAEzD,SAAgB,cAAc;IAC5B,MAAM,IAAI,GAAW;;;;;;sNAM+L,CAAC;IAErN,MAAM,OAAO,GAAa,IAAA,sCAAgB,EAAC,IAAI,CAAC,CAAC;IACjD,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;AACH,CAAC;AAED,SAAgB,SAAS;IACvB,MAAM,IAAI,GAAW;;;;;;;;;;;;;;;;;;;;;;;CAuBtB,CAAC;IAEA,MAAM,OAAO,GAAa,IAAA,sCAAgB,EAAC,IAAI,CAAC,CAAC;IACjD,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;AACH,CAAC;AAED,SAAgB,iBAAiB;IAC/B,MAAM,IAAI,GAAW;;;;;;;;;;;;;;;;;;;;;;4DAsBqC,CAAC;IAE3D,MAAM,OAAO,GAAa,IAAA,sCAAgB,EAAC,IAAI,CAAC,CAAC;IACjD,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { wrapWordsToLines } from './wrap-words-to-lines';\n\nexport function printPruneHelp(): void {\n const help: string = `eslint-bulk prune\n\nUsage:\n\neslint-bulk prune\n\nThis command is a thin wrapper around ESLint that communicates with @rushstack/eslint-patch to delete all unused suppression entries in all .eslint-bulk-suppressions.json files under the current working directory.`;\n\n const wrapped: string[] = wrapWordsToLines(help);\n for (const line of wrapped) {\n console.log(line);\n }\n}\n\nexport function printHelp(): void {\n const help: string = `eslint-bulk <command>\n\nUsage:\n\neslint-bulk suppress --rule RULENAME1 [--rule RULENAME2...] PATH1 [PATH2...]\neslint-bulk suppress --all PATH1 [PATH2...]\neslint-bulk suppress --help\n\neslint-bulk prune\neslint-bulk prune --help\n\neslint-bulk --help\n\nThis command line tool is a thin wrapper around ESLint that communicates with @rushstack/eslint-patch to suppress or prune unused suppressions in the local .eslint-bulk-suppressions.json file.\n\nCommands:\n eslint-bulk suppress [options] <path...>\n Use this command to generate a new .eslint-bulk-suppressions.json file or add suppression entries to the existing file. Specify the files and rules you want to suppress.\n Please run \"eslint-bulk suppress --help\" to learn more.\n\n eslint-bulk prune\n Use this command to delete all unused suppression entries in all .eslint-bulk-suppressions.json files under the current working directory.\n Please run \"eslint-bulk prune --help\" to learn more.\n`;\n\n const wrapped: string[] = wrapWordsToLines(help);\n for (const line of wrapped) {\n console.log(line);\n }\n}\n\nexport function printSuppressHelp(): void {\n const help: string = `eslint-bulk suppress [options] <path...>\n\nUsage:\n\neslint-bulk suppress --rule RULENAME1 [--rule RULENAME2...] PATH1 [PATH2...]\neslint-bulk suppress --all PATH1 [PATH2...]\neslint-bulk suppress --help\n\nThis command is a thin wrapper around ESLint that communicates with @rushstack/eslint-patch to either generate a new .eslint-bulk-suppressions.json file or add suppression entries to the existing file. Specify the files and rules you want to suppress.\n\nArgument:\n <path...>\n Glob patterns for paths to suppress, same as eslint files argument. Should be relative to the project root.\n\nOptions:\n -h, -H, --help\n Display this help message.\n\n -R, --rule\n The full name of the ESLint rule you want to bulk-suppress. Specify multiple rules with --rule NAME1 --rule RULENAME2.\n\n -A, --all\n Bulk-suppress all rules in the specified file patterns.`;\n\n const wrapped: string[] = wrapWordsToLines(help);\n for (const line of wrapped) {\n console.log(line);\n }\n}\n"]}

View File

@@ -0,0 +1,26 @@
/**
* Applies word wrapping and returns an array of lines.
*
* @param text - The text to wrap
* @param maxLineLength - The maximum length of a line, defaults to the console width
* @param indent - The number of spaces to indent the wrapped lines, defaults to 0
*/
export declare function wrapWordsToLines(text: string, maxLineLength?: number, indent?: number): string[];
/**
* Applies word wrapping and returns an array of lines.
*
* @param text - The text to wrap
* @param maxLineLength - The maximum length of a line, defaults to the console width
* @param linePrefix - The string to prefix each line with, defaults to ''
*/
export declare function wrapWordsToLines(text: string, maxLineLength?: number, linePrefix?: string): string[];
/**
* Applies word wrapping and returns an array of lines.
*
* @param text - The text to wrap
* @param maxLineLength - The maximum length of a line, defaults to the console width
* @param indentOrLinePrefix - The number of spaces to indent the wrapped lines or the string to prefix
* each line with, defaults to no prefix
*/
export declare function wrapWordsToLines(text: string, maxLineLength?: number, indentOrLinePrefix?: number | string): string[];
//# sourceMappingURL=wrap-words-to-lines.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"wrap-words-to-lines.d.ts","sourceRoot":"","sources":["../../../../src/eslint-bulk-suppressions/cli/utils/wrap-words-to-lines.ts"],"names":[],"mappings":"AAWA;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;AAClG;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;AACtG;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,aAAa,CAAC,EAAE,MAAM,EACtB,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,GACnC,MAAM,EAAE,CAAC"}

View File

@@ -0,0 +1,68 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.wrapWordsToLines = wrapWordsToLines;
function wrapWordsToLines(text, maxLineLength, indentOrLinePrefix) {
var _a;
let linePrefix;
switch (typeof indentOrLinePrefix) {
case 'number':
linePrefix = ' '.repeat(indentOrLinePrefix);
break;
case 'string':
linePrefix = indentOrLinePrefix;
break;
default:
linePrefix = '';
break;
}
const linePrefixLength = linePrefix.length;
if (!maxLineLength) {
maxLineLength = process.stdout.getWindowSize()[0];
}
// Apply word wrapping and the provided line prefix, while also respecting existing newlines
// and prefix spaces that may exist in the text string already.
const lines = text.split(/\r?\n/);
const wrappedLines = [];
for (const line of lines) {
if (line.length + linePrefixLength <= maxLineLength) {
wrappedLines.push(linePrefix + line);
}
else {
const lineAdditionalPrefix = ((_a = line.match(/^\s*/)) === null || _a === void 0 ? void 0 : _a[0]) || '';
const whitespaceRegexp = /\s+/g;
let currentWhitespaceMatch = null;
let previousWhitespaceMatch;
let currentLineStartIndex = lineAdditionalPrefix.length;
let previousBreakRanOver = false;
while ((currentWhitespaceMatch = whitespaceRegexp.exec(line)) !== null) {
if (currentWhitespaceMatch.index + linePrefixLength - currentLineStartIndex > maxLineLength) {
let whitespaceToSplitAt;
if (!previousWhitespaceMatch ||
// Handle the case where there are two words longer than the maxLineLength in a row
previousBreakRanOver) {
whitespaceToSplitAt = currentWhitespaceMatch;
}
else {
whitespaceToSplitAt = previousWhitespaceMatch;
}
wrappedLines.push(linePrefix +
lineAdditionalPrefix +
line.substring(currentLineStartIndex, whitespaceToSplitAt.index));
previousBreakRanOver = whitespaceToSplitAt.index - currentLineStartIndex > maxLineLength;
currentLineStartIndex = whitespaceToSplitAt.index + whitespaceToSplitAt[0].length;
}
else {
previousBreakRanOver = false;
}
previousWhitespaceMatch = currentWhitespaceMatch;
}
if (currentLineStartIndex < line.length) {
wrappedLines.push(linePrefix + lineAdditionalPrefix + line.substring(currentLineStartIndex));
}
}
}
return wrappedLines;
}
//# sourceMappingURL=wrap-words-to-lines.js.map

File diff suppressed because one or more lines are too long