eslint-plugin-svelte 3.3.0 → 3.3.2
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/rules/no-unused-props.js +27 -7
- package/lib/rules/no-useless-mustaches.js +5 -2
- 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.3.
|
|
17
|
+
version: "3.3.2";
|
|
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.3.
|
|
2
|
+
export declare const version = "3.3.2";
|
package/lib/meta.js
CHANGED
|
@@ -133,7 +133,10 @@ export default createRule('no-unused-props', {
|
|
|
133
133
|
return [];
|
|
134
134
|
const paths = [];
|
|
135
135
|
for (const reference of variable.references) {
|
|
136
|
-
if ('identifier' in reference &&
|
|
136
|
+
if ('identifier' in reference &&
|
|
137
|
+
reference.identifier.type === 'Identifier' &&
|
|
138
|
+
(reference.identifier.range[0] !== node.range[0] ||
|
|
139
|
+
reference.identifier.range[1] !== node.range[1])) {
|
|
137
140
|
const referencePath = getPropertyPath(reference.identifier);
|
|
138
141
|
paths.push(referencePath);
|
|
139
142
|
}
|
|
@@ -222,10 +225,14 @@ export default createRule('no-unused-props', {
|
|
|
222
225
|
if (reportedProps.has(currentPathStr))
|
|
223
226
|
continue;
|
|
224
227
|
const propType = typeChecker.getTypeOfSymbol(prop);
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
+
const joinedUsedPaths = usedPaths.map((path) => path.join('.'));
|
|
229
|
+
const isUsedThisInPath = joinedUsedPaths.includes(currentPathStr);
|
|
230
|
+
const isUsedInPath = joinedUsedPaths.some((path) => {
|
|
231
|
+
return path.startsWith(`${currentPathStr}.`);
|
|
228
232
|
});
|
|
233
|
+
if (isUsedThisInPath && !isUsedInPath) {
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
229
236
|
const isUsedInProps = usedProps.has(propName);
|
|
230
237
|
if (!isUsedInPath && !isUsedInProps) {
|
|
231
238
|
reportedProps.add(currentPathStr);
|
|
@@ -237,9 +244,10 @@ export default createRule('no-unused-props', {
|
|
|
237
244
|
parent: parentPath.join('.')
|
|
238
245
|
}
|
|
239
246
|
});
|
|
247
|
+
continue;
|
|
240
248
|
}
|
|
241
|
-
const isUsedNested =
|
|
242
|
-
return path.
|
|
249
|
+
const isUsedNested = joinedUsedPaths.some((path) => {
|
|
250
|
+
return path.startsWith(`${currentPathStr}.`);
|
|
243
251
|
});
|
|
244
252
|
if (isUsedNested || isUsedInProps) {
|
|
245
253
|
checkUnusedProperties(propType, usedPaths, usedProps, reportNode, currentPath, checkedTypes, reportedProps);
|
|
@@ -265,6 +273,18 @@ export default createRule('no-unused-props', {
|
|
|
265
273
|
function hasRestElement(usedProps) {
|
|
266
274
|
return usedProps.size === 0;
|
|
267
275
|
}
|
|
276
|
+
function normalizeUsedPaths(paths) {
|
|
277
|
+
const normalized = [];
|
|
278
|
+
for (const path of paths.sort((a, b) => a.length - b.length)) {
|
|
279
|
+
if (path.length === 0)
|
|
280
|
+
continue;
|
|
281
|
+
if (normalized.some((p) => p.every((part, idx) => part === path[idx]))) {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
normalized.push(path);
|
|
285
|
+
}
|
|
286
|
+
return normalized;
|
|
287
|
+
}
|
|
268
288
|
return {
|
|
269
289
|
'VariableDeclaration > VariableDeclarator': (node) => {
|
|
270
290
|
// Only check $props declarations
|
|
@@ -295,7 +315,7 @@ export default createRule('no-unused-props', {
|
|
|
295
315
|
else if (node.id.type === 'Identifier') {
|
|
296
316
|
usedPaths = getUsedNestedPropertyNames(node.id);
|
|
297
317
|
}
|
|
298
|
-
checkUnusedProperties(propType, usedPaths, usedProps, node.id, [], new Set(), new Set());
|
|
318
|
+
checkUnusedProperties(propType, normalizeUsedPaths(usedPaths), usedProps, node.id, [], new Set(), new Set());
|
|
299
319
|
}
|
|
300
320
|
};
|
|
301
321
|
}
|
|
@@ -124,14 +124,17 @@ export default createRule('no-useless-mustaches', {
|
|
|
124
124
|
if (node.parent.type === 'SvelteAttribute' ||
|
|
125
125
|
node.parent.type === 'SvelteStyleDirective') {
|
|
126
126
|
const div = sourceCode.text.slice(node.parent.key.range[1], node.parent.value[0].range[0]);
|
|
127
|
-
|
|
127
|
+
const quote = div.endsWith('"') ? 'quot' : div.endsWith("'") ? 'apos' : null;
|
|
128
|
+
if (!quote) {
|
|
128
129
|
return [
|
|
129
130
|
fixer.insertTextBefore(node.parent.value[0], '"'),
|
|
130
131
|
fixer.replaceText(node, unescaped.replace(/"/gu, '"')),
|
|
131
132
|
fixer.insertTextAfter(node.parent.value[node.parent.value.length - 1], '"')
|
|
132
133
|
];
|
|
133
134
|
}
|
|
134
|
-
return fixer.replaceText(node,
|
|
135
|
+
return fixer.replaceText(node, quote === 'quot'
|
|
136
|
+
? unescaped.replace(/"/gu, '"')
|
|
137
|
+
: unescaped.replace(/'/gu, '''));
|
|
135
138
|
}
|
|
136
139
|
return fixer.replaceText(node, unescaped.replace(/</gu, '<').replace(/>/gu, '>'));
|
|
137
140
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-svelte",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.2",
|
|
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",
|