File size: 2,764 Bytes
cc651f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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.deleteBulkSuppressionsFileInEslintrcFolder)(normalizedCwd);
    }
}
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