eslint-interactive 12.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/README.md +34 -58
- package/bin/eslint-interactive.js +8 -11
- package/dist/action/index.d.ts +0 -2
- package/dist/action/index.d.ts.map +1 -1
- package/dist/action/index.js +0 -2
- package/dist/action/index.js.map +1 -1
- package/dist/action/print-result-details.d.ts.map +1 -1
- package/dist/action/print-result-details.js +6 -1
- package/dist/action/print-result-details.js.map +1 -1
- package/dist/cli/log.d.ts +3 -3
- package/dist/cli/log.d.ts.map +1 -1
- package/dist/cli/log.js +5 -4
- package/dist/cli/log.js.map +1 -1
- package/dist/cli/parse-argv.d.ts +2 -22
- package/dist/cli/parse-argv.d.ts.map +1 -1
- package/dist/cli/parse-argv.js +37 -43
- package/dist/cli/parse-argv.js.map +1 -1
- package/dist/cli/prompt.d.ts +1 -11
- package/dist/cli/prompt.d.ts.map +1 -1
- package/dist/cli/prompt.js +3 -44
- package/dist/cli/prompt.js.map +1 -1
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +6 -20
- package/dist/cli/run.js.map +1 -1
- package/dist/core-worker.d.ts +2 -4
- package/dist/core-worker.d.ts.map +1 -1
- package/dist/core-worker.js +3 -10
- package/dist/core-worker.js.map +1 -1
- package/dist/core.d.ts +8 -5
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +61 -47
- package/dist/core.js.map +1 -1
- package/dist/eslint/linter.d.ts +2 -3
- package/dist/eslint/linter.d.ts.map +1 -1
- package/dist/eslint/linter.js.map +1 -1
- package/dist/eslint/source-code-fixer.d.ts +1 -5
- package/dist/eslint/source-code-fixer.d.ts.map +1 -1
- package/dist/fix/make-fixable-and-fix.d.ts +2 -3
- package/dist/fix/make-fixable-and-fix.d.ts.map +1 -1
- package/dist/fix/make-fixable-and-fix.js +14 -41
- package/dist/fix/make-fixable-and-fix.js.map +1 -1
- package/dist/formatter/format-by-files.d.ts.map +1 -1
- package/dist/formatter/format-by-files.js +1 -0
- package/dist/formatter/format-by-files.js.map +1 -1
- package/dist/formatter/format-by-rules.d.ts +6 -1
- package/dist/formatter/format-by-rules.d.ts.map +1 -1
- package/dist/formatter/format-by-rules.js +7 -2
- package/dist/formatter/format-by-rules.js.map +1 -1
- package/dist/formatter/index.d.ts +3 -1
- package/dist/formatter/index.d.ts.map +1 -1
- package/dist/formatter/index.js +3 -2
- package/dist/formatter/index.js.map +1 -1
- 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/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +14 -0
- package/dist/plugin.js.map +1 -1
- package/dist/scene/lint.d.ts.map +1 -1
- package/dist/scene/lint.js +13 -14
- package/dist/scene/lint.js.map +1 -1
- package/dist/scene/select-action.d.ts.map +1 -1
- package/dist/scene/select-action.js +3 -9
- package/dist/scene/select-action.js.map +1 -1
- 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/eslint.d.ts.map +1 -1
- package/dist/util/eslint.js +1 -1
- package/dist/util/eslint.js.map +1 -1
- package/dist/util/type-check.d.ts +0 -3
- package/dist/util/type-check.d.ts.map +1 -1
- package/package.json +20 -20
- package/src/action/index.ts +0 -2
- package/src/action/print-result-details.ts +7 -1
- package/src/cli/log.ts +5 -4
- package/src/cli/parse-argv.ts +45 -61
- package/src/cli/prompt.ts +4 -48
- package/src/cli/run.ts +6 -22
- package/src/core-worker.ts +6 -21
- package/src/core.ts +52 -50
- package/src/eslint/linter.ts +2 -3
- package/src/fix/make-fixable-and-fix.ts +15 -47
- package/src/formatter/format-by-files.ts +1 -0
- package/src/formatter/format-by-rules.ts +18 -3
- package/src/formatter/index.ts +8 -3
- package/src/formatter/sort-rule-statistics.ts +35 -0
- package/src/index.ts +2 -2
- package/src/plugin.ts +14 -0
- package/src/scene/lint.ts +16 -18
- package/src/scene/select-action.ts +1 -8
- package/src/type.ts +13 -0
- package/src/util/eslint.ts +2 -2
- package/src/util/type-check.ts +0 -4
- package/bin/_eslint-interactive.js +0 -9
- package/dist/action/apply-suggestions.d.ts +0 -6
- package/dist/action/apply-suggestions.d.ts.map +0 -1
- package/dist/action/apply-suggestions.js +0 -27
- package/dist/action/apply-suggestions.js.map +0 -1
- package/dist/action/make-fixable-and-fix.d.ts +0 -6
- package/dist/action/make-fixable-and-fix.d.ts.map +0 -1
- package/dist/action/make-fixable-and-fix.js +0 -27
- package/dist/action/make-fixable-and-fix.js.map +0 -1
- package/dist/config.d.ts +0 -47
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -98
- package/dist/config.js.map +0 -1
- package/dist/eslint/use-at-your-own-risk.d.ts +0 -5
- package/dist/eslint/use-at-your-own-risk.d.ts.map +0 -1
- package/dist/eslint/use-at-your-own-risk.js +0 -6
- package/dist/eslint/use-at-your-own-risk.js.map +0 -1
- package/dist/util/file-system.d.ts +0 -5
- package/dist/util/file-system.d.ts.map +0 -1
- package/dist/util/file-system.js +0 -10
- package/dist/util/file-system.js.map +0 -1
- package/dist/util/filter-script.d.ts +0 -6
- package/dist/util/filter-script.d.ts.map +0 -1
- package/dist/util/filter-script.js +0 -38
- package/dist/util/filter-script.js.map +0 -1
- package/src/action/apply-suggestions.ts +0 -39
- package/src/action/make-fixable-and-fix.ts +0 -39
- package/src/config.ts +0 -142
- package/src/eslint/use-at-your-own-risk.js +0 -6
- package/src/util/file-system.ts +0 -10
- package/src/util/filter-script.ts +0 -45
- package/static/example-filter-script.js +0 -40
- package/static/example-fixable-maker-script.js +0 -38
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { access, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { dirname } from 'node:path';
|
|
3
|
-
import type { Remote } from 'comlink';
|
|
4
|
-
import type { ESLint } from 'eslint';
|
|
5
|
-
import { promptToInputReuseScript } from '../cli/prompt.js';
|
|
6
|
-
import { fixingSpinner } from '../cli/spinner.js';
|
|
7
|
-
import type { Undo } from '../core.js';
|
|
8
|
-
import type { SerializableCore } from '../core-worker.js';
|
|
9
|
-
import {
|
|
10
|
-
editFileWithEditor,
|
|
11
|
-
generateExampleFixableMakerScriptFilePath,
|
|
12
|
-
generateFixableMakerScriptFilePath,
|
|
13
|
-
} from '../util/filter-script.js';
|
|
14
|
-
|
|
15
|
-
export async function doMakeFixableAndFixAction(
|
|
16
|
-
core: Remote<SerializableCore>,
|
|
17
|
-
results: ESLint.LintResult[],
|
|
18
|
-
selectedRuleIds: string[],
|
|
19
|
-
): Promise<Undo> {
|
|
20
|
-
const exampleScript = await readFile(generateExampleFixableMakerScriptFilePath(), 'utf8');
|
|
21
|
-
const fixableMakerScriptFilePath = generateFixableMakerScriptFilePath(selectedRuleIds);
|
|
22
|
-
const isFixableMakerScriptExist = await access(fixableMakerScriptFilePath)
|
|
23
|
-
.then(() => true)
|
|
24
|
-
.catch(() => false);
|
|
25
|
-
if (isFixableMakerScriptExist) {
|
|
26
|
-
const reuseScript = await promptToInputReuseScript();
|
|
27
|
-
if (!reuseScript) {
|
|
28
|
-
await writeFile(fixableMakerScriptFilePath, exampleScript);
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
await mkdir(dirname(fixableMakerScriptFilePath), { recursive: true }); // Create the directory because it might not exist
|
|
32
|
-
await writeFile(fixableMakerScriptFilePath, exampleScript);
|
|
33
|
-
}
|
|
34
|
-
console.log('Opening editor...');
|
|
35
|
-
|
|
36
|
-
const fixableMakerScript = await editFileWithEditor(fixableMakerScriptFilePath);
|
|
37
|
-
const undo = await fixingSpinner(async () => core.makeFixableAndFix(results, selectedRuleIds, fixableMakerScript));
|
|
38
|
-
return undo;
|
|
39
|
-
}
|
package/src/config.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import type { ESLint } from 'eslint';
|
|
2
|
-
import type { ParsedCLIOptions } from './cli/parse-argv.js';
|
|
3
|
-
import { cliOptionsDefaults } from './cli/parse-argv.js';
|
|
4
|
-
import type { DeepPartial } from './util/type-check.js';
|
|
5
|
-
|
|
6
|
-
type LegacyESLintOptions = { type: 'eslintrc' } & Pick<
|
|
7
|
-
ESLint.LegacyOptions,
|
|
8
|
-
| 'useEslintrc'
|
|
9
|
-
| 'overrideConfigFile'
|
|
10
|
-
| 'extensions'
|
|
11
|
-
| 'rulePaths'
|
|
12
|
-
| 'ignorePath'
|
|
13
|
-
| 'cache'
|
|
14
|
-
| 'cacheLocation'
|
|
15
|
-
| 'overrideConfig'
|
|
16
|
-
| 'cwd'
|
|
17
|
-
| 'resolvePluginsRelativeTo'
|
|
18
|
-
| 'plugins'
|
|
19
|
-
>;
|
|
20
|
-
type FlatESLintOptions = { type: 'flat' } & Pick<
|
|
21
|
-
ESLint.Options,
|
|
22
|
-
'overrideConfigFile' | 'cache' | 'cacheLocation' | 'overrideConfig' | 'cwd' | 'flags'
|
|
23
|
-
>;
|
|
24
|
-
|
|
25
|
-
export type ESLintOptions = LegacyESLintOptions | FlatESLintOptions;
|
|
26
|
-
|
|
27
|
-
/** The config of eslint-interactive */
|
|
28
|
-
export type Config = {
|
|
29
|
-
patterns: string[];
|
|
30
|
-
formatterName?: string | undefined;
|
|
31
|
-
quiet?: boolean | undefined;
|
|
32
|
-
cwd?: string | undefined;
|
|
33
|
-
eslintOptions: ESLintOptions;
|
|
34
|
-
flags?: string[] | undefined;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
type ESLintOptionsType = 'eslintrc' | 'flat';
|
|
38
|
-
|
|
39
|
-
export function translateCLIOptions(options: ParsedCLIOptions, eslintOptionsType: ESLintOptionsType): Config {
|
|
40
|
-
if (eslintOptionsType === 'eslintrc') {
|
|
41
|
-
return {
|
|
42
|
-
patterns: options.patterns,
|
|
43
|
-
formatterName: options.formatterName,
|
|
44
|
-
quiet: options.quiet,
|
|
45
|
-
eslintOptions: {
|
|
46
|
-
type: 'eslintrc',
|
|
47
|
-
useEslintrc: options.useEslintrc,
|
|
48
|
-
overrideConfigFile: options.overrideConfigFile,
|
|
49
|
-
extensions: options.extensions,
|
|
50
|
-
rulePaths: options.rulePaths,
|
|
51
|
-
ignorePath: options.ignorePath,
|
|
52
|
-
cache: options.cache,
|
|
53
|
-
cacheLocation: options.cacheLocation,
|
|
54
|
-
resolvePluginsRelativeTo: options.resolvePluginsRelativeTo,
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
} else if (eslintOptionsType === 'flat') {
|
|
58
|
-
return {
|
|
59
|
-
patterns: options.patterns,
|
|
60
|
-
formatterName: options.formatterName,
|
|
61
|
-
quiet: options.quiet,
|
|
62
|
-
eslintOptions: {
|
|
63
|
-
type: 'flat',
|
|
64
|
-
overrideConfigFile: options.overrideConfigFile,
|
|
65
|
-
cache: options.cache,
|
|
66
|
-
cacheLocation: options.cacheLocation,
|
|
67
|
-
// Pass flags conditionally to avoid errors in ESLint v8
|
|
68
|
-
...(options.flags && options.flags.length > 0 ? { flags: options.flags } : {}),
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
} else {
|
|
72
|
-
throw new Error(`Unexpected configType: ${String(eslintOptionsType)}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Default config of `Core` */
|
|
77
|
-
export const configDefaults = {
|
|
78
|
-
formatterName: cliOptionsDefaults.formatterName,
|
|
79
|
-
quiet: cliOptionsDefaults.quiet,
|
|
80
|
-
cwd: process.cwd(),
|
|
81
|
-
eslintOptions: {
|
|
82
|
-
useEslintrc: cliOptionsDefaults.useEslintrc,
|
|
83
|
-
overrideConfigFile: undefined,
|
|
84
|
-
extensions: undefined,
|
|
85
|
-
rulePaths: undefined,
|
|
86
|
-
ignorePath: undefined,
|
|
87
|
-
cache: cliOptionsDefaults.cache,
|
|
88
|
-
cacheLocation: undefined,
|
|
89
|
-
overrideConfig: undefined,
|
|
90
|
-
resolvePluginsRelativeTo: undefined,
|
|
91
|
-
},
|
|
92
|
-
} satisfies DeepPartial<Config>;
|
|
93
|
-
|
|
94
|
-
export type NormalizedConfig = {
|
|
95
|
-
patterns: string[];
|
|
96
|
-
formatterName: string;
|
|
97
|
-
quiet: boolean;
|
|
98
|
-
cwd: string;
|
|
99
|
-
eslintOptions: ESLintOptions;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export function normalizeConfig(config: Config): NormalizedConfig {
|
|
103
|
-
const cwd = config.cwd ?? configDefaults.cwd;
|
|
104
|
-
let eslintOptions: NormalizedConfig['eslintOptions'];
|
|
105
|
-
if (config.eslintOptions.type === 'eslintrc') {
|
|
106
|
-
eslintOptions = {
|
|
107
|
-
type: 'eslintrc',
|
|
108
|
-
useEslintrc: config.eslintOptions.useEslintrc ?? configDefaults.eslintOptions.useEslintrc,
|
|
109
|
-
overrideConfigFile: config.eslintOptions.overrideConfigFile ?? configDefaults.eslintOptions.overrideConfigFile,
|
|
110
|
-
extensions: config.eslintOptions.extensions ?? configDefaults.eslintOptions.extensions,
|
|
111
|
-
rulePaths: config.eslintOptions.rulePaths ?? configDefaults.eslintOptions.rulePaths,
|
|
112
|
-
ignorePath: config.eslintOptions.ignorePath ?? configDefaults.eslintOptions.ignorePath,
|
|
113
|
-
cache: config.eslintOptions.cache ?? configDefaults.eslintOptions.cache,
|
|
114
|
-
cacheLocation: config.eslintOptions.cacheLocation ?? configDefaults.eslintOptions.cacheLocation,
|
|
115
|
-
overrideConfig: config.eslintOptions.overrideConfig ?? configDefaults.eslintOptions.overrideConfig,
|
|
116
|
-
cwd,
|
|
117
|
-
resolvePluginsRelativeTo:
|
|
118
|
-
config.eslintOptions.resolvePluginsRelativeTo ?? configDefaults.eslintOptions.resolvePluginsRelativeTo,
|
|
119
|
-
plugins: config.eslintOptions.plugins,
|
|
120
|
-
};
|
|
121
|
-
} else {
|
|
122
|
-
eslintOptions = {
|
|
123
|
-
type: 'flat',
|
|
124
|
-
overrideConfigFile: config.eslintOptions.overrideConfigFile ?? configDefaults.eslintOptions.overrideConfigFile,
|
|
125
|
-
cache: config.eslintOptions.cache ?? configDefaults.eslintOptions.cache,
|
|
126
|
-
cacheLocation: config.eslintOptions.cacheLocation ?? configDefaults.eslintOptions.cacheLocation,
|
|
127
|
-
overrideConfig: config.eslintOptions.overrideConfig ?? configDefaults.eslintOptions.overrideConfig,
|
|
128
|
-
cwd,
|
|
129
|
-
// Pass flags conditionally to avoid errors in ESLint v8
|
|
130
|
-
...(config.eslintOptions.flags && config.eslintOptions.flags.length > 0 ?
|
|
131
|
-
{ flags: config.eslintOptions.flags }
|
|
132
|
-
: {}),
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
return {
|
|
136
|
-
patterns: config.patterns,
|
|
137
|
-
formatterName: config.formatterName ?? configDefaults.formatterName,
|
|
138
|
-
quiet: config.quiet ?? configDefaults.quiet,
|
|
139
|
-
cwd,
|
|
140
|
-
eslintOptions,
|
|
141
|
-
};
|
|
142
|
-
}
|
package/src/util/file-system.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { tmpdir } from 'node:os';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { VERSION } from '../cli/package.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Get the path of the temporary directory for eslint-interactive.
|
|
7
|
-
*/
|
|
8
|
-
export function getTempDir(): string {
|
|
9
|
-
return join(tmpdir(), 'eslint-interactive', VERSION);
|
|
10
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { exec as execOriginal } from 'node:child_process';
|
|
2
|
-
import { access, appendFile, mkdir, readFile } from 'node:fs/promises';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { promisify } from 'node:util';
|
|
6
|
-
import { getTempDir } from './file-system.js';
|
|
7
|
-
|
|
8
|
-
const exec = promisify(execOriginal);
|
|
9
|
-
|
|
10
|
-
const DEFAULT_EDITOR_COMMAND = 'vi';
|
|
11
|
-
|
|
12
|
-
function getEditorCommand(): string {
|
|
13
|
-
return process.env['EDITOR'] ?? DEFAULT_EDITOR_COMMAND;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function editFileWithEditor(filepath: string): Promise<string> {
|
|
17
|
-
const command = getEditorCommand();
|
|
18
|
-
await mkdir(dirname(filepath), { recursive: true });
|
|
19
|
-
await access(filepath).catch(async () => {
|
|
20
|
-
await appendFile(filepath, '', 'utf8');
|
|
21
|
-
});
|
|
22
|
-
await exec(`${command} ${filepath}`);
|
|
23
|
-
const newContent = await readFile(filepath, 'utf8');
|
|
24
|
-
return newContent;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function generateFilterScriptFilePath(ruleIds: string[]): string {
|
|
28
|
-
const basename = `${ruleIds.join('_').replace(/[^\w-]/gu, '')}.js`;
|
|
29
|
-
const filepath = join(getTempDir(), 'filter-script', basename);
|
|
30
|
-
return filepath;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function generateFixableMakerScriptFilePath(ruleIds: string[]): string {
|
|
34
|
-
const basename = `${ruleIds.join('_').replace(/[^\w-]/gu, '')}.js`;
|
|
35
|
-
const filepath = join(getTempDir(), 'fixable-maker-script', basename);
|
|
36
|
-
return filepath;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function generateExampleFilterScriptFilePath(): string {
|
|
40
|
-
return join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'static', 'example-filter-script.js');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function generateExampleFixableMakerScriptFilePath(): string {
|
|
44
|
-
return join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'static', 'example-fixable-maker-script.js');
|
|
45
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
// Edit this file to customize how the suggestion is applied.
|
|
4
|
-
// Save and close this file to apply the suggestion.
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A function that takes a list of suggestions that can be applied to a problem as arguments,
|
|
8
|
-
* and selects the suggestion to be applied from the list and returns it.
|
|
9
|
-
* @param {import('eslint').Linter.LintSuggestion[]} suggestions - The list of suggestions that can be applied to the problem
|
|
10
|
-
* @param {import('eslint').Linter.LintMessage} message - The `message` that contained a `suggestion`
|
|
11
|
-
* @param {import('eslint-interactive').FixContext} context - The context of the fix.
|
|
12
|
-
* @returns {import('eslint').Linter.LintSuggestion | null | undefined} Suggestion to apply. If null or undefined is returned, do not apply any suggestion.
|
|
13
|
-
*/
|
|
14
|
-
function filterSuggestions(suggestions, message, context) {
|
|
15
|
-
// example:
|
|
16
|
-
|
|
17
|
-
console.log(context.filename);
|
|
18
|
-
|
|
19
|
-
if (message.ruleId === 'no-unsafe-negation') {
|
|
20
|
-
return suggestions.find((suggestion) => suggestion.desc.startsWith('Wrap negation'));
|
|
21
|
-
} else if (message.ruleId === 'no-useless-escape') {
|
|
22
|
-
if (message.severity === 2) {
|
|
23
|
-
// error
|
|
24
|
-
// ref: https://github.com/eslint/eslint/blob/99b1fca0e61902f0d69aea4b4cdbf75d37ea20c4/lib/rules/no-useless-escape.js#L125
|
|
25
|
-
return suggestions.find((suggestion) => suggestion.messageId === 'removeEscape');
|
|
26
|
-
} else {
|
|
27
|
-
// warning
|
|
28
|
-
return suggestions.find((suggestion) => suggestion.messageId === 'escapeBackslash');
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
// apply first suggestion
|
|
32
|
-
// NOTE: `suggestion.length` must be greater than 0
|
|
33
|
-
return suggestions[0];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Here, `filterSuggestions` is passed to eslint-interactive pass.
|
|
38
|
-
// NOTE: The value evaluated on the last line of the file will be passed to eslint-interactive.
|
|
39
|
-
// This is because eslint-interactive evaluates this file with `eval`.
|
|
40
|
-
filterSuggestions;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
// Edit this file to customize how you want to convert `Linter.LintMessage` to `Rule.Fix`.
|
|
4
|
-
// Save and close this file to run `eslint --fix`.
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A function to convert `Linter.LintMessage` to `Rule.Fix`.
|
|
8
|
-
* @param {import('eslint').Linter.LintMessage} message - The `Linter.LintMessage` to be converted.
|
|
9
|
-
* @param {import('estree').Node | null} node - The node corresponding to the message.
|
|
10
|
-
* @param {import('eslint-interactive').FixContext} context - The context of the fix.
|
|
11
|
-
* @returns {import('eslint').Rule.Fix | null | undefined} The `Rule.Fix` converted from `Linter.LintMessage`. If null or undefined, the message is not fixable.
|
|
12
|
-
*/
|
|
13
|
-
function fixableMaker(message, node, context) {
|
|
14
|
-
// example:
|
|
15
|
-
|
|
16
|
-
console.log(context.filename);
|
|
17
|
-
|
|
18
|
-
// Edge case handling
|
|
19
|
-
if (!node) return null;
|
|
20
|
-
if (!node.range) return null;
|
|
21
|
-
|
|
22
|
-
if (message.ruleId === 'no-unused-vars' || message.ruleId === '@typescript-eslint/no-unused-vars') {
|
|
23
|
-
// Add underscores to the head of unused variable names.
|
|
24
|
-
// target codes: https://astexplorer.net/#/gist/e33d44d2e69a733766abbc9706fd3ed5/169a615afba7b0d5c88e87894db93fc7346250d2
|
|
25
|
-
|
|
26
|
-
if (node.type !== 'Identifier') return null;
|
|
27
|
-
// For more information about the fixer API, see the following:
|
|
28
|
-
// https://eslint.org/docs/developer-guide/working-with-rules#applying-fixes
|
|
29
|
-
return context.fixer.insertTextBefore(node, '_');
|
|
30
|
-
} else {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Here, `fixableMaker` is passed to eslint-interactive pass.
|
|
36
|
-
// NOTE: The value evaluated on the last line of the file will be passed to eslint-interactive.
|
|
37
|
-
// This is because eslint-interactive evaluates this file with `eval`.
|
|
38
|
-
fixableMaker;
|