eslint-plugin-svelte 3.8.2 → 3.9.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/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.8.2";
17
+ version: "3.9.1";
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.8.2";
2
+ export declare const version: "3.9.1";
package/lib/meta.js CHANGED
@@ -2,4 +2,4 @@
2
2
  // This file has been automatically generated,
3
3
  // in order to update its content execute "pnpm run update"
4
4
  export const name = 'eslint-plugin-svelte';
5
- export const version = '3.8.2';
5
+ export const version = '3.9.1';
@@ -586,6 +586,7 @@ type SveltePreferConst = [] | [
586
586
  destructuring?: ("any" | "all");
587
587
  ignoreReadBeforeAssign?: boolean;
588
588
  excludedRunes?: string[];
589
+ [k: string]: unknown | undefined;
589
590
  }
590
591
  ];
591
592
  type SvelteRequireEventPrefix = [] | [
@@ -56,7 +56,8 @@ export default createRule('prefer-const', {
56
56
  }
57
57
  }
58
58
  },
59
- additionalProperties: false
59
+ // Allow ESLint core rule properties in case new options are added in the future.
60
+ additionalProperties: true
60
61
  }
61
62
  ]
62
63
  },
@@ -1,4 +1,4 @@
1
- const SVELTE_IGNORE_PATTERN = /^\s*svelte-ignore/m;
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 ignores = extractSvelteIgnore(comment.value, comment.range[0] + 2, comment);
23
- if (ignores) {
24
- ignoreComments.push(...ignores);
22
+ const match = SVELTE_IGNORE_PATTERN.exec(comment.value);
23
+ if (!match) {
24
+ continue;
25
25
  }
26
- else if (hasMissingCodeIgnore(comment.value)) {
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 ignores = extractSvelteIgnore(text, token.range[0] + 4, token);
38
- if (ignores) {
39
- ignoreComments.push(...ignores);
45
+ const match = SVELTE_IGNORE_PATTERN.exec(text);
46
+ if (!match) {
47
+ continue;
40
48
  }
41
- else if (hasMissingCodeIgnore(text)) {
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(text, startIndex, token) {
55
- const m1 = SVELTE_IGNORE_PATTERN.exec(text);
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
- for (const code of beforeText.split(/\s/)) {
67
- const end = start + code.length;
68
- const trimmed = code.trim();
69
- if (trimmed) {
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: trimmed,
72
- codeForV5: V5_REPLACEMENTS[trimmed] || trimmed.replace(/-/gu, '_'),
73
- range: [start, end],
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
- start = end + 1; /* space */
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(text) {
83
- const m1 = SVELTE_IGNORE_PATTERN.exec(text);
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.8.2",
3
+ "version": "3.9.1",
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",