eslint-plugin-svelte 3.2.1 → 3.3.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/README.md +1 -1
- 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 +2 -1
- package/lib/rules/no-unused-props.js +35 -13
- package/package.json +1 -1
package/README.md
CHANGED
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.3.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.3.0";
|
package/lib/meta.js
CHANGED
package/lib/rule-types.d.ts
CHANGED
|
@@ -545,7 +545,8 @@ type SvelteNoUnusedClassName = [] | [
|
|
|
545
545
|
type SvelteNoUnusedProps = [] | [
|
|
546
546
|
{
|
|
547
547
|
checkImportedTypes?: boolean;
|
|
548
|
-
|
|
548
|
+
ignoreTypePatterns?: string[];
|
|
549
|
+
ignorePropertyPatterns?: string[];
|
|
549
550
|
}
|
|
550
551
|
];
|
|
551
552
|
type SvelteNoUselessMustaches = [] | [
|
|
@@ -3,6 +3,7 @@ import { getTypeScriptTools } from '../utils/ts-utils/index.js';
|
|
|
3
3
|
import { findVariable } from '../utils/ast-utils.js';
|
|
4
4
|
import { toRegExp } from '../utils/regexp.js';
|
|
5
5
|
import { getFilename } from '../utils/compat.js';
|
|
6
|
+
let isRemovedWarningShown = false;
|
|
6
7
|
export default createRule('no-unused-props', {
|
|
7
8
|
meta: {
|
|
8
9
|
docs: {
|
|
@@ -18,7 +19,14 @@ export default createRule('no-unused-props', {
|
|
|
18
19
|
type: 'boolean',
|
|
19
20
|
default: false
|
|
20
21
|
},
|
|
21
|
-
|
|
22
|
+
ignoreTypePatterns: {
|
|
23
|
+
type: 'array',
|
|
24
|
+
items: {
|
|
25
|
+
type: 'string'
|
|
26
|
+
},
|
|
27
|
+
default: []
|
|
28
|
+
},
|
|
29
|
+
ignorePropertyPatterns: {
|
|
22
30
|
type: 'array',
|
|
23
31
|
items: {
|
|
24
32
|
type: 'string'
|
|
@@ -53,31 +61,43 @@ export default createRule('no-unused-props', {
|
|
|
53
61
|
return {};
|
|
54
62
|
}
|
|
55
63
|
const options = context.options[0] ?? {};
|
|
64
|
+
// TODO: Remove in v4
|
|
65
|
+
// MEMO: `ignorePatterns` was a property that only existed from v3.2.0 to v3.2.2.
|
|
66
|
+
// From v3.3.0, it was replaced with `ignorePropertyPatterns` and `ignoreTypePatterns`.
|
|
67
|
+
if (options.ignorePatterns != null && !isRemovedWarningShown) {
|
|
68
|
+
console.warn('eslint-plugin-svelte: The `ignorePatterns` option in the `no-unused-props` rule has been removed. Please use `ignorePropertyPatterns` or/and `ignoreTypePatterns` instead.');
|
|
69
|
+
isRemovedWarningShown = true;
|
|
70
|
+
}
|
|
56
71
|
const checkImportedTypes = options.checkImportedTypes ?? false;
|
|
57
|
-
const
|
|
72
|
+
const ignoreTypePatterns = (options.ignoreTypePatterns ?? []).map((p) => {
|
|
73
|
+
if (typeof p === 'string') {
|
|
74
|
+
return toRegExp(p);
|
|
75
|
+
}
|
|
76
|
+
return p;
|
|
77
|
+
});
|
|
78
|
+
const ignorePropertyPatterns = (options.ignorePropertyPatterns ?? []).map((p) => {
|
|
58
79
|
if (typeof p === 'string') {
|
|
59
80
|
return toRegExp(p);
|
|
60
81
|
}
|
|
61
82
|
return p;
|
|
62
83
|
});
|
|
63
|
-
function
|
|
64
|
-
return
|
|
84
|
+
function shouldIgnoreProperty(name) {
|
|
85
|
+
return ignorePropertyPatterns.some((pattern) => pattern.test(name));
|
|
65
86
|
}
|
|
66
87
|
function shouldIgnoreType(type) {
|
|
88
|
+
function isMatched(name) {
|
|
89
|
+
return ignoreTypePatterns.some((pattern) => pattern.test(name));
|
|
90
|
+
}
|
|
67
91
|
const typeStr = typeChecker.typeToString(type);
|
|
68
92
|
const symbol = type.getSymbol();
|
|
69
93
|
const symbolName = symbol?.getName();
|
|
70
|
-
return
|
|
94
|
+
return isMatched(typeStr) || (symbolName ? isMatched(symbolName) : false);
|
|
71
95
|
}
|
|
72
|
-
function
|
|
73
|
-
const symbol = type.getSymbol();
|
|
74
|
-
if (!symbol)
|
|
75
|
-
return false;
|
|
96
|
+
function isInternalProperty(symbol) {
|
|
76
97
|
const declarations = symbol.getDeclarations();
|
|
77
98
|
if (!declarations || declarations.length === 0)
|
|
78
99
|
return false;
|
|
79
|
-
|
|
80
|
-
return sourceFile.fileName !== fileName;
|
|
100
|
+
return declarations.every((decl) => decl.getSourceFile().fileName === fileName);
|
|
81
101
|
}
|
|
82
102
|
/**
|
|
83
103
|
* Extracts property paths from member expressions.
|
|
@@ -179,8 +199,6 @@ export default createRule('no-unused-props', {
|
|
|
179
199
|
checkedTypes.add(typeStr);
|
|
180
200
|
if (shouldIgnoreType(type))
|
|
181
201
|
return;
|
|
182
|
-
if (!checkImportedTypes && isExternalType(type))
|
|
183
|
-
return;
|
|
184
202
|
const properties = typeChecker.getPropertiesOfType(type);
|
|
185
203
|
const baseTypes = type.getBaseTypes();
|
|
186
204
|
if (!properties.length && (!baseTypes || baseTypes.length === 0)) {
|
|
@@ -194,7 +212,11 @@ export default createRule('no-unused-props', {
|
|
|
194
212
|
for (const prop of properties) {
|
|
195
213
|
if (isBuiltInProperty(prop))
|
|
196
214
|
continue;
|
|
215
|
+
if (!checkImportedTypes && !isInternalProperty(prop))
|
|
216
|
+
continue;
|
|
197
217
|
const propName = prop.getName();
|
|
218
|
+
if (shouldIgnoreProperty(propName))
|
|
219
|
+
continue;
|
|
198
220
|
const currentPath = [...parentPath, propName];
|
|
199
221
|
const currentPathStr = [...parentPath, propName].join('.');
|
|
200
222
|
if (reportedProps.has(currentPathStr))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-svelte",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.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",
|