@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,167 +0,0 @@
1
- function extractLangAttribute(source) {
2
- const langIndex = source.indexOf("lang");
3
- if (langIndex === -1) return void 0;
4
- let cursor = langIndex + 4;
5
- while (cursor < source.length && isWhitespace(source[cursor])) {
6
- cursor++;
7
- }
8
- if (source[cursor] !== "=") return void 0;
9
- cursor++;
10
- while (cursor < source.length && isWhitespace(source[cursor])) {
11
- cursor++;
12
- }
13
- const quote = source[cursor];
14
- if (quote !== '"' && quote !== "'") return void 0;
15
- cursor++;
16
- let value = "";
17
- while (cursor < source.length && source[cursor] !== quote) {
18
- value += source[cursor++];
19
- }
20
- if (value === "js" || value === "jsx" || value === "ts" || value === "tsx") {
21
- return value;
22
- }
23
- return void 0;
24
- }
25
- function extractScriptBlocks(sourceText, offset, maxBlocks, parseLangAttribute) {
26
- const results = [];
27
- while (offset < sourceText.length) {
28
- const idx = sourceText.indexOf("<script", offset);
29
- if (idx === -1) break;
30
- const nextChar = sourceText[idx + 7];
31
- if (nextChar !== " " && nextChar !== ">" && nextChar !== "\n" && nextChar !== " ") {
32
- offset = idx + 7;
33
- continue;
34
- }
35
- let i = idx + 7;
36
- let inQuote = null;
37
- let genericDepth = 0;
38
- let selfClosing = false;
39
- while (i < sourceText.length) {
40
- const c = sourceText[i];
41
- if (inQuote) {
42
- if (c === inQuote) inQuote = null;
43
- } else if (c === '"' || c === "'") {
44
- inQuote = c;
45
- } else if (c === "<") {
46
- genericDepth++;
47
- } else if (c === ">") {
48
- if (genericDepth > 0) {
49
- genericDepth--;
50
- } else {
51
- if (i > idx && sourceText[i - 1] === "/") {
52
- selfClosing = true;
53
- }
54
- i++;
55
- break;
56
- }
57
- }
58
- i++;
59
- }
60
- if (selfClosing) {
61
- offset = i;
62
- continue;
63
- }
64
- if (i >= sourceText.length) break;
65
- let lang = void 0;
66
- if (parseLangAttribute) {
67
- lang = extractLangAttribute(sourceText.slice(idx, i));
68
- }
69
- const contentStart = i;
70
- const closeTag = "<\/script>";
71
- const closeIdx = sourceText.indexOf(closeTag, contentStart);
72
- if (closeIdx === -1) break;
73
- const content = sourceText.slice(contentStart, closeIdx);
74
- results.push({ sourceText: content, offset: contentStart, lang });
75
- if (results.length >= maxBlocks) {
76
- break;
77
- }
78
- offset = closeIdx + closeTag.length;
79
- }
80
- return results;
81
- }
82
- function partialSourceTextLoader(absoluteFilePath, fileContent) {
83
- if (absoluteFilePath.endsWith(".vue")) {
84
- return partialVueSourceTextLoader(fileContent);
85
- } else if (absoluteFilePath.endsWith(".astro")) {
86
- return partialAstroSourceTextLoader(fileContent);
87
- } else if (absoluteFilePath.endsWith(".svelte")) {
88
- return partialSvelteSourceTextLoader(fileContent);
89
- }
90
- return [
91
- {
92
- sourceText: fileContent,
93
- offset: 0
94
- }
95
- ];
96
- }
97
- function isWhitespace(char) {
98
- return char === " " || char === " " || char === "\r";
99
- }
100
- function findDelimiter(sourceText, startPos) {
101
- let i = startPos;
102
- while (i < sourceText.length) {
103
- if (i === 0 || sourceText[i - 1] === "\n") {
104
- let j = i;
105
- while (j < sourceText.length && isWhitespace(sourceText[j])) j++;
106
- if (sourceText[j] === "-" && sourceText[j + 1] === "-" && sourceText[j + 2] === "-") {
107
- let k = j + 3;
108
- while (k < sourceText.length && sourceText[k] !== "\n") {
109
- if (!isWhitespace(sourceText[k])) break;
110
- k++;
111
- }
112
- if (k === sourceText.length || sourceText[k] === "\n") {
113
- return j;
114
- }
115
- }
116
- }
117
- i++;
118
- }
119
- return -1;
120
- }
121
- function partialVueSourceTextLoader(sourceText) {
122
- return extractScriptBlocks(sourceText, 0, 2, true);
123
- }
124
- function partialSvelteSourceTextLoader(sourceText) {
125
- return extractScriptBlocks(sourceText, 0, 2, true);
126
- }
127
- function partialAstroSourceTextLoader(sourceText) {
128
- const results = [];
129
- let pos = 0;
130
- const frontmatterStartDelimiter = findDelimiter(sourceText, pos);
131
- if (frontmatterStartDelimiter !== -1) {
132
- const frontmatterContentStart = frontmatterStartDelimiter + 3;
133
- const frontmatterEndDelimiter = findDelimiter(
134
- sourceText,
135
- frontmatterContentStart
136
- );
137
- if (frontmatterEndDelimiter !== -1) {
138
- const content = sourceText.slice(
139
- frontmatterContentStart,
140
- frontmatterEndDelimiter
141
- );
142
- results.push({
143
- sourceText: content,
144
- offset: frontmatterContentStart,
145
- lang: "ts",
146
- sourceType: "module"
147
- });
148
- pos = frontmatterEndDelimiter + 3;
149
- }
150
- }
151
- results.push(
152
- ...extractScriptBlocks(sourceText, pos, Number.MAX_SAFE_INTEGER, false).map(
153
- (sourceText2) => ({
154
- ...sourceText2,
155
- lang: "ts",
156
- sourceType: "module"
157
- })
158
- )
159
- );
160
- return results;
161
- }
162
- export {
163
- partialSourceTextLoader as default,
164
- partialAstroSourceTextLoader,
165
- partialSvelteSourceTextLoader,
166
- partialVueSourceTextLoader
167
- };
@@ -1,2 +0,0 @@
1
- import { Options } from '../types.js';
2
- export default function replaceCommentsInFile(absoluteFilePath: string, fileContent: string, options: Options): string;
@@ -1,60 +0,0 @@
1
- import { parseSync } from "oxc-parser";
2
- import replaceComments from "./comments/index.mjs";
3
- import partialSourceTextLoader from "./partialSourceTextLoader.mjs";
4
- const getComments = (absoluteFilePath, partialSourceText, options) => {
5
- const parserResult = parseSync(
6
- absoluteFilePath,
7
- partialSourceText.sourceText,
8
- {
9
- lang: partialSourceText.lang,
10
- sourceType: partialSourceText.sourceType
11
- }
12
- );
13
- if (parserResult.errors.length > 0) {
14
- options.reporter?.report(`${absoluteFilePath}: failed to parse`);
15
- }
16
- return parserResult.comments;
17
- };
18
- function replaceCommentsInSourceText(absoluteFilePath, partialSourceText, options) {
19
- const comments = getComments(absoluteFilePath, partialSourceText, options);
20
- let sourceText = partialSourceText.sourceText;
21
- for (const comment of comments) {
22
- try {
23
- const replacedStr = replaceComments(comment.value, comment.type, options);
24
- if (replacedStr !== comment.value) {
25
- const newComment = comment.type === "Line" ? `//${replacedStr}` : `/*${replacedStr}*/`;
26
- sourceText = sourceText.slice(0, comment.start) + newComment + sourceText.slice(comment.end);
27
- }
28
- } catch (error) {
29
- if (error instanceof Error) {
30
- options.reporter?.report(
31
- `${absoluteFilePath}, char offset ${comment.start + partialSourceText.offset}: ${error.message}`
32
- );
33
- continue;
34
- }
35
- throw error;
36
- }
37
- }
38
- return sourceText;
39
- }
40
- function replaceCommentsInFile(absoluteFilePath, fileContent, options) {
41
- for (const partialSourceText of partialSourceTextLoader(
42
- absoluteFilePath,
43
- fileContent
44
- )) {
45
- const newSourceText = replaceCommentsInSourceText(
46
- absoluteFilePath,
47
- partialSourceText,
48
- options
49
- );
50
- if (newSourceText !== partialSourceText.sourceText) {
51
- fileContent = fileContent.slice(0, partialSourceText.offset) + newSourceText + fileContent.slice(
52
- partialSourceText.offset + partialSourceText.sourceText.length
53
- );
54
- }
55
- }
56
- return fileContent;
57
- }
58
- export {
59
- replaceCommentsInFile as default
60
- };