eslint-plugin-svelte 3.4.1 → 3.5.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/rule-types.d.ts +1 -0
- package/lib/rules/no-unnecessary-state-wrap.js +9 -3
- package/lib/rules/no-unused-props.js +26 -8
- 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.5.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.5.0";
|
package/lib/meta.js
CHANGED
package/lib/rule-types.d.ts
CHANGED
|
@@ -50,7 +50,11 @@ export default createRule('no-unnecessary-state-wrap', {
|
|
|
50
50
|
const options = context.options[0] ?? {};
|
|
51
51
|
const additionalReactiveClasses = options.additionalReactiveClasses ?? [];
|
|
52
52
|
const allowReassign = options.allowReassign ?? false;
|
|
53
|
-
const
|
|
53
|
+
const { globalScope } = context.sourceCode.scopeManager;
|
|
54
|
+
if (globalScope == null) {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
const referenceTracker = new ReferenceTracker(globalScope);
|
|
54
58
|
const traceMap = {};
|
|
55
59
|
for (const reactiveClass of REACTIVE_CLASSES) {
|
|
56
60
|
traceMap[reactiveClass] = {
|
|
@@ -72,8 +76,10 @@ export default createRule('no-unnecessary-state-wrap', {
|
|
|
72
76
|
};
|
|
73
77
|
});
|
|
74
78
|
function isReassigned(identifier) {
|
|
75
|
-
const
|
|
76
|
-
|
|
79
|
+
const references = context.sourceCode.scopeManager
|
|
80
|
+
.getDeclaredVariables(identifier.parent)
|
|
81
|
+
.flatMap((v) => v.references);
|
|
82
|
+
return references.some((ref) => {
|
|
77
83
|
return ref.isWrite() && ref.identifier !== identifier;
|
|
78
84
|
});
|
|
79
85
|
}
|
|
@@ -31,6 +31,10 @@ export default createRule('no-unused-props', {
|
|
|
31
31
|
type: 'string'
|
|
32
32
|
},
|
|
33
33
|
default: []
|
|
34
|
+
},
|
|
35
|
+
allowUnusedNestedProperties: {
|
|
36
|
+
type: 'boolean',
|
|
37
|
+
default: false
|
|
34
38
|
}
|
|
35
39
|
},
|
|
36
40
|
additionalProperties: false
|
|
@@ -159,8 +163,15 @@ export default createRule('no-unused-props', {
|
|
|
159
163
|
function getUsedPropertyNamesFromPattern(pattern) {
|
|
160
164
|
const usedProps = new Set();
|
|
161
165
|
for (const prop of pattern.properties) {
|
|
162
|
-
if (prop.type === 'Property'
|
|
163
|
-
|
|
166
|
+
if (prop.type === 'Property') {
|
|
167
|
+
if (prop.key.type === 'Identifier') {
|
|
168
|
+
usedProps.add({ originalName: prop.key.name, aliasName: prop.key.name });
|
|
169
|
+
}
|
|
170
|
+
else if (prop.key.type === 'Literal' &&
|
|
171
|
+
typeof prop.key.value === 'string' &&
|
|
172
|
+
prop.value.type === 'Identifier') {
|
|
173
|
+
usedProps.add({ originalName: prop.key.value, aliasName: prop.value.name });
|
|
174
|
+
}
|
|
164
175
|
}
|
|
165
176
|
else if (prop.type === 'RestElement') {
|
|
166
177
|
// If there's a rest element, all properties are potentially used
|
|
@@ -239,7 +250,9 @@ export default createRule('no-unused-props', {
|
|
|
239
250
|
if (isUsedThisInPath && !isUsedInPath) {
|
|
240
251
|
continue;
|
|
241
252
|
}
|
|
242
|
-
const isUsedInProps = declaredPropertyNames.
|
|
253
|
+
const isUsedInProps = Array.from(declaredPropertyNames).some((p) => {
|
|
254
|
+
return p.originalName === propName;
|
|
255
|
+
});
|
|
243
256
|
if (!isUsedInPath && !isUsedInProps) {
|
|
244
257
|
reportedPropertyPaths.add(currentPathStr);
|
|
245
258
|
context.report({
|
|
@@ -284,10 +297,10 @@ export default createRule('no-unused-props', {
|
|
|
284
297
|
* Returns true if the destructuring pattern includes a rest element,
|
|
285
298
|
* which means all remaining properties are potentially used.
|
|
286
299
|
*/
|
|
287
|
-
function hasRestElement(
|
|
288
|
-
return
|
|
300
|
+
function hasRestElement(declaredPropertyNames) {
|
|
301
|
+
return declaredPropertyNames.size === 0;
|
|
289
302
|
}
|
|
290
|
-
function normalizeUsedPaths(paths) {
|
|
303
|
+
function normalizeUsedPaths(paths, allowUnusedNestedProperties) {
|
|
291
304
|
const normalized = [];
|
|
292
305
|
for (const path of paths.sort((a, b) => a.length - b.length)) {
|
|
293
306
|
if (path.length === 0)
|
|
@@ -297,7 +310,12 @@ export default createRule('no-unused-props', {
|
|
|
297
310
|
}
|
|
298
311
|
normalized.push(path);
|
|
299
312
|
}
|
|
300
|
-
return normalized
|
|
313
|
+
return normalized.map((path) => {
|
|
314
|
+
// If we allow unused nested properties, only return first level properties
|
|
315
|
+
if (allowUnusedNestedProperties)
|
|
316
|
+
return [path[0]];
|
|
317
|
+
return path;
|
|
318
|
+
});
|
|
301
319
|
}
|
|
302
320
|
return {
|
|
303
321
|
'VariableDeclaration > VariableDeclarator': (node) => {
|
|
@@ -339,7 +357,7 @@ export default createRule('no-unused-props', {
|
|
|
339
357
|
}
|
|
340
358
|
checkUnusedProperties({
|
|
341
359
|
propsType,
|
|
342
|
-
usedPropertyPaths: normalizeUsedPaths(usedPropertyPathsArray).map((pathArray) => {
|
|
360
|
+
usedPropertyPaths: normalizeUsedPaths(usedPropertyPathsArray, options.allowUnusedNestedProperties).map((pathArray) => {
|
|
343
361
|
return pathArray.join('.');
|
|
344
362
|
}),
|
|
345
363
|
declaredPropertyNames,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-svelte",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.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",
|