| 1 | "use strict";
|
|---|
| 2 | // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|---|
| 3 | // See LICENSE in the project root for license information.
|
|---|
| 4 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
|---|
| 5 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
|---|
| 6 | };
|
|---|
| 7 | Object.defineProperty(exports, "__esModule", { value: true });
|
|---|
| 8 | exports.pruneAsync = pruneAsync;
|
|---|
| 9 | const node_fs_1 = __importDefault(require("node:fs"));
|
|---|
| 10 | const print_help_1 = require("./utils/print-help");
|
|---|
| 11 | const runEslint_1 = require("./runEslint");
|
|---|
| 12 | const constants_1 = require("../constants");
|
|---|
| 13 | const bulk_suppressions_file_1 = require("../bulk-suppressions-file");
|
|---|
| 14 | async function pruneAsync() {
|
|---|
| 15 | const args = process.argv.slice(3);
|
|---|
| 16 | if (args.includes('--help') || args.includes('-h')) {
|
|---|
| 17 | (0, print_help_1.printPruneHelp)();
|
|---|
| 18 | process.exit(0);
|
|---|
| 19 | }
|
|---|
| 20 | if (args.length > 0) {
|
|---|
| 21 | throw new Error(`@rushstack/eslint-bulk: Unknown arguments: ${args.join(' ')}`);
|
|---|
| 22 | }
|
|---|
| 23 | const normalizedCwd = process.cwd().replace(/\\/g, '/');
|
|---|
| 24 | const allFiles = await getAllFilesWithExistingSuppressionsForCwdAsync(normalizedCwd);
|
|---|
| 25 | if (allFiles.length > 0) {
|
|---|
| 26 | process.env[constants_1.ESLINT_BULK_PRUNE_ENV_VAR_NAME] = '1';
|
|---|
| 27 | console.log(`Pruning suppressions for ${allFiles.length} files...`);
|
|---|
| 28 | await (0, runEslint_1.runEslintAsync)(allFiles, 'prune');
|
|---|
| 29 | }
|
|---|
| 30 | else {
|
|---|
| 31 | console.log('No files with existing suppressions found.');
|
|---|
| 32 | (0, bulk_suppressions_file_1.deleteBulkSuppressionsFileInEslintConfigFolder)(normalizedCwd);
|
|---|
| 33 | }
|
|---|
| 34 | }
|
|---|
| 35 | async function getAllFilesWithExistingSuppressionsForCwdAsync(normalizedCwd) {
|
|---|
| 36 | const { jsonObject: bulkSuppressionsConfigJson } = (0, bulk_suppressions_file_1.getSuppressionsConfigForEslintConfigFolderPath)(normalizedCwd);
|
|---|
| 37 | const allFiles = new Set();
|
|---|
| 38 | for (const { file: filePath } of bulkSuppressionsConfigJson.suppressions) {
|
|---|
| 39 | allFiles.add(filePath);
|
|---|
| 40 | }
|
|---|
| 41 | const allFilesArray = Array.from(allFiles);
|
|---|
| 42 | const allExistingFiles = [];
|
|---|
| 43 | // TODO: limit parallelism here with something similar to `Async.forEachAsync` from `node-core-library`.
|
|---|
| 44 | await Promise.all(allFilesArray.map(async (filePath) => {
|
|---|
| 45 | try {
|
|---|
| 46 | await node_fs_1.default.promises.access(filePath, node_fs_1.default.constants.F_OK);
|
|---|
| 47 | allExistingFiles.push(filePath);
|
|---|
| 48 | }
|
|---|
| 49 | catch (_a) {
|
|---|
| 50 | // Doesn't exist - ignore
|
|---|
| 51 | }
|
|---|
| 52 | }));
|
|---|
| 53 | console.log(`Found ${allExistingFiles.length} files with existing suppressions.`);
|
|---|
| 54 | const deletedCount = allFilesArray.length - allExistingFiles.length;
|
|---|
| 55 | if (deletedCount > 0) {
|
|---|
| 56 | console.log(`${deletedCount} files with suppressions were deleted.`);
|
|---|
| 57 | }
|
|---|
| 58 | return allExistingFiles;
|
|---|
| 59 | }
|
|---|
| 60 | //# sourceMappingURL=prune.js.map |
|---|