eslint-plugin-svelte 3.8.2 → 3.9.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.
- package/lib/main.d.ts +1 -1
- package/lib/meta.d.ts +1 -1
- package/lib/meta.js +1 -1
- package/lib/shared/svelte-compile-warns/ignore-comment.js +48 -36
- package/package.json +1 -1
package/lib/main.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare const configs: {
|
|
|
14
14
|
export declare const rules: Record<string, Rule.RuleModule>;
|
|
15
15
|
export declare const meta: {
|
|
16
16
|
name: "eslint-plugin-svelte";
|
|
17
|
-
version: "3.
|
|
17
|
+
version: "3.9.0";
|
|
18
18
|
};
|
|
19
19
|
export declare const processors: {
|
|
20
20
|
'.svelte': typeof processor;
|
package/lib/meta.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name: "eslint-plugin-svelte";
|
|
2
|
-
export declare const version: "3.
|
|
2
|
+
export declare const version: "3.9.0";
|
package/lib/meta.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const SVELTE_IGNORE_PATTERN = /^\s*svelte-ignore
|
|
1
|
+
const SVELTE_IGNORE_PATTERN = /^\s*svelte-ignore\s+/;
|
|
2
2
|
/**
|
|
3
3
|
* Map of legacy code -> new code
|
|
4
4
|
* See https://github.com/sveltejs/svelte/blob/c9202a889612df3c2fcb369096a5573668be99d6/packages/svelte/src/compiler/utils/extract_svelte_ignore.js#L6
|
|
@@ -19,72 +19,84 @@ export function getSvelteIgnoreItems(context) {
|
|
|
19
19
|
const sourceCode = context.sourceCode;
|
|
20
20
|
const ignoreComments = [];
|
|
21
21
|
for (const comment of sourceCode.getAllComments()) {
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
|
|
22
|
+
const match = SVELTE_IGNORE_PATTERN.exec(comment.value);
|
|
23
|
+
if (!match) {
|
|
24
|
+
continue;
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
const codeListStart = match.index + match[0].length;
|
|
27
|
+
const codeList = comment.value.slice(codeListStart);
|
|
28
|
+
if (hasMissingCodeIgnore(codeList)) {
|
|
27
29
|
ignoreComments.push({
|
|
28
30
|
range: comment.range,
|
|
29
31
|
code: null,
|
|
30
32
|
token: comment
|
|
31
33
|
});
|
|
32
34
|
}
|
|
35
|
+
else {
|
|
36
|
+
const ignores = extractSvelteIgnore(comment.range[0] + 2, comment, codeList, codeListStart);
|
|
37
|
+
if (ignores) {
|
|
38
|
+
ignoreComments.push(...ignores);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
33
41
|
}
|
|
34
42
|
for (const token of sourceCode.ast.tokens) {
|
|
35
43
|
if (token.type === 'HTMLComment') {
|
|
36
44
|
const text = token.value.slice(4, -3);
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
|
|
45
|
+
const match = SVELTE_IGNORE_PATTERN.exec(text);
|
|
46
|
+
if (!match) {
|
|
47
|
+
continue;
|
|
40
48
|
}
|
|
41
|
-
|
|
49
|
+
const codeListStart = match.index + match[0].length;
|
|
50
|
+
const codeList = text.slice(codeListStart);
|
|
51
|
+
if (hasMissingCodeIgnore(codeList)) {
|
|
42
52
|
ignoreComments.push({
|
|
43
53
|
range: token.range,
|
|
44
54
|
code: null,
|
|
45
55
|
token
|
|
46
56
|
});
|
|
47
57
|
}
|
|
58
|
+
else {
|
|
59
|
+
const ignores = extractSvelteIgnore(token.range[0] + 4, token, codeList, codeListStart);
|
|
60
|
+
if (ignores) {
|
|
61
|
+
ignoreComments.push(...ignores);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
48
64
|
}
|
|
49
65
|
}
|
|
50
66
|
ignoreComments.sort((a, b) => b.range[0] - a.range[0]);
|
|
51
67
|
return ignoreComments;
|
|
52
68
|
}
|
|
53
69
|
/** Extract svelte-ignore rule names */
|
|
54
|
-
function extractSvelteIgnore(
|
|
55
|
-
const
|
|
56
|
-
if (!m1) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
const ignoreStart = m1.index + m1[0].length;
|
|
60
|
-
const beforeText = text.slice(ignoreStart);
|
|
61
|
-
if (!/^\s/.test(beforeText) || !beforeText.trim()) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
let start = startIndex + ignoreStart;
|
|
70
|
+
function extractSvelteIgnore(startIndex, token, codeList, ignoreStart) {
|
|
71
|
+
const start = startIndex + ignoreStart;
|
|
65
72
|
const results = [];
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
const separatorPattern = /\s*[\s,]\s*/g;
|
|
74
|
+
const separators = codeList.matchAll(separatorPattern);
|
|
75
|
+
let lastSeparatorEnd = 0;
|
|
76
|
+
for (const separator of separators) {
|
|
77
|
+
const code = codeList.slice(lastSeparatorEnd, separator.index);
|
|
78
|
+
if (code) {
|
|
70
79
|
results.push({
|
|
71
|
-
code
|
|
72
|
-
codeForV5: V5_REPLACEMENTS[
|
|
73
|
-
range: [start,
|
|
80
|
+
code,
|
|
81
|
+
codeForV5: V5_REPLACEMENTS[code] || code.replace(/-/gu, '_'),
|
|
82
|
+
range: [start + lastSeparatorEnd, start + separator.index],
|
|
74
83
|
token
|
|
75
84
|
});
|
|
76
85
|
}
|
|
77
|
-
|
|
86
|
+
lastSeparatorEnd = separator.index + separator[0].length;
|
|
87
|
+
}
|
|
88
|
+
if (results.length === 0) {
|
|
89
|
+
const code = codeList;
|
|
90
|
+
results.push({
|
|
91
|
+
code,
|
|
92
|
+
codeForV5: V5_REPLACEMENTS[code] || code.replace(/-/gu, '_'),
|
|
93
|
+
range: [start, start + code.length],
|
|
94
|
+
token
|
|
95
|
+
});
|
|
78
96
|
}
|
|
79
97
|
return results;
|
|
80
98
|
}
|
|
81
99
|
/** Checks whether given comment has missing code svelte-ignore */
|
|
82
|
-
function hasMissingCodeIgnore(
|
|
83
|
-
|
|
84
|
-
if (!m1) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
const ignoreStart = m1.index + m1[0].length;
|
|
88
|
-
const beforeText = text.slice(ignoreStart);
|
|
89
|
-
return !beforeText.trim();
|
|
100
|
+
function hasMissingCodeIgnore(codeList) {
|
|
101
|
+
return !codeList.trim();
|
|
90
102
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-svelte",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "ESLint plugin for Svelte using AST",
|
|
5
5
|
"repository": "git+https://github.com/sveltejs/eslint-plugin-svelte.git",
|
|
6
6
|
"homepage": "https://sveltejs.github.io/eslint-plugin-svelte",
|