@oxlint/migrate 1.32.0 → 1.34.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 (44) hide show
  1. package/dist/bin/oxlint-migrate.d.mts +1 -0
  2. package/dist/bin/oxlint-migrate.mjs +330 -78
  3. package/dist/src/index.d.mts +46 -0
  4. package/dist/src/index.mjs +3 -80
  5. package/dist/src-MX2M8fZn.mjs +1494 -0
  6. package/package.json +37 -38
  7. package/dist/bin/config-loader.mjs +0 -46
  8. package/dist/bin/project-loader.mjs +0 -16
  9. package/dist/package.json.mjs +0 -8
  10. package/dist/src/cleanup.d.ts +0 -2
  11. package/dist/src/cleanup.mjs +0 -154
  12. package/dist/src/cleanup.test.d.ts +0 -1
  13. package/dist/src/constants.d.ts +0 -3
  14. package/dist/src/constants.mjs +0 -104
  15. package/dist/src/env_globals.d.ts +0 -16
  16. package/dist/src/env_globals.mjs +0 -233
  17. package/dist/src/generated/rules.d.ts +0 -7
  18. package/dist/src/generated/rules.mjs +0 -697
  19. package/dist/src/ignorePatterns.d.ts +0 -3
  20. package/dist/src/ignorePatterns.mjs +0 -20
  21. package/dist/src/index.d.ts +0 -4
  22. package/dist/src/jsPlugins.d.ts +0 -3
  23. package/dist/src/jsPlugins.mjs +0 -52
  24. package/dist/src/js_plugin_fixes.d.ts +0 -5
  25. package/dist/src/js_plugin_fixes.mjs +0 -39
  26. package/dist/src/overrides.d.ts +0 -2
  27. package/dist/src/overrides.mjs +0 -16
  28. package/dist/src/plugins_rules.d.ts +0 -13
  29. package/dist/src/plugins_rules.mjs +0 -251
  30. package/dist/src/reporter.d.ts +0 -10
  31. package/dist/src/reporter.mjs +0 -12
  32. package/dist/src/types.d.ts +0 -39
  33. package/dist/src/utilities.d.ts +0 -1
  34. package/dist/src/utilities.mjs +0 -12
  35. package/dist/src/walker/comments/index.d.ts +0 -2
  36. package/dist/src/walker/comments/index.mjs +0 -20
  37. package/dist/src/walker/comments/replaceRuleDirectiveComment.d.ts +0 -2
  38. package/dist/src/walker/comments/replaceRuleDirectiveComment.mjs +0 -59
  39. package/dist/src/walker/index.d.ts +0 -10
  40. package/dist/src/walker/index.mjs +0 -19
  41. package/dist/src/walker/partialSourceTextLoader.d.ts +0 -10
  42. package/dist/src/walker/partialSourceTextLoader.mjs +0 -167
  43. package/dist/src/walker/replaceCommentsInFile.d.ts +0 -2
  44. package/dist/src/walker/replaceCommentsInFile.mjs +0 -60
@@ -1,3 +0,0 @@
1
- import { Linter } from 'eslint';
2
- import { Options, OxlintConfigOrOverride } from './types.js';
3
- export declare const transformIgnorePatterns: (eslintConfig: Linter.Config, targetConfig: OxlintConfigOrOverride, options?: Options) => void;
@@ -1,20 +0,0 @@
1
- const transformIgnorePatterns = (eslintConfig, targetConfig, options) => {
2
- if (eslintConfig.ignores === void 0) {
3
- return;
4
- }
5
- if ("files" in targetConfig) {
6
- options?.reporter?.report("ignore list inside overrides is not supported");
7
- return;
8
- }
9
- if (targetConfig.ignorePatterns === void 0) {
10
- targetConfig.ignorePatterns = [];
11
- }
12
- for (const ignores of eslintConfig.ignores) {
13
- if (!targetConfig.ignorePatterns.includes(ignores)) {
14
- targetConfig.ignorePatterns.push(ignores);
15
- }
16
- }
17
- };
18
- export {
19
- transformIgnorePatterns
20
- };
@@ -1,4 +0,0 @@
1
- import { Linter } from 'eslint';
2
- import { Options, OxlintConfig } from './types.js';
3
- declare const main: (configs: Linter.Config | Linter.Config[] | Promise<Linter.Config> | Promise<Linter.Config[]>, oxlintConfig?: OxlintConfig, options?: Options) => Promise<OxlintConfig>;
4
- export default main;
@@ -1,3 +0,0 @@
1
- import { Linter } from 'eslint';
2
- import { OxlintConfigOrOverride } from './types.js';
3
- export declare const enableJsPluginRule: (targetConfig: OxlintConfigOrOverride, rule: string, ruleEntry: Linter.RuleEntry | undefined) => boolean;
@@ -1,52 +0,0 @@
1
- import { rulesPrefixesForPlugins } from "./constants.mjs";
2
- const ignorePlugins = /* @__PURE__ */ new Set([
3
- ...Object.keys(rulesPrefixesForPlugins),
4
- ...Object.values(rulesPrefixesForPlugins),
5
- "local"
6
- // ToDo: handle local plugin rules
7
- ]);
8
- const guessEslintPluginName = (pluginName) => {
9
- if (pluginName.startsWith("@")) {
10
- const [scope, maybeSub] = pluginName.split("/");
11
- if (maybeSub) {
12
- return `${scope}/eslint-plugin-${maybeSub}`;
13
- }
14
- return `${scope}/eslint-plugin`;
15
- }
16
- return `eslint-plugin-${pluginName}`;
17
- };
18
- const extractPluginId = (ruleId) => {
19
- const firstSlash = ruleId.indexOf("/");
20
- if (firstSlash === -1) {
21
- return;
22
- }
23
- if (ruleId.startsWith("@")) {
24
- const secondSlash = ruleId.indexOf("/", firstSlash + 1);
25
- if (secondSlash !== -1) {
26
- return ruleId.substring(0, secondSlash);
27
- }
28
- }
29
- return ruleId.substring(0, firstSlash);
30
- };
31
- const enableJsPluginRule = (targetConfig, rule, ruleEntry) => {
32
- const pluginName = extractPluginId(rule);
33
- if (pluginName === void 0) {
34
- return false;
35
- }
36
- if (ignorePlugins.has(pluginName)) {
37
- return false;
38
- }
39
- if (targetConfig.jsPlugins === void 0) {
40
- targetConfig.jsPlugins = [];
41
- }
42
- const eslintPluginName = guessEslintPluginName(pluginName);
43
- if (!targetConfig.jsPlugins.includes(eslintPluginName)) {
44
- targetConfig.jsPlugins.push(eslintPluginName);
45
- }
46
- targetConfig.rules = targetConfig.rules || {};
47
- targetConfig.rules[rule] = ruleEntry;
48
- return true;
49
- };
50
- export {
51
- enableJsPluginRule
52
- };
@@ -1,5 +0,0 @@
1
- import { Linter } from 'eslint';
2
- type PossibleConfigs = Linter.Config | Linter.Config[] | Promise<Linter.Config> | Promise<Linter.Config[]>;
3
- export default function fixForJsPlugins(configs: PossibleConfigs): PossibleConfigs;
4
- export declare const preFixForJsPlugins: () => Promise<() => void>;
5
- export {};
@@ -1,39 +0,0 @@
1
- const fixForAntfuEslintConfig = (config) => {
2
- if ("renamePlugins" in config && typeof config.renamePlugins === "function") {
3
- return config.renamePlugins({
4
- ts: "@typescript-eslint",
5
- test: "vitest",
6
- next: "@next/next",
7
- style: "@stylistic"
8
- });
9
- }
10
- return config;
11
- };
12
- const fixForNextEslintConfig = async () => {
13
- if ("Deno" in globalThis || "Bun" in globalThis) {
14
- return () => {
15
- };
16
- }
17
- const Module = await import("module");
18
- const mod = Module.default || Module;
19
- const originalLoad = mod._load;
20
- mod._load = function(request, ...args) {
21
- if (request && request.includes("@rushstack/eslint-patch")) {
22
- return {};
23
- }
24
- return originalLoad.apply(mod, [request, ...args]);
25
- };
26
- return () => {
27
- mod._load = originalLoad;
28
- };
29
- };
30
- function fixForJsPlugins(configs) {
31
- return fixForAntfuEslintConfig(configs);
32
- }
33
- const preFixForJsPlugins = () => {
34
- return fixForNextEslintConfig();
35
- };
36
- export {
37
- fixForJsPlugins as default,
38
- preFixForJsPlugins
39
- };
@@ -1,2 +0,0 @@
1
- import { OxlintConfig, OxlintConfigOverride } from './types.js';
2
- export declare const detectSameOverride: (config: OxlintConfig, override: OxlintConfigOverride) => [boolean, OxlintConfigOverride];
@@ -1,16 +0,0 @@
1
- import { isEqualDeep } from "./utilities.mjs";
2
- const detectSameOverride = (config, override) => {
3
- if (config.overrides === void 0) {
4
- return [true, override];
5
- }
6
- const matchedOverride = config.overrides.find(({ files, categories }) => {
7
- return categories === void 0 && isEqualDeep(files, override.files);
8
- });
9
- if (matchedOverride !== void 0) {
10
- return [false, matchedOverride];
11
- }
12
- return [true, override];
13
- };
14
- export {
15
- detectSameOverride
16
- };
@@ -1,13 +0,0 @@
1
- import { Linter } from 'eslint';
2
- import { Options, OxlintConfig, OxlintConfigOrOverride } from './types.js';
3
- export declare const transformRuleEntry: (eslintConfig: Linter.Config, targetConfig: OxlintConfigOrOverride, options?: Options) => void;
4
- export declare const detectNeededRulesPlugins: (targetConfig: OxlintConfigOrOverride) => void;
5
- export declare const cleanUpUselessOverridesPlugins: (config: OxlintConfig) => void;
6
- export declare const cleanUpUselessOverridesRules: (config: OxlintConfig) => void;
7
- export declare const cleanUpRulesWhichAreCoveredByCategory: (config: OxlintConfigOrOverride) => void;
8
- export declare const cleanUpDisabledRootRules: (config: OxlintConfig) => void;
9
- export declare const replaceTypescriptAliasRules: (config: OxlintConfigOrOverride) => void;
10
- /**
11
- * Oxlint support them only under the node plugin name
12
- */
13
- export declare const replaceNodePluginName: (config: OxlintConfigOrOverride) => void;
@@ -1,251 +0,0 @@
1
- import * as rules from "./generated/rules.mjs";
2
- import { nurseryRules } from "./generated/rules.mjs";
3
- import { typescriptTypeAwareRules, rulesPrefixesForPlugins, typescriptRulesExtendEslintRules } from "./constants.mjs";
4
- import { enableJsPluginRule } from "./jsPlugins.mjs";
5
- const allRules = Object.values(rules).flat();
6
- const isValueInSet = (value, validSet) => validSet.includes(value) || Array.isArray(value) && validSet.includes(value[0]);
7
- const isActiveValue = (value) => isValueInSet(value, ["error", "warn", 1, 2]);
8
- const isOffValue = (value) => isValueInSet(value, ["off", 0]);
9
- const isWarnValue = (value) => isValueInSet(value, ["warn", 1]);
10
- const isErrorValue = (value) => isValueInSet(value, ["error", 2]);
11
- const normalizeSeverityValue = (value) => {
12
- if (value === void 0) {
13
- return value;
14
- }
15
- if (isWarnValue(value)) {
16
- if (Array.isArray(value)) {
17
- value[0] = "warn";
18
- return value;
19
- }
20
- return "warn";
21
- } else if (isErrorValue(value)) {
22
- if (Array.isArray(value)) {
23
- value[0] = "error";
24
- return value;
25
- }
26
- return "error";
27
- }
28
- if (isOffValue(value)) {
29
- if (Array.isArray(value)) {
30
- value[0] = "off";
31
- return value;
32
- }
33
- return "off";
34
- }
35
- return void 0;
36
- };
37
- const transformRuleEntry = (eslintConfig, targetConfig, options) => {
38
- if (eslintConfig.rules === void 0) {
39
- return;
40
- }
41
- if (targetConfig.rules === void 0) {
42
- targetConfig.rules = {};
43
- }
44
- for (const [rule, config] of Object.entries(eslintConfig.rules)) {
45
- if (allRules.includes(rule)) {
46
- if (!options?.withNursery && nurseryRules.includes(rule)) {
47
- options?.reporter?.report(
48
- `unsupported rule, but in development: ${rule}`
49
- );
50
- continue;
51
- }
52
- if (!options?.typeAware && typescriptTypeAwareRules.includes(rule)) {
53
- options?.reporter?.report(
54
- `type-aware rule detected, but \`--type-aware\` is not enabled: ${rule}`
55
- );
56
- continue;
57
- }
58
- if (options?.merge) {
59
- if (!(rule in targetConfig.rules)) {
60
- targetConfig.rules[rule] = normalizeSeverityValue(config);
61
- }
62
- } else {
63
- targetConfig.rules[rule] = normalizeSeverityValue(config);
64
- }
65
- } else {
66
- if (options?.jsPlugins) {
67
- if (isActiveValue(config) && !enableJsPluginRule(
68
- targetConfig,
69
- rule,
70
- normalizeSeverityValue(config)
71
- )) {
72
- options?.reporter?.report(`unsupported rule: ${rule}`);
73
- }
74
- } else if (isActiveValue(config)) {
75
- options?.reporter?.report(`unsupported rule: ${rule}`);
76
- }
77
- }
78
- }
79
- };
80
- const detectNeededRulesPlugins = (targetConfig) => {
81
- if (targetConfig.rules === void 0) {
82
- return;
83
- }
84
- if (targetConfig.plugins === void 0) {
85
- targetConfig.plugins = [];
86
- }
87
- for (const rule of Object.keys(targetConfig.rules)) {
88
- if (!rule.includes("/")) {
89
- continue;
90
- }
91
- for (const [prefix, plugin] of Object.entries(rulesPrefixesForPlugins)) {
92
- if (rule.startsWith(`${prefix}/`) && !targetConfig.plugins.includes(plugin)) {
93
- targetConfig.plugins.push(plugin);
94
- }
95
- }
96
- }
97
- if ("files" in targetConfig && targetConfig.plugins.length === 0) {
98
- delete targetConfig.plugins;
99
- }
100
- };
101
- const cleanUpUselessOverridesPlugins = (config) => {
102
- if (config.overrides === void 0) {
103
- return;
104
- }
105
- if (config.plugins !== void 0) {
106
- for (const override of config.overrides) {
107
- if (override.plugins === void 0) {
108
- continue;
109
- }
110
- override.plugins = override.plugins.filter(
111
- (overridePlugin) => !config.plugins.includes(overridePlugin)
112
- );
113
- if (override.plugins.length === 0) {
114
- delete override.plugins;
115
- }
116
- }
117
- }
118
- };
119
- const cleanUpUselessOverridesRules = (config) => {
120
- if (config.rules === void 0 || config.overrides === void 0) {
121
- return;
122
- }
123
- const filesPatternMap = /* @__PURE__ */ new Map();
124
- for (const [i, override] of config.overrides.entries()) {
125
- if (override.files === void 0) {
126
- continue;
127
- }
128
- const filesKey = JSON.stringify(override.files);
129
- let entry = filesPatternMap.get(filesKey);
130
- if (!entry) {
131
- entry = {
132
- firstIndex: i,
133
- finalRules: {},
134
- indicesToRemove: []
135
- };
136
- filesPatternMap.set(filesKey, entry);
137
- } else {
138
- entry.indicesToRemove.push(i);
139
- }
140
- if (override.rules) {
141
- Object.assign(entry.finalRules, override.rules);
142
- }
143
- }
144
- for (const entry of filesPatternMap.values()) {
145
- const firstOverride = config.overrides[entry.firstIndex];
146
- firstOverride.rules = entry.finalRules;
147
- if (firstOverride.rules) {
148
- for (const [rule, settings] of Object.entries(firstOverride.rules)) {
149
- if (config.rules[rule] === settings) {
150
- delete firstOverride.rules[rule];
151
- }
152
- }
153
- if (Object.keys(firstOverride.rules).length === 0) {
154
- delete firstOverride.rules;
155
- }
156
- }
157
- for (const indexToRemove of entry.indicesToRemove) {
158
- delete config.overrides[indexToRemove].rules;
159
- }
160
- }
161
- };
162
- const cleanUpRulesWhichAreCoveredByCategory = (config) => {
163
- if (config.rules === void 0 || config.categories === void 0) {
164
- return;
165
- }
166
- const enabledCategories = Object.entries(config.categories).filter(([, severity]) => severity === "warn" || severity === "error").map(([category]) => category);
167
- for (const [rule, settings] of Object.entries(config.rules)) {
168
- for (const category of enabledCategories) {
169
- if (`${category}Rules` in rules && // @ts-expect-error -- ts can not resolve the type
170
- rules[`${category}Rules`].includes(rule)) {
171
- if (settings === config.categories[category] || Array.isArray(settings) && settings.length === 1 && settings[0] === config.categories[category]) {
172
- delete config.rules[rule];
173
- }
174
- }
175
- }
176
- }
177
- };
178
- const getEnabledCategories = (config) => {
179
- if (config.categories === void 0) {
180
- return ["correctness"];
181
- }
182
- const categories = Object.entries(config.categories).filter(([, severity]) => severity === "warn" || severity === "error").map(([category]) => category);
183
- if (Object.keys(config.categories).includes("correctness")) {
184
- return categories;
185
- }
186
- return [...categories, "correctness"];
187
- };
188
- const isRuleInEnabledCategory = (rule, enabledCategories) => {
189
- for (const category of enabledCategories) {
190
- if (`${category}Rules` in rules && // @ts-expect-error -- ts can not resolve the type
191
- rules[`${category}Rules`].includes(rule)) {
192
- return true;
193
- }
194
- }
195
- return false;
196
- };
197
- const cleanUpDisabledRootRules = (config) => {
198
- if (config.rules === void 0) {
199
- return;
200
- }
201
- const enabledCategories = getEnabledCategories(config);
202
- for (const [rule, settings] of Object.entries(config.rules)) {
203
- if (isOffValue(settings) && !isRuleInEnabledCategory(rule, enabledCategories)) {
204
- delete config.rules[rule];
205
- }
206
- }
207
- };
208
- const replaceTypescriptAliasRules = (config) => {
209
- if (config.rules === void 0) {
210
- return;
211
- }
212
- for (const rule of Object.keys(config.rules)) {
213
- const prefix = "@typescript-eslint/";
214
- if (!rule.startsWith(prefix)) {
215
- continue;
216
- }
217
- const eslintRule = rule.slice(prefix.length);
218
- if (!typescriptRulesExtendEslintRules.includes(eslintRule)) {
219
- continue;
220
- }
221
- config.rules[eslintRule] = config.rules[rule];
222
- delete config.rules[rule];
223
- }
224
- if (Object.keys(config.rules).length === 0) {
225
- delete config.rules;
226
- }
227
- };
228
- const replaceNodePluginName = (config) => {
229
- if (config.rules === void 0) {
230
- return;
231
- }
232
- for (const rule of Object.keys(config.rules)) {
233
- const prefix = "n/";
234
- if (!rule.startsWith(prefix)) {
235
- continue;
236
- }
237
- const nodeRule = `node/${rule.slice(prefix.length)}`;
238
- config.rules[nodeRule] = config.rules[rule];
239
- delete config.rules[rule];
240
- }
241
- };
242
- export {
243
- cleanUpDisabledRootRules,
244
- cleanUpRulesWhichAreCoveredByCategory,
245
- cleanUpUselessOverridesPlugins,
246
- cleanUpUselessOverridesRules,
247
- detectNeededRulesPlugins,
248
- replaceNodePluginName,
249
- replaceTypescriptAliasRules,
250
- transformRuleEntry
251
- };
@@ -1,10 +0,0 @@
1
- import { Reporter } from './types.js';
2
- export declare class DefaultReporter implements Reporter {
3
- private reports;
4
- report(message: string): void;
5
- getReports(): string[];
6
- }
7
- export declare class SilentReporter implements Reporter {
8
- report(_message: string): void;
9
- getReports(): string[];
10
- }
@@ -1,12 +0,0 @@
1
- class DefaultReporter {
2
- reports = /* @__PURE__ */ new Set();
3
- report(message) {
4
- this.reports.add(message);
5
- }
6
- getReports() {
7
- return Array.from(this.reports);
8
- }
9
- }
10
- export {
11
- DefaultReporter
12
- };
@@ -1,39 +0,0 @@
1
- import { Linter } from 'eslint';
2
- type OxlintConfigPlugins = string[];
3
- type OxlintConfigJsPlugins = string[];
4
- type OxlintConfigCategories = Record<string, unknown>;
5
- type OxlintConfigEnv = Record<string, boolean>;
6
- type OxlintConfigIgnorePatterns = string[];
7
- export type OxlintConfigOverride = {
8
- files: string[];
9
- env?: OxlintConfigEnv;
10
- globals?: Linter.Globals;
11
- plugins?: OxlintConfigPlugins;
12
- jsPlugins?: OxlintConfigJsPlugins;
13
- categories?: OxlintConfigCategories;
14
- rules?: Partial<Linter.RulesRecord>;
15
- };
16
- export type OxlintConfig = {
17
- $schema?: string;
18
- env?: OxlintConfigEnv;
19
- globals?: Linter.Globals;
20
- plugins?: OxlintConfigPlugins;
21
- jsPlugins?: OxlintConfigJsPlugins;
22
- categories?: OxlintConfigCategories;
23
- rules?: Partial<Linter.RulesRecord>;
24
- overrides?: OxlintConfigOverride[];
25
- ignorePatterns?: OxlintConfigIgnorePatterns;
26
- };
27
- export type OxlintConfigOrOverride = OxlintConfig | OxlintConfigOverride;
28
- export type Reporter = {
29
- report(message: string): void;
30
- getReports(): string[];
31
- };
32
- export type Options = {
33
- reporter?: Reporter;
34
- merge?: boolean;
35
- withNursery?: boolean;
36
- typeAware?: boolean;
37
- jsPlugins?: boolean;
38
- };
39
- export {};
@@ -1 +0,0 @@
1
- export declare const isEqualDeep: <T>(a: T, b: T) => boolean;
@@ -1,12 +0,0 @@
1
- const isEqualDeep = (a, b) => {
2
- if (a === b) {
3
- return true;
4
- }
5
- const bothAreObjects = a && b && typeof a === "object" && typeof b === "object";
6
- return Boolean(
7
- bothAreObjects && Object.keys(a).length === Object.keys(b).length && Object.entries(a).every(([k, v]) => isEqualDeep(v, b[k]))
8
- );
9
- };
10
- export {
11
- isEqualDeep
12
- };
@@ -1,2 +0,0 @@
1
- import { Options } from '../../types.js';
2
- export default function replaceComments(comment: string, type: 'Line' | 'Block', options: Options): string;
@@ -1,20 +0,0 @@
1
- import replaceRuleDirectiveComment from "./replaceRuleDirectiveComment.mjs";
2
- function replaceComments(comment, type, options) {
3
- const originalComment = comment;
4
- comment = comment.trim();
5
- if (comment.startsWith("eslint-")) {
6
- return replaceRuleDirectiveComment(originalComment, type, options);
7
- } else if (type === "Block") {
8
- if (comment.startsWith("eslint ")) {
9
- throw new Error(
10
- "changing eslint rules with inline comment is not supported"
11
- );
12
- } else if (comment.startsWith("global ")) {
13
- throw new Error("changing globals with inline comment is not supported");
14
- }
15
- }
16
- return originalComment;
17
- }
18
- export {
19
- replaceComments as default
20
- };
@@ -1,2 +0,0 @@
1
- import { Options } from '../../types.js';
2
- export default function replaceRuleDirectiveComment(comment: string, type: 'Line' | 'Block', options: Options): string;
@@ -1,59 +0,0 @@
1
- import * as rules from "../../generated/rules.mjs";
2
- import { nurseryRules } from "../../generated/rules.mjs";
3
- const allRules = Object.values(rules).flat();
4
- function replaceRuleDirectiveComment(comment, type, options) {
5
- const originalComment = comment;
6
- comment = comment.split(" -- ")[0].trimStart();
7
- if (!comment.startsWith("eslint-")) {
8
- return originalComment;
9
- }
10
- comment = comment.substring(7);
11
- if (comment.startsWith("enable")) {
12
- comment = comment.substring(6);
13
- } else if (comment.startsWith("disable")) {
14
- comment = comment.substring(7);
15
- if (type === "Line") {
16
- if (comment.startsWith("-next-line")) {
17
- comment = comment.substring(10);
18
- } else if (comment.startsWith("-line")) {
19
- comment = comment.substring(5);
20
- }
21
- }
22
- } else {
23
- return originalComment;
24
- }
25
- if (!comment.startsWith(" ")) {
26
- return originalComment;
27
- }
28
- comment = comment.trimStart();
29
- if (comment.length === 0) {
30
- return originalComment;
31
- }
32
- while (comment.length) {
33
- let foundRule = false;
34
- for (const rule of allRules) {
35
- if (comment.startsWith(rule)) {
36
- if (!options.withNursery && nurseryRules.includes(rule)) {
37
- continue;
38
- }
39
- foundRule = true;
40
- comment = comment.substring(rule.length).trimStart();
41
- break;
42
- }
43
- }
44
- if (!foundRule) {
45
- return originalComment;
46
- }
47
- if (!comment.length) {
48
- break;
49
- }
50
- if (!comment.startsWith(", ")) {
51
- return originalComment;
52
- }
53
- comment = comment.substring(1).trimStart();
54
- }
55
- return originalComment.replace(/eslint-/, "oxlint-");
56
- }
57
- export {
58
- replaceRuleDirectiveComment as default
59
- };
@@ -1,10 +0,0 @@
1
- import { Options } from '../types.js';
2
- export declare const walkAndReplaceProjectFiles: (
3
- /** all projects files to check */
4
- projectFiles: string[],
5
- /** function for reading the file */
6
- readFileSync: (filePath: string) => string | undefined,
7
- /** function for writing the file */
8
- writeFile: (filePath: string, content: string) => Promise<void>,
9
- /** options for the walker, for `reporter` and `withNurseryRules` */
10
- options: Options) => Promise<void[]>;
@@ -1,19 +0,0 @@
1
- import replaceCommentsInFile from "./replaceCommentsInFile.mjs";
2
- const walkAndReplaceProjectFiles = (projectFiles, readFileSync, writeFile, options) => {
3
- return Promise.all(
4
- projectFiles.map((file) => {
5
- const sourceText = readFileSync(file);
6
- if (!sourceText) {
7
- return Promise.resolve();
8
- }
9
- const newSourceText = replaceCommentsInFile(file, sourceText, options);
10
- if (newSourceText === sourceText) {
11
- return Promise.resolve();
12
- }
13
- return writeFile(file, newSourceText);
14
- })
15
- );
16
- };
17
- export {
18
- walkAndReplaceProjectFiles
19
- };
@@ -1,10 +0,0 @@
1
- export type PartialSourceText = {
2
- sourceText: string;
3
- offset: number;
4
- lang?: 'js' | 'jsx' | 'ts' | 'tsx';
5
- sourceType?: 'script' | 'module';
6
- };
7
- export default function partialSourceTextLoader(absoluteFilePath: string, fileContent: string): PartialSourceText[];
8
- export declare function partialVueSourceTextLoader(sourceText: string): PartialSourceText[];
9
- export declare function partialSvelteSourceTextLoader(sourceText: string): PartialSourceText[];
10
- export declare function partialAstroSourceTextLoader(sourceText: string): PartialSourceText[];