eslint-interactive 13.0.0 → 14.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 +19 -10
- package/dist/action/convert-error-to-warning-per-file.d.ts +4 -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/disable-per-file.d.ts +4 -0
- package/dist/action/disable-per-file.d.ts.map +1 -0
- package/dist/action/disable-per-file.js +12 -0
- package/dist/action/disable-per-file.js.map +1 -0
- package/dist/action/disable-per-line.d.ts +4 -0
- package/dist/action/disable-per-line.d.ts.map +1 -0
- package/dist/action/disable-per-line.js +12 -0
- package/dist/action/disable-per-line.js.map +1 -0
- package/dist/action/fix.d.ts +4 -0
- package/dist/action/fix.d.ts.map +1 -0
- package/dist/action/fix.js +6 -0
- package/dist/action/fix.js.map +1 -0
- package/dist/action/index.d.ts +6 -0
- package/dist/action/index.d.ts.map +1 -0
- package/dist/action/index.js +6 -0
- package/dist/action/index.js.map +1 -0
- package/dist/action/print-result-details.d.ts +4 -0
- package/dist/action/print-result-details.d.ts.map +1 -0
- package/dist/action/print-result-details.js +36 -0
- package/dist/action/print-result-details.js.map +1 -0
- package/dist/cli/log.d.ts +7 -0
- package/dist/cli/log.d.ts.map +1 -0
- package/dist/cli/log.js +35 -0
- package/dist/cli/log.js.map +1 -0
- package/dist/cli/package.d.ts +2 -0
- package/dist/cli/package.d.ts.map +1 -0
- package/dist/cli/package.js +6 -0
- package/dist/cli/package.js.map +1 -0
- package/dist/cli/pager.d.ts +2 -0
- package/dist/cli/pager.d.ts.map +1 -0
- package/dist/cli/pager.js +34 -0
- package/dist/cli/pager.js.map +1 -0
- package/dist/cli/parse-argv.d.ts +4 -0
- package/dist/cli/parse-argv.d.ts.map +1 -0
- package/dist/cli/parse-argv.js +103 -0
- package/dist/cli/parse-argv.js.map +1 -0
- package/dist/cli/prompt.d.ts +51 -0
- package/dist/cli/prompt.d.ts.map +1 -0
- package/dist/cli/prompt.js +97 -0
- package/dist/cli/prompt.js.map +1 -0
- package/dist/cli/run.d.ts +6 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +28 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/core.d.ts +82 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +189 -0
- package/dist/core.js.map +1 -0
- package/dist/eslint/linter.d.ts +18 -0
- package/dist/eslint/linter.d.ts.map +1 -0
- package/dist/eslint/linter.js +71 -0
- package/dist/eslint/linter.js.map +1 -0
- package/dist/eslint/report-translator.d.ts +9 -0
- package/dist/eslint/report-translator.d.ts.map +1 -0
- package/dist/eslint/report-translator.js +75 -0
- package/dist/eslint/report-translator.js.map +1 -0
- package/dist/eslint/rule-fixer.d.ts +80 -0
- package/dist/eslint/rule-fixer.d.ts.map +1 -0
- package/dist/eslint/rule-fixer.js +114 -0
- package/dist/eslint/rule-fixer.js.map +1 -0
- package/dist/eslint/source-code-fixer.d.ts +15 -0
- package/dist/eslint/source-code-fixer.d.ts.map +1 -0
- package/dist/eslint/source-code-fixer.js +131 -0
- package/dist/eslint/source-code-fixer.js.map +1 -0
- package/dist/fix/apply-auto-fixes.d.ts +8 -0
- package/dist/fix/apply-auto-fixes.d.ts.map +1 -0
- package/dist/fix/apply-auto-fixes.js +8 -0
- package/dist/fix/apply-auto-fixes.js.map +1 -0
- package/dist/fix/apply-suggestions.d.ts +11 -0
- package/dist/fix/apply-suggestions.d.ts.map +1 -0
- package/dist/fix/apply-suggestions.js +25 -0
- package/dist/fix/apply-suggestions.js.map +1 -0
- package/dist/fix/convert-error-to-warning-per-file.d.ts +10 -0
- package/dist/fix/convert-error-to-warning-per-file.d.ts.map +1 -0
- package/dist/fix/convert-error-to-warning-per-file.js +28 -0
- package/dist/fix/convert-error-to-warning-per-file.js.map +1 -0
- package/dist/fix/disable-per-file.d.ts +12 -0
- package/dist/fix/disable-per-file.d.ts.map +1 -0
- package/dist/fix/disable-per-file.js +63 -0
- package/dist/fix/disable-per-file.js.map +1 -0
- package/dist/fix/disable-per-line.d.ts +12 -0
- package/dist/fix/disable-per-line.d.ts.map +1 -0
- package/dist/fix/disable-per-line.js +72 -0
- package/dist/fix/disable-per-line.js.map +1 -0
- package/dist/fix/index.d.ts +19 -0
- package/dist/fix/index.d.ts.map +1 -0
- package/dist/fix/index.js +8 -0
- package/dist/fix/index.js.map +1 -0
- package/dist/fix/make-fixable-and-fix.d.ts +11 -0
- package/dist/fix/make-fixable-and-fix.d.ts.map +1 -0
- package/dist/fix/make-fixable-and-fix.js +35 -0
- package/dist/fix/make-fixable-and-fix.js.map +1 -0
- package/dist/formatter/colors.d.ts +4 -0
- package/dist/formatter/colors.d.ts.map +1 -0
- package/dist/formatter/colors.js +5 -0
- package/dist/formatter/colors.js.map +1 -0
- package/dist/formatter/filter-rule-statistics.d.ts +9 -0
- package/dist/formatter/filter-rule-statistics.d.ts.map +1 -0
- package/dist/formatter/filter-rule-statistics.js +22 -0
- package/dist/formatter/filter-rule-statistics.js.map +1 -0
- package/dist/formatter/format-by-files.d.ts +3 -0
- package/dist/formatter/format-by-files.d.ts.map +1 -0
- package/dist/formatter/format-by-files.js +42 -0
- package/dist/formatter/format-by-files.js.map +1 -0
- package/dist/formatter/format-by-rules.d.ts +9 -0
- package/dist/formatter/format-by-rules.d.ts.map +1 -0
- package/dist/formatter/format-by-rules.js +33 -0
- package/dist/formatter/format-by-rules.js.map +1 -0
- package/dist/formatter/format-table.d.ts +4 -0
- package/dist/formatter/format-table.d.ts.map +1 -0
- package/dist/formatter/format-table.js +62 -0
- package/dist/formatter/format-table.js.map +1 -0
- package/dist/formatter/index.d.ts +7 -0
- package/dist/formatter/index.d.ts.map +1 -0
- package/dist/formatter/index.js +9 -0
- package/dist/formatter/index.js.map +1 -0
- package/dist/formatter/sort-rule-statistics.d.ts +5 -0
- package/dist/formatter/sort-rule-statistics.d.ts.map +1 -0
- package/dist/formatter/sort-rule-statistics.js +34 -0
- package/dist/formatter/sort-rule-statistics.js.map +1 -0
- package/dist/formatter/take-rule-statistics.d.ts +18 -0
- package/dist/formatter/take-rule-statistics.d.ts.map +1 -0
- package/dist/formatter/take-rule-statistics.js +51 -0
- package/dist/formatter/take-rule-statistics.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +4 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +87 -0
- package/dist/plugin.js.map +1 -0
- package/dist/scene/check-results.d.ts +21 -0
- package/dist/scene/check-results.d.ts.map +1 -0
- package/dist/scene/check-results.js +19 -0
- package/dist/scene/check-results.js.map +1 -0
- package/dist/scene/index.d.ts +25 -0
- package/dist/scene/index.d.ts.map +1 -0
- package/dist/scene/index.js +6 -0
- package/dist/scene/index.js.map +1 -0
- package/dist/scene/lint.d.ts +7 -0
- package/dist/scene/lint.d.ts.map +1 -0
- package/dist/scene/lint.js +34 -0
- package/dist/scene/lint.js.map +1 -0
- package/dist/scene/select-action.d.ts +19 -0
- package/dist/scene/select-action.d.ts.map +1 -0
- package/dist/scene/select-action.js +44 -0
- package/dist/scene/select-action.js.map +1 -0
- package/dist/scene/select-rule-ids.d.ts +14 -0
- package/dist/scene/select-rule-ids.d.ts.map +1 -0
- package/dist/scene/select-rule-ids.js +10 -0
- package/dist/scene/select-rule-ids.js.map +1 -0
- package/dist/type.d.ts +14 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js +2 -0
- package/dist/type.js.map +1 -0
- package/dist/util/array.d.ts +3 -0
- package/dist/util/array.d.ts.map +1 -0
- package/dist/util/array.js +14 -0
- package/dist/util/array.js.map +1 -0
- package/dist/util/eslint.d.ts +103 -0
- package/dist/util/eslint.d.ts.map +1 -0
- package/dist/util/eslint.js +220 -0
- package/dist/util/eslint.js.map +1 -0
- package/dist/util/terminal-link.d.ts +2 -0
- package/dist/util/terminal-link.d.ts.map +1 -0
- package/dist/util/terminal-link.js +16 -0
- package/dist/util/terminal-link.js.map +1 -0
- package/dist/util/type-check.d.ts +3 -0
- package/dist/util/type-check.d.ts.map +1 -0
- package/dist/util/type-check.js +8 -0
- package/dist/util/type-check.js.map +1 -0
- package/package.json +22 -24
- package/src/action/convert-error-to-warning-per-file.ts +4 -6
- package/src/action/disable-per-file.ts +4 -6
- package/src/action/disable-per-line.ts +4 -6
- package/src/action/fix.ts +4 -10
- package/src/action/print-result-details.ts +5 -9
- package/src/cli/log.ts +25 -0
- package/src/cli/parse-argv.ts +32 -11
- package/src/cli/prompt.ts +56 -92
- package/src/cli/run.ts +3 -29
- package/src/core.ts +13 -6
- package/src/fix/disable-per-file.ts +1 -1
- package/src/fix/disable-per-line.ts +1 -1
- package/src/formatter/filter-rule-statistics.ts +27 -0
- package/src/formatter/format-by-rules.ts +10 -7
- package/src/formatter/index.ts +4 -3
- package/src/index.ts +1 -1
- package/src/scene/check-results.ts +2 -5
- package/src/scene/lint.ts +14 -12
- package/src/scene/select-action.ts +2 -4
- package/src/scene/select-rule-ids.ts +2 -6
- package/src/type.ts +2 -0
- package/src/util/terminal-link.ts +16 -0
- package/src/cli/spinner.ts +0 -22
- package/src/core-worker.ts +0 -55
- package/src/typings/enquirer.d.ts +0 -7
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/* istanbul ignore file */
|
|
2
|
+
import { isCancel, multiselect, select, text } from '@clack/prompts';
|
|
3
|
+
import { takeRuleStatistics } from '../formatter/index.js';
|
|
4
|
+
function exitIfCancel(value) {
|
|
5
|
+
if (isCancel(value)) {
|
|
6
|
+
// eslint-disable-next-line n/no-process-exit
|
|
7
|
+
process.exit();
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Ask the user for the rule ids to which they want to apply the action.
|
|
13
|
+
* @param ruleIdsInResults The rule ids that are in the lint results.
|
|
14
|
+
* @returns The rule ids
|
|
15
|
+
*/
|
|
16
|
+
export async function promptToInputRuleIds(ruleIdsInResults) {
|
|
17
|
+
return exitIfCancel(await multiselect({
|
|
18
|
+
message: 'Which rules would you like to apply action?',
|
|
19
|
+
options: ruleIdsInResults.map((ruleId) => ({ value: ruleId })),
|
|
20
|
+
required: true,
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Ask the user what action they want to perform.
|
|
25
|
+
* @returns The action name
|
|
26
|
+
*/
|
|
27
|
+
export async function promptToInputAction(results, selectedRuleIds, initialAction) {
|
|
28
|
+
const ruleStatistics = takeRuleStatistics(results).filter((ruleStatistic) => selectedRuleIds.includes(ruleStatistic.ruleId));
|
|
29
|
+
const foldedStatistics = ruleStatistics.reduce((a, b) => ({
|
|
30
|
+
isFixableCount: a.isFixableCount + b.isFixableCount,
|
|
31
|
+
}), { isFixableCount: 0 });
|
|
32
|
+
return exitIfCancel(await select({
|
|
33
|
+
message: 'Which action do you want to do?',
|
|
34
|
+
options: [
|
|
35
|
+
{ value: 'printResultDetails', label: '🔎 Display details of lint results' },
|
|
36
|
+
{ value: 'applyAutoFixes', label: '🔧 Run `eslint --fix`', disabled: foldedStatistics.isFixableCount === 0 },
|
|
37
|
+
{ value: 'disablePerLine', label: '🔧 Disable per line' },
|
|
38
|
+
{ value: 'disablePerFile', label: '🔧 Disable per file' },
|
|
39
|
+
{ value: 'convertErrorToWarningPerFile', label: '🔧 Convert error to warning per file' },
|
|
40
|
+
{ value: 'relintAndReselectRules', label: '↩️ Go back (with re-lint)' },
|
|
41
|
+
{ value: 'reselectRules', label: '↩️ Go back' },
|
|
42
|
+
],
|
|
43
|
+
initialValue: initialAction,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Ask the user how to display the lint results.
|
|
48
|
+
* @returns How to display
|
|
49
|
+
*/
|
|
50
|
+
export async function promptToInputDisplayMode() {
|
|
51
|
+
return exitIfCancel(await select({
|
|
52
|
+
message: 'In what way are the details displayed?',
|
|
53
|
+
options: [
|
|
54
|
+
{ value: 'printInTerminal', label: '🖨 Print in terminal' },
|
|
55
|
+
{ value: 'printInTerminalWithPager', label: '↕️ Print in terminal with pager' },
|
|
56
|
+
{ value: 'writeToFile', label: '📝 Write to file' },
|
|
57
|
+
],
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Ask the user a description to leave in directive.
|
|
62
|
+
* @returns The description
|
|
63
|
+
*/
|
|
64
|
+
export async function promptToInputDescription() {
|
|
65
|
+
const description = exitIfCancel(await text({
|
|
66
|
+
message: 'Leave a code comment with your reason for fixing (Optional)',
|
|
67
|
+
}));
|
|
68
|
+
return description.trim() === '' ? undefined : description.trim();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Ask the user a position of the description
|
|
72
|
+
* @returns The description position
|
|
73
|
+
*/
|
|
74
|
+
export async function promptToInputDescriptionPosition() {
|
|
75
|
+
return exitIfCancel(await select({
|
|
76
|
+
message: 'Where would you like to position the code comment?',
|
|
77
|
+
options: [
|
|
78
|
+
{ value: 'sameLine', label: "Same Line - Place on the same line as the eslint's disable comment." },
|
|
79
|
+
{ value: 'previousLine', label: "Previous Line - Place on the line before the eslint's disable comment." },
|
|
80
|
+
],
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Ask the user what to do next.
|
|
85
|
+
* @returns What to do next.
|
|
86
|
+
*/
|
|
87
|
+
export async function promptToInputWhatToDoNext() {
|
|
88
|
+
return exitIfCancel(await select({
|
|
89
|
+
message: "What's the next step?",
|
|
90
|
+
options: [
|
|
91
|
+
{ value: 'fixOtherRules', label: '🔧 Fix other rules' },
|
|
92
|
+
{ value: 'undoTheFix', label: '↩️ Undo the fix' },
|
|
93
|
+
{ value: 'exit', label: '💚 Exit' },
|
|
94
|
+
],
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+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EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;AACpE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gCAAgC;IACpD,OAAO,YAAY,CACjB,MAAM,MAAM,CAAsB;QAChC,OAAO,EAAE,oDAAoD;QAC7D,OAAO,EAAE;YACP,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,qEAAqE,EAAE;YACnG,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,wEAAwE,EAAE;SAC3G;KACF,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB;IAC7C,OAAO,YAAY,CACjB,MAAM,MAAM,CAAW;QACrB,OAAO,EAAE,uBAAuB;QAChC,OAAO,EAAE;YACP,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,oBAAoB,EAAE;YACvD,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,kBAAkB,EAAE;YAClD,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE;SACpC;KACF,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/cli/run.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAEF,8BAA8B;AAC9B,wBAAsB,GAAG,CAAC,OAAO,EAAE,OAAO,iBAoBzC"}
|
package/dist/cli/run.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { parseArgv } from '../cli/parse-argv.js';
|
|
2
|
+
import { Core } from '../core.js';
|
|
3
|
+
import { checkResults, lint, selectAction, selectRuleIds } from '../scene/index.js';
|
|
4
|
+
/** Run eslint-interactive. */
|
|
5
|
+
export async function run(options) {
|
|
6
|
+
const config = parseArgv(options.argv);
|
|
7
|
+
const core = new Core(config);
|
|
8
|
+
let nextScene = { name: 'lint' };
|
|
9
|
+
while (nextScene.name !== 'exit') {
|
|
10
|
+
if (nextScene.name === 'lint') {
|
|
11
|
+
// eslint-disable-next-line no-await-in-loop
|
|
12
|
+
nextScene = await lint(core);
|
|
13
|
+
}
|
|
14
|
+
else if (nextScene.name === 'selectRuleIds') {
|
|
15
|
+
// eslint-disable-next-line no-await-in-loop
|
|
16
|
+
nextScene = await selectRuleIds(core, nextScene.args);
|
|
17
|
+
}
|
|
18
|
+
else if (nextScene.name === 'selectAction') {
|
|
19
|
+
// eslint-disable-next-line no-await-in-loop
|
|
20
|
+
nextScene = await selectAction(core, nextScene.args);
|
|
21
|
+
}
|
|
22
|
+
else if (nextScene.name === 'checkResults') {
|
|
23
|
+
// eslint-disable-next-line no-await-in-loop
|
|
24
|
+
nextScene = await checkResults(nextScene.args);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/cli/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMpF,8BAA8B;AAC9B,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,OAAgB;IACxC,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC;IAE9B,IAAI,SAAS,GAAc,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC5C,OAAO,SAAS,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACjC,IAAI,SAAS,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC9B,4CAA4C;YAC5C,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;aAAM,IAAI,SAAS,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;YAC9C,4CAA4C;YAC5C,SAAS,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QACxD,CAAC;aAAM,IAAI,SAAS,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;YAC7C,4CAA4C;YAC5C,SAAS,GAAG,MAAM,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QACvD,CAAC;aAAM,IAAI,SAAS,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;YAC7C,4CAA4C;YAC5C,SAAS,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ESLint } from 'eslint';
|
|
2
|
+
import type { DescriptionPosition } from './cli/prompt.js';
|
|
3
|
+
import type { FixableMaker, SuggestionFilter } from './fix/index.js';
|
|
4
|
+
import type { Config } from './type.js';
|
|
5
|
+
export type Undo = () => Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* The core of eslint-interactive.
|
|
8
|
+
* It uses ESLint's Node.js API to output a summary of problems, fix problems, apply suggestions, etc.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Core {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(config: Config);
|
|
13
|
+
/**
|
|
14
|
+
* Lint project.
|
|
15
|
+
* @returns The results of linting
|
|
16
|
+
*/
|
|
17
|
+
lint(): Promise<ESLint.LintResult[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Returns summary of lint results.
|
|
20
|
+
* @param results The lint results of the project to print summary
|
|
21
|
+
*/
|
|
22
|
+
formatResultSummary(results: ESLint.LintResult[]): string;
|
|
23
|
+
/**
|
|
24
|
+
* Returns ruleIds from lint results, filtered and sorted according to the configured options.
|
|
25
|
+
* @param results The lint results of the project
|
|
26
|
+
*/
|
|
27
|
+
getFilteredAndSortedRuleIds(results: ESLint.LintResult[]): string[];
|
|
28
|
+
/**
|
|
29
|
+
* Returns details of lint results.
|
|
30
|
+
* @param results The lint results of the project to print summary
|
|
31
|
+
* @param ruleIds The rule ids to print details
|
|
32
|
+
*/
|
|
33
|
+
formatResultDetails(results: ESLint.LintResult[], ruleIds: (string | null)[]): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Run `eslint --fix`.
|
|
36
|
+
* @param ruleIds The rule ids to fix
|
|
37
|
+
*/
|
|
38
|
+
applyAutoFixes(results: ESLint.LintResult[], ruleIds: string[]): Promise<Undo>;
|
|
39
|
+
/**
|
|
40
|
+
* Add disable comments per line.
|
|
41
|
+
* @param results The lint results of the project to add disable comments
|
|
42
|
+
* @param ruleIds The rule ids to add disable comments
|
|
43
|
+
* @param description The description of the disable comments
|
|
44
|
+
* @param descriptionPosition The position of the description
|
|
45
|
+
*/
|
|
46
|
+
disablePerLine(results: ESLint.LintResult[], ruleIds: string[], description?: string, descriptionPosition?: DescriptionPosition): Promise<Undo>;
|
|
47
|
+
/**
|
|
48
|
+
* Add disable comments per file.
|
|
49
|
+
* @param results The lint results of the project to add disable comments
|
|
50
|
+
* @param ruleIds The rule ids to add disable comments
|
|
51
|
+
* @param description The description of the disable comments
|
|
52
|
+
* @param descriptionPosition The position of the description
|
|
53
|
+
*/
|
|
54
|
+
disablePerFile(results: ESLint.LintResult[], ruleIds: string[], description?: string, descriptionPosition?: DescriptionPosition): Promise<Undo>;
|
|
55
|
+
/**
|
|
56
|
+
* Convert error to warning per file.
|
|
57
|
+
* @param results The lint results of the project to convert
|
|
58
|
+
* @param ruleIds The rule ids to convert
|
|
59
|
+
* @param description The comment explaining the reason for converting
|
|
60
|
+
*/
|
|
61
|
+
convertErrorToWarningPerFile(results: ESLint.LintResult[], ruleIds: string[], description?: string): Promise<Undo>;
|
|
62
|
+
/**
|
|
63
|
+
* Apply suggestions.
|
|
64
|
+
* @param results The lint results of the project to apply suggestions
|
|
65
|
+
* @param ruleIds The rule ids to apply suggestions
|
|
66
|
+
* @param filter The script to filter suggestions
|
|
67
|
+
*/
|
|
68
|
+
applySuggestions(results: ESLint.LintResult[], ruleIds: string[], filter: SuggestionFilter): Promise<Undo>;
|
|
69
|
+
/**
|
|
70
|
+
* Make forcibly fixable and run `eslint --fix`.
|
|
71
|
+
* @param results The lint results of the project to apply suggestions
|
|
72
|
+
* @param ruleIds The rule ids to apply suggestions
|
|
73
|
+
* @param fixableMaker The function to make `Linter.LintMessage` forcibly fixable.
|
|
74
|
+
*/
|
|
75
|
+
makeFixableAndFix(results: ESLint.LintResult[], ruleIds: string[], fixableMaker: FixableMaker): Promise<Undo>;
|
|
76
|
+
/**
|
|
77
|
+
* Fix source codes.
|
|
78
|
+
* @param fix The fix information to do.
|
|
79
|
+
*/
|
|
80
|
+
private fix;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAc,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAYjF,OAAO,KAAK,EAAE,MAAM,EAAyC,MAAM,WAAW,CAAC;AAe/E,MAAM,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvC;;;GAGG;AACH,qBAAa,IAAI;;gBAUH,MAAM,EAAE,MAAM;I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,CAAC,IAAI,CAAC;IAIhH;;;;;OAKG;IACG,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAInH;;;OAGG;YACW,GAAG;CA2BlB"}
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _Core_cwd, _Core_patterns, _Core_quiet, _Core_formatterName, _Core_sort, _Core_sortOrder, _Core_filters, _Core_eslint;
|
|
13
|
+
import { writeFile } from 'node:fs/promises';
|
|
14
|
+
import { ESLint } from 'eslint';
|
|
15
|
+
import { createFixToApplyAutoFixes, createFixToApplySuggestions, createFixToConvertErrorToWarningPerFile, createFixToDisablePerFile, createFixToDisablePerLine, createFixToMakeFixableAndFix, verifyAndFix, } from './fix/index.js';
|
|
16
|
+
import { filterRuleStatistics, format, sortRuleStatistics, takeRuleStatistics } from './formatter/index.js';
|
|
17
|
+
import { plugin } from './plugin.js';
|
|
18
|
+
import { filterResultsByRuleId } from './util/eslint.js';
|
|
19
|
+
/**
|
|
20
|
+
* Generate results to undo.
|
|
21
|
+
* @param resultsOfLint The results of lint.
|
|
22
|
+
* @returns The results to undo.
|
|
23
|
+
*/
|
|
24
|
+
function generateResultsToUndo(resultsOfLint) {
|
|
25
|
+
return resultsOfLint.map((resultOfLint) => {
|
|
26
|
+
// NOTE: THIS IS HACK.
|
|
27
|
+
return { ...resultOfLint, output: resultOfLint.source };
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The core of eslint-interactive.
|
|
32
|
+
* It uses ESLint's Node.js API to output a summary of problems, fix problems, apply suggestions, etc.
|
|
33
|
+
*/
|
|
34
|
+
export class Core {
|
|
35
|
+
constructor(config) {
|
|
36
|
+
_Core_cwd.set(this, void 0);
|
|
37
|
+
_Core_patterns.set(this, void 0);
|
|
38
|
+
_Core_quiet.set(this, void 0);
|
|
39
|
+
_Core_formatterName.set(this, void 0);
|
|
40
|
+
_Core_sort.set(this, void 0);
|
|
41
|
+
_Core_sortOrder.set(this, void 0);
|
|
42
|
+
_Core_filters.set(this, void 0);
|
|
43
|
+
_Core_eslint.set(this, void 0);
|
|
44
|
+
__classPrivateFieldSet(this, _Core_cwd, config.cwd ?? process.cwd(), "f");
|
|
45
|
+
__classPrivateFieldSet(this, _Core_patterns, config.patterns, "f");
|
|
46
|
+
__classPrivateFieldSet(this, _Core_quiet, config.quiet ?? false, "f");
|
|
47
|
+
__classPrivateFieldSet(this, _Core_formatterName, config.formatterName, "f");
|
|
48
|
+
__classPrivateFieldSet(this, _Core_sort, config.sort, "f");
|
|
49
|
+
__classPrivateFieldSet(this, _Core_sortOrder, config.sortOrder, "f");
|
|
50
|
+
__classPrivateFieldSet(this, _Core_filters, config.filters, "f");
|
|
51
|
+
// NOTE: Passing an option that does not exist to `new ESLint(...)` will throw an error.
|
|
52
|
+
// Therefore, only options supported by ESLint are extracted into the `eslintOptions` variable.
|
|
53
|
+
const { formatterName, patterns, quiet, sort, sortOrder, filters, ...eslintOptions } = config;
|
|
54
|
+
const overrideConfigs = Array.isArray(eslintOptions.overrideConfig) ? eslintOptions.overrideConfig
|
|
55
|
+
: eslintOptions.overrideConfig ? [eslintOptions.overrideConfig]
|
|
56
|
+
: [];
|
|
57
|
+
__classPrivateFieldSet(this, _Core_eslint, new ESLint({
|
|
58
|
+
...eslintOptions,
|
|
59
|
+
overrideConfig: [
|
|
60
|
+
...overrideConfigs,
|
|
61
|
+
{
|
|
62
|
+
plugins: { 'eslint-interactive': plugin },
|
|
63
|
+
rules: {
|
|
64
|
+
'eslint-interactive/source-code-snatcher': 'error',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
}), "f");
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Lint project.
|
|
72
|
+
* @returns The results of linting
|
|
73
|
+
*/
|
|
74
|
+
async lint() {
|
|
75
|
+
let results = await __classPrivateFieldGet(this, _Core_eslint, "f").lintFiles(__classPrivateFieldGet(this, _Core_patterns, "f"));
|
|
76
|
+
if (__classPrivateFieldGet(this, _Core_quiet, "f"))
|
|
77
|
+
results = ESLint.getErrorResults(results);
|
|
78
|
+
return results;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns summary of lint results.
|
|
82
|
+
* @param results The lint results of the project to print summary
|
|
83
|
+
*/
|
|
84
|
+
formatResultSummary(results) {
|
|
85
|
+
const rulesMeta = __classPrivateFieldGet(this, _Core_eslint, "f").getRulesMetaForResults(results);
|
|
86
|
+
return format(results, { rulesMeta, cwd: __classPrivateFieldGet(this, _Core_cwd, "f") }, { sort: __classPrivateFieldGet(this, _Core_sort, "f"), sortOrder: __classPrivateFieldGet(this, _Core_sortOrder, "f"), filters: __classPrivateFieldGet(this, _Core_filters, "f") });
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns ruleIds from lint results, filtered and sorted according to the configured options.
|
|
90
|
+
* @param results The lint results of the project
|
|
91
|
+
*/
|
|
92
|
+
getFilteredAndSortedRuleIds(results) {
|
|
93
|
+
let ruleStatistics = takeRuleStatistics(results);
|
|
94
|
+
ruleStatistics = filterRuleStatistics(ruleStatistics, __classPrivateFieldGet(this, _Core_filters, "f"));
|
|
95
|
+
if (__classPrivateFieldGet(this, _Core_sort, "f")) {
|
|
96
|
+
ruleStatistics = sortRuleStatistics(ruleStatistics, __classPrivateFieldGet(this, _Core_sort, "f"), __classPrivateFieldGet(this, _Core_sortOrder, "f"));
|
|
97
|
+
}
|
|
98
|
+
return ruleStatistics.map((s) => s.ruleId);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns details of lint results.
|
|
102
|
+
* @param results The lint results of the project to print summary
|
|
103
|
+
* @param ruleIds The rule ids to print details
|
|
104
|
+
*/
|
|
105
|
+
async formatResultDetails(results, ruleIds) {
|
|
106
|
+
const formatter = await __classPrivateFieldGet(this, _Core_eslint, "f").loadFormatter(__classPrivateFieldGet(this, _Core_formatterName, "f"));
|
|
107
|
+
return formatter.format(filterResultsByRuleId(results, ruleIds));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Run `eslint --fix`.
|
|
111
|
+
* @param ruleIds The rule ids to fix
|
|
112
|
+
*/
|
|
113
|
+
async applyAutoFixes(results, ruleIds) {
|
|
114
|
+
return this.fix(results, ruleIds, (context) => createFixToApplyAutoFixes(context, {}));
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Add disable comments per line.
|
|
118
|
+
* @param results The lint results of the project to add disable comments
|
|
119
|
+
* @param ruleIds The rule ids to add disable comments
|
|
120
|
+
* @param description The description of the disable comments
|
|
121
|
+
* @param descriptionPosition The position of the description
|
|
122
|
+
*/
|
|
123
|
+
async disablePerLine(results, ruleIds, description, descriptionPosition) {
|
|
124
|
+
return this.fix(results, ruleIds, (context) => createFixToDisablePerLine(context, { description, descriptionPosition }));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Add disable comments per file.
|
|
128
|
+
* @param results The lint results of the project to add disable comments
|
|
129
|
+
* @param ruleIds The rule ids to add disable comments
|
|
130
|
+
* @param description The description of the disable comments
|
|
131
|
+
* @param descriptionPosition The position of the description
|
|
132
|
+
*/
|
|
133
|
+
async disablePerFile(results, ruleIds, description, descriptionPosition) {
|
|
134
|
+
return this.fix(results, ruleIds, (context) => createFixToDisablePerFile(context, { description, descriptionPosition }));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Convert error to warning per file.
|
|
138
|
+
* @param results The lint results of the project to convert
|
|
139
|
+
* @param ruleIds The rule ids to convert
|
|
140
|
+
* @param description The comment explaining the reason for converting
|
|
141
|
+
*/
|
|
142
|
+
async convertErrorToWarningPerFile(results, ruleIds, description) {
|
|
143
|
+
return this.fix(results, ruleIds, (context) => createFixToConvertErrorToWarningPerFile(context, { description }));
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Apply suggestions.
|
|
147
|
+
* @param results The lint results of the project to apply suggestions
|
|
148
|
+
* @param ruleIds The rule ids to apply suggestions
|
|
149
|
+
* @param filter The script to filter suggestions
|
|
150
|
+
*/
|
|
151
|
+
async applySuggestions(results, ruleIds, filter) {
|
|
152
|
+
return this.fix(results, ruleIds, (context) => createFixToApplySuggestions(context, { filter }));
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Make forcibly fixable and run `eslint --fix`.
|
|
156
|
+
* @param results The lint results of the project to apply suggestions
|
|
157
|
+
* @param ruleIds The rule ids to apply suggestions
|
|
158
|
+
* @param fixableMaker The function to make `Linter.LintMessage` forcibly fixable.
|
|
159
|
+
*/
|
|
160
|
+
async makeFixableAndFix(results, ruleIds, fixableMaker) {
|
|
161
|
+
return this.fix(results, ruleIds, (context) => createFixToMakeFixableAndFix(context, { fixableMaker }));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Fix source codes.
|
|
165
|
+
* @param fix The fix information to do.
|
|
166
|
+
*/
|
|
167
|
+
async fix(resultsOfLint, ruleIds, fixCreator) {
|
|
168
|
+
// NOTE: Extract only necessary results and files for performance
|
|
169
|
+
const filteredResultsOfLint = filterResultsByRuleId(resultsOfLint, ruleIds);
|
|
170
|
+
// eslint-disable-next-line prefer-const
|
|
171
|
+
for (let { filePath, source } of filteredResultsOfLint) {
|
|
172
|
+
if (!source)
|
|
173
|
+
throw new Error('Source code is required to apply fixes.');
|
|
174
|
+
// eslint-disable-next-line no-await-in-loop
|
|
175
|
+
const fixedResult = await verifyAndFix(__classPrivateFieldGet(this, _Core_eslint, "f"), source, filePath, ruleIds, fixCreator);
|
|
176
|
+
// Write the fixed source code to the file
|
|
177
|
+
if (fixedResult.fixed) {
|
|
178
|
+
// eslint-disable-next-line no-await-in-loop
|
|
179
|
+
await writeFile(filePath, fixedResult.output);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return async () => {
|
|
183
|
+
const resultsToUndo = generateResultsToUndo(filteredResultsOfLint);
|
|
184
|
+
await ESLint.outputFixes(resultsToUndo);
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
_Core_cwd = new WeakMap(), _Core_patterns = new WeakMap(), _Core_quiet = new WeakMap(), _Core_formatterName = new WeakMap(), _Core_sort = new WeakMap(), _Core_sortOrder = new WeakMap(), _Core_filters = new WeakMap(), _Core_eslint = new WeakMap();
|
|
189
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,uCAAuC,EACvC,yBAAyB,EAC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AC;YAExE,4CAA4C;YAC5C,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,uBAAA,IAAI,oBAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;YAE5F,0CAA0C;YAC1C,IAAI,WAAW,CAAC,KAAK,EAAE,CAAC;gBACtB,4CAA4C;gBAC5C,MAAM,SAAS,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;QAED,OAAO,KAAK,IAAI,EAAE;YAChB,MAAM,aAAa,GAAG,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;YACnE,MAAM,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;QAC1C,CAAC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Main Linter Class
|
|
3
|
+
* @author Gyandeep Singh
|
|
4
|
+
* @author aladdin-add
|
|
5
|
+
*/
|
|
6
|
+
import type { ESLint, Rule } from 'eslint';
|
|
7
|
+
import type { FixContext } from '../fix/index.js';
|
|
8
|
+
type FixedResult = {
|
|
9
|
+
fixed: boolean;
|
|
10
|
+
output: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Performs multiple autofix passes over the text until as many fixes as possible have been applied.
|
|
14
|
+
* @param linter
|
|
15
|
+
*/
|
|
16
|
+
export declare function verifyAndFix(eslint: ESLint, text: string, filePath: string, ruleIds: string[], fixCreator: (context: FixContext) => Rule.Fix[]): Promise<FixedResult>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=linter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linter.d.ts","sourceRoot":"","sources":["../../src/eslint/linter.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAOlD,KAAK,WAAW,GAAG;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;GAGG;AAEH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EAAE,EACjB,UAAU,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,IAAI,CAAC,GAAG,EAAE,GAC9C,OAAO,CAAC,WAAW,CAAC,CAuEtB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// forked from: https://github.com/eslint/eslint/blob/d191bdd67214c33e65bd605e616ca7cc947fd045/lib/linter/linter.js
|
|
2
|
+
// I wanted a customized `linter.verifyAndFix`, so I forked the original `linter.verifyAndFix`.
|
|
3
|
+
import { getLastSourceCode } from '../plugin.js';
|
|
4
|
+
import { ruleFixer } from './rule-fixer.js';
|
|
5
|
+
import { SourceCodeFixer } from './source-code-fixer.js';
|
|
6
|
+
const MAX_AUTOFIX_PASSES = 10;
|
|
7
|
+
/**
|
|
8
|
+
* Performs multiple autofix passes over the text until as many fixes as possible have been applied.
|
|
9
|
+
* @param linter
|
|
10
|
+
*/
|
|
11
|
+
export async function verifyAndFix(eslint, text, filePath, ruleIds, fixCreator) {
|
|
12
|
+
let fixedResult;
|
|
13
|
+
let fixed = false;
|
|
14
|
+
let passNumber = 0;
|
|
15
|
+
let currentText = text;
|
|
16
|
+
/**
|
|
17
|
+
* This loop continues until one of the following is true:
|
|
18
|
+
*
|
|
19
|
+
* 1. No more fixes have been applied.
|
|
20
|
+
* 2. Ten passes have been made.
|
|
21
|
+
*
|
|
22
|
+
* That means anytime a fix is successfully applied, there will be another pass.
|
|
23
|
+
* Essentially, guaranteeing a minimum of two passes.
|
|
24
|
+
*/
|
|
25
|
+
do {
|
|
26
|
+
passNumber++;
|
|
27
|
+
// eslint-disable-next-line no-await-in-loop
|
|
28
|
+
const results = await eslint.lintText(currentText, { filePath });
|
|
29
|
+
const messages = results
|
|
30
|
+
.flatMap((result) => result.messages)
|
|
31
|
+
.filter((message) => message.ruleId && ruleIds.includes(message.ruleId));
|
|
32
|
+
const sourceCode = getLastSourceCode();
|
|
33
|
+
if (!sourceCode)
|
|
34
|
+
throw new Error('Failed to get the last source code.');
|
|
35
|
+
// Create `Rule.Fix[]`
|
|
36
|
+
const fixContext = {
|
|
37
|
+
filename: filePath,
|
|
38
|
+
sourceCode,
|
|
39
|
+
messages,
|
|
40
|
+
ruleIds,
|
|
41
|
+
fixer: ruleFixer,
|
|
42
|
+
};
|
|
43
|
+
const fixes = fixCreator(fixContext);
|
|
44
|
+
fixedResult = SourceCodeFixer.applyFixes(currentText, fixes.map((fix) => {
|
|
45
|
+
return {
|
|
46
|
+
ruleId: 'eslint-interactive/fix',
|
|
47
|
+
severity: 2,
|
|
48
|
+
message: 'fix',
|
|
49
|
+
line: 0,
|
|
50
|
+
column: 0,
|
|
51
|
+
fix,
|
|
52
|
+
};
|
|
53
|
+
}), true);
|
|
54
|
+
/**
|
|
55
|
+
* stop if there are any syntax errors.
|
|
56
|
+
* 'fixedResult.output' is a empty string.
|
|
57
|
+
*/
|
|
58
|
+
if (messages.length === 1 && messages[0] && messages[0].fatal) {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
// keep track if any fixes were ever applied - important for return value
|
|
62
|
+
fixed = fixed || fixedResult.fixed;
|
|
63
|
+
// update to use the fixed output instead of the original text
|
|
64
|
+
currentText = fixedResult.output;
|
|
65
|
+
} while (fixedResult.fixed && passNumber < MAX_AUTOFIX_PASSES);
|
|
66
|
+
// ensure the last result properly reflects if fixes were done
|
|
67
|
+
fixedResult.fixed = fixed;
|
|
68
|
+
fixedResult.output = currentText;
|
|
69
|
+
return fixedResult;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=linter.js.map
|
|
@@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AC;QACF,MAAM,KAAK,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;QAErC,WAAW,GAAG,eAAe,CAAC,UAAU,CACtC,WAAW,EACX,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YAChB,OAAO;gBACL,MAAM,EAAE,wBAAwB;gBAChC,QAAQ,EAAE,CAAC;gBACX,OAAO,EAAE,KAAK;gBACd,IAAI,EAAE,CAAC;gBACP,MAAM,EAAE,CAAC;gBACT,GAAG;aACJ,CAAC;QACJ,CAAC,CAAC,EACF,IAAI,CACL,CAAC;QAEF;;;WAGG;QACH,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;YAC9D,MAAM;QACR,CAAC;QAED,yEAAyE;QACzE,KAAK,GAAG,KAAK,IAAI,WAAW,CAAC,KAAK,CAAC;QAEnC,8DAA8D;QAC9D,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC;IACnC,CAAC,QAAQ,WAAW,CAAC,KAAK,IAAI,UAAU,GAAG,kBAAkB,EAAE;IAE/D,8DAA8D;IAC9D,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC;IAC1B,WAAW,CAAC,MAAM,GAAG,WAAW,CAAC;IAEjC,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Rule, SourceCode } from 'eslint';
|
|
2
|
+
/**
|
|
3
|
+
* Merges the given fixes array into one.
|
|
4
|
+
* @param {Fix[]} fixes The fixes to merge.
|
|
5
|
+
* @param {SourceCode} sourceCode The source code object to get the text between fixes.
|
|
6
|
+
* @returns {{text: string, range: number[]}} The merged fixes
|
|
7
|
+
*/
|
|
8
|
+
export declare function mergeFixes(fixes: Rule.Fix[], sourceCode: SourceCode): Rule.Fix | null;
|
|
9
|
+
//# sourceMappingURL=report-translator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report-translator.d.ts","sourceRoot":"","sources":["../../src/eslint/report-translator.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AA2C/C;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC,GAAG,GAAG,IAAI,CAkCrF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// copy from: https://github.com/eslint/eslint/blob/d191bdd67214c33e65bd605e616ca7cc947fd045/lib/linter/report-translator.js
|
|
2
|
+
// ESLint does not export `mergeFixes`. So, I've copied the implementation.
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview A helper that translates context.report() calls from the rule API into generic problem objects
|
|
5
|
+
* @author Teddy Katz
|
|
6
|
+
*/
|
|
7
|
+
import assert from 'node:assert';
|
|
8
|
+
/**
|
|
9
|
+
* Clones the given fix object.
|
|
10
|
+
* @param {Fix|null} fix The fix to clone.
|
|
11
|
+
* @returns {Fix|null} Deep cloned fix object or `null` if `null` or `undefined` was passed in.
|
|
12
|
+
*/
|
|
13
|
+
function cloneFix(fix) {
|
|
14
|
+
if (!fix) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
range: [fix.range[0], fix.range[1]],
|
|
19
|
+
text: fix.text,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Check that a fix has a valid range.
|
|
24
|
+
* @param {Fix|null} fix The fix to validate.
|
|
25
|
+
* @returns {void}
|
|
26
|
+
*/
|
|
27
|
+
function assertValidFix(fix) {
|
|
28
|
+
if (fix) {
|
|
29
|
+
assert(fix.range && typeof fix.range[0] === 'number' && typeof fix.range[1] === 'number', `Fix has invalid range: ${JSON.stringify(fix, null, 2)}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Compares items in a fixes array by range.
|
|
34
|
+
* @param {Fix} a The first message.
|
|
35
|
+
* @param {Fix} b The second message.
|
|
36
|
+
* @returns {int} -1 if a comes before b, 1 if a comes after b, 0 if equal.
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
function compareFixesByRange(a, b) {
|
|
40
|
+
return a.range[0] - b.range[0] || a.range[1] - b.range[1];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Merges the given fixes array into one.
|
|
44
|
+
* @param {Fix[]} fixes The fixes to merge.
|
|
45
|
+
* @param {SourceCode} sourceCode The source code object to get the text between fixes.
|
|
46
|
+
* @returns {{text: string, range: number[]}} The merged fixes
|
|
47
|
+
*/
|
|
48
|
+
export function mergeFixes(fixes, sourceCode) {
|
|
49
|
+
for (const fix of fixes) {
|
|
50
|
+
assertValidFix(fix);
|
|
51
|
+
}
|
|
52
|
+
if (fixes.length === 0) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
if (fixes.length === 1) {
|
|
56
|
+
return cloneFix(fixes[0]);
|
|
57
|
+
}
|
|
58
|
+
fixes.sort(compareFixesByRange);
|
|
59
|
+
const originalText = sourceCode.text;
|
|
60
|
+
const start = fixes[0].range[0];
|
|
61
|
+
const end = fixes[fixes.length - 1].range[1];
|
|
62
|
+
let text = '';
|
|
63
|
+
let lastPos = Number.MIN_SAFE_INTEGER;
|
|
64
|
+
for (const fix of fixes) {
|
|
65
|
+
assert(fix.range[0] >= lastPos, 'Fix objects must not be overlapped in a report.');
|
|
66
|
+
if (fix.range[0] >= 0) {
|
|
67
|
+
text += originalText.slice(Math.max(0, start, lastPos), fix.range[0]);
|
|
68
|
+
}
|
|
69
|
+
text += fix.text;
|
|
70
|
+
lastPos = fix.range[1];
|
|
71
|
+
}
|
|
72
|
+
text += originalText.slice(Math.max(0, start, lastPos), end);
|
|
73
|
+
return { range: [start, end], text };
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=report-translator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report-translator.js","sourceRoot":"","sources":["../../src/eslint/report-translator.ts"],"names":[],"mappings":"AAAA,4HAA4H;AAC5H,2EAA2E;AAE3E;;;GAGG;AAEH,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC;;;;GAIG;AACH,SAAS,QAAQ,CAAC,GAAgC;IAChD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,KAAK,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACnC,IAAI,EAAE,GAAG,CAAC,IAAI;KACf,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,GAAoB;IAC1C,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,CACJ,GAAG,CAAC,KAAK,IAAI,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,EACjF,0BAA0B,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CACzD,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,mBAAmB,CAAC,CAAW,EAAE,CAAW;IACnD,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAiB,EAAE,UAAsB;IAClE,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,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