main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 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,61 @@
"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 = void 0;
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.deleteBulkSuppressionsFileInEslintrcFolder)(normalizedCwd);
}
}
exports.pruneAsync = pruneAsync;
async function getAllFilesWithExistingSuppressionsForCwdAsync(normalizedCwd) {
const { jsonObject: bulkSuppressionsConfigJson } = (0, bulk_suppressions_file_1.getSuppressionsConfigForEslintrcFolderPath)(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;;;;;;AAE3D,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,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAa,MAAM,8CAA8C,CAAC,aAAa,CAAC,CAAC;IAC/F,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,GAAG,CAAC,0CAA8B,CAAC,GAAG,GAAG,CAAC;QAClD,OAAO,CAAC,GAAG,CAAC,4BAA4B,QAAQ,CAAC,MAAM,WAAW,CAAC,CAAC;QACpE,MAAM,IAAA,0BAAc,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;QAC1D,IAAA,mEAA0C,EAAC,aAAa,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC;AAtBD,gCAsBC;AAED,KAAK,UAAU,8CAA8C,CAAC,aAAqB;IACjF,MAAM,EAAE,UAAU,EAAE,0BAA0B,EAAE,GAC9C,IAAA,mEAA0C,EAAC,aAAa,CAAC,CAAC;IAC5D,MAAM,QAAQ,GAAgB,IAAI,GAAG,EAAE,CAAC;IACxC,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,0BAA0B,CAAC,YAAY,EAAE,CAAC;QACzE,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;IAED,MAAM,aAAa,GAAa,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAErD,MAAM,gBAAgB,GAAa,EAAE,CAAC;IACtC,wGAAwG;IACxG,MAAM,OAAO,CAAC,GAAG,CACf,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,QAAgB,EAAE,EAAE;QAC3C,IAAI,CAAC;YACH,MAAM,YAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACtD,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;QAAC,WAAM,CAAC;YACP,yBAAyB;QAC3B,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 deleteBulkSuppressionsFileInEslintrcFolder,\n getSuppressionsConfigForEslintrcFolderPath\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 deleteBulkSuppressionsFileInEslintrcFolder(normalizedCwd);\n }\n}\n\nasync function getAllFilesWithExistingSuppressionsForCwdAsync(normalizedCwd: string): Promise<string[]> {\n const { jsonObject: bulkSuppressionsConfigJson } =\n getSuppressionsConfigForEslintrcFolderPath(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":"AAMA,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAuC/F"}

View File

@@ -0,0 +1,65 @@
"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 (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runEslintAsync = void 0;
const get_eslint_cli_1 = require("./utils/get-eslint-cli");
async function runEslintAsync(files, mode) {
const cwd = process.cwd();
const eslintPath = (0, get_eslint_cli_1.getEslintPath)(cwd);
const { ESLint } = require(eslintPath);
const eslint = new ESLint({
useEslintrc: true,
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();
const formattedResults = 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}`);
}
exports.runEslintAsync = runEslintAsync;
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;AAG3D,2DAAuD;AAEhD,KAAK,UAAU,cAAc,CAAC,KAAe,EAAE,IAA0B;IAC9E,MAAM,GAAG,GAAW,OAAO,CAAC,GAAG,EAAE,CAAC;IAClC,MAAM,UAAU,GAAW,IAAA,8BAAa,EAAC,GAAG,CAAC,CAAC;IAC9C,MAAM,EAAE,MAAM,EAAE,GAA4B,OAAO,CAAC,UAAU,CAAC,CAAC;IAChE,MAAM,MAAM,GAAW,IAAI,MAAM,CAAC;QAChC,WAAW,EAAE,IAAI;QACjB,GAAG;KACJ,CAAC,CAAC;IAEH,IAAI,OAA4B,CAAC;IACjC,IAAI,CAAC;QACH,OAAO,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,wDAAa,4BAA4B,GAAC,CAAC;IACpE,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,UAAU,CAAC,CAAC,CAAC;YAChB,MAAM,KAAK,EAAE,CAAC;YACd,MAAM;QACR,CAAC;QAED,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,MAAM,KAAK,EAAE,CAAC;YACd,MAAM;QACR,CAAC;IACH,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,gBAAgB,GAAqB,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC;QACxE,MAAM,gBAAgB,GAAW,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAClE,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,CAAC,GAAG,CACT,wGAAwG;QACtG,yBAAyB,GAAG,EAAE,CACjC,CAAC;AACJ,CAAC;AAvCD,wCAuCC","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 } from 'eslint';\nimport { getEslintPath } 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: string = getEslintPath(cwd);\n const { ESLint }: typeof import('eslint') = require(eslintPath);\n const eslint: ESLint = new ESLint({\n useEslintrc: true,\n cwd\n });\n\n let results: ESLint.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: ESLint.Formatter = await eslint.loadFormatter();\n const formattedResults: string = stylishFormatter.format(results);\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,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;IAClG,IAAA,sBAAS,GAAE,CAAC;IACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;IAC5B,IAAA,sBAAS,GAAE,CAAC;IACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,IAAI,CAAC,IAAA,6BAAY,EAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;IACjC,OAAO,CAAC,KAAK,CACX,iHAAiH,CAClH,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,GAAW,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC3C,IAAI,cAA6B,CAAC;AAClC,QAAQ,UAAU,EAAE,CAAC;IACnB,KAAK,UAAU,CAAC,CAAC,CAAC;QAChB,cAAc,GAAG,IAAA,wBAAa,GAAE,CAAC;QACjC,MAAM;IACR,CAAC;IAED,KAAK,OAAO,CAAC,CAAC,CAAC;QACb,cAAc,GAAG,IAAA,kBAAU,GAAE,CAAC;QAC9B,MAAM;IACR,CAAC;IAED,OAAO,CAAC,CAAC,CAAC;QACR,OAAO,CAAC,KAAK,CAAC,8CAA8C,GAAG,UAAU,CAAC,CAAC;QAC3E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACzB,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;QACvB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,CAAC,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,64 @@
"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 = void 0;
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}`);
}
}
exports.suppressAsync = suppressAsync;
//# sourceMappingURL=suppress.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
export declare function getEslintPath(packagePath: 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":"AAkBA,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CA8CzD"}

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.getEslintPath = void 0;
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'
]);
function getEslintPath(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;
}
catch (e) {
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 (e) {
throw new Error("@rushstack/eslint-bulk: This command must be run in the same folder as a project's package.json file.");
}
}
}
exports.getEslintPath = getEslintPath;
//# 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;;;;;;AAE3D,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;CACT,CAAC,CAAC;AAEH,SAAgB,aAAa,CAAC,WAAmB;IAC/C,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,kBAAkB,CAAC;IAC5B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,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,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CACb,uGAAuG,CACxG,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AA9CD,sCA8CC","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]);\n\nexport function getEslintPath(packagePath: 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;\n } catch (e) {\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 (e) {\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,CAEjD"}

View File

@@ -0,0 +1,14 @@
"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 = void 0;
const fs_1 = __importDefault(require("fs"));
function isCorrectCwd(cwd) {
return fs_1.default.existsSync(`${cwd}/.eslintrc.js`) || fs_1.default.existsSync(`${cwd}/.eslintrc.cjs`);
}
exports.isCorrectCwd = isCorrectCwd;
//# 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;;;;;;AAE3D,4CAAoB;AAEpB,SAAgB,YAAY,CAAC,GAAW;IACtC,OAAO,YAAE,CAAC,UAAU,CAAC,GAAG,GAAG,eAAe,CAAC,IAAI,YAAE,CAAC,UAAU,CAAC,GAAG,GAAG,gBAAgB,CAAC,CAAC;AACvF,CAAC;AAFD,oCAEC","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 fs.existsSync(`${cwd}/.eslintrc.js`) || fs.existsSync(`${cwd}/.eslintrc.cjs`);\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,82 @@
"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.printSuppressHelp = exports.printHelp = exports.printPruneHelp = void 0;
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);
}
}
exports.printPruneHelp = printPruneHelp;
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);
}
}
exports.printHelp = printHelp;
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);
}
}
exports.printSuppressHelp = printSuppressHelp;
//# 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;;;AAE3D,+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;AAbD,wCAaC;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;AA9BD,8BA8BC;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;AA7BD,8CA6BC","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,69 @@
"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 = void 0;
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;
}
exports.wrapWordsToLines = wrapWordsToLines;
//# sourceMappingURL=wrap-words-to-lines.js.map

File diff suppressed because one or more lines are too long