eslint-plugin-svelte 3.3.1 → 3.3.3
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 +39 -11
- 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.3";
|
|
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.3";
|
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
|
|
@@ -283,10 +303,18 @@ export default createRule('no-unused-props', {
|
|
|
283
303
|
usedProps = getUsedPropertiesFromPattern(node.id);
|
|
284
304
|
if (usedProps.size === 0)
|
|
285
305
|
return;
|
|
286
|
-
const identifiers =
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
306
|
+
const identifiers = [];
|
|
307
|
+
for (const p of node.id.properties) {
|
|
308
|
+
if (p.type !== 'Property') {
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (p.value.type === 'Identifier') {
|
|
312
|
+
identifiers.push(p.value);
|
|
313
|
+
}
|
|
314
|
+
else if (p.value.type === 'AssignmentPattern' && p.value.left.type === 'Identifier') {
|
|
315
|
+
identifiers.push(p.value.left);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
290
318
|
for (const identifier of identifiers) {
|
|
291
319
|
const paths = getUsedNestedPropertyNames(identifier);
|
|
292
320
|
usedPaths.push(...paths.map((path) => [identifier.name, ...path]));
|
|
@@ -295,7 +323,7 @@ export default createRule('no-unused-props', {
|
|
|
295
323
|
else if (node.id.type === 'Identifier') {
|
|
296
324
|
usedPaths = getUsedNestedPropertyNames(node.id);
|
|
297
325
|
}
|
|
298
|
-
checkUnusedProperties(propType, usedPaths, usedProps, node.id, [], new Set(), new Set());
|
|
326
|
+
checkUnusedProperties(propType, normalizeUsedPaths(usedPaths), usedProps, node.id, [], new Set(), new Set());
|
|
299
327
|
}
|
|
300
328
|
};
|
|
301
329
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-svelte",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.3",
|
|
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",
|