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.
Files changed (181) hide show
  1. package/dist/action/apply-suggestions.d.ts +6 -0
  2. package/dist/action/apply-suggestions.d.ts.map +1 -0
  3. package/dist/action/apply-suggestions.js +28 -0
  4. package/dist/action/apply-suggestions.js.map +1 -0
  5. package/dist/action/convert-error-to-warning-per-file.d.ts +6 -0
  6. package/dist/action/convert-error-to-warning-per-file.d.ts.map +1 -0
  7. package/dist/action/convert-error-to-warning-per-file.js +8 -0
  8. package/dist/action/convert-error-to-warning-per-file.js.map +1 -0
  9. package/dist/action/disable-per-file.d.ts +6 -0
  10. package/dist/action/disable-per-file.d.ts.map +1 -0
  11. package/dist/action/disable-per-file.js +12 -0
  12. package/dist/action/disable-per-file.js.map +1 -0
  13. package/dist/action/disable-per-line.d.ts +6 -0
  14. package/dist/action/disable-per-line.d.ts.map +1 -0
  15. package/dist/action/disable-per-line.js +12 -0
  16. package/dist/action/disable-per-line.js.map +1 -0
  17. package/dist/action/fix.d.ts +6 -0
  18. package/dist/action/fix.d.ts.map +1 -0
  19. package/dist/action/fix.js +6 -0
  20. package/dist/action/fix.js.map +1 -0
  21. package/dist/action/index.d.ts +8 -0
  22. package/dist/action/index.d.ts.map +1 -0
  23. package/dist/action/index.js +8 -0
  24. package/dist/action/index.js.map +1 -0
  25. package/dist/action/make-fixable-and-fix.d.ts +6 -0
  26. package/dist/action/make-fixable-and-fix.d.ts.map +1 -0
  27. package/dist/action/make-fixable-and-fix.js +28 -0
  28. package/dist/action/make-fixable-and-fix.js.map +1 -0
  29. package/dist/action/print-result-details.d.ts +5 -0
  30. package/dist/action/print-result-details.d.ts.map +1 -0
  31. package/dist/action/print-result-details.js +28 -0
  32. package/dist/action/print-result-details.js.map +1 -0
  33. package/dist/cli/log.d.ts +6 -0
  34. package/dist/cli/log.d.ts.map +1 -0
  35. package/dist/cli/log.js +9 -0
  36. package/dist/cli/log.js.map +1 -0
  37. package/dist/cli/ora.d.ts +4 -0
  38. package/dist/cli/ora.d.ts.map +1 -0
  39. package/dist/cli/ora.js +23 -0
  40. package/dist/cli/ora.js.map +1 -0
  41. package/dist/cli/package.d.ts +2 -0
  42. package/dist/cli/package.d.ts.map +1 -0
  43. package/dist/cli/package.js +6 -0
  44. package/dist/cli/package.js.map +1 -0
  45. package/dist/cli/pager.d.ts +2 -0
  46. package/dist/cli/pager.d.ts.map +1 -0
  47. package/dist/cli/pager.js +34 -0
  48. package/dist/cli/pager.js.map +1 -0
  49. package/dist/cli/parse-argv.d.ts +24 -0
  50. package/dist/cli/parse-argv.d.ts.map +1 -0
  51. package/dist/cli/parse-argv.js +102 -0
  52. package/dist/cli/parse-argv.js.map +1 -0
  53. package/dist/cli/prompt.d.ts +61 -0
  54. package/dist/cli/prompt.d.ts.map +1 -0
  55. package/dist/cli/prompt.js +176 -0
  56. package/dist/cli/prompt.js.map +1 -0
  57. package/dist/cli/run.d.ts +8 -0
  58. package/dist/cli/run.d.ts.map +1 -0
  59. package/dist/cli/run.js +66 -0
  60. package/dist/cli/run.js.map +1 -0
  61. package/dist/config.d.ts +46 -0
  62. package/dist/config.d.ts.map +1 -0
  63. package/dist/config.js +91 -0
  64. package/dist/config.js.map +1 -0
  65. package/dist/core-worker.d.ts +23 -0
  66. package/dist/core-worker.d.ts.map +1 -0
  67. package/dist/core-worker.js +55 -0
  68. package/dist/core-worker.js.map +1 -0
  69. package/dist/core.d.ts +79 -0
  70. package/dist/core.d.ts.map +1 -0
  71. package/dist/core.js +159 -0
  72. package/dist/core.js.map +1 -0
  73. package/dist/eslint/linter.d.ts +18 -0
  74. package/dist/eslint/linter.d.ts.map +1 -0
  75. package/dist/eslint/linter.js +67 -0
  76. package/dist/eslint/linter.js.map +1 -0
  77. package/dist/eslint/report-translator.d.ts +9 -0
  78. package/dist/eslint/report-translator.d.ts.map +1 -0
  79. package/dist/eslint/report-translator.js +77 -0
  80. package/dist/eslint/report-translator.js.map +1 -0
  81. package/dist/eslint/rule-fixer.d.ts +80 -0
  82. package/dist/eslint/rule-fixer.d.ts.map +1 -0
  83. package/dist/eslint/rule-fixer.js +118 -0
  84. package/dist/eslint/rule-fixer.js.map +1 -0
  85. package/dist/eslint/source-code-fixer.d.ts +19 -0
  86. package/dist/eslint/source-code-fixer.d.ts.map +1 -0
  87. package/dist/eslint/source-code-fixer.js +131 -0
  88. package/dist/eslint/source-code-fixer.js.map +1 -0
  89. package/dist/fix/apply-auto-fixes.d.ts +8 -0
  90. package/dist/fix/apply-auto-fixes.d.ts.map +1 -0
  91. package/dist/fix/apply-auto-fixes.js +8 -0
  92. package/dist/fix/apply-auto-fixes.js.map +1 -0
  93. package/dist/fix/apply-suggestions.d.ts +11 -0
  94. package/dist/fix/apply-suggestions.d.ts.map +1 -0
  95. package/dist/fix/apply-suggestions.js +25 -0
  96. package/dist/fix/apply-suggestions.js.map +1 -0
  97. package/dist/fix/convert-error-to-warning-per-file.d.ts +10 -0
  98. package/dist/fix/convert-error-to-warning-per-file.d.ts.map +1 -0
  99. package/dist/fix/convert-error-to-warning-per-file.js +28 -0
  100. package/dist/fix/convert-error-to-warning-per-file.js.map +1 -0
  101. package/dist/fix/disable-per-file.d.ts +12 -0
  102. package/dist/fix/disable-per-file.d.ts.map +1 -0
  103. package/dist/fix/disable-per-file.js +63 -0
  104. package/dist/fix/disable-per-file.js.map +1 -0
  105. package/dist/fix/disable-per-line.d.ts +12 -0
  106. package/dist/fix/disable-per-line.d.ts.map +1 -0
  107. package/dist/fix/disable-per-line.js +61 -0
  108. package/dist/fix/disable-per-line.js.map +1 -0
  109. package/dist/fix/index.d.ts +19 -0
  110. package/dist/fix/index.d.ts.map +1 -0
  111. package/dist/fix/index.js +8 -0
  112. package/dist/fix/index.js.map +1 -0
  113. package/dist/fix/make-fixable-and-fix.d.ts +12 -0
  114. package/dist/fix/make-fixable-and-fix.d.ts.map +1 -0
  115. package/dist/fix/make-fixable-and-fix.js +60 -0
  116. package/dist/fix/make-fixable-and-fix.js.map +1 -0
  117. package/dist/formatter/colors.d.ts +4 -0
  118. package/dist/formatter/colors.d.ts.map +1 -0
  119. package/dist/formatter/colors.js +5 -0
  120. package/dist/formatter/colors.js.map +1 -0
  121. package/dist/formatter/format-by-files.d.ts +3 -0
  122. package/dist/formatter/format-by-files.d.ts.map +1 -0
  123. package/dist/formatter/format-by-files.js +41 -0
  124. package/dist/formatter/format-by-files.js.map +1 -0
  125. package/dist/formatter/format-by-rules.d.ts +3 -0
  126. package/dist/formatter/format-by-rules.d.ts.map +1 -0
  127. package/dist/formatter/format-by-rules.js +39 -0
  128. package/dist/formatter/format-by-rules.js.map +1 -0
  129. package/dist/formatter/index.d.ts +4 -0
  130. package/dist/formatter/index.d.ts.map +1 -0
  131. package/dist/formatter/index.js +7 -0
  132. package/dist/formatter/index.js.map +1 -0
  133. package/dist/formatter/take-rule-statistics.d.ts +18 -0
  134. package/dist/formatter/take-rule-statistics.d.ts.map +1 -0
  135. package/dist/formatter/take-rule-statistics.js +51 -0
  136. package/dist/formatter/take-rule-statistics.js.map +1 -0
  137. package/dist/index.d.ts +6 -0
  138. package/dist/index.d.ts.map +1 -0
  139. package/dist/index.js +5 -0
  140. package/dist/index.js.map +1 -0
  141. package/dist/scene/check-results.d.ts +21 -0
  142. package/dist/scene/check-results.d.ts.map +1 -0
  143. package/dist/scene/check-results.js +22 -0
  144. package/dist/scene/check-results.js.map +1 -0
  145. package/dist/scene/index.d.ts +25 -0
  146. package/dist/scene/index.d.ts.map +1 -0
  147. package/dist/scene/index.js +6 -0
  148. package/dist/scene/index.js.map +1 -0
  149. package/dist/scene/lint.d.ts +8 -0
  150. package/dist/scene/lint.d.ts.map +1 -0
  151. package/dist/scene/lint.js +31 -0
  152. package/dist/scene/lint.js.map +1 -0
  153. package/dist/scene/select-action.d.ts +20 -0
  154. package/dist/scene/select-action.d.ts.map +1 -0
  155. package/dist/scene/select-action.js +50 -0
  156. package/dist/scene/select-action.js.map +1 -0
  157. package/dist/scene/select-rule-ids.d.ts +15 -0
  158. package/dist/scene/select-rule-ids.d.ts.map +1 -0
  159. package/dist/scene/select-rule-ids.js +10 -0
  160. package/dist/scene/select-rule-ids.js.map +1 -0
  161. package/dist/util/array.d.ts +3 -0
  162. package/dist/util/array.d.ts.map +1 -0
  163. package/dist/util/array.js +14 -0
  164. package/dist/util/array.js.map +1 -0
  165. package/dist/util/cache.d.ts +5 -0
  166. package/dist/util/cache.d.ts.map +1 -0
  167. package/dist/util/cache.js +15 -0
  168. package/dist/util/cache.js.map +1 -0
  169. package/dist/util/eslint.d.ts +99 -0
  170. package/dist/util/eslint.d.ts.map +1 -0
  171. package/dist/util/eslint.js +201 -0
  172. package/dist/util/eslint.js.map +1 -0
  173. package/dist/util/filter-script.d.ts +6 -0
  174. package/dist/util/filter-script.d.ts.map +1 -0
  175. package/dist/util/filter-script.js +38 -0
  176. package/dist/util/filter-script.js.map +1 -0
  177. package/dist/util/type-check.d.ts +6 -0
  178. package/dist/util/type-check.d.ts.map +1 -0
  179. package/dist/util/type-check.js +8 -0
  180. package/dist/util/type-check.js.map +1 -0
  181. package/package.json +2 -2
package/dist/core.js ADDED
@@ -0,0 +1,159 @@
1
+ import { writeFile } from 'node:fs/promises';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { Linter } from 'eslint';
4
+ import eslintPkg from 'eslint/use-at-your-own-risk';
5
+ import isInstalledGlobally from 'is-installed-globally';
6
+ import { normalizeConfig } from './config.js';
7
+ import { createFixToApplyAutoFixes, createFixToApplySuggestions, createFixToConvertErrorToWarningPerFile, createFixToDisablePerFile, createFixToDisablePerLine, createFixToMakeFixableAndFix, verifyAndFix, } from './fix/index.js';
8
+ import { format } from './formatter/index.js';
9
+ import { filterResultsByRuleId } from './util/eslint.js';
10
+ const { LegacyESLint, FlatESLint } = eslintPkg;
11
+ /**
12
+ * Generate results to undo.
13
+ * @param resultsOfLint The results of lint.
14
+ * @returns The results to undo.
15
+ */
16
+ function generateResultsToUndo(resultsOfLint) {
17
+ return resultsOfLint.map((resultOfLint) => {
18
+ // NOTE: THIS IS HACK.
19
+ return { ...resultOfLint, output: resultOfLint.source };
20
+ });
21
+ }
22
+ /**
23
+ * The core of eslint-interactive.
24
+ * It uses ESLint's Node.js API to output a summary of problems, fix problems, apply suggestions, etc.
25
+ */
26
+ export class Core {
27
+ config;
28
+ eslint;
29
+ constructor(config) {
30
+ this.config = normalizeConfig(config);
31
+ const eslintOptions = this.config.eslintOptions;
32
+ if (eslintOptions.type === 'eslintrc') {
33
+ const { type, ...rest } = eslintOptions;
34
+ this.eslint = new LegacyESLint(rest);
35
+ }
36
+ else {
37
+ const { type, ...rest } = eslintOptions;
38
+ this.eslint = new FlatESLint(rest);
39
+ }
40
+ }
41
+ /**
42
+ * Lint project.
43
+ * @returns The results of linting
44
+ */
45
+ async lint() {
46
+ let results = await this.eslint.lintFiles(this.config.patterns);
47
+ if (this.config.quiet)
48
+ results = LegacyESLint.getErrorResults(results);
49
+ return results;
50
+ }
51
+ /**
52
+ * Returns summary of lint results.
53
+ * @param results The lint results of the project to print summary
54
+ */
55
+ formatResultSummary(results) {
56
+ const rulesMeta = this.eslint.getRulesMetaForResults(results);
57
+ return format(results, { rulesMeta, cwd: this.config.cwd });
58
+ }
59
+ /**
60
+ * Returns details of lint results.
61
+ * @param results The lint results of the project to print summary
62
+ * @param ruleIds The rule ids to print details
63
+ */
64
+ async formatResultDetails(results, ruleIds) {
65
+ const formatterName = this.config.formatterName;
66
+ // When eslint-interactive is installed globally, eslint-formatter-codeframe will also be installed globally.
67
+ // On the other hand, `eslint.loadFormatter` cannot load the globally installed formatter by name. So here it loads them by path.
68
+ const resolvedFormatterNameOrPath = isInstalledGlobally && formatterName === 'codeframe'
69
+ ? fileURLToPath(import.meta.resolve('eslint-formatter-codeframe', import.meta.resolve('eslint-interactive')))
70
+ : formatterName;
71
+ const formatter = await this.eslint.loadFormatter(resolvedFormatterNameOrPath);
72
+ return formatter.format(filterResultsByRuleId(results, ruleIds));
73
+ }
74
+ /**
75
+ * Run `eslint --fix`.
76
+ * @param ruleIds The rule ids to fix
77
+ */
78
+ async applyAutoFixes(results, ruleIds) {
79
+ return this.fix(results, ruleIds, (context) => createFixToApplyAutoFixes(context, {}));
80
+ }
81
+ /**
82
+ * Add disable comments per line.
83
+ * @param results The lint results of the project to add disable comments
84
+ * @param ruleIds The rule ids to add disable comments
85
+ * @param description The description of the disable comments
86
+ * @param descriptionPosition The position of the description
87
+ */
88
+ async disablePerLine(results, ruleIds, description, descriptionPosition) {
89
+ return this.fix(results, ruleIds, (context) => createFixToDisablePerLine(context, { description, descriptionPosition }));
90
+ }
91
+ /**
92
+ * Add disable comments per file.
93
+ * @param results The lint results of the project to add disable comments
94
+ * @param ruleIds The rule ids to add disable comments
95
+ * @param description The description of the disable comments
96
+ * @param descriptionPosition The position of the description
97
+ */
98
+ async disablePerFile(results, ruleIds, description, descriptionPosition) {
99
+ return this.fix(results, ruleIds, (context) => createFixToDisablePerFile(context, { description, descriptionPosition }));
100
+ }
101
+ /**
102
+ * Convert error to warning per file.
103
+ * @param results The lint results of the project to convert
104
+ * @param ruleIds The rule ids to convert
105
+ * @param description The comment explaining the reason for converting
106
+ */
107
+ async convertErrorToWarningPerFile(results, ruleIds, description) {
108
+ return this.fix(results, ruleIds, (context) => createFixToConvertErrorToWarningPerFile(context, { description }));
109
+ }
110
+ /**
111
+ * Apply suggestions.
112
+ * @param results The lint results of the project to apply suggestions
113
+ * @param ruleIds The rule ids to apply suggestions
114
+ * @param filter The script to filter suggestions
115
+ */
116
+ async applySuggestions(results, ruleIds, filter) {
117
+ return this.fix(results, ruleIds, (context) => createFixToApplySuggestions(context, { filter }));
118
+ }
119
+ /**
120
+ * Make forcibly fixable and run `eslint --fix`.
121
+ * @param results The lint results of the project to apply suggestions
122
+ * @param ruleIds The rule ids to apply suggestions
123
+ * @param fixableMaker The function to make `Linter.LintMessage` forcibly fixable.
124
+ */
125
+ async makeFixableAndFix(results, ruleIds, fixableMaker) {
126
+ return this.fix(results, ruleIds, (context) => createFixToMakeFixableAndFix(context, { fixableMaker }));
127
+ }
128
+ /**
129
+ * Fix source codes.
130
+ * @param fix The fix information to do.
131
+ */
132
+ async fix(resultsOfLint, ruleIds, fixCreator) {
133
+ // NOTE: Extract only necessary results and files for performance
134
+ const filteredResultsOfLint = filterResultsByRuleId(resultsOfLint, ruleIds);
135
+ const linter = new Linter({ configType: this.config.eslintOptions.type });
136
+ // eslint-disable-next-line prefer-const
137
+ for (let { filePath, source } of filteredResultsOfLint) {
138
+ if (!source)
139
+ throw new Error('Source code is required to apply fixes.');
140
+ const config = this.config.eslintOptions.type === 'eslintrc'
141
+ ? // eslint-disable-next-line no-await-in-loop
142
+ await this.eslint.calculateConfigForFile(filePath)
143
+ : // NOTE: For some reason, if files is not specified, it will not match .jsx
144
+ // eslint-disable-next-line no-await-in-loop
145
+ [{ ...(await this.eslint.calculateConfigForFile(filePath)), files: ['**/*.*', '**/*'] }];
146
+ const fixedResult = verifyAndFix(linter, source, config, filePath, ruleIds, fixCreator);
147
+ // Write the fixed source code to the file
148
+ if (fixedResult.fixed) {
149
+ // eslint-disable-next-line no-await-in-loop, @typescript-eslint/no-non-null-assertion
150
+ await writeFile(filePath, fixedResult.output);
151
+ }
152
+ }
153
+ return async () => {
154
+ const resultsToUndo = generateResultsToUndo(filteredResultsOfLint);
155
+ await LegacyESLint.outputFixes(resultsToUndo);
156
+ };
157
+ }
158
+ }
159
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAU,MAAM,EAAQ,MAAM,QAAQ,CAAC;AAC9C,OAAO,SAA6C,MAAM,6BAA6B,CAAC;AACxF,OAAO,mBAAmB,MAAM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qB,CAAC,qBAAqB,CAAC,CAAC;YACnE,MAAM,YAAY,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;QAChD,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 { Linter, Rule } from 'eslint';
7
+ import { 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(linter: Linter, text: string, config: Linter.Config | Linter.FlatConfig[], filePath: string, ruleIds: string[], fixCreator: (context: FixContext) => Rule.Fix[]): 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,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAM7C,KAAK,WAAW,GAAG;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;GAGG;AAEH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,EAAE,EAC3C,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EAAE,EACjB,UAAU,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,IAAI,CAAC,GAAG,EAAE,GAC9C,WAAW,CAoEb"}
@@ -0,0 +1,67 @@
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 { ruleFixer } from './rule-fixer.js';
4
+ import { SourceCodeFixer } from './source-code-fixer.js';
5
+ const MAX_AUTOFIX_PASSES = 10;
6
+ /**
7
+ * Performs multiple autofix passes over the text until as many fixes as possible have been applied.
8
+ * @param linter
9
+ */
10
+ // eslint-disable-next-line max-params
11
+ export function verifyAndFix(linter, text, config, 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
+ const messages = linter
28
+ .verify(currentText, config, filePath)
29
+ .filter((message) => message.ruleId && ruleIds.includes(message.ruleId));
30
+ const sourceCode = linter.getSourceCode();
31
+ // Create `Rule.Fix[]`
32
+ const fixContext = {
33
+ filename: filePath,
34
+ sourceCode,
35
+ messages,
36
+ ruleIds,
37
+ fixer: ruleFixer,
38
+ };
39
+ const fixes = fixCreator(fixContext);
40
+ fixedResult = SourceCodeFixer.applyFixes(currentText, fixes.map((fix) => {
41
+ return {
42
+ ruleId: 'eslint-interactive/fix',
43
+ severity: 2,
44
+ message: 'fix',
45
+ line: 0,
46
+ column: 0,
47
+ fix,
48
+ };
49
+ }), true);
50
+ /**
51
+ * stop if there are any syntax errors.
52
+ * 'fixedResult.output' is a empty string.
53
+ */
54
+ if (messages.length === 1 && messages[0] && messages[0].fatal) {
55
+ break;
56
+ }
57
+ // keep track if any fixes were ever applied - important for return value
58
+ fixed = fixed || fixedResult.fixed;
59
+ // update to use the fixed output instead of the original text
60
+ currentText = fixedResult.output;
61
+ } while (fixedResult.fixed && passNumber < MAX_AUTOFIX_PASSES);
62
+ // ensure the last result properly reflects if fixes were done
63
+ fixedResult.fixed = fixed;
64
+ fixedResult.output = currentText;
65
+ return fixedResult;
66
+ }
67
+ //# sourceMappingURL=linter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linter.js","sourceRoot":"","sources":["../../src/eslint/linter.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,+FAA+F;AAU/F,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAO9B;;;GAGG;AACH,sCAAsC;AACtC,MAAM,UAAU,YAAY,CAC1B,MAAc,EACd,IAAY,EACZ,MAA2C,EAC3C,QAAgB,EAChB,OAAiB,EACjB,UAA+C;IAE/C,IAAI,WAAwB,CAAC;IAC7B,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,WAAW,GAAG,IAAI,CAAC;IAEvB;;;;;;;;OAQG;IACH,GAAG;QACD,UAAU,EAAE,CAAC;QAEb,MAAM,QAAQ,GAAG,MAAM;aACpB,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC;aACrC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QAC3E,MAAM,UAAU,GAAG,MAAM,CAAC,aAAa,EAAE,CAAC;QAE1C,sBAAsB;QACtB,MAAM,UAAU,GAAe;YAC7B,QAAQ,EAAE,QAAQ;YAClB,UAAU;YACV,QAAQ;YACR,OAAO;YACP,KAAK,EAAE,SAAS;SACjB,CAAC;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;YAC7D,MAAM;SACP;QAED,yEAAyE;QACzE,KAAK,GAAG,KAAK,IAAI,WAAW,CAAC,KAAK,CAAC;QAEnC,8DAA8D;QAC9D,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC;KAClC,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 { 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,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AA2C1C;;;;;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,77 @@
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
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
61
+ const start = fixes[0].range[0];
62
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
63
+ const end = fixes[fixes.length - 1].range[1];
64
+ let text = '';
65
+ let lastPos = Number.MIN_SAFE_INTEGER;
66
+ for (const fix of fixes) {
67
+ assert(fix.range[0] >= lastPos, 'Fix objects must not be overlapped in a report.');
68
+ if (fix.range[0] >= 0) {
69
+ text += originalText.slice(Math.max(0, start, lastPos), fix.range[0]);
70
+ }
71
+ text += fix.text;
72
+ lastPos = fix.range[1];
73
+ }
74
+ text += originalText.slice(Math.max(0, start, lastPos), end);
75
+ return { range: [start, end], text };
76
+ }
77
+ //# 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;QACR,OAAO,IAAI,CAAC;KACb;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;QACP,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,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,CAAC,CAAC;QAEnF,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE;YACrB,IAAI,IAAI,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SACvE;QACD,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC;QACjB,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACxB;IACD,IAAI,IAAI,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC;IAE7D,OAAO,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;AACvC,CAAC"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * @fileoverview An object that creates fix commands for rules.
3
+ * @author Nicholas C. Zakas
4
+ */
5
+ import { 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,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAoBnC;;GAEG;AAEH,8CAA8C;AAC9C,QAAA,MAAM,SAAS;IACb;;;;;;OAMG;iCAC0B,IAAI,GAAG,IAAI,KAAK,QAAQ,MAAM,GAAG,KAAK,GAAG;IAKtE;;;;;;;OAOG;iDAC0C,MAAM,GAAG,KAAK,GAAG;IAI9D;;;;;;OAMG;kCAC2B,IAAI,GAAG,IAAI,KAAK,QAAQ,MAAM,GAAG,KAAK,GAAG;IAKvE;;;;;;;OAOG;kDAC2C,MAAM,GAAG,KAAK,GAAG;IAI/D;;;;;;OAMG;6BACsB,IAAI,GAAG,IAAI,KAAK,QAAQ,MAAM,GAAG,KAAK,GAAG;IAKlE;;;;;;;OAOG;6CACsC,MAAM,GAAG,KAAK,GAAG;IAO1D;;;;;OAKG;wBACiB,IAAI,GAAG,IAAI,KAAK,GAAG,KAAK,GAAG;IAK/C;;;;;;OAMG;mCAC4B,KAAK,GAAG;EAMvC,CAAC;AAEH,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,118 @@
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
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
33
+ return this.insertTextAfterRange(nodeOrToken.range, text);
34
+ },
35
+ /**
36
+ * Creates a fix command that inserts text after the specified range in the source text.
37
+ * The fix is not applied until applyFixes() is called.
38
+ * @param {int[]} range The range to replace, first item is start of range, second
39
+ * is end of range.
40
+ * @param {string} text The text to insert.
41
+ * @returns {Object} The fix command.
42
+ */
43
+ insertTextAfterRange(range, text) {
44
+ return insertTextAt(range[1], text);
45
+ },
46
+ /**
47
+ * Creates a fix command that inserts text before the given node or token.
48
+ * The fix is not applied until applyFixes() is called.
49
+ * @param {ASTNode|Token} nodeOrToken The node or token to insert before.
50
+ * @param {string} text The text to insert.
51
+ * @returns {Object} The fix command.
52
+ */
53
+ insertTextBefore(nodeOrToken, text) {
54
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
55
+ return this.insertTextBeforeRange(nodeOrToken.range, text);
56
+ },
57
+ /**
58
+ * Creates a fix command that inserts text before the specified range in the source text.
59
+ * The fix is not applied until applyFixes() is called.
60
+ * @param {int[]} range The range to replace, first item is start of range, second
61
+ * is end of range.
62
+ * @param {string} text The text to insert.
63
+ * @returns {Object} The fix command.
64
+ */
65
+ insertTextBeforeRange(range, text) {
66
+ return insertTextAt(range[0], text);
67
+ },
68
+ /**
69
+ * Creates a fix command that replaces text at the node or token.
70
+ * The fix is not applied until applyFixes() is called.
71
+ * @param {ASTNode|Token} nodeOrToken The node or token to remove.
72
+ * @param {string} text The text to insert.
73
+ * @returns {Object} The fix command.
74
+ */
75
+ replaceText(nodeOrToken, text) {
76
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
77
+ return this.replaceTextRange(nodeOrToken.range, text);
78
+ },
79
+ /**
80
+ * Creates a fix command that replaces text at the specified range in the source text.
81
+ * The fix is not applied until applyFixes() is called.
82
+ * @param {int[]} range The range to replace, first item is start of range, second
83
+ * is end of range.
84
+ * @param {string} text The text to insert.
85
+ * @returns {Object} The fix command.
86
+ */
87
+ replaceTextRange(range, text) {
88
+ return {
89
+ range,
90
+ text,
91
+ };
92
+ },
93
+ /**
94
+ * Creates a fix command that removes the node or token from the source.
95
+ * The fix is not applied until applyFixes() is called.
96
+ * @param {ASTNode|Token} nodeOrToken The node or token to remove.
97
+ * @returns {Object} The fix command.
98
+ */
99
+ remove(nodeOrToken) {
100
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
101
+ return this.removeRange(nodeOrToken.range);
102
+ },
103
+ /**
104
+ * Creates a fix command that removes the specified range of text from the source.
105
+ * The fix is not applied until applyFixes() is called.
106
+ * @param {int[]} range The range to remove, first item is start of range, second
107
+ * is end of range.
108
+ * @returns {Object} The fix command.
109
+ */
110
+ removeRange(range) {
111
+ return {
112
+ range,
113
+ text: '',
114
+ };
115
+ },
116
+ });
117
+ export { ruleFixer };
118
+ //# 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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fileoverview An object that caches and applies source code fixes.
3
+ * @author Nicholas C. Zakas
4
+ */
5
+ import { 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: (sourceText: string, messages: Linter.LintMessage[], shouldFix: boolean | ((message: Linter.LintMessage) => boolean)) => {
13
+ fixed: boolean;
14
+ messages: Linter.LintMessage[];
15
+ output: string;
16
+ };
17
+ }
18
+ export { SourceCodeFixer };
19
+ //# 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,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAqChC;;;GAGG;AACH,iBAAS,eAAe,SAGvB;kBAHQ,eAAe;;;;;;;AA0GxB,OAAO,EAAE,eAAe,EAAE,CAAC"}