eslint-interactive 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +147 -0
  3. package/bin/eslint-interactive.js +10 -0
  4. package/dist/action/apply-suggestions.d.ts +6 -0
  5. package/dist/action/apply-suggestions.d.ts.map +1 -0
  6. package/dist/action/apply-suggestions.js +28 -0
  7. package/dist/action/apply-suggestions.js.map +1 -0
  8. package/dist/action/disable-per-file.d.ts +6 -0
  9. package/dist/action/disable-per-file.d.ts.map +1 -0
  10. package/dist/action/disable-per-file.js +8 -0
  11. package/dist/action/disable-per-file.js.map +1 -0
  12. package/dist/action/disable-per-line.d.ts +6 -0
  13. package/dist/action/disable-per-line.d.ts.map +1 -0
  14. package/dist/action/disable-per-line.js +8 -0
  15. package/dist/action/disable-per-line.js.map +1 -0
  16. package/dist/action/fix.d.ts +6 -0
  17. package/dist/action/fix.d.ts.map +1 -0
  18. package/dist/action/fix.js +6 -0
  19. package/dist/action/fix.js.map +1 -0
  20. package/dist/action/index.d.ts +7 -0
  21. package/dist/action/index.d.ts.map +1 -0
  22. package/dist/action/index.js +7 -0
  23. package/dist/action/index.js.map +1 -0
  24. package/dist/action/make-fixable-and-fix.d.ts +6 -0
  25. package/dist/action/make-fixable-and-fix.d.ts.map +1 -0
  26. package/dist/action/make-fixable-and-fix.js +28 -0
  27. package/dist/action/make-fixable-and-fix.js.map +1 -0
  28. package/dist/action/print-result-details.d.ts +5 -0
  29. package/dist/action/print-result-details.d.ts.map +1 -0
  30. package/dist/action/print-result-details.js +12 -0
  31. package/dist/action/print-result-details.js.map +1 -0
  32. package/dist/cli/log.d.ts +6 -0
  33. package/dist/cli/log.d.ts.map +1 -0
  34. package/dist/cli/log.js +9 -0
  35. package/dist/cli/log.js.map +1 -0
  36. package/dist/cli/ora.d.ts +4 -0
  37. package/dist/cli/ora.d.ts.map +1 -0
  38. package/dist/cli/ora.js +23 -0
  39. package/dist/cli/ora.js.map +1 -0
  40. package/dist/cli/package.d.ts +2 -0
  41. package/dist/cli/package.d.ts.map +1 -0
  42. package/dist/cli/package.js +6 -0
  43. package/dist/cli/package.js.map +1 -0
  44. package/dist/cli/parse-argv.d.ts +4 -0
  45. package/dist/cli/parse-argv.d.ts.map +1 -0
  46. package/dist/cli/parse-argv.js +50 -0
  47. package/dist/cli/parse-argv.js.map +1 -0
  48. package/dist/cli/prompt.d.ts +53 -0
  49. package/dist/cli/prompt.d.ts.map +1 -0
  50. package/dist/cli/prompt.js +154 -0
  51. package/dist/cli/prompt.js.map +1 -0
  52. package/dist/cli/run.d.ts +8 -0
  53. package/dist/cli/run.d.ts.map +1 -0
  54. package/dist/cli/run.js +46 -0
  55. package/dist/cli/run.js.map +1 -0
  56. package/dist/core-worker.d.ts +21 -0
  57. package/dist/core-worker.d.ts.map +1 -0
  58. package/dist/core-worker.js +52 -0
  59. package/dist/core-worker.js.map +1 -0
  60. package/dist/core.d.ts +84 -0
  61. package/dist/core.d.ts.map +1 -0
  62. package/dist/core.js +196 -0
  63. package/dist/core.js.map +1 -0
  64. package/dist/formatter/colors.d.ts +4 -0
  65. package/dist/formatter/colors.d.ts.map +1 -0
  66. package/dist/formatter/colors.js +5 -0
  67. package/dist/formatter/colors.js.map +1 -0
  68. package/dist/formatter/format-by-files.d.ts +3 -0
  69. package/dist/formatter/format-by-files.d.ts.map +1 -0
  70. package/dist/formatter/format-by-files.js +41 -0
  71. package/dist/formatter/format-by-files.js.map +1 -0
  72. package/dist/formatter/format-by-rules.d.ts +3 -0
  73. package/dist/formatter/format-by-rules.d.ts.map +1 -0
  74. package/dist/formatter/format-by-rules.js +34 -0
  75. package/dist/formatter/format-by-rules.js.map +1 -0
  76. package/dist/formatter/index.d.ts +4 -0
  77. package/dist/formatter/index.d.ts.map +1 -0
  78. package/dist/formatter/index.js +7 -0
  79. package/dist/formatter/index.js.map +1 -0
  80. package/dist/formatter/take-rule-statistics.d.ts +18 -0
  81. package/dist/formatter/take-rule-statistics.d.ts.map +1 -0
  82. package/dist/formatter/take-rule-statistics.js +51 -0
  83. package/dist/formatter/take-rule-statistics.js.map +1 -0
  84. package/dist/index.d.ts +5 -0
  85. package/dist/index.d.ts.map +1 -0
  86. package/dist/index.js +4 -0
  87. package/dist/index.js.map +1 -0
  88. package/dist/plugin/fix/apply-auto-fixes.d.ts +8 -0
  89. package/dist/plugin/fix/apply-auto-fixes.d.ts.map +1 -0
  90. package/dist/plugin/fix/apply-auto-fixes.js +8 -0
  91. package/dist/plugin/fix/apply-auto-fixes.js.map +1 -0
  92. package/dist/plugin/fix/apply-suggestions.d.ts +11 -0
  93. package/dist/plugin/fix/apply-suggestions.d.ts.map +1 -0
  94. package/dist/plugin/fix/apply-suggestions.js +25 -0
  95. package/dist/plugin/fix/apply-suggestions.js.map +1 -0
  96. package/dist/plugin/fix/disable-per-file.d.ts +10 -0
  97. package/dist/plugin/fix/disable-per-file.d.ts.map +1 -0
  98. package/dist/plugin/fix/disable-per-file.js +39 -0
  99. package/dist/plugin/fix/disable-per-file.js.map +1 -0
  100. package/dist/plugin/fix/disable-per-line.d.ts +10 -0
  101. package/dist/plugin/fix/disable-per-line.d.ts.map +1 -0
  102. package/dist/plugin/fix/disable-per-line.js +54 -0
  103. package/dist/plugin/fix/disable-per-line.js.map +1 -0
  104. package/dist/plugin/fix/index.d.ts +6 -0
  105. package/dist/plugin/fix/index.d.ts.map +1 -0
  106. package/dist/plugin/fix/index.js +6 -0
  107. package/dist/plugin/fix/index.js.map +1 -0
  108. package/dist/plugin/fix/make-fixable-and-fix.d.ts +12 -0
  109. package/dist/plugin/fix/make-fixable-and-fix.d.ts.map +1 -0
  110. package/dist/plugin/fix/make-fixable-and-fix.js +61 -0
  111. package/dist/plugin/fix/make-fixable-and-fix.js.map +1 -0
  112. package/dist/plugin/fix-rule.d.ts +10 -0
  113. package/dist/plugin/fix-rule.d.ts.map +1 -0
  114. package/dist/plugin/fix-rule.js +124 -0
  115. package/dist/plugin/fix-rule.js.map +1 -0
  116. package/dist/plugin/index.d.ts +49 -0
  117. package/dist/plugin/index.d.ts.map +1 -0
  118. package/dist/plugin/index.js +11 -0
  119. package/dist/plugin/index.js.map +1 -0
  120. package/dist/plugin/prefer-addition-shorthand-rule.d.ts +7 -0
  121. package/dist/plugin/prefer-addition-shorthand-rule.d.ts.map +1 -0
  122. package/dist/plugin/prefer-addition-shorthand-rule.js +54 -0
  123. package/dist/plugin/prefer-addition-shorthand-rule.js.map +1 -0
  124. package/dist/plugin/rule-fixer.d.ts +80 -0
  125. package/dist/plugin/rule-fixer.d.ts.map +1 -0
  126. package/dist/plugin/rule-fixer.js +118 -0
  127. package/dist/plugin/rule-fixer.js.map +1 -0
  128. package/dist/scene/check-results.d.ts +21 -0
  129. package/dist/scene/check-results.d.ts.map +1 -0
  130. package/dist/scene/check-results.js +22 -0
  131. package/dist/scene/check-results.js.map +1 -0
  132. package/dist/scene/index.d.ts +25 -0
  133. package/dist/scene/index.d.ts.map +1 -0
  134. package/dist/scene/index.js +6 -0
  135. package/dist/scene/index.js.map +1 -0
  136. package/dist/scene/lint.d.ts +8 -0
  137. package/dist/scene/lint.d.ts.map +1 -0
  138. package/dist/scene/lint.js +31 -0
  139. package/dist/scene/lint.js.map +1 -0
  140. package/dist/scene/select-action.d.ts +20 -0
  141. package/dist/scene/select-action.d.ts.map +1 -0
  142. package/dist/scene/select-action.js +46 -0
  143. package/dist/scene/select-action.js.map +1 -0
  144. package/dist/scene/select-rule-ids.d.ts +15 -0
  145. package/dist/scene/select-rule-ids.d.ts.map +1 -0
  146. package/dist/scene/select-rule-ids.js +10 -0
  147. package/dist/scene/select-rule-ids.js.map +1 -0
  148. package/dist/tsconfig.src.tsbuildinfo +1 -0
  149. package/dist/util/array.d.ts +3 -0
  150. package/dist/util/array.d.ts.map +1 -0
  151. package/dist/util/array.js +14 -0
  152. package/dist/util/array.js.map +1 -0
  153. package/dist/util/cache.d.ts +5 -0
  154. package/dist/util/cache.d.ts.map +1 -0
  155. package/dist/util/cache.js +13 -0
  156. package/dist/util/cache.js.map +1 -0
  157. package/dist/util/eslint.d.ts +68 -0
  158. package/dist/util/eslint.d.ts.map +1 -0
  159. package/dist/util/eslint.js +147 -0
  160. package/dist/util/eslint.js.map +1 -0
  161. package/dist/util/filter-script.d.ts +6 -0
  162. package/dist/util/filter-script.d.ts.map +1 -0
  163. package/dist/util/filter-script.js +39 -0
  164. package/dist/util/filter-script.js.map +1 -0
  165. package/dist/util/type-check.d.ts +3 -0
  166. package/dist/util/type-check.d.ts.map +1 -0
  167. package/dist/util/type-check.js +8 -0
  168. package/dist/util/type-check.js.map +1 -0
  169. package/package.json +93 -0
  170. package/src/action/apply-suggestions.ts +40 -0
  171. package/src/action/disable-per-file.ts +16 -0
  172. package/src/action/disable-per-line.ts +16 -0
  173. package/src/action/fix.ts +14 -0
  174. package/src/action/index.ts +6 -0
  175. package/src/action/make-fixable-and-fix.ts +40 -0
  176. package/src/action/print-result-details.ts +18 -0
  177. package/src/cli/log.ts +11 -0
  178. package/src/cli/ora.ts +25 -0
  179. package/src/cli/package.ts +9 -0
  180. package/src/cli/parse-argv.ts +52 -0
  181. package/src/cli/prompt.ts +205 -0
  182. package/src/cli/run.ts +50 -0
  183. package/src/core-worker.ts +66 -0
  184. package/src/core.ts +240 -0
  185. package/src/formatter/colors.ts +5 -0
  186. package/src/formatter/format-by-files.ts +48 -0
  187. package/src/formatter/format-by-rules.ts +37 -0
  188. package/src/formatter/index.ts +9 -0
  189. package/src/formatter/take-rule-statistics.ts +66 -0
  190. package/src/index.ts +4 -0
  191. package/src/plugin/fix/apply-auto-fixes.ts +13 -0
  192. package/src/plugin/fix/apply-suggestions.ts +44 -0
  193. package/src/plugin/fix/disable-per-file.ts +53 -0
  194. package/src/plugin/fix/disable-per-line.ts +65 -0
  195. package/src/plugin/fix/index.ts +13 -0
  196. package/src/plugin/fix/make-fixable-and-fix.ts +77 -0
  197. package/src/plugin/fix-rule.ts +142 -0
  198. package/src/plugin/index.ts +66 -0
  199. package/src/plugin/prefer-addition-shorthand-rule.ts +56 -0
  200. package/src/plugin/rule-fixer.ts +147 -0
  201. package/src/scene/check-results.ts +43 -0
  202. package/src/scene/index.ts +18 -0
  203. package/src/scene/lint.ts +41 -0
  204. package/src/scene/select-action.ts +70 -0
  205. package/src/scene/select-rule-ids.ts +24 -0
  206. package/src/typings/cachedir.d.ts +5 -0
  207. package/src/typings/node-pager.d.ts +4 -0
  208. package/src/util/array.ts +16 -0
  209. package/src/util/cache.ts +11 -0
  210. package/src/util/eslint.ts +162 -0
  211. package/src/util/filter-script.ts +45 -0
  212. package/src/util/type-check.ts +8 -0
  213. package/static/example-filter-script.js +49 -0
  214. package/static/example-fixable-maker-script.js +47 -0
@@ -0,0 +1,124 @@
1
+ import { createFixToApplyAutoFixes, createFixToApplySuggestions, createFixToDisablePerFile, createFixToDisablePerLine, createFixToMakeFixableAndFix, } from './fix/index.js';
2
+ import { ruleFixer } from './rule-fixer.js';
3
+ export const OVERLAPPED_PROBLEM_MESSAGE = 'overlapped';
4
+ // from: https://github.com/eslint/eslint/blob/58840ac844a61c72eabb603ecfb761812b82a7ed/lib/linter/report-translator.js#L136
5
+ function compareFixesByRange(a, b) {
6
+ return a.range[0] - b.range[0] || a.range[1] - b.range[1];
7
+ }
8
+ /**
9
+ * @file The rule to do the fix.
10
+ * The fix function returns the `Rule.Fix` that describes how to fix the code.
11
+ * To apply the fix to your code, you need to use ESLint's API to apply the `Rule.Fix`.
12
+ *
13
+ * However, there is no dedicated API in ESLint to apply `Rule.Fix` (there is an internal API
14
+ * called `SourceCodeFixer`,but it is not exposed to the public). For now, the only way
15
+ * to apply `Rule.Fix` is to report a fixable problem from a rule and fix it
16
+ * with `ESLint.outputFixes`.
17
+ *
18
+ * This module is a rule that executes a fix function and converts the return value
19
+ * to a fixable problem.
20
+ */
21
+ const fileStatusMap = new Map();
22
+ function createFixes(context, ruleOption, fixer) {
23
+ const { fix, results, ruleIds } = ruleOption;
24
+ const result = results.find((result) => result.filePath === context.getFilename());
25
+ if (!result)
26
+ return null;
27
+ const messages = result.messages.filter((message) => message.ruleId && ruleIds.includes(message.ruleId));
28
+ const fixContext = {
29
+ filename: context.getFilename(),
30
+ sourceCode: context.getSourceCode(),
31
+ messages,
32
+ ruleIds,
33
+ fixer,
34
+ };
35
+ let fixes = [];
36
+ if (fix.name === 'applyAutoFixes') {
37
+ fixes = createFixToApplyAutoFixes(fixContext, fix.args);
38
+ }
39
+ else if (fix.name === 'disablePerLine') {
40
+ fixes = createFixToDisablePerLine(fixContext, fix.args);
41
+ }
42
+ else if (fix.name === 'disablePerFile') {
43
+ fixes = createFixToDisablePerFile(fixContext, fix.args);
44
+ }
45
+ else if (fix.name === 'applySuggestions') {
46
+ fixes = createFixToApplySuggestions(fixContext, fix.args);
47
+ }
48
+ else if (fix.name === 'makeFixableAndFix') {
49
+ fixes = createFixToMakeFixableAndFix(fixContext, fix.args);
50
+ }
51
+ else {
52
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-explicit-any
53
+ throw new Error(`Unknown fix: ${fix.name}`);
54
+ }
55
+ if (fixes.length === 0)
56
+ return null;
57
+ return fixes;
58
+ }
59
+ export const fixRule = {
60
+ meta: {
61
+ fixable: 'code',
62
+ },
63
+ create(context) {
64
+ // TODO: refactor
65
+ return {
66
+ // eslint-disable-next-line @typescript-eslint/naming-convention
67
+ Program: () => {
68
+ var _a;
69
+ const filename = context.getFilename();
70
+ // 🤯🤯🤯 THIS IS SUPER HACK!!! 🤯🤯🤯
71
+ // fix するとコードが変わり、また別の lint エラーが発生する可能性があるため、eslint は `context.report` で
72
+ // 報告されたエラーの fix がすべて終わったら、再び create を呼び出し、また `context.report` で fix 可能なエラーが
73
+ // 報告されないかを確認する仕様になっている (これは `context.report` で fix 可能なものがなくなるまで続く)。
74
+ // そのため、ここでは2回目以降 create が呼び出された時に、誤って再び fix してしまわないよう、fix 済み
75
+ // であれば early return するようにしている。
76
+ const status = (_a = fileStatusMap.get(filename)) !== null && _a !== void 0 ? _a : { isAlreadyFixed: false, hasOverlappedProblem: false };
77
+ if (status.isAlreadyFixed) {
78
+ fileStatusMap.delete(filename); // Reset just in case.
79
+ if (status.hasOverlappedProblem) {
80
+ context.report({
81
+ loc: {
82
+ // The location is required, so set dummy values.
83
+ line: 0,
84
+ column: 0,
85
+ },
86
+ message: OVERLAPPED_PROBLEM_MESSAGE,
87
+ });
88
+ }
89
+ return;
90
+ }
91
+ const ruleOption = context.options[0];
92
+ const newStatus = {
93
+ isAlreadyFixed: true,
94
+ hasOverlappedProblem: false,
95
+ };
96
+ const fixes = createFixes(context, ruleOption, ruleFixer);
97
+ if (!fixes)
98
+ return;
99
+ fixes.sort(compareFixesByRange);
100
+ let lastPos = 0;
101
+ const fixesToReport = [];
102
+ for (const fix of fixes) {
103
+ if (fix.range[0] < lastPos) {
104
+ newStatus.hasOverlappedProblem = true;
105
+ continue;
106
+ }
107
+ fixesToReport.push(fix);
108
+ lastPos = fix.range[1];
109
+ }
110
+ fileStatusMap.set(filename, newStatus);
111
+ context.report({
112
+ loc: {
113
+ // The location is required, so set dummy values.
114
+ line: 0,
115
+ column: 0,
116
+ },
117
+ message: `fix`,
118
+ fix: () => fixesToReport,
119
+ });
120
+ },
121
+ };
122
+ },
123
+ };
124
+ //# sourceMappingURL=fix-rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-rule.js","sourceRoot":"","sources":["../../src/plugin/fix-rule.ts"],"names":[],"mappings":"AACA,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,yBAAyB,EACzB,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,MAAM,CAAC,MAAM,0BAA0B,GAAG,YAAY,CAAC;AAEvD,4HAA4H;AAC5H,SAAS,mBAAmB,CAAC,CAAW,EAAE,CAAW;IACnD,OAAO,CA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uleOption } from './fix-rule.js';
3
+ import { type FixableMaker, type SuggestionFilter, type FixToApplySuggestionsArgs, type FixToDisablePerFileArgs, type FixToDisablePerLineArgs, type FixToMakeFixableAndFixArgs, type FixToApplyAutoFixesArgs } from './fix/index.js';
4
+ export { OVERLAPPED_PROBLEM_MESSAGE } from './fix-rule.js';
5
+ export { FixRuleOption, type FixableMaker, type SuggestionFilter };
6
+ export declare const eslintInteractivePlugin: {
7
+ rules: {
8
+ fix: Rule.RuleModule;
9
+ 'prefer-addition-shorthand': Rule.RuleModule;
10
+ };
11
+ };
12
+ /**
13
+ * The type representing the fix to do.
14
+ */
15
+ export declare type Fix = {
16
+ name: 'applyAutoFixes';
17
+ args: FixArg<'applyAutoFixes'>;
18
+ } | {
19
+ name: 'disablePerLine';
20
+ args: FixArg<'disablePerLine'>;
21
+ } | {
22
+ name: 'disablePerFile';
23
+ args: FixArg<'disablePerFile'>;
24
+ } | {
25
+ name: 'applySuggestions';
26
+ args: FixArg<'applySuggestions'>;
27
+ } | {
28
+ name: 'makeFixableAndFix';
29
+ args: FixArg<'makeFixableAndFix'>;
30
+ };
31
+ /** For test */
32
+ export declare type FixName = 'applyAutoFixes' | 'disablePerLine' | 'disablePerFile' | 'applySuggestions' | 'makeFixableAndFix';
33
+ /** For test */
34
+ export declare type FixArg<T extends FixName> = T extends 'applyAutoFixes' ? FixToApplyAutoFixesArgs : T extends 'disablePerLine' ? FixToDisablePerLineArgs : T extends 'disablePerFile' ? FixToDisablePerFileArgs : T extends 'applySuggestions' ? FixToApplySuggestionsArgs : T extends 'makeFixableAndFix' ? FixToMakeFixableAndFixArgs : never;
35
+ /**
36
+ * The type representing the additional information for the fix.
37
+ */
38
+ export declare type FixContext = {
39
+ filename: string;
40
+ sourceCode: SourceCode;
41
+ messages: Linter.LintMessage[];
42
+ ruleIds: string[];
43
+ fixer: Rule.RuleFixer;
44
+ };
45
+ /**
46
+ * The type representing the fix function.
47
+ */
48
+ export declare type FixFunction<T> = (context: FixContext, args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AAmB,CAAC;AAExH,eAAe;AACf,oBAAY,MAAM,CAAC,CAAC,SAAS,OAAO,IAAI,CAAC,SAAS,gBAAgB,GAC9D,uBAAuB,GACvB,CAAC,SAAS,gBAAgB,GAC1B,uBAAuB,GACvB,CAAC,SAAS,gBAAgB,GAC1B,uBAAuB,GACvB,CAAC,SAAS,kBAAkB,GAC5B,yBAAyB,GACzB,CAAC,SAAS,mBAAmB,GAC7B,0BAA0B,GAC1B,KAAK,CAAC;AAEV;;GAEG;AACH,oBAAY,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;AAEF;;GAEG;AACH,oBAAY,WAAW,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { fixRule } from './fix-rule.js';
2
+ import { preferAdditionShorthandRule } from './prefer-addition-shorthand-rule.js';
3
+ export { OVERLAPPED_PROBLEM_MESSAGE } from './fix-rule.js';
4
+ export const eslintInteractivePlugin = {
5
+ rules: {
6
+ 'fix': fixRule,
7
+ // for test
8
+ 'prefer-addition-shorthand': preferAdditionShorthandRule,
9
+ },
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAsB,MAAM,eAAe,CAAC;AAU5D,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAElF,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAI3D,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,KAAK,EAAE;QACL,KAAK,EAAE,OAAO;QACd,WAAW;QACX,2BAA2B,EAAE,2BAA2B;KACzD;CACF,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Rule } from 'eslint';
2
+ /**
3
+ * @file This is a rule for testing purposes.
4
+ */
5
+ export declare type ApplyFixesRuleOption = Rule.Fix[];
6
+ export declare const preferAdditionShorthandRule: Rule.RuleModule;
7
+ //# sourceMappingURL=prefer-addition-shorthand-rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefer-addition-shorthand-rule.d.ts","sourceRoot":"","sources":["../../src/plugin/prefer-addition-shorthand-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B;;GAEG;AAEH,oBAAY,oBAAoB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AAE9C,eAAO,MAAM,2BAA2B,EAAE,IAAI,CAAC,UA+C9C,CAAC"}
@@ -0,0 +1,54 @@
1
+ export const preferAdditionShorthandRule = {
2
+ meta: {
3
+ type: 'suggestion',
4
+ // @ts-ignore
5
+ hasSuggestions: true,
6
+ },
7
+ create(context) {
8
+ return {
9
+ // eslint-disable-next-line @typescript-eslint/naming-convention
10
+ AssignmentExpression: (node) => {
11
+ if (node.left.type !== 'Identifier')
12
+ return;
13
+ const leftIdentifier = node.left;
14
+ if (node.right.type !== 'BinaryExpression')
15
+ return;
16
+ const rightBinaryExpression = node.right;
17
+ if (rightBinaryExpression.operator !== '+')
18
+ return;
19
+ if (rightBinaryExpression.left.type !== 'Identifier')
20
+ return;
21
+ const rightIdentifier = rightBinaryExpression.left;
22
+ if (leftIdentifier.name !== rightIdentifier.name)
23
+ return;
24
+ if (rightBinaryExpression.right.type !== 'Literal' || rightBinaryExpression.right.value !== 1)
25
+ return;
26
+ context.report({
27
+ node,
28
+ message: 'The addition method is redundant.',
29
+ suggest: [
30
+ {
31
+ desc: 'Use `val += 1` instead.',
32
+ fix: function (fixer) {
33
+ return fixer.replaceText(node, `${leftIdentifier.name} += 1`);
34
+ },
35
+ },
36
+ {
37
+ desc: 'Use `val++` instead.',
38
+ fix: function (fixer) {
39
+ return fixer.replaceText(node, `${leftIdentifier.name}++`);
40
+ },
41
+ },
42
+ {
43
+ desc: 'Use `++val` instead.',
44
+ fix: function (fixer) {
45
+ return fixer.replaceText(node, `++${leftIdentifier.name}`);
46
+ },
47
+ },
48
+ ],
49
+ });
50
+ },
51
+ };
52
+ },
53
+ };
54
+ //# sourceMappingURL=prefer-addition-shorthand-rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefer-addition-shorthand-rule.js","sourceRoot":"","sources":["../../src/plugin/prefer-addition-shorthand-rule.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,2BAA2B,GAAoB;IAC1D,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,aAAa;QACb,cAAc,EAAE,IAAI;KACrB;IACD,MAAM,CAAC,OAAyB;QAC9B,OAAO;YACL,gEAAgE;YAChE,oBAAoB,EAAE,CAAC,IAAI,EAAE,EAAE;gBAC7B,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY;oBAAE,OAAO;gBAC5C,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC;gBACjC,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,kBAAkB;oBAAE,OAAO;gBACnD,MAAM,qBAAqB,GAAG,IAAI,CAAC,KAAK,CAAC;gBACzC,IAAI,qBAAqB,CAAC,QAAQ,KAAK,GAAG;oBAAE,OAAO;gBACnD,IAAI,qBAAqB,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY;oBAAE,OAAO;gBAC7D,MAAM,eAAe,GAAG,qBAAqB,CAAC,IAAI,CAAC;gBACnD,IAAI,cAAc,CAAC,IAAI,KAAK,eAAe,CAAC,IAAI;oBAAE,OAAO;gBACzD,IAAI,qBAAqB,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,qBAAqB,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC;oBAAE,OAAO;gBAEtG,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI;oBACJ,OAAO,EAAE,mCAAmC;oBAC5C,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,yBAAyB;4BAC/B,GAAG,EAAE,UAAU,KAAK;gCAClB,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,cAAc,CAAC,IAAI,OAAO,CAAC,CAAC;4BAChE,CAAC;yBACF;wBACD;4BACE,IAAI,EAAE,sBAAsB;4BAC5B,GAAG,EAAE,UAAU,KAAK;gCAClB,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,cAAc,CAAC,IAAI,IAAI,CAAC,CAAC;4BAC7D,CAAC;yBACF;wBACD;4BACE,IAAI,EAAE,sBAAsB;4BAC5B,GAAG,EAAE,UAAU,KAAK;gCAClB,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC;4BAC7D,CAAC;yBACF;qBACF;iBACF,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,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/plugin/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/plugin/rule-fixer.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,4EAA4E;AAoB5E;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,KAAa,EAAE,IAAY;IAC/C,OAAO;QACL,K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ACH,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,21 @@
1
+ import { ESLint } from 'eslint';
2
+ import { Action } from '../cli/prompt.js';
3
+ import { Undo } from '../core.js';
4
+ import { NextScene } from './index.js';
5
+ export declare type CheckResultsArgs = {
6
+ /** The lint results of the project */
7
+ results: ESLint.LintResult[];
8
+ /** The rule ids that are in the `results`. */
9
+ ruleIdsInResults: string[];
10
+ /** The rule ids to perform the action. */
11
+ selectedRuleIds: string[];
12
+ /** The function to execute undo. */
13
+ undo: Undo;
14
+ /** The selected actions. */
15
+ selectedAction: Action;
16
+ };
17
+ /**
18
+ * Run the scene where a user check the fix results.
19
+ */
20
+ export declare function checkResults({ results, ruleIdsInResults, selectedRuleIds, undo, selectedAction, }: CheckResultsArgs): Promise<NextScene>;
21
+ //# sourceMappingURL=check-results.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-results.d.ts","sourceRoot":"","sources":["../../src/scene/check-results.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,MAAM,EAA6B,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,oBAAY,gBAAgB,GAAG;IAC7B,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;IAC7B,8CAA8C;IAC9C,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,0CAA0C;IAC1C,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,oCAAoC;IACpC,IAAI,EAAE,IAAI,CAAC;IACX,4BAA4B;IAC5B,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,wBAAsB,YAAY,CAAC,EACjC,OAAO,EACP,gBAAgB,EAChB,eAAe,EACf,IAAI,EACJ,cAAc,GACf,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAcvC"}
@@ -0,0 +1,22 @@
1
+ import { undoingSpinner } from '../cli/ora.js';
2
+ import { promptToInputWhatToDoNext } from '../cli/prompt.js';
3
+ /**
4
+ * Run the scene where a user check the fix results.
5
+ */
6
+ export async function checkResults({ results, ruleIdsInResults, selectedRuleIds, undo, selectedAction, }) {
7
+ const nextStep = await promptToInputWhatToDoNext();
8
+ if (nextStep === 'exit')
9
+ return { name: 'exit' };
10
+ if (nextStep === 'undoTheFix') {
11
+ await undoingSpinner(async () => undo());
12
+ return {
13
+ name: 'selectAction',
14
+ args: { results, ruleIdsInResults, selectedRuleIds, initialAction: selectedAction },
15
+ };
16
+ }
17
+ console.log();
18
+ console.log('─'.repeat(process.stdout.columns));
19
+ console.log();
20
+ return { name: 'lint' };
21
+ }
22
+ //# sourceMappingURL=check-results.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-results.js","sourceRoot":"","sources":["../../src/scene/check-results.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAU,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAiBrE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,EACjC,OAAO,EACP,gBAAgB,EAChB,eAAe,EACf,IAAI,EACJ,cAAc,GACG;IACjB,MAAM,QAAQ,GAAG,MAAM,yBAAyB,EAAE,CAAC;IACnD,IAAI,QAAQ,KAAK,MAAM;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IACjD,IAAI,QAAQ,KAAK,YAAY,EAAE;QAC7B,MAAM,cAAc,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QACzC,OAAO;YACL,IAAI,EAAE,cAAc;YACpB,IAAI,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE;SACpF,CAAC;KACH;IACD,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAChD,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { CheckResultsArgs } from './check-results.js';
2
+ import { selectAction, type SelectActionArgs } from './select-action.js';
3
+ import { selectRuleIds, type SelectRuleIdsArgs } from './select-rule-ids.js';
4
+ export { selectAction, type SelectActionArgs, selectRuleIds, type SelectRuleIdsArgs };
5
+ export { lint } from './lint.js';
6
+ export { checkResults } from './check-results.js';
7
+ /**
8
+ * The return type when calling a scene function.
9
+ * Indicates which scene to jump to next.
10
+ */
11
+ export declare type NextScene = {
12
+ name: 'lint';
13
+ } | {
14
+ name: 'selectRuleIds';
15
+ args: SelectRuleIdsArgs;
16
+ } | {
17
+ name: 'selectAction';
18
+ args: SelectActionArgs;
19
+ } | {
20
+ name: 'checkResults';
21
+ args: CheckResultsArgs;
22
+ } | {
23
+ name: 'exit';
24
+ };
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scene/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,CAAC;AACtF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;GAGG;AACH,oBAAY,SAAS,GACjB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,iBAAiB,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { selectAction } from './select-action.js';
2
+ import { selectRuleIds } from './select-rule-ids.js';
3
+ export { selectAction, selectRuleIds };
4
+ export { lint } from './lint.js';
5
+ export { checkResults } from './check-results.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scene/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAyB,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,aAAa,EAA0B,MAAM,sBAAsB,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAyB,aAAa,EAA0B,CAAC;AACtF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Remote } from 'comlink';
2
+ import { SerializableCore } from '../core-worker.js';
3
+ import { NextScene } from './index.js';
4
+ /**
5
+ * Run the scene to lint.
6
+ */
7
+ export declare function lint(core: Remote<SerializableCore>): Promise<NextScene>;
8
+ //# sourceMappingURL=lint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../../src/scene/lint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGrD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC;;GAEG;AACH,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CA6B7E"}
@@ -0,0 +1,31 @@
1
+ import { warn } from '../cli/log.js';
2
+ import { lintingSpinner } from '../cli/ora.js';
3
+ import { unique } from '../util/array.js';
4
+ import { notEmpty } from '../util/type-check.js';
5
+ /**
6
+ * Run the scene to lint.
7
+ */
8
+ export async function lint(core) {
9
+ const results = await lintingSpinner(async () => core.lint());
10
+ console.log();
11
+ const ruleIdsInResults = unique(results
12
+ .flatMap((result) => result.messages)
13
+ .flatMap((message) => message.ruleId)
14
+ .filter(notEmpty));
15
+ if (ruleIdsInResults.length === 0) {
16
+ console.log('💚 No error found.');
17
+ return { name: 'exit' };
18
+ }
19
+ console.log(await core.formatResultSummary(results));
20
+ const hasESLintCoreProblems = results.flatMap((result) => result.messages).some((message) => message.ruleId === null);
21
+ if (hasESLintCoreProblems) {
22
+ warn('ESLint Core Problems are found. ' +
23
+ 'The problems cannot be fixed by eslint-interactive. ' +
24
+ 'Check the details of the problem and fix it. ' +
25
+ 'This is usually caused by the invalid eslintrc or the invalid syntax of the linted code.');
26
+ console.log(await core.formatResultDetails(results, [null]));
27
+ }
28
+ console.log();
29
+ return { name: 'selectRuleIds', args: { results, ruleIdsInResults } };
30
+ }
31
+ //# sourceMappingURL=lint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.js","sourceRoot":"","sources":["../../src/scene/lint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC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