eslint-plugin-svelte 3.3.1 → 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 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.1";
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.1";
2
+ export declare const version = "3.3.2";
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.3.1';
5
+ export const version = '3.3.2';
@@ -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 && reference.identifier.type === 'Identifier') {
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 isUsedInPath = usedPaths.some((path) => {
226
- const usedPath = path.join('.');
227
- return usedPath === currentPathStr || usedPath.startsWith(`${currentPathStr}.`);
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 = usedPaths.some((path) => {
242
- return path.join('.').startsWith(`${currentPathStr}.`);
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-svelte",
3
- "version": "3.3.1",
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",