source: frontend/node_modules/@rushstack/eslint-patch/lib-esm/eslint-bulk-suppressions/cli/suppress.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.7 KB
Line 
1// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2// See LICENSE in the project root for license information.
3import { printSuppressHelp } from './utils/print-help';
4import { runEslintAsync } from './runEslint';
5import { ESLINT_BULK_SUPPRESS_ENV_VAR_NAME } from '../constants';
6export async function suppressAsync() {
7 const args = process.argv.slice(3);
8 if (args.includes('--help') || args.includes('-h')) {
9 printSuppressHelp();
10 process.exit(0);
11 }
12 // Use reduce to create an object with all the parsed arguments
13 const parsedArgs = args.reduce((acc, arg, index, arr) => {
14 if (arg === '--rule') {
15 // continue because next arg should be the rule
16 }
17 else if (index > 0 && arr[index - 1] === '--rule' && arr[index + 1]) {
18 acc.rules.push(arg);
19 }
20 else if (arg === '--all') {
21 acc.all = true;
22 }
23 else if (arg.startsWith('--')) {
24 throw new Error(`@rushstack/eslint-bulk: Unknown option: ${arg}`);
25 }
26 else {
27 acc.files.push(arg);
28 }
29 return acc;
30 }, { rules: [], all: false, files: [] });
31 if (parsedArgs.files.length === 0) {
32 throw new Error('@rushstack/eslint-bulk: Files argument is required. Use glob patterns to specify files or use ' +
33 '`.` to suppress all files for the specified rules.');
34 }
35 if (parsedArgs.rules.length === 0 && !parsedArgs.all) {
36 throw new Error('@rushstack/eslint-bulk: Please specify at least one rule to suppress. Use --all to suppress all rules.');
37 }
38 // Find the index of the last argument that starts with '--'
39 const lastOptionIndex = args
40 .map((arg, i) => (arg.startsWith('--') ? i : -1))
41 .reduce((lastIndex, currentIndex) => Math.max(lastIndex, currentIndex), -1);
42 // Check if options come before files
43 if (parsedArgs.files.some((file) => args.indexOf(file) < lastOptionIndex)) {
44 throw new Error('@rushstack/eslint-bulk: Unable to parse command line arguments. All options should come before files argument.');
45 }
46 if (parsedArgs.all) {
47 process.env[ESLINT_BULK_SUPPRESS_ENV_VAR_NAME] = '*';
48 }
49 else if (parsedArgs.rules.length > 0) {
50 process.env[ESLINT_BULK_SUPPRESS_ENV_VAR_NAME] = parsedArgs.rules.join(',');
51 }
52 await runEslintAsync(parsedArgs.files, 'suppress');
53 if (parsedArgs.all) {
54 console.log(`@rushstack/eslint-bulk: Successfully suppressed all rules for file(s) ${parsedArgs.files}`);
55 }
56 else if (parsedArgs.rules.length > 0) {
57 console.log(`@rushstack/eslint-bulk: Successfully suppressed rules ${parsedArgs.rules} for file(s) ${parsedArgs.files}`);
58 }
59}
60//# sourceMappingURL=suppress.js.map
Note: See TracBrowser for help on using the repository browser.