eslint-interactive 13.0.0 → 13.0.1
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/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 +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 +5 -0
- package/dist/action/print-result-details.d.ts.map +1 -0
- package/dist/action/print-result-details.js +35 -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 +10 -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 +82 -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 +135 -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 +52 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/spinner.d.ts +4 -0
- package/dist/cli/spinner.d.ts.map +1 -0
- package/dist/cli/spinner.js +20 -0
- package/dist/cli/spinner.js.map +1 -0
- package/dist/core-worker.d.ts +21 -0
- package/dist/core-worker.d.ts.map +1 -0
- package/dist/core-worker.js +47 -0
- package/dist/core-worker.js.map +1 -0
- package/dist/core.d.ts +82 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +186 -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/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 +8 -0
- package/dist/formatter/format-by-rules.d.ts.map +1 -0
- package/dist/formatter/format-by-rules.js +31 -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 +6 -0
- package/dist/formatter/index.d.ts.map +1 -0
- package/dist/formatter/index.js +8 -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 +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 +30 -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 +44 -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/type.d.ts +12 -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/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 +18 -19
- package/src/index.ts +0 -0
|
@@ -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,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 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview An object that creates fix commands for rules.
|
|
3
|
+
* @author Nicholas C. Zakas
|
|
4
|
+
*/
|
|
5
|
+
import type { AST, Rule } from 'eslint';
|
|
6
|
+
import type { Node } from 'estree';
|
|
7
|
+
/**
|
|
8
|
+
* Creates code fixing commands for rules.
|
|
9
|
+
*/
|
|
10
|
+
/** @type {import('eslint').Rule.RuleFixer} */
|
|
11
|
+
declare const ruleFixer: Readonly<{
|
|
12
|
+
/**
|
|
13
|
+
* Creates a fix command that inserts text after the given node or token.
|
|
14
|
+
* The fix is not applied until applyFixes() is called.
|
|
15
|
+
* @param {ASTNode|Token} nodeOrToken The node or token to insert after.
|
|
16
|
+
* @param {string} text The text to insert.
|
|
17
|
+
* @returns {Object} The fix command.
|
|
18
|
+
*/
|
|
19
|
+
insertTextAfter(nodeOrToken: Node | AST.Token, text: string): Rule.Fix;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a fix command that inserts text after the specified range in the source text.
|
|
22
|
+
* The fix is not applied until applyFixes() is called.
|
|
23
|
+
* @param {int[]} range The range to replace, first item is start of range, second
|
|
24
|
+
* is end of range.
|
|
25
|
+
* @param {string} text The text to insert.
|
|
26
|
+
* @returns {Object} The fix command.
|
|
27
|
+
*/
|
|
28
|
+
insertTextAfterRange(range: AST.Range, text: string): Rule.Fix;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a fix command that inserts text before the given node or token.
|
|
31
|
+
* The fix is not applied until applyFixes() is called.
|
|
32
|
+
* @param {ASTNode|Token} nodeOrToken The node or token to insert before.
|
|
33
|
+
* @param {string} text The text to insert.
|
|
34
|
+
* @returns {Object} The fix command.
|
|
35
|
+
*/
|
|
36
|
+
insertTextBefore(nodeOrToken: Node | AST.Token, text: string): Rule.Fix;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a fix command that inserts text before the specified range in the source text.
|
|
39
|
+
* The fix is not applied until applyFixes() is called.
|
|
40
|
+
* @param {int[]} range The range to replace, first item is start of range, second
|
|
41
|
+
* is end of range.
|
|
42
|
+
* @param {string} text The text to insert.
|
|
43
|
+
* @returns {Object} The fix command.
|
|
44
|
+
*/
|
|
45
|
+
insertTextBeforeRange(range: AST.Range, text: string): Rule.Fix;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a fix command that replaces text at the node or token.
|
|
48
|
+
* The fix is not applied until applyFixes() is called.
|
|
49
|
+
* @param {ASTNode|Token} nodeOrToken The node or token to remove.
|
|
50
|
+
* @param {string} text The text to insert.
|
|
51
|
+
* @returns {Object} The fix command.
|
|
52
|
+
*/
|
|
53
|
+
replaceText(nodeOrToken: Node | AST.Token, text: string): Rule.Fix;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a fix command that replaces text at the specified range in the source text.
|
|
56
|
+
* The fix is not applied until applyFixes() is called.
|
|
57
|
+
* @param {int[]} range The range to replace, first item is start of range, second
|
|
58
|
+
* is end of range.
|
|
59
|
+
* @param {string} text The text to insert.
|
|
60
|
+
* @returns {Object} The fix command.
|
|
61
|
+
*/
|
|
62
|
+
replaceTextRange(range: AST.Range, text: string): Rule.Fix;
|
|
63
|
+
/**
|
|
64
|
+
* Creates a fix command that removes the node or token from the source.
|
|
65
|
+
* The fix is not applied until applyFixes() is called.
|
|
66
|
+
* @param {ASTNode|Token} nodeOrToken The node or token to remove.
|
|
67
|
+
* @returns {Object} The fix command.
|
|
68
|
+
*/
|
|
69
|
+
remove(nodeOrToken: Node | AST.Token): Rule.Fix;
|
|
70
|
+
/**
|
|
71
|
+
* Creates a fix command that removes the specified range of text from the source.
|
|
72
|
+
* The fix is not applied until applyFixes() is called.
|
|
73
|
+
* @param {int[]} range The range to remove, first item is start of range, second
|
|
74
|
+
* is end of range.
|
|
75
|
+
* @returns {Object} The fix command.
|
|
76
|
+
*/
|
|
77
|
+
removeRange(range: AST.Range): Rule.Fix;
|
|
78
|
+
}>;
|
|
79
|
+
export { ruleFixer };
|
|
80
|
+
//# sourceMappingURL=rule-fixer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-fixer.d.ts","sourceRoot":"","sources":["../../src/eslint/rule-fixer.ts"],"names":[],"mappings":"AAGA;;;GAGG;AAYH,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAoBnC;;GAEG;AAEH,8CAA8C;AAC9C,QAAA,MAAM,SAAS;IACb;;;;;;OAMG;iCAC0B,IAAI,GAAG,GAAG,CAAC,KAAK,QAAQ,MAAM,GAAG,IAAI,CAAC,GAAG;IAItE;;;;;;;OAOG;gCACyB,GAAG,CAAC,KAAK,QAAQ,MAAM,GAAG,IAAI,CAAC,GAAG;IAI9D;;;;;;OAMG;kCAC2B,IAAI,GAAG,GAAG,CAAC,KAAK,QAAQ,MAAM,GAAG,IAAI,CAAC,GAAG;IAIvE;;;;;;;OAOG;iCAC0B,GAAG,CAAC,KAAK,QAAQ,MAAM,GAAG,IAAI,CAAC,GAAG;IAI/D;;;;;;OAMG;6BACsB,IAAI,GAAG,GAAG,CAAC,KAAK,QAAQ,MAAM,GAAG,IAAI,CAAC,GAAG;IAIlE;;;;;;;OAOG;4BACqB,GAAG,CAAC,KAAK,QAAQ,MAAM,GAAG,IAAI,CAAC,GAAG;IAO1D;;;;;OAKG;wBACiB,IAAI,GAAG,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG;IAI/C;;;;;;OAMG;uBACgB,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG;EAMvC,CAAC;AAEH,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// copy from: https://github.com/eslint/eslint/blob/219aecb78bc646d44bad27dc775a9b3d3dc58232/lib/linter/rule-fixer.js
|
|
2
|
+
// ESLint does not export the RuleFixer. So, I've copied the implementation.
|
|
3
|
+
/**
|
|
4
|
+
* Creates a fix command that inserts text at the specified index in the source text.
|
|
5
|
+
* @param {int} index The 0-based index at which to insert the new text.
|
|
6
|
+
* @param {string} text The text to insert.
|
|
7
|
+
* @returns {Object} The fix command.
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
function insertTextAt(index, text) {
|
|
11
|
+
return {
|
|
12
|
+
range: [index, index],
|
|
13
|
+
text,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
// ------------------------------------------------------------------------------
|
|
17
|
+
// Public Interface
|
|
18
|
+
// ------------------------------------------------------------------------------
|
|
19
|
+
/**
|
|
20
|
+
* Creates code fixing commands for rules.
|
|
21
|
+
*/
|
|
22
|
+
/** @type {import('eslint').Rule.RuleFixer} */
|
|
23
|
+
const ruleFixer = Object.freeze({
|
|
24
|
+
/**
|
|
25
|
+
* Creates a fix command that inserts text after the given node or token.
|
|
26
|
+
* The fix is not applied until applyFixes() is called.
|
|
27
|
+
* @param {ASTNode|Token} nodeOrToken The node or token to insert after.
|
|
28
|
+
* @param {string} text The text to insert.
|
|
29
|
+
* @returns {Object} The fix command.
|
|
30
|
+
*/
|
|
31
|
+
insertTextAfter(nodeOrToken, text) {
|
|
32
|
+
return this.insertTextAfterRange(nodeOrToken.range, text);
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Creates a fix command that inserts text after the specified range in the source text.
|
|
36
|
+
* The fix is not applied until applyFixes() is called.
|
|
37
|
+
* @param {int[]} range The range to replace, first item is start of range, second
|
|
38
|
+
* is end of range.
|
|
39
|
+
* @param {string} text The text to insert.
|
|
40
|
+
* @returns {Object} The fix command.
|
|
41
|
+
*/
|
|
42
|
+
insertTextAfterRange(range, text) {
|
|
43
|
+
return insertTextAt(range[1], text);
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Creates a fix command that inserts text before the given node or token.
|
|
47
|
+
* The fix is not applied until applyFixes() is called.
|
|
48
|
+
* @param {ASTNode|Token} nodeOrToken The node or token to insert before.
|
|
49
|
+
* @param {string} text The text to insert.
|
|
50
|
+
* @returns {Object} The fix command.
|
|
51
|
+
*/
|
|
52
|
+
insertTextBefore(nodeOrToken, text) {
|
|
53
|
+
return this.insertTextBeforeRange(nodeOrToken.range, text);
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* Creates a fix command that inserts text before the specified range in the source text.
|
|
57
|
+
* The fix is not applied until applyFixes() is called.
|
|
58
|
+
* @param {int[]} range The range to replace, first item is start of range, second
|
|
59
|
+
* is end of range.
|
|
60
|
+
* @param {string} text The text to insert.
|
|
61
|
+
* @returns {Object} The fix command.
|
|
62
|
+
*/
|
|
63
|
+
insertTextBeforeRange(range, text) {
|
|
64
|
+
return insertTextAt(range[0], text);
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Creates a fix command that replaces text at the node or token.
|
|
68
|
+
* The fix is not applied until applyFixes() is called.
|
|
69
|
+
* @param {ASTNode|Token} nodeOrToken The node or token to remove.
|
|
70
|
+
* @param {string} text The text to insert.
|
|
71
|
+
* @returns {Object} The fix command.
|
|
72
|
+
*/
|
|
73
|
+
replaceText(nodeOrToken, text) {
|
|
74
|
+
return this.replaceTextRange(nodeOrToken.range, text);
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Creates a fix command that replaces text at the specified range in the source text.
|
|
78
|
+
* The fix is not applied until applyFixes() is called.
|
|
79
|
+
* @param {int[]} range The range to replace, first item is start of range, second
|
|
80
|
+
* is end of range.
|
|
81
|
+
* @param {string} text The text to insert.
|
|
82
|
+
* @returns {Object} The fix command.
|
|
83
|
+
*/
|
|
84
|
+
replaceTextRange(range, text) {
|
|
85
|
+
return {
|
|
86
|
+
range,
|
|
87
|
+
text,
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
/**
|
|
91
|
+
* Creates a fix command that removes the node or token from the source.
|
|
92
|
+
* The fix is not applied until applyFixes() is called.
|
|
93
|
+
* @param {ASTNode|Token} nodeOrToken The node or token to remove.
|
|
94
|
+
* @returns {Object} The fix command.
|
|
95
|
+
*/
|
|
96
|
+
remove(nodeOrToken) {
|
|
97
|
+
return this.removeRange(nodeOrToken.range);
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* Creates a fix command that removes the specified range of text from the source.
|
|
101
|
+
* The fix is not applied until applyFixes() is called.
|
|
102
|
+
* @param {int[]} range The range to remove, first item is start of range, second
|
|
103
|
+
* is end of range.
|
|
104
|
+
* @returns {Object} The fix command.
|
|
105
|
+
*/
|
|
106
|
+
removeRange(range) {
|
|
107
|
+
return {
|
|
108
|
+
range,
|
|
109
|
+
text: '',
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
export { ruleFixer };
|
|
114
|
+
//# sourceMappingURL=rule-fixer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-fixer.js","sourceRoot":"","sources":["../../src/eslint/rule-fixer.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,4EAA4E;AAoB5E;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,KAAa,EAAE,IAAY;IAC/C,OAAO;QACL,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;QACrB,IAAI;KACL,CAAC;AACJ,CAAC;AAED,iFAAiF;AACjF,mBAAmB;AACnB,iFAAiF;AAEjF;;GAEG;AAEH,8CAA8C;AAC9C,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B;;;;;;OAMG;IACH,eAAe,CAAC,WAA6B,EAAE,IAAY;QACzD,OAAO,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,KAAM,EAAE,IAAI,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;;;OAOG;IACH,oBAAoB,CAAC,KAAgB,EAAE,IAAY;QACjD,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACH,gBAAgB,CAAC,WAA6B,EAAE,IAAY;QAC1D,OAAO,IAAI,CAAC,qBAAqB,CAAC,WAAW,CAAC,KAAM,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;IAED;;;;;;;OAOG;IACH,qBAAqB,CAAC,KAAgB,EAAE,IAAY;QAClD,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CAAC,WAA6B,EAAE,IAAY;QACrD,OAAO,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,KAAM,EAAE,IAAI,CAAC,CAAC;IACzD,CAAC;IAED;;;;;;;OAOG;IACH,gBAAgB,CAAC,KAAgB,EAAE,IAAY;QAC7C,OAAO;YACL,KAAK;YACL,IAAI;SACL,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,WAA6B;QAClC,OAAO,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,KAAM,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CAAC,KAAgB;QAC1B,OAAO;YACL,KAAK;YACL,IAAI,EAAE,EAAE;SACT,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview An object that caches and applies source code fixes.
|
|
3
|
+
* @author Nicholas C. Zakas
|
|
4
|
+
*/
|
|
5
|
+
import type { Linter } from 'eslint';
|
|
6
|
+
/**
|
|
7
|
+
* Utility for apply fixes to source code.
|
|
8
|
+
* @constructor
|
|
9
|
+
*/
|
|
10
|
+
declare function SourceCodeFixer(): void;
|
|
11
|
+
declare namespace SourceCodeFixer {
|
|
12
|
+
var applyFixes;
|
|
13
|
+
}
|
|
14
|
+
export { SourceCodeFixer };
|
|
15
|
+
//# sourceMappingURL=source-code-fixer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-code-fixer.d.ts","sourceRoot":"","sources":["../../src/eslint/source-code-fixer.ts"],"names":[],"mappings":"AAGA;;;GAGG;AAOH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAqCrC;;;GAGG;AACH,iBAAS,eAAe,SAGvB;kBAHQ,eAAe;;;AA0GxB,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -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;IACb,MAAM,CA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,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;QACD,MAAM,IAAI,IAAI,CAAC,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;IACJ,CAAC;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 type { Rule } from 'eslint';
|
|
2
|
+
import type { 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,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C,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 type { Linter, Rule } from 'eslint';
|
|
2
|
+
import type { 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,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,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,CAAC;QACvC,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;IAC3B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import type { 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,KAAK,EAAU,IAAI,EAAE,MAAM,QAAQ,CAAC;AAI3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,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 type { Rule } from 'eslint';
|
|
2
|
+
import type { DescriptionPosition } from 'src/cli/prompt.js';
|
|
3
|
+
import type { 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,KAAK,EAAE,IAAI,EAAc,MAAM,QAAQ,CAAC;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAc7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,mBAAmB,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;CACvD,CAAC;AAqEF;;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, insertDescriptionCommentStatementBeforeLine, insertDisableCommentStatementBeforeLine, mergeDescription, mergeRuleIds, parseDisableComment, 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 ? disableCommentPerFile.loc.start.line
|
|
18
|
+
: shebang ? sourceCode.getLocFromIndex(shebang.range[0]).line + 1
|
|
19
|
+
: 1;
|
|
20
|
+
const fixes = [];
|
|
21
|
+
const isPreviousLine = description !== undefined && descriptionPosition === 'previousLine';
|
|
22
|
+
if (isPreviousLine) {
|
|
23
|
+
fixes.push(insertDescriptionCommentStatementBeforeLine({
|
|
24
|
+
fixer,
|
|
25
|
+
sourceCode,
|
|
26
|
+
line: lineToInsert,
|
|
27
|
+
column: 0,
|
|
28
|
+
description,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
if (disableCommentPerFile) {
|
|
32
|
+
fixes.push(updateDisableComment({
|
|
33
|
+
fixer,
|
|
34
|
+
disableComment: disableCommentPerFile,
|
|
35
|
+
newRules: mergeRuleIds(disableCommentPerFile.ruleIds, ruleIdsToDisable),
|
|
36
|
+
newDescription: isPreviousLine ?
|
|
37
|
+
disableCommentPerFile.description
|
|
38
|
+
: mergeDescription(disableCommentPerFile.description, description),
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
fixes.push(insertDisableCommentStatementBeforeLine({
|
|
43
|
+
fixer,
|
|
44
|
+
sourceCode,
|
|
45
|
+
line: lineToInsert,
|
|
46
|
+
column: 0,
|
|
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
|