eslint-interactive 11.0.0 → 11.0.2
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/dist/action/apply-suggestions.d.ts +6 -0
- package/dist/action/apply-suggestions.d.ts.map +1 -0
- package/dist/action/apply-suggestions.js +28 -0
- package/dist/action/apply-suggestions.js.map +1 -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/disable-per-file.d.ts +6 -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 +6 -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 +6 -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 +8 -0
- package/dist/action/index.d.ts.map +1 -0
- package/dist/action/index.js +8 -0
- package/dist/action/index.js.map +1 -0
- package/dist/action/make-fixable-and-fix.d.ts +6 -0
- package/dist/action/make-fixable-and-fix.d.ts.map +1 -0
- package/dist/action/make-fixable-and-fix.js +28 -0
- package/dist/action/make-fixable-and-fix.js.map +1 -0
- package/dist/action/print-result-details.d.ts +5 -0
- package/dist/action/print-result-details.d.ts.map +1 -0
- package/dist/action/print-result-details.js +28 -0
- package/dist/action/print-result-details.js.map +1 -0
- package/dist/cli/log.d.ts +6 -0
- package/dist/cli/log.d.ts.map +1 -0
- package/dist/cli/log.js +9 -0
- package/dist/cli/log.js.map +1 -0
- package/dist/cli/ora.d.ts +4 -0
- package/dist/cli/ora.d.ts.map +1 -0
- package/dist/cli/ora.js +23 -0
- package/dist/cli/ora.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 +24 -0
- package/dist/cli/parse-argv.d.ts.map +1 -0
- package/dist/cli/parse-argv.js +102 -0
- package/dist/cli/parse-argv.js.map +1 -0
- package/dist/cli/prompt.d.ts +61 -0
- package/dist/cli/prompt.d.ts.map +1 -0
- package/dist/cli/prompt.js +176 -0
- package/dist/cli/prompt.js.map +1 -0
- package/dist/cli/run.d.ts +8 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +66 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/config.d.ts +46 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +91 -0
- package/dist/config.js.map +1 -0
- package/dist/core-worker.d.ts +23 -0
- package/dist/core-worker.d.ts.map +1 -0
- package/dist/core-worker.js +55 -0
- package/dist/core-worker.js.map +1 -0
- package/dist/core.d.ts +79 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +159 -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 +67 -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 +77 -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 +118 -0
- package/dist/eslint/rule-fixer.js.map +1 -0
- package/dist/eslint/source-code-fixer.d.ts +19 -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 +61 -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 +12 -0
- package/dist/fix/make-fixable-and-fix.d.ts.map +1 -0
- package/dist/fix/make-fixable-and-fix.js +60 -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/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 +41 -0
- package/dist/formatter/format-by-files.js.map +1 -0
- package/dist/formatter/format-by-rules.d.ts +3 -0
- package/dist/formatter/format-by-rules.d.ts.map +1 -0
- package/dist/formatter/format-by-rules.js +39 -0
- package/dist/formatter/format-by-rules.js.map +1 -0
- package/dist/formatter/index.d.ts +4 -0
- package/dist/formatter/index.d.ts.map +1 -0
- package/dist/formatter/index.js +7 -0
- package/dist/formatter/index.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 +5 -0
- package/dist/index.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 +22 -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 +8 -0
- package/dist/scene/lint.d.ts.map +1 -0
- package/dist/scene/lint.js +31 -0
- package/dist/scene/lint.js.map +1 -0
- package/dist/scene/select-action.d.ts +20 -0
- package/dist/scene/select-action.d.ts.map +1 -0
- package/dist/scene/select-action.js +50 -0
- package/dist/scene/select-action.js.map +1 -0
- package/dist/scene/select-rule-ids.d.ts +15 -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/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/cache.d.ts +5 -0
- package/dist/util/cache.d.ts.map +1 -0
- package/dist/util/cache.js +15 -0
- package/dist/util/cache.js.map +1 -0
- package/dist/util/eslint.d.ts +99 -0
- package/dist/util/eslint.d.ts.map +1 -0
- package/dist/util/eslint.js +201 -0
- package/dist/util/eslint.js.map +1 -0
- package/dist/util/filter-script.d.ts +6 -0
- package/dist/util/filter-script.d.ts.map +1 -0
- package/dist/util/filter-script.js +38 -0
- package/dist/util/filter-script.js.map +1 -0
- package/dist/util/type-check.d.ts +6 -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 +2 -2
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// copy from: https://github.com/eslint/eslint/blob/a79c9f35d665c2bcc63267bdf359a8176e0a84ce/lib/linter/source-code-fixer.js#L0-L1
|
|
2
|
+
// ESLint does not export the SourceCodeFixer. So, I've copied the implementation.
|
|
3
|
+
const debug = (..._args) => { };
|
|
4
|
+
// const debug = require('debug')('eslint:source-code-fixer');
|
|
5
|
+
// ------------------------------------------------------------------------------
|
|
6
|
+
// Helpers
|
|
7
|
+
// ------------------------------------------------------------------------------
|
|
8
|
+
const BOM = '\uFEFF';
|
|
9
|
+
/**
|
|
10
|
+
* Compares items in a messages array by range.
|
|
11
|
+
* @param {Message} a The first message.
|
|
12
|
+
* @param {Message} b The second message.
|
|
13
|
+
* @returns {int} -1 if a comes before b, 1 if a comes after b, 0 if equal.
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
function compareMessagesByFixRange(a, b) {
|
|
17
|
+
if (!a.fix || !b.fix)
|
|
18
|
+
throw new Error('Message should have a fix property.');
|
|
19
|
+
return a.fix.range[0] - b.fix.range[0] || a.fix.range[1] - b.fix.range[1];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Compares items in a messages array by line and column.
|
|
23
|
+
* @param {Message} a The first message.
|
|
24
|
+
* @param {Message} b The second message.
|
|
25
|
+
* @returns {int} -1 if a comes before b, 1 if a comes after b, 0 if equal.
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
function compareMessagesByLocation(a, b) {
|
|
29
|
+
return a.line - b.line || a.column - b.column;
|
|
30
|
+
}
|
|
31
|
+
// ------------------------------------------------------------------------------
|
|
32
|
+
// Public Interface
|
|
33
|
+
// ------------------------------------------------------------------------------
|
|
34
|
+
/**
|
|
35
|
+
* Utility for apply fixes to source code.
|
|
36
|
+
* @constructor
|
|
37
|
+
*/
|
|
38
|
+
function SourceCodeFixer() {
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
Object.freeze(this);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Applies the fixes specified by the messages to the given text. Tries to be
|
|
44
|
+
* smart about the fixes and won't apply fixes over the same area in the text.
|
|
45
|
+
* @param {string} sourceText The text to apply the changes to.
|
|
46
|
+
* @param {Message[]} messages The array of messages reported by ESLint.
|
|
47
|
+
* @param {boolean|Function} [shouldFix=true] Determines whether each message should be fixed
|
|
48
|
+
* @returns {Object} An object containing the fixed text and any unfixed messages.
|
|
49
|
+
*/
|
|
50
|
+
SourceCodeFixer.applyFixes = function (sourceText, messages, shouldFix) {
|
|
51
|
+
debug('Applying fixes');
|
|
52
|
+
if (shouldFix === false) {
|
|
53
|
+
debug('shouldFix parameter was false, not attempting fixes');
|
|
54
|
+
return {
|
|
55
|
+
fixed: false,
|
|
56
|
+
messages,
|
|
57
|
+
output: sourceText,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// clone the array
|
|
61
|
+
const remainingMessages = [];
|
|
62
|
+
const fixes = [];
|
|
63
|
+
const bom = sourceText.startsWith(BOM) ? BOM : '';
|
|
64
|
+
const text = bom ? sourceText.slice(1) : sourceText;
|
|
65
|
+
let lastPos = Number.NEGATIVE_INFINITY;
|
|
66
|
+
let output = bom;
|
|
67
|
+
/**
|
|
68
|
+
* Try to use the 'fix' from a problem.
|
|
69
|
+
* @param {Message} problem The message object to apply fixes from
|
|
70
|
+
* @returns {boolean} Whether fix was successfully applied
|
|
71
|
+
*/
|
|
72
|
+
function attemptFix(problem) {
|
|
73
|
+
if (!problem.fix)
|
|
74
|
+
throw new Error('Problem should have a fix property.');
|
|
75
|
+
const fix = problem.fix;
|
|
76
|
+
const start = fix.range[0];
|
|
77
|
+
const end = fix.range[1];
|
|
78
|
+
// Remain it as a problem if it's overlapped or it's a negative range
|
|
79
|
+
if (lastPos >= start || start > end) {
|
|
80
|
+
remainingMessages.push(problem);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
// Remove BOM.
|
|
84
|
+
if ((start < 0 && end >= 0) || (start === 0 && fix.text.startsWith(BOM))) {
|
|
85
|
+
output = '';
|
|
86
|
+
}
|
|
87
|
+
// Make output to this fix.
|
|
88
|
+
output += text.slice(Math.max(0, lastPos), Math.max(0, start));
|
|
89
|
+
output += fix.text;
|
|
90
|
+
lastPos = end;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
messages.forEach((problem) => {
|
|
94
|
+
if (Object.prototype.hasOwnProperty.call(problem, 'fix')) {
|
|
95
|
+
fixes.push(problem);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
remainingMessages.push(problem);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
if (fixes.length) {
|
|
102
|
+
debug('Found fixes to apply');
|
|
103
|
+
let fixesWereApplied = false;
|
|
104
|
+
for (const problem of fixes.sort(compareMessagesByFixRange)) {
|
|
105
|
+
if (typeof shouldFix !== 'function' || shouldFix(problem)) {
|
|
106
|
+
attemptFix(problem);
|
|
107
|
+
// The only time attemptFix will fail is if a previous fix was
|
|
108
|
+
// applied which conflicts with it. So we can mark this as true.
|
|
109
|
+
fixesWereApplied = true;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
remainingMessages.push(problem);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
output += text.slice(Math.max(0, lastPos));
|
|
116
|
+
return {
|
|
117
|
+
fixed: fixesWereApplied,
|
|
118
|
+
messages: remainingMessages.sort(compareMessagesByLocation),
|
|
119
|
+
output,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
debug('No fixes to apply');
|
|
123
|
+
return {
|
|
124
|
+
fixed: false,
|
|
125
|
+
messages,
|
|
126
|
+
output: bom + text,
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
export { SourceCodeFixer };
|
|
130
|
+
// module.exports = SourceCodeFixer;
|
|
131
|
+
//# sourceMappingURL=source-code-fixer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-code-fixer.js","sourceRoot":"","sources":["../../src/eslint/source-code-fixer.ts"],"names":[],"mappings":"AAAA,kIAAkI;AAClI,kFAAkF;AAalF,MAAM,KAAK,GAAG,CAAC,GAAG,KAAgB,EAAE,EAAE,GAAE,CAAC,CAAC;AAC1C,8DAA8D;AAE9D,iFAAiF;AACjF,UAAU;AACV,iFAAiF;AAEjF,MAAM,GAAG,GAAG,QAAQ,CAAC;AAErB;;;;;;GAMG;AACH,SAAS,yBAAyB,CAAC,CAAqB,EAAE,CAAqB;IAC7E,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IAC7E,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;GAMG;AACH,SAAS,yBAAyB,CAAC,CAAqB,EAAE,CAAqB;IAC7E,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;AAChD,CAAC;AAED,iFAAiF;AACjF,mBAAmB;AACnB,iFAAiF;AAEjF;;;GAGG;AACH,SAAS,eAAe;IACtB,aAAa;I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AC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;QAE3C,OAAO;YACL,KAAK,EAAE,gBAAgB;YACvB,QAAQ,EAAE,iBAAiB,CAAC,IAAI,CAAC,yBAAyB,CAAC;YAC3D,MAAM;SACP,CAAC;KACH;IAED,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAC3B,OAAO;QACL,KAAK,EAAE,KAAK;QACZ,QAAQ;QACR,MAAM,EAAE,GAAG,GAAG,IAAI;KACnB,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,CAAC;AAC3B,oCAAoC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Rule } from 'eslint';
|
|
2
|
+
import { FixContext } from './index.js';
|
|
3
|
+
export type FixToApplyAutoFixesArgs = {};
|
|
4
|
+
/**
|
|
5
|
+
* Create fix to apply auto-fixes.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createFixToApplyAutoFixes(context: FixContext, _args: FixToApplyAutoFixesArgs): Rule.Fix[];
|
|
8
|
+
//# sourceMappingURL=apply-auto-fixes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-auto-fixes.d.ts","sourceRoot":"","sources":["../../src/fix/apply-auto-fixes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,MAAM,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAEzC;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,uBAAuB,GAAG,IAAI,CAAC,GAAG,EAAE,CAEzG"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { notEmpty } from '../util/type-check.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create fix to apply auto-fixes.
|
|
4
|
+
*/
|
|
5
|
+
export function createFixToApplyAutoFixes(context, _args) {
|
|
6
|
+
return context.messages.map((message) => message.fix).filter(notEmpty);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=apply-auto-fixes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-auto-fixes.js","sourceRoot":"","sources":["../../src/fix/apply-auto-fixes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAMjD;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAmB,EAAE,KAA8B;IAC3F,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Linter, Rule } from 'eslint';
|
|
2
|
+
import { FixContext } from './index.js';
|
|
3
|
+
export type SuggestionFilter = (suggestions: Linter.LintSuggestion[], message: Linter.LintMessage, context: FixContext) => Linter.LintSuggestion | null | undefined;
|
|
4
|
+
export type FixToApplySuggestionsArgs = {
|
|
5
|
+
filter: SuggestionFilter;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Create fix to apply suggestions.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createFixToApplySuggestions(context: FixContext, args: FixToApplySuggestionsArgs): Rule.Fix[];
|
|
11
|
+
//# sourceMappingURL=apply-suggestions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-suggestions.d.ts","sourceRoot":"","sources":["../../src/fix/apply-suggestions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,MAAM,gBAAgB,GAAG,CAC7B,WAAW,EAAE,MAAM,CAAC,cAAc,EAAE,EACpC,OAAO,EAAE,MAAM,CAAC,WAAW,EAC3B,OAAO,EAAE,UAAU,KAChB,MAAM,CAAC,cAAc,GAAG,IAAI,GAAG,SAAS,CAAC;AAE9C,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,EAAE,gBAAgB,CAAC;CAC1B,CAAC;AAsBF;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,yBAAyB,GAAG,IAAI,CAAC,GAAG,EAAE,CAO5G"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function getApplicableSuggestion(message, filter, context) {
|
|
2
|
+
if (!message.suggestions || message.suggestions.length === 0)
|
|
3
|
+
return null;
|
|
4
|
+
const suggestion = filter(message.suggestions, message, context);
|
|
5
|
+
return suggestion ?? null;
|
|
6
|
+
}
|
|
7
|
+
function generateFixPerMessage(context, filter, message) {
|
|
8
|
+
const suggestion = getApplicableSuggestion(message, filter, context);
|
|
9
|
+
if (!suggestion)
|
|
10
|
+
return null;
|
|
11
|
+
return suggestion.fix;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create fix to apply suggestions.
|
|
15
|
+
*/
|
|
16
|
+
export function createFixToApplySuggestions(context, args) {
|
|
17
|
+
const fixes = [];
|
|
18
|
+
for (const message of context.messages) {
|
|
19
|
+
const fix = generateFixPerMessage(context, args.filter, message);
|
|
20
|
+
if (fix)
|
|
21
|
+
fixes.push(fix);
|
|
22
|
+
}
|
|
23
|
+
return fixes;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=apply-suggestions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-suggestions.js","sourceRoot":"","sources":["../../src/fix/apply-suggestions.ts"],"names":[],"mappings":"AAaA,SAAS,uBAAuB,CAC9B,OAA2B,EAC3B,MAAwB,EACxB,OAAmB;IAEnB,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1E,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACjE,OAAO,UAAU,IAAI,IAAI,CAAC;AAC5B,CAAC;AAED,SAAS,qBAAqB,CAC5B,OAAmB,EACnB,MAAwB,EACxB,OAA2B;IAE3B,MAAM,UAAU,GAAG,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACrE,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IAC7B,OAAO,UAAU,CAAC,GAAG,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAAmB,EAAE,IAA+B;IAC9F,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE;QACtC,MAAM,GAAG,GAAG,qBAAqB,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACjE,IAAI,GAAG;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KAC1B;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Rule } from 'eslint';
|
|
2
|
+
import { FixContext } from './index.js';
|
|
3
|
+
export type FixToConvertErrorToWarningPerFileArgs = {
|
|
4
|
+
description?: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Create fix to convert error to warning per file.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createFixToConvertErrorToWarningPerFile(context: FixContext, args: FixToConvertErrorToWarningPerFileArgs): Rule.Fix[];
|
|
10
|
+
//# sourceMappingURL=convert-error-to-warning-per-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-error-to-warning-per-file.d.ts","sourceRoot":"","sources":["../../src/fix/convert-error-to-warning-per-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAU,MAAM,QAAQ,CAAC;AAItC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,MAAM,qCAAqC,GAAG;IAClD,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC,CAAC;AA2BF;;GAEG;AACH,wBAAgB,uCAAuC,CACrD,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,qCAAqC,GAC1C,IAAI,CAAC,GAAG,EAAE,CAGZ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { unique } from '../util/array.js';
|
|
2
|
+
import { findShebang, toInlineConfigCommentText } from '../util/eslint.js';
|
|
3
|
+
import { notEmpty } from '../util/type-check.js';
|
|
4
|
+
function generateFix(context, description) {
|
|
5
|
+
const ruleIdsToConverting = unique(context.messages
|
|
6
|
+
// Ignore warnings
|
|
7
|
+
.filter((message) => message.severity === 2)
|
|
8
|
+
.map((message) => message.ruleId)
|
|
9
|
+
.filter(notEmpty));
|
|
10
|
+
if (ruleIdsToConverting.length === 0)
|
|
11
|
+
return null;
|
|
12
|
+
const rulesRecordToConverting = Object.fromEntries(ruleIdsToConverting.map((ruleId) => [ruleId, 1]));
|
|
13
|
+
// Insert the inline config comment at the top of the file.
|
|
14
|
+
// NOTE: Merging settings into an existing inline config comment is intentionally avoided
|
|
15
|
+
// because of the complexity of the implementation.
|
|
16
|
+
const text = `${toInlineConfigCommentText({ rulesRecord: rulesRecordToConverting, description })}\n`;
|
|
17
|
+
const shebang = findShebang(context.sourceCode.text);
|
|
18
|
+
// if shebang exists, insert comment after shebang
|
|
19
|
+
return context.fixer.insertTextAfterRange(shebang?.range ?? [0, 0], text);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create fix to convert error to warning per file.
|
|
23
|
+
*/
|
|
24
|
+
export function createFixToConvertErrorToWarningPerFile(context, args) {
|
|
25
|
+
const fix = generateFix(context, args.description);
|
|
26
|
+
return fix ? [fix] : [];
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=convert-error-to-warning-per-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-error-to-warning-per-file.js","sourceRoot":"","sources":["../../src/fix/convert-error-to-warning-per-file.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAOjD,SAAS,WAAW,CAAC,OAAmB,EAAE,WAAoB;IAC5D,MAAM,mBAAmB,GAAG,MAAM,CAChC,OAAO,CAAC,QAAQ;QACd,kBAAkB;SACjB,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAC;SAC3C,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;SAChC,MAAM,CAAC,QAAQ,CAAC,CACpB,CAAC;IACF,IAAI,mBAAmB,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAElD,MAAM,uBAAuB,GAAgC,MAAM,CAAC,WAAW,CAC7E,mBAAmB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CACjD,CAAC;IAEF,2DAA2D;IAC3D,yFAAyF;IACzF,mDAAmD;IAEnD,MAAM,IAAI,GAAG,GAAG,yBAAyB,CAAC,EAAE,WAAW,EAAE,uBAAuB,EAAE,WAAW,EAAE,CAAC,IAAI,CAAC;IAErG,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACrD,kDAAkD;IAClD,OAAO,OAAO,CAAC,KAAK,CAAC,oBAAoB,CAAC,OAAO,EAAE,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AAC5E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uCAAuC,CACrD,OAAmB,EACnB,IAA2C;IAE3C,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IACnD,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Rule } from 'eslint';
|
|
2
|
+
import { DescriptionPosition } from 'src/cli/prompt.js';
|
|
3
|
+
import { FixContext } from './index.js';
|
|
4
|
+
export type FixToDisablePerFileArgs = {
|
|
5
|
+
description?: string | undefined;
|
|
6
|
+
descriptionPosition?: DescriptionPosition | undefined;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Create fix to add disable comment per file.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createFixToDisablePerFile(context: FixContext, args: FixToDisablePerFileArgs): Rule.Fix[];
|
|
12
|
+
//# sourceMappingURL=disable-per-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disable-per-file.d.ts","sourceRoot":"","sources":["../../src/fix/disable-per-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAcxD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,mBAAmB,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;CACvD,CAAC;AAmEF;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,uBAAuB,GAAG,IAAI,CAAC,GAAG,EAAE,CAIxG"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { mergeFixes } from '../eslint/report-translator.js';
|
|
2
|
+
import { unique } from '../util/array.js';
|
|
3
|
+
import { findShebang, parseDisableComment, insertDescriptionCommentStatementBeforeLine, insertDisableCommentStatementBeforeLine, mergeDescription, mergeRuleIds, updateDisableComment, } from '../util/eslint.js';
|
|
4
|
+
import { notEmpty } from '../util/type-check.js';
|
|
5
|
+
function findDisableCommentPerFile(sourceCode) {
|
|
6
|
+
const commentsInFile = sourceCode.getAllComments();
|
|
7
|
+
return commentsInFile.map(parseDisableComment).find((comment) => comment?.scope === 'file');
|
|
8
|
+
}
|
|
9
|
+
function generateFix(context, description, descriptionPosition) {
|
|
10
|
+
const { fixer, sourceCode } = context;
|
|
11
|
+
const ruleIdsToDisable = unique(context.messages.map((message) => message.ruleId).filter(notEmpty));
|
|
12
|
+
if (ruleIdsToDisable.length === 0)
|
|
13
|
+
return null;
|
|
14
|
+
const disableCommentPerFile = findDisableCommentPerFile(sourceCode);
|
|
15
|
+
// if shebang exists, insert comment after shebang
|
|
16
|
+
const shebang = findShebang(context.sourceCode.text);
|
|
17
|
+
const lineToInsert = disableCommentPerFile
|
|
18
|
+
? disableCommentPerFile.loc.start.line
|
|
19
|
+
: shebang
|
|
20
|
+
? sourceCode.getLocFromIndex(shebang.range[0]).line + 1
|
|
21
|
+
: 1;
|
|
22
|
+
const fixes = [];
|
|
23
|
+
const isPreviousLine = description !== undefined && descriptionPosition === 'previousLine';
|
|
24
|
+
if (isPreviousLine) {
|
|
25
|
+
fixes.push(insertDescriptionCommentStatementBeforeLine({
|
|
26
|
+
fixer,
|
|
27
|
+
sourceCode,
|
|
28
|
+
line: lineToInsert,
|
|
29
|
+
description,
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
if (disableCommentPerFile) {
|
|
33
|
+
fixes.push(updateDisableComment({
|
|
34
|
+
fixer,
|
|
35
|
+
disableComment: disableCommentPerFile,
|
|
36
|
+
newRules: mergeRuleIds(disableCommentPerFile.ruleIds, ruleIdsToDisable),
|
|
37
|
+
newDescription: isPreviousLine
|
|
38
|
+
? disableCommentPerFile.description
|
|
39
|
+
: mergeDescription(disableCommentPerFile.description, description),
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
fixes.push(insertDisableCommentStatementBeforeLine({
|
|
44
|
+
fixer,
|
|
45
|
+
sourceCode,
|
|
46
|
+
line: lineToInsert,
|
|
47
|
+
scope: 'file',
|
|
48
|
+
ruleIds: ruleIdsToDisable,
|
|
49
|
+
description: isPreviousLine ? undefined : description,
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
return mergeFixes(fixes, context.sourceCode);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create fix to add disable comment per file.
|
|
56
|
+
*/
|
|
57
|
+
export function createFixToDisablePerFile(context, args) {
|
|
58
|
+
const fix = generateFix(context, args.description, args.descriptionPosition);
|
|
59
|
+
if (fix)
|
|
60
|
+
return [fix];
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=disable-per-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disable-per-file.js","sourceRoot":"","sources":["../../src/fix/disable-per-file.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAEL,WAAW,EACX,mBAAmB,EACnB,2CAA2C,EAC3C,uCAAuC,EACvC,gBAAgB,EAChB,YAAY,EACZ,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAQjD,SAAS,yBAAyB,CAA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ACZ,CAAC,CACH,CAAC;KACH;IAED,IAAI,qBAAqB,EAAE;QACzB,KAAK,CAAC,IAAI,CACR,oBAAoB,CAAC;YACnB,KAAK;YACL,cAAc,EAAE,qBAAqB;YACrC,QAAQ,EAAE,YAAY,CAAC,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,CAAC;YACvE,cAAc,EAAE,cAAc;gBAC5B,CAAC,CAAC,qBAAqB,CAAC,WAAW;gBACnC,CAAC,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,WAAW,EAAE,WAAW,CAAC;SACrE,CAAC,CACH,CAAC;KACH;SAAM;QACL,KAAK,CAAC,IAAI,CACR,uCAAuC,CAAC;YACtC,KAAK;YACL,UAAU;YACV,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,gBAAgB;YACzB,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW;SACtD,CAAC,CACH,CAAC;KACH;IACD,OAAO,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAmB,EAAE,IAA6B;IAC1F,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAC7E,IAAI,GAAG;QAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IACtB,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Rule } from 'eslint';
|
|
2
|
+
import { DescriptionPosition } from 'src/cli/prompt.js';
|
|
3
|
+
import { FixContext } from './index.js';
|
|
4
|
+
export type FixToDisablePerLineArgs = {
|
|
5
|
+
description?: string | undefined;
|
|
6
|
+
descriptionPosition?: DescriptionPosition | undefined;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Create fix to add disable comment per line.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createFixToDisablePerLine(context: FixContext, args: FixToDisablePerLineArgs): Rule.Fix[];
|
|
12
|
+
//# sourceMappingURL=disable-per-line.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disable-per-line.d.ts","sourceRoot":"","sources":["../../src/fix/disable-per-line.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,IAAI,EAAc,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAaxD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,mBAAmB,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;CACvD,CAAC;AA6DF;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,uBAAuB,GAAG,IAAI,CAAC,GAAG,EAAE,CAQxG"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { mergeFixes } from '../eslint/report-translator.js';
|
|
2
|
+
import { groupBy, unique } from '../util/array.js';
|
|
3
|
+
import { insertDescriptionCommentStatementBeforeLine, insertDisableCommentStatementBeforeLine, mergeDescription, mergeRuleIds, parseDisableComment, updateDisableComment, } from '../util/eslint.js';
|
|
4
|
+
import { notEmpty } from '../util/type-check.js';
|
|
5
|
+
function findDisableCommentPerLine(sourceCode, line) {
|
|
6
|
+
const commentsInFile = sourceCode.getAllComments();
|
|
7
|
+
const commentsInPreviousLine = commentsInFile.filter((comment) => comment.loc?.start.line === line - 1);
|
|
8
|
+
return commentsInPreviousLine.map(parseDisableComment).find((comment) => comment?.scope === 'next-line');
|
|
9
|
+
}
|
|
10
|
+
function generateFixesPerLine(context, description, descriptionPosition, line, messagesInLine) {
|
|
11
|
+
const { fixer, sourceCode } = context;
|
|
12
|
+
const ruleIdsToDisable = unique(messagesInLine.map((message) => message.ruleId).filter(notEmpty));
|
|
13
|
+
if (ruleIdsToDisable.length === 0)
|
|
14
|
+
return null;
|
|
15
|
+
const disableCommentPerLine = findDisableCommentPerLine(sourceCode, line);
|
|
16
|
+
const fixes = [];
|
|
17
|
+
const isPreviousLine = description !== undefined && descriptionPosition === 'previousLine';
|
|
18
|
+
if (isPreviousLine) {
|
|
19
|
+
fixes.push(insertDescriptionCommentStatementBeforeLine({
|
|
20
|
+
fixer,
|
|
21
|
+
sourceCode,
|
|
22
|
+
line: disableCommentPerLine ? disableCommentPerLine.loc.start.line : line,
|
|
23
|
+
description,
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
if (disableCommentPerLine) {
|
|
27
|
+
fixes.push(updateDisableComment({
|
|
28
|
+
fixer,
|
|
29
|
+
disableComment: disableCommentPerLine,
|
|
30
|
+
newRules: mergeRuleIds(disableCommentPerLine.ruleIds, ruleIdsToDisable),
|
|
31
|
+
newDescription: isPreviousLine
|
|
32
|
+
? disableCommentPerLine.description
|
|
33
|
+
: mergeDescription(disableCommentPerLine.description, description),
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
fixes.push(insertDisableCommentStatementBeforeLine({
|
|
38
|
+
fixer,
|
|
39
|
+
sourceCode,
|
|
40
|
+
line,
|
|
41
|
+
scope: 'next-line',
|
|
42
|
+
ruleIds: ruleIdsToDisable,
|
|
43
|
+
description: isPreviousLine ? undefined : description,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
return mergeFixes(fixes, context.sourceCode);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create fix to add disable comment per line.
|
|
50
|
+
*/
|
|
51
|
+
export function createFixToDisablePerLine(context, args) {
|
|
52
|
+
const lineToMessages = groupBy(context.messages, (message) => message.line);
|
|
53
|
+
const fixes = [];
|
|
54
|
+
for (const [line, messagesInLine] of lineToMessages) {
|
|
55
|
+
const fix = generateFixesPerLine(context, args.description, args.descriptionPosition, line, messagesInLine);
|
|
56
|
+
if (fix)
|
|
57
|
+
fixes.push(fix);
|
|
58
|
+
}
|
|
59
|
+
return fixes;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=disable-per-line.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disable-per-line.js","sourceRoot":"","sources":["../../src/fix/disable-per-line.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAEL,2CAA2C,EAC3C,uCAAuC,EACvC,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAQjD,SAAS,yBAAyB,CAAC,UAAsB,EAAE,IAAY;IACrE,MAAM,cAAc,GAAG,UAAU,CAAC,cAAc,EAAE,CAAC;IACnD,MAAM,sBAAsB,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC;IACxG,OAAO,sBAAsB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,KAAK,WAAW,CAAC,CAAC;AAC3G,CAAC;AAED,SAAS,oBAAoB,CAC3B,OAAmB,EACnB,WAA+B,EAC/B,mBAAoD,EACpD,IAAY,EACZ,cAAoC;IAEpC,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAEtC,MAAM,gBAAgB,GAAG,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,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AED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAmB,EAAE,IAA6B;IAC1F,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5E,MAAM,KAAK,GAAe,EAAE,CAAC;IAC7B,KAAK,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,cAAc,EAAE;QACnD,MAAM,GAAG,GAAG,oBAAoB,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,mBAAmB,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;QAC5G,IAAI,GAAG;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KAC1B;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Linter, Rule, SourceCode } from 'eslint';
|
|
2
|
+
export { verifyAndFix } from '../eslint/linter.js';
|
|
3
|
+
export { type SuggestionFilter, type FixToApplySuggestionsArgs, createFixToApplySuggestions, } from './apply-suggestions.js';
|
|
4
|
+
export { type FixToApplyAutoFixesArgs, createFixToApplyAutoFixes } from './apply-auto-fixes.js';
|
|
5
|
+
export { type FixToDisablePerFileArgs, createFixToDisablePerFile } from './disable-per-file.js';
|
|
6
|
+
export { type FixToDisablePerLineArgs, createFixToDisablePerLine } from './disable-per-line.js';
|
|
7
|
+
export { type FixToConvertErrorToWarningPerFileArgs, createFixToConvertErrorToWarningPerFile, } from './convert-error-to-warning-per-file.js';
|
|
8
|
+
export { type FixableMaker, type FixToMakeFixableAndFixArgs, createFixToMakeFixableAndFix, } from './make-fixable-and-fix.js';
|
|
9
|
+
/**
|
|
10
|
+
* The type representing the additional information for the fix.
|
|
11
|
+
*/
|
|
12
|
+
export type FixContext = {
|
|
13
|
+
filename: string;
|
|
14
|
+
sourceCode: SourceCode;
|
|
15
|
+
messages: Linter.LintMessage[];
|
|
16
|
+
ruleIds: string[];
|
|
17
|
+
fixer: Rule.RuleFixer;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fix/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,EAC9B,2BAA2B,GAC5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,KAAK,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,KAAK,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EACL,KAAK,qCAAqC,EAC1C,uCAAuC,GACxC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,0BAA0B,EAC/B,4BAA4B,GAC7B,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC;CACvB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { verifyAndFix } from '../eslint/linter.js';
|
|
2
|
+
export { createFixToApplySuggestions, } from './apply-suggestions.js';
|
|
3
|
+
export { createFixToApplyAutoFixes } from './apply-auto-fixes.js';
|
|
4
|
+
export { createFixToDisablePerFile } from './disable-per-file.js';
|
|
5
|
+
export { createFixToDisablePerLine } from './disable-per-line.js';
|
|
6
|
+
export { createFixToConvertErrorToWarningPerFile, } from './convert-error-to-warning-per-file.js';
|
|
7
|
+
export { createFixToMakeFixableAndFix, } from './make-fixable-and-fix.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fix/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAGL,2BAA2B,GAC5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAgC,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAgC,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAgC,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAEL,uCAAuC,GACxC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAGL,4BAA4B,GAC7B,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Linter, Rule } from 'eslint';
|
|
2
|
+
import type { Node } from 'estree';
|
|
3
|
+
import { FixContext } from './index.js';
|
|
4
|
+
export type FixableMaker = (message: Linter.LintMessage, node: Node | null, context: FixContext) => Rule.Fix | null | undefined;
|
|
5
|
+
export type FixToMakeFixableAndFixArgs = {
|
|
6
|
+
fixableMaker: FixableMaker;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Create fix to make fixable and fix.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createFixToMakeFixableAndFix(context: FixContext, args: FixToMakeFixableAndFixArgs): Rule.Fix[];
|
|
12
|
+
//# sourceMappingURL=make-fixable-and-fix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-fixable-and-fix.d.ts","sourceRoot":"","sources":["../../src/fix/make-fixable-and-fix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAc,MAAM,QAAQ,CAAC;AAElD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,MAAM,YAAY,GAAG,CACzB,OAAO,EAAE,MAAM,CAAC,WAAW,EAC3B,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,OAAO,EAAE,UAAU,KAChB,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,SAAS,CAAC;AAEjC,MAAM,MAAM,0BAA0B,GAAG;IACvC,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAyDF;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,0BAA0B,GAAG,IAAI,CAAC,GAAG,EAAE,CAE9G"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { traverse } from 'estraverse';
|
|
2
|
+
import { unreachable } from '../util/type-check.js';
|
|
3
|
+
/**
|
|
4
|
+
* Check the node is the source of the message.
|
|
5
|
+
*/
|
|
6
|
+
function isMessageSourceNode(sourceCode, node, message) {
|
|
7
|
+
if (message.nodeType === undefined)
|
|
8
|
+
return false;
|
|
9
|
+
// In some cases there may be no `endLine` or `endColumn`.
|
|
10
|
+
if (message.endLine === undefined || message.endColumn === undefined)
|
|
11
|
+
return false;
|
|
12
|
+
// If `nodeType` is exists, `range` must be exists.
|
|
13
|
+
if (node.range === undefined)
|
|
14
|
+
return unreachable();
|
|
15
|
+
const index = sourceCode.getIndexFromLoc({
|
|
16
|
+
line: message.line,
|
|
17
|
+
// NOTE: `column` of `ESLint.LintMessage` is 1-based, but `column` of `ESTree.Position` is 0-based.
|
|
18
|
+
column: message.column - 1,
|
|
19
|
+
});
|
|
20
|
+
const endIndex = sourceCode.getIndexFromLoc({
|
|
21
|
+
line: message.endLine,
|
|
22
|
+
// NOTE: `column` of `ESLint.LintMessage` is 1-based, but `column` of `ESTree.Position` is 0-based.
|
|
23
|
+
column: message.endColumn - 1,
|
|
24
|
+
});
|
|
25
|
+
const nodeType = message.nodeType;
|
|
26
|
+
return node.range[0] === index && node.range[1] === endIndex && node.type === nodeType;
|
|
27
|
+
}
|
|
28
|
+
function getMessageToSourceNode(sourceCode, messages) {
|
|
29
|
+
const result = new Map();
|
|
30
|
+
traverse(sourceCode.ast, {
|
|
31
|
+
// Required to traverse extension nodes such as `JSXElement`.
|
|
32
|
+
fallback: 'iteration',
|
|
33
|
+
enter(node) {
|
|
34
|
+
for (const message of messages) {
|
|
35
|
+
if (isMessageSourceNode(sourceCode, node, message)) {
|
|
36
|
+
result.set(message, node);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
function generateFixes(context, args) {
|
|
44
|
+
const messageToNode = getMessageToSourceNode(context.sourceCode, context.messages);
|
|
45
|
+
const fixes = [];
|
|
46
|
+
for (const message of context.messages) {
|
|
47
|
+
const node = messageToNode.get(message) ?? null;
|
|
48
|
+
const fix = args.fixableMaker(message, node, context);
|
|
49
|
+
if (fix)
|
|
50
|
+
fixes.push(fix);
|
|
51
|
+
}
|
|
52
|
+
return fixes;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create fix to make fixable and fix.
|
|
56
|
+
*/
|
|
57
|
+
export function createFixToMakeFixableAndFix(context, args) {
|
|
58
|
+
return generateFixes(context, args);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=make-fixable-and-fix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-fixable-and-fix.js","sourceRoot":"","sources":["../../src/fix/make-fixable-and-fix.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC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,IAAI,EAAE,OAAO,CAAC,EAAE;oBAClD,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;iBAC3B;aACF;QACH,CAAC;KACF,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,aAAa,CAAC,OAAmB,EAAE,IAAgC;IAC1E,MAAM,aAAa,GAAG,sBAAsB,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEnF,MAAM,KAAK,GAAe,EAAE,CAAC;IAC7B,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE;QACtC,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;QAChD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACtD,IAAI,GAAG;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KAC1B;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,4BAA4B,CAAC,OAAmB,EAAE,IAAgC;IAChG,OAAO,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/formatter/colors.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,aAAuB,CAAC;AACjD,eAAO,MAAM,WAAW,OAAiB,CAAC;AAC1C,eAAO,MAAM,aAAa,UAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../../src/formatter/colors.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAE1B,MAAM,CAAC,MAAM,YAAY,GAAG,WAAoB,CAAC;AACjD,MAAM,CAAC,MAAM,WAAW,GAAG,KAAc,CAAC;AAC1C,MAAM,CAAC,MAAM,aAAa,GAAG,QAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-by-files.d.ts","sourceRoot":"","sources":["../../src/formatter/format-by-files.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAOhC,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,GAAG,MAAM,CAuClE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { ERROR_COLOR, FAILED_COLOR, WARNING_COLOR } from './colors.js';
|
|
3
|
+
function pluralize(word, count) {
|
|
4
|
+
return count > 1 ? `${word}s` : word;
|
|
5
|
+
}
|
|
6
|
+
export function formatByFiles(results) {
|
|
7
|
+
let errorCount = 0;
|
|
8
|
+
let failureCount = 0;
|
|
9
|
+
let passCount = 0;
|
|
10
|
+
let warningCount = 0;
|
|
11
|
+
results.forEach((result) => {
|
|
12
|
+
const messages = result.messages;
|
|
13
|
+
if (messages.length === 0) {
|
|
14
|
+
passCount++;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
failureCount++;
|
|
18
|
+
warningCount += result.warningCount;
|
|
19
|
+
errorCount += result.errorCount;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const fileCount = passCount + failureCount;
|
|
23
|
+
const problemCount = errorCount + warningCount;
|
|
24
|
+
let summary = '';
|
|
25
|
+
summary += `- ${fileCount} ${pluralize('file', fileCount)}`;
|
|
26
|
+
summary += ' (';
|
|
27
|
+
summary += `${passCount} ${pluralize('file', passCount)} passed`;
|
|
28
|
+
summary += ', ';
|
|
29
|
+
summary += chalk[FAILED_COLOR](`${failureCount} ${pluralize('file', failureCount)} failed`);
|
|
30
|
+
summary += ') checked.\n';
|
|
31
|
+
if (problemCount > 0) {
|
|
32
|
+
summary += `- ${problemCount} ${pluralize('problem', problemCount)}`;
|
|
33
|
+
summary += ' (';
|
|
34
|
+
summary += chalk[ERROR_COLOR](`${errorCount} ${pluralize('error', errorCount)}`);
|
|
35
|
+
summary += ', ';
|
|
36
|
+
summary += chalk[WARNING_COLOR](`${warningCount} ${pluralize('warning', warningCount)}`);
|
|
37
|
+
summary += ') found.';
|
|
38
|
+
}
|
|
39
|
+
return chalk.bold(summary);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=format-by-files.js.map
|