eslint-interactive 9.0.0 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/action/convert-error-to-warning-per-file.d.ts +6 -0
- package/dist/action/convert-error-to-warning-per-file.d.ts.map +1 -0
- package/dist/action/convert-error-to-warning-per-file.js +8 -0
- package/dist/action/convert-error-to-warning-per-file.js.map +1 -0
- package/dist/action/index.d.ts +1 -0
- package/dist/action/index.d.ts.map +1 -1
- package/dist/action/index.js +1 -0
- package/dist/action/index.js.map +1 -1
- package/dist/cli/parse-argv.d.ts.map +1 -1
- package/dist/cli/parse-argv.js +6 -0
- package/dist/cli/parse-argv.js.map +1 -1
- package/dist/cli/prompt.d.ts +2 -2
- package/dist/cli/prompt.d.ts.map +1 -1
- package/dist/cli/prompt.js +3 -2
- package/dist/cli/prompt.js.map +1 -1
- package/dist/core-worker.d.ts +1 -0
- package/dist/core-worker.d.ts.map +1 -1
- package/dist/core-worker.js +3 -0
- package/dist/core-worker.js.map +1 -1
- package/dist/core.d.ts +9 -0
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +14 -5
- package/dist/core.js.map +1 -1
- package/dist/formatter/format-by-rules.d.ts.map +1 -1
- package/dist/formatter/format-by-rules.js +1 -4
- package/dist/formatter/format-by-rules.js.map +1 -1
- package/dist/plugin/fix/convert-error-to-warning-per-file.d.ts +10 -0
- package/dist/plugin/fix/convert-error-to-warning-per-file.d.ts.map +1 -0
- package/dist/plugin/fix/convert-error-to-warning-per-file.js +29 -0
- package/dist/plugin/fix/convert-error-to-warning-per-file.js.map +1 -0
- package/dist/plugin/fix/index.d.ts +1 -0
- package/dist/plugin/fix/index.d.ts.map +1 -1
- package/dist/plugin/fix/index.js +1 -0
- package/dist/plugin/fix/index.js.map +1 -1
- package/dist/plugin/fix-rule.d.ts.map +1 -1
- package/dist/plugin/fix-rule.js +4 -1
- package/dist/plugin/fix-rule.js.map +1 -1
- package/dist/plugin/index.d.ts +6 -3
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js.map +1 -1
- package/dist/scene/select-action.d.ts.map +1 -1
- package/dist/scene/select-action.js +5 -1
- package/dist/scene/select-action.js.map +1 -1
- package/dist/tsconfig.src.tsbuildinfo +1 -1
- package/dist/util/cache.d.ts.map +1 -1
- package/dist/util/cache.js +1 -4
- package/dist/util/cache.js.map +1 -1
- package/dist/util/eslint.d.ts +10 -1
- package/dist/util/eslint.d.ts.map +1 -1
- package/dist/util/eslint.js +18 -0
- package/dist/util/eslint.js.map +1 -1
- package/package.json +40 -28
- package/src/action/convert-error-to-warning-per-file.ts +18 -0
- package/src/action/index.ts +1 -0
- package/src/cli/parse-argv.ts +6 -0
- package/src/cli/prompt.ts +4 -2
- package/src/core-worker.ts +5 -0
- package/src/core.ts +19 -3
- package/src/formatter/format-by-rules.ts +1 -2
- package/src/index.ts +0 -0
- package/src/plugin/fix/convert-error-to-warning-per-file.ts +45 -0
- package/src/plugin/fix/index.ts +4 -0
- package/src/plugin/fix-rule.ts +3 -0
- package/src/plugin/index.ts +11 -1
- package/src/scene/select-action.ts +4 -0
- package/src/typings/cachedir.d.ts +2 -1
- package/src/util/cache.ts +1 -2
- package/src/util/eslint.ts +25 -1
package/src/core.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
3
|
import { ESLint } from 'eslint';
|
|
4
|
-
|
|
5
|
-
import isInstalledGlobally = require('is-installed-globally');
|
|
4
|
+
import isInstalledGlobally from 'is-installed-globally';
|
|
6
5
|
import { format } from './formatter/index.js';
|
|
7
6
|
import {
|
|
8
7
|
eslintInteractivePlugin,
|
|
@@ -56,6 +55,7 @@ export type Config = {
|
|
|
56
55
|
rulePaths?: string[] | undefined;
|
|
57
56
|
extensions?: string[] | undefined;
|
|
58
57
|
formatterName?: string;
|
|
58
|
+
quiet?: boolean;
|
|
59
59
|
cache?: boolean;
|
|
60
60
|
cacheLocation?: string;
|
|
61
61
|
cwd?: string;
|
|
@@ -66,6 +66,7 @@ export const DEFAULT_BASE_CONFIG = {
|
|
|
66
66
|
cache: true,
|
|
67
67
|
cacheLocation: join(getCacheDir(), '.eslintcache'),
|
|
68
68
|
formatterName: 'codeframe',
|
|
69
|
+
quiet: false,
|
|
69
70
|
};
|
|
70
71
|
|
|
71
72
|
/**
|
|
@@ -94,7 +95,8 @@ export class Core {
|
|
|
94
95
|
*/
|
|
95
96
|
async lint(): Promise<ESLint.LintResult[]> {
|
|
96
97
|
const eslint = new ESLint(this.baseOptions);
|
|
97
|
-
|
|
98
|
+
let results = await eslint.lintFiles(this.config.patterns);
|
|
99
|
+
if (this.config.quiet) results = ESLint.getErrorResults(results);
|
|
98
100
|
return results;
|
|
99
101
|
}
|
|
100
102
|
|
|
@@ -173,6 +175,20 @@ export class Core {
|
|
|
173
175
|
return await this.fix(results, ruleIds, { name: 'disablePerFile', args: { description } });
|
|
174
176
|
}
|
|
175
177
|
|
|
178
|
+
/**
|
|
179
|
+
* Convert error to warning per file.
|
|
180
|
+
* @param results The lint results of the project to convert
|
|
181
|
+
* @param ruleIds The rule ids to convert
|
|
182
|
+
* @param description The comment explaining the reason for converting
|
|
183
|
+
*/
|
|
184
|
+
async convertErrorToWarningPerFile(
|
|
185
|
+
results: ESLint.LintResult[],
|
|
186
|
+
ruleIds: string[],
|
|
187
|
+
description?: string,
|
|
188
|
+
): Promise<Undo> {
|
|
189
|
+
return await this.fix(results, ruleIds, { name: 'convertErrorToWarningPerFile', args: { description } });
|
|
190
|
+
}
|
|
191
|
+
|
|
176
192
|
/**
|
|
177
193
|
* Apply suggestions.
|
|
178
194
|
* @param results The lint results of the project to apply suggestions
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { ESLint } from 'eslint';
|
|
3
|
-
|
|
4
|
-
import table = require('table');
|
|
3
|
+
import table from 'table';
|
|
5
4
|
import terminalLink from 'terminal-link';
|
|
6
5
|
import { ERROR_COLOR } from './colors.js';
|
|
7
6
|
import { takeRuleStatistics } from './take-rule-statistics.js';
|
package/src/index.ts
CHANGED
|
File without changes
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Rule, Linter } from 'eslint';
|
|
2
|
+
import { unique } from '../../util/array.js';
|
|
3
|
+
import { findShebang, toInlineConfigCommentText } from '../../util/eslint.js';
|
|
4
|
+
import { notEmpty } from '../../util/type-check.js';
|
|
5
|
+
import { FixContext } from '../index.js';
|
|
6
|
+
|
|
7
|
+
export type FixToConvertErrorToWarningPerFileArgs = {
|
|
8
|
+
description?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function generateFix(context: FixContext, description?: string): Rule.Fix | null {
|
|
12
|
+
const ruleIdsToConverting = unique(
|
|
13
|
+
context.messages
|
|
14
|
+
// Ignore warnings
|
|
15
|
+
.filter((message) => message.severity === 2)
|
|
16
|
+
.map((message) => message.ruleId)
|
|
17
|
+
.filter(notEmpty),
|
|
18
|
+
);
|
|
19
|
+
if (ruleIdsToConverting.length === 0) return null;
|
|
20
|
+
|
|
21
|
+
const rulesRecordToConverting: Partial<Linter.RulesRecord> = Object.fromEntries(
|
|
22
|
+
ruleIdsToConverting.map((ruleId) => [ruleId, 1]),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// Insert the inline config comment at the top of the file.
|
|
26
|
+
// NOTE: Merging settings into an existing inline config comment is intentionally avoided
|
|
27
|
+
// because of the complexity of the implementation.
|
|
28
|
+
|
|
29
|
+
const text = toInlineConfigCommentText({ rulesRecord: rulesRecordToConverting, description }) + '\n';
|
|
30
|
+
|
|
31
|
+
const shebang = findShebang(context.sourceCode.text);
|
|
32
|
+
// if shebang exists, insert comment after shebang
|
|
33
|
+
return context.fixer.insertTextAfterRange(shebang?.range ?? [0, 0], text);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create fix to convert error to warning per file.
|
|
38
|
+
*/
|
|
39
|
+
export function createFixToConvertErrorToWarningPerFile(
|
|
40
|
+
context: FixContext,
|
|
41
|
+
args: FixToConvertErrorToWarningPerFileArgs,
|
|
42
|
+
): Rule.Fix[] {
|
|
43
|
+
const fix = generateFix(context, args.description);
|
|
44
|
+
return fix ? [fix] : [];
|
|
45
|
+
}
|
package/src/plugin/fix/index.ts
CHANGED
|
@@ -6,6 +6,10 @@ export {
|
|
|
6
6
|
export { type FixToApplyAutoFixesArgs, createFixToApplyAutoFixes } from './apply-auto-fixes.js';
|
|
7
7
|
export { type FixToDisablePerFileArgs, createFixToDisablePerFile } from './disable-per-file.js';
|
|
8
8
|
export { type FixToDisablePerLineArgs, createFixToDisablePerLine } from './disable-per-line.js';
|
|
9
|
+
export {
|
|
10
|
+
type FixToConvertErrorToWarningPerFileArgs,
|
|
11
|
+
createFixToConvertErrorToWarningPerFile,
|
|
12
|
+
} from './convert-error-to-warning-per-file.js';
|
|
9
13
|
export {
|
|
10
14
|
type FixableMaker,
|
|
11
15
|
type FixToMakeFixableAndFixArgs,
|
package/src/plugin/fix-rule.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ESLint, Rule } from 'eslint';
|
|
|
2
2
|
import {
|
|
3
3
|
createFixToApplyAutoFixes,
|
|
4
4
|
createFixToApplySuggestions,
|
|
5
|
+
createFixToConvertErrorToWarningPerFile,
|
|
5
6
|
createFixToDisablePerFile,
|
|
6
7
|
createFixToDisablePerLine,
|
|
7
8
|
createFixToMakeFixableAndFix,
|
|
@@ -53,6 +54,8 @@ function createFixes(context: Rule.RuleContext, ruleOption: FixRuleOption, fixer
|
|
|
53
54
|
fixes = createFixToDisablePerLine(fixContext, fix.args);
|
|
54
55
|
} else if (fix.name === 'disablePerFile') {
|
|
55
56
|
fixes = createFixToDisablePerFile(fixContext, fix.args);
|
|
57
|
+
} else if (fix.name === 'convertErrorToWarningPerFile') {
|
|
58
|
+
fixes = createFixToConvertErrorToWarningPerFile(fixContext, fix.args);
|
|
56
59
|
} else if (fix.name === 'applySuggestions') {
|
|
57
60
|
fixes = createFixToApplySuggestions(fixContext, fix.args);
|
|
58
61
|
} else if (fix.name === 'makeFixableAndFix') {
|
package/src/plugin/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
type FixToDisablePerLineArgs,
|
|
9
9
|
type FixToMakeFixableAndFixArgs,
|
|
10
10
|
type FixToApplyAutoFixesArgs,
|
|
11
|
+
FixToConvertErrorToWarningPerFileArgs,
|
|
11
12
|
} from './fix/index.js';
|
|
12
13
|
import { preferAdditionShorthandRule } from './prefer-addition-shorthand-rule.js';
|
|
13
14
|
|
|
@@ -30,11 +31,18 @@ export type Fix =
|
|
|
30
31
|
| { name: 'applyAutoFixes'; args: FixArg<'applyAutoFixes'> }
|
|
31
32
|
| { name: 'disablePerLine'; args: FixArg<'disablePerLine'> }
|
|
32
33
|
| { name: 'disablePerFile'; args: FixArg<'disablePerFile'> }
|
|
34
|
+
| { name: 'convertErrorToWarningPerFile'; args: FixArg<'convertErrorToWarningPerFile'> }
|
|
33
35
|
| { name: 'applySuggestions'; args: FixArg<'applySuggestions'> }
|
|
34
36
|
| { name: 'makeFixableAndFix'; args: FixArg<'makeFixableAndFix'> };
|
|
35
37
|
|
|
36
38
|
/** For test */
|
|
37
|
-
export type FixName =
|
|
39
|
+
export type FixName =
|
|
40
|
+
| 'applyAutoFixes'
|
|
41
|
+
| 'disablePerLine'
|
|
42
|
+
| 'disablePerFile'
|
|
43
|
+
| 'convertErrorToWarningPerFile'
|
|
44
|
+
| 'applySuggestions'
|
|
45
|
+
| 'makeFixableAndFix';
|
|
38
46
|
|
|
39
47
|
/** For test */
|
|
40
48
|
export type FixArg<T extends FixName> = T extends 'applyAutoFixes'
|
|
@@ -43,6 +51,8 @@ export type FixArg<T extends FixName> = T extends 'applyAutoFixes'
|
|
|
43
51
|
? FixToDisablePerLineArgs
|
|
44
52
|
: T extends 'disablePerFile'
|
|
45
53
|
? FixToDisablePerFileArgs
|
|
54
|
+
: T extends 'convertErrorToWarningPerFile'
|
|
55
|
+
? FixToConvertErrorToWarningPerFileArgs
|
|
46
56
|
: T extends 'applySuggestions'
|
|
47
57
|
? FixToApplySuggestionsArgs
|
|
48
58
|
: T extends 'makeFixableAndFix'
|
|
@@ -2,6 +2,7 @@ import { Remote } from 'comlink';
|
|
|
2
2
|
import { ESLint } from 'eslint';
|
|
3
3
|
import {
|
|
4
4
|
doApplySuggestionsAction,
|
|
5
|
+
doConvertErrorToWarningPerFileAction,
|
|
5
6
|
doDisablePerFileAction,
|
|
6
7
|
doDisablePerLineAction,
|
|
7
8
|
doFixAction,
|
|
@@ -58,6 +59,9 @@ export async function selectAction(
|
|
|
58
59
|
} else if (selectedAction === 'disablePerFile') {
|
|
59
60
|
const undo = await doDisablePerFileAction(core, results, selectedRuleIds);
|
|
60
61
|
return createCheckResultsScene(undo);
|
|
62
|
+
} else if (selectedAction === 'convertErrorToWarningPerFile') {
|
|
63
|
+
const undo = await doConvertErrorToWarningPerFileAction(core, results, selectedRuleIds);
|
|
64
|
+
return createCheckResultsScene(undo);
|
|
61
65
|
} else if (selectedAction === 'applySuggestions') {
|
|
62
66
|
const undo = await doApplySuggestionsAction(core, results, selectedRuleIds);
|
|
63
67
|
return createCheckResultsScene(undo);
|
package/src/util/cache.ts
CHANGED
package/src/util/eslint.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AST, ESLint } from 'eslint';
|
|
1
|
+
import { AST, ESLint, Linter } from 'eslint';
|
|
2
2
|
import type { Comment } from 'estree';
|
|
3
3
|
import { unique } from './array.js';
|
|
4
4
|
import { notEmpty } from './type-check.js';
|
|
@@ -97,6 +97,30 @@ export function toCommentText({ type, scope, ruleIds, description }: Omit<Disabl
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
export type InlineConfigComment = {
|
|
101
|
+
description?: string;
|
|
102
|
+
rulesRecord: Partial<Linter.RulesRecord>;
|
|
103
|
+
range: [number, number];
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Convert `InlineConfigComment` to comment text.
|
|
108
|
+
*/
|
|
109
|
+
export function toInlineConfigCommentText({ rulesRecord, description }: Omit<InlineConfigComment, 'range'>): string {
|
|
110
|
+
const header = 'eslint';
|
|
111
|
+
const rulesRecordText = Object.entries(rulesRecord)
|
|
112
|
+
.map(([ruleId, ruleEntry]) => {
|
|
113
|
+
// TODO: Inherit options of the rule set by the user in eslintrc if the option exists.
|
|
114
|
+
return `${ruleId}: ${JSON.stringify(ruleEntry)}`;
|
|
115
|
+
})
|
|
116
|
+
.join(', ');
|
|
117
|
+
if (description === undefined) {
|
|
118
|
+
return `/* ${header} ${rulesRecordText} */`;
|
|
119
|
+
} else {
|
|
120
|
+
return `/* ${header} ${rulesRecordText} -- ${description} */`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
100
124
|
/**
|
|
101
125
|
* Create the results with only messages with the specified rule ids.
|
|
102
126
|
* @param results The lint results.
|