eslint-plugin-svelte 3.2.2 → 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/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 +31 -5
- 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.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,21 +61,37 @@ 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) => {
|
|
58
73
|
if (typeof p === 'string') {
|
|
59
74
|
return toRegExp(p);
|
|
60
75
|
}
|
|
61
76
|
return p;
|
|
62
77
|
});
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
const ignorePropertyPatterns = (options.ignorePropertyPatterns ?? []).map((p) => {
|
|
79
|
+
if (typeof p === 'string') {
|
|
80
|
+
return toRegExp(p);
|
|
81
|
+
}
|
|
82
|
+
return p;
|
|
83
|
+
});
|
|
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
96
|
function isInternalProperty(symbol) {
|
|
73
97
|
const declarations = symbol.getDeclarations();
|
|
@@ -191,6 +215,8 @@ export default createRule('no-unused-props', {
|
|
|
191
215
|
if (!checkImportedTypes && !isInternalProperty(prop))
|
|
192
216
|
continue;
|
|
193
217
|
const propName = prop.getName();
|
|
218
|
+
if (shouldIgnoreProperty(propName))
|
|
219
|
+
continue;
|
|
194
220
|
const currentPath = [...parentPath, propName];
|
|
195
221
|
const currentPathStr = [...parentPath, propName].join('.');
|
|
196
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",
|