zeiger-eslint-plugin 0.1.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/LICENSE +21 -0
- package/README.md +99 -0
- package/dist/index.cjs +193 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +159 -0
- package/dist/rules/zeiger-deps.d.ts +4 -0
- package/dist/rules/zeiger-deps.d.ts.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Marek Honzal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# zeiger-eslint-plugin
|
|
2
|
+
|
|
3
|
+
ESLint plugin for [Zeiger](https://github.com/DNepovim/zeiger) - ensures proper usage of Zeiger hooks with dependency arrays.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev zeiger-eslint-plugin
|
|
9
|
+
# or
|
|
10
|
+
pnpm add -D zeiger-eslint-plugin
|
|
11
|
+
# or
|
|
12
|
+
yarn add -D zeiger-eslint-plugin
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Flat Config (ESLint 9+)
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import zeigerPlugin from 'zeiger-eslint-plugin';
|
|
21
|
+
|
|
22
|
+
export default [
|
|
23
|
+
{
|
|
24
|
+
plugins: {
|
|
25
|
+
zeiger: zeigerPlugin,
|
|
26
|
+
},
|
|
27
|
+
rules: {
|
|
28
|
+
...zeigerPlugin.configs.recommended.rules,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Legacy Config (ESLint 8)
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"plugins": ["zeiger"],
|
|
39
|
+
"extends": ["plugin:zeiger/recommended"]
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Rules
|
|
44
|
+
|
|
45
|
+
### `zeiger/zeiger-deps`
|
|
46
|
+
|
|
47
|
+
Ensures that Zeiger hooks created with `createCollectionPointer` or `createCollectionItemPointer` have:
|
|
48
|
+
|
|
49
|
+
1. Non-empty dependency arrays
|
|
50
|
+
2. All listed dependencies are actually used in the code
|
|
51
|
+
|
|
52
|
+
#### Examples
|
|
53
|
+
|
|
54
|
+
**❌ Empty dependency array:**
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
const useUsersPointer = createCollectionPointer(useStore, 'users');
|
|
58
|
+
const users = useUsersPointer([]); // Error: dependency array must not be empty
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**❌ Unused dependency:**
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
const useUserPointer = createCollectionItemPointer(useStore, 'users', 'id');
|
|
65
|
+
const user = useUserPointer('1', ['firstName', 'surname', 'email']);
|
|
66
|
+
|
|
67
|
+
// Only firstName and email are used
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
{user?.firstName} - {user?.email}
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
// Error: Property 'surname' is listed in dependency array but not used
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**✅ Correct usage:**
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
const useUserPointer = createCollectionItemPointer(useStore, 'users', 'id');
|
|
80
|
+
const user = useUserPointer('1', ['firstName', 'email']);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div>
|
|
84
|
+
{user?.firstName} - {user?.email}
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Why This Plugin?
|
|
90
|
+
|
|
91
|
+
Zeiger hooks use dependency arrays to specify which properties to subscribe to. This plugin helps you:
|
|
92
|
+
|
|
93
|
+
- **Avoid unnecessary subscriptions** - Catch unused properties in dependency arrays
|
|
94
|
+
- **Prevent empty arrays** - Ensure you're always subscribing to at least one property
|
|
95
|
+
- **Maintain code quality** - Keep your Zeiger hooks clean and efficient
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
default: ()=>src
|
|
28
|
+
});
|
|
29
|
+
const rule = {
|
|
30
|
+
meta: {
|
|
31
|
+
type: 'problem',
|
|
32
|
+
docs: {
|
|
33
|
+
description: 'Ensure zeiger hook dependency arrays are not empty and all dependencies are used'
|
|
34
|
+
},
|
|
35
|
+
messages: {
|
|
36
|
+
emptyDeps: 'Zeiger hook dependency array must not be empty. Provide at least one property.',
|
|
37
|
+
unusedDep: "Property '{{property}}' is listed in dependency array but not used in the code."
|
|
38
|
+
},
|
|
39
|
+
schema: []
|
|
40
|
+
},
|
|
41
|
+
create (context) {
|
|
42
|
+
const sourceCode = context.sourceCode;
|
|
43
|
+
function isZeigerHookCall(node) {
|
|
44
|
+
if ('CallExpression' !== node.type) return false;
|
|
45
|
+
const callNode = node;
|
|
46
|
+
const callee = callNode.callee;
|
|
47
|
+
if ('Identifier' !== callee.type) return false;
|
|
48
|
+
const hookName = callee.name;
|
|
49
|
+
if (!hookName.startsWith('use')) return false;
|
|
50
|
+
const scope = sourceCode.getScope(node);
|
|
51
|
+
const variable = scope.variables.find((v)=>v.name === hookName);
|
|
52
|
+
if (!variable) return false;
|
|
53
|
+
for (const def of variable.defs)if ('Variable' === def.type && def.node.init) {
|
|
54
|
+
const init = def.node.init;
|
|
55
|
+
if ('CallExpression' === init.type) {
|
|
56
|
+
const initCall = init;
|
|
57
|
+
const initCallee = initCall.callee;
|
|
58
|
+
if ('Identifier' === initCallee.type) {
|
|
59
|
+
const initName = initCallee.name;
|
|
60
|
+
if ('createCollectionPointer' === initName || 'createCollectionItemPointer' === initName) return true;
|
|
61
|
+
}
|
|
62
|
+
if ('MemberExpression' === initCallee.type) {
|
|
63
|
+
const member = initCallee;
|
|
64
|
+
if ('Identifier' === member.property.type && ('createCollectionPointer' === member.property.name || 'createCollectionItemPointer' === member.property.name)) return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
function getDependencyArray(node) {
|
|
71
|
+
if ('CallExpression' !== node.type) return null;
|
|
72
|
+
const callNode = node;
|
|
73
|
+
const args = callNode.arguments;
|
|
74
|
+
if (0 === args.length) return null;
|
|
75
|
+
let depsArg = null;
|
|
76
|
+
if (1 === args.length) depsArg = args[0];
|
|
77
|
+
else if (2 === args.length) depsArg = args[1];
|
|
78
|
+
if (!depsArg || 'ArrayExpression' !== depsArg.type) return null;
|
|
79
|
+
const arrayNode = depsArg;
|
|
80
|
+
const deps = [];
|
|
81
|
+
for (const element of arrayNode.elements)if (element && 'Literal' === element.type && 'string' == typeof element.value) deps.push(element.value);
|
|
82
|
+
return deps;
|
|
83
|
+
}
|
|
84
|
+
function getUsedProperties(node, resultVarName) {
|
|
85
|
+
const used = new Set();
|
|
86
|
+
function traverse(currentNode) {
|
|
87
|
+
if ('MemberExpression' === currentNode.type) {
|
|
88
|
+
const member = currentNode;
|
|
89
|
+
const object = member.object;
|
|
90
|
+
if ('Identifier' === object.type && object.name === resultVarName && 'Identifier' === member.property.type) used.add(member.property.name);
|
|
91
|
+
}
|
|
92
|
+
if ('ChainExpression' === currentNode.type) {
|
|
93
|
+
const chain = currentNode;
|
|
94
|
+
const expr = chain.expression;
|
|
95
|
+
if ('MemberExpression' === expr.type) {
|
|
96
|
+
const member = expr;
|
|
97
|
+
const object = member.object;
|
|
98
|
+
if ('Identifier' === object.type && object.name === resultVarName && 'Identifier' === member.property.type) used.add(member.property.name);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
for(const key in currentNode){
|
|
102
|
+
if ('parent' === key || 'range' === key || 'loc' === key) continue;
|
|
103
|
+
const value = currentNode[key];
|
|
104
|
+
if (value && 'object' == typeof value) {
|
|
105
|
+
if (Array.isArray(value)) {
|
|
106
|
+
for (const item of value)if (item && 'object' == typeof item && 'type' in item) traverse(item);
|
|
107
|
+
} else if (value && 'type' in value) traverse(value);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
traverse(node);
|
|
112
|
+
return used;
|
|
113
|
+
}
|
|
114
|
+
function getResultVariableName(node) {
|
|
115
|
+
if ('CallExpression' !== node.type) return null;
|
|
116
|
+
const parent = node.parent;
|
|
117
|
+
if (!parent) return null;
|
|
118
|
+
if ('VariableDeclarator' === parent.type) {
|
|
119
|
+
const declarator = parent;
|
|
120
|
+
if ('Identifier' === declarator.id.type) return declarator.id.name;
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
function findFunctionScope(scope) {
|
|
125
|
+
if ('function' === scope.type || 'class' === scope.type) return scope;
|
|
126
|
+
if (scope.upper) return findFunctionScope(scope.upper);
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
CallExpression (node) {
|
|
131
|
+
if (!isZeigerHookCall(node)) return;
|
|
132
|
+
const deps = getDependencyArray(node);
|
|
133
|
+
if (null === deps) return;
|
|
134
|
+
if (0 === deps.length) return void context.report({
|
|
135
|
+
node,
|
|
136
|
+
messageId: 'emptyDeps'
|
|
137
|
+
});
|
|
138
|
+
const resultVarName = getResultVariableName(node);
|
|
139
|
+
if (!resultVarName) return;
|
|
140
|
+
const currentScope = sourceCode.getScope(node);
|
|
141
|
+
const functionScope = findFunctionScope(currentScope);
|
|
142
|
+
if (!functionScope || !functionScope.block) return;
|
|
143
|
+
const usedProperties = getUsedProperties(functionScope.block, resultVarName);
|
|
144
|
+
const callNode = node;
|
|
145
|
+
const depsArg = callNode.arguments.length > 0 ? callNode.arguments[callNode.arguments.length - 1] : null;
|
|
146
|
+
if (depsArg && 'ArrayExpression' === depsArg.type) {
|
|
147
|
+
const arrayNode = depsArg;
|
|
148
|
+
for(let i = 0; i < deps.length; i++){
|
|
149
|
+
const dep = deps[i];
|
|
150
|
+
if (!usedProperties.has(dep)) {
|
|
151
|
+
const depElement = arrayNode.elements[i];
|
|
152
|
+
if (depElement) context.report({
|
|
153
|
+
node: depElement,
|
|
154
|
+
messageId: 'unusedDep',
|
|
155
|
+
data: {
|
|
156
|
+
property: dep
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const zeiger_deps = rule;
|
|
167
|
+
const src_plugin = {
|
|
168
|
+
meta: {
|
|
169
|
+
name: 'zeiger-eslint-plugin',
|
|
170
|
+
version: '1.0.0'
|
|
171
|
+
},
|
|
172
|
+
rules: {
|
|
173
|
+
'zeiger-deps': zeiger_deps
|
|
174
|
+
},
|
|
175
|
+
configs: {
|
|
176
|
+
recommended: {
|
|
177
|
+
plugins: [
|
|
178
|
+
'zeiger'
|
|
179
|
+
],
|
|
180
|
+
rules: {
|
|
181
|
+
'zeiger/zeiger-deps': 'error'
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
const src = src_plugin;
|
|
187
|
+
exports["default"] = __webpack_exports__["default"];
|
|
188
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
189
|
+
"default"
|
|
190
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
191
|
+
Object.defineProperty(exports, '__esModule', {
|
|
192
|
+
value: true
|
|
193
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGrC,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,MAgBpB,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const rule = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: 'problem',
|
|
4
|
+
docs: {
|
|
5
|
+
description: 'Ensure zeiger hook dependency arrays are not empty and all dependencies are used'
|
|
6
|
+
},
|
|
7
|
+
messages: {
|
|
8
|
+
emptyDeps: 'Zeiger hook dependency array must not be empty. Provide at least one property.',
|
|
9
|
+
unusedDep: "Property '{{property}}' is listed in dependency array but not used in the code."
|
|
10
|
+
},
|
|
11
|
+
schema: []
|
|
12
|
+
},
|
|
13
|
+
create (context) {
|
|
14
|
+
const sourceCode = context.sourceCode;
|
|
15
|
+
function isZeigerHookCall(node) {
|
|
16
|
+
if ('CallExpression' !== node.type) return false;
|
|
17
|
+
const callNode = node;
|
|
18
|
+
const callee = callNode.callee;
|
|
19
|
+
if ('Identifier' !== callee.type) return false;
|
|
20
|
+
const hookName = callee.name;
|
|
21
|
+
if (!hookName.startsWith('use')) return false;
|
|
22
|
+
const scope = sourceCode.getScope(node);
|
|
23
|
+
const variable = scope.variables.find((v)=>v.name === hookName);
|
|
24
|
+
if (!variable) return false;
|
|
25
|
+
for (const def of variable.defs)if ('Variable' === def.type && def.node.init) {
|
|
26
|
+
const init = def.node.init;
|
|
27
|
+
if ('CallExpression' === init.type) {
|
|
28
|
+
const initCall = init;
|
|
29
|
+
const initCallee = initCall.callee;
|
|
30
|
+
if ('Identifier' === initCallee.type) {
|
|
31
|
+
const initName = initCallee.name;
|
|
32
|
+
if ('createCollectionPointer' === initName || 'createCollectionItemPointer' === initName) return true;
|
|
33
|
+
}
|
|
34
|
+
if ('MemberExpression' === initCallee.type) {
|
|
35
|
+
const member = initCallee;
|
|
36
|
+
if ('Identifier' === member.property.type && ('createCollectionPointer' === member.property.name || 'createCollectionItemPointer' === member.property.name)) return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
function getDependencyArray(node) {
|
|
43
|
+
if ('CallExpression' !== node.type) return null;
|
|
44
|
+
const callNode = node;
|
|
45
|
+
const args = callNode.arguments;
|
|
46
|
+
if (0 === args.length) return null;
|
|
47
|
+
let depsArg = null;
|
|
48
|
+
if (1 === args.length) depsArg = args[0];
|
|
49
|
+
else if (2 === args.length) depsArg = args[1];
|
|
50
|
+
if (!depsArg || 'ArrayExpression' !== depsArg.type) return null;
|
|
51
|
+
const arrayNode = depsArg;
|
|
52
|
+
const deps = [];
|
|
53
|
+
for (const element of arrayNode.elements)if (element && 'Literal' === element.type && 'string' == typeof element.value) deps.push(element.value);
|
|
54
|
+
return deps;
|
|
55
|
+
}
|
|
56
|
+
function getUsedProperties(node, resultVarName) {
|
|
57
|
+
const used = new Set();
|
|
58
|
+
function traverse(currentNode) {
|
|
59
|
+
if ('MemberExpression' === currentNode.type) {
|
|
60
|
+
const member = currentNode;
|
|
61
|
+
const object = member.object;
|
|
62
|
+
if ('Identifier' === object.type && object.name === resultVarName && 'Identifier' === member.property.type) used.add(member.property.name);
|
|
63
|
+
}
|
|
64
|
+
if ('ChainExpression' === currentNode.type) {
|
|
65
|
+
const chain = currentNode;
|
|
66
|
+
const expr = chain.expression;
|
|
67
|
+
if ('MemberExpression' === expr.type) {
|
|
68
|
+
const member = expr;
|
|
69
|
+
const object = member.object;
|
|
70
|
+
if ('Identifier' === object.type && object.name === resultVarName && 'Identifier' === member.property.type) used.add(member.property.name);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for(const key in currentNode){
|
|
74
|
+
if ('parent' === key || 'range' === key || 'loc' === key) continue;
|
|
75
|
+
const value = currentNode[key];
|
|
76
|
+
if (value && 'object' == typeof value) {
|
|
77
|
+
if (Array.isArray(value)) {
|
|
78
|
+
for (const item of value)if (item && 'object' == typeof item && 'type' in item) traverse(item);
|
|
79
|
+
} else if (value && 'type' in value) traverse(value);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
traverse(node);
|
|
84
|
+
return used;
|
|
85
|
+
}
|
|
86
|
+
function getResultVariableName(node) {
|
|
87
|
+
if ('CallExpression' !== node.type) return null;
|
|
88
|
+
const parent = node.parent;
|
|
89
|
+
if (!parent) return null;
|
|
90
|
+
if ('VariableDeclarator' === parent.type) {
|
|
91
|
+
const declarator = parent;
|
|
92
|
+
if ('Identifier' === declarator.id.type) return declarator.id.name;
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
function findFunctionScope(scope) {
|
|
97
|
+
if ('function' === scope.type || 'class' === scope.type) return scope;
|
|
98
|
+
if (scope.upper) return findFunctionScope(scope.upper);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
CallExpression (node) {
|
|
103
|
+
if (!isZeigerHookCall(node)) return;
|
|
104
|
+
const deps = getDependencyArray(node);
|
|
105
|
+
if (null === deps) return;
|
|
106
|
+
if (0 === deps.length) return void context.report({
|
|
107
|
+
node,
|
|
108
|
+
messageId: 'emptyDeps'
|
|
109
|
+
});
|
|
110
|
+
const resultVarName = getResultVariableName(node);
|
|
111
|
+
if (!resultVarName) return;
|
|
112
|
+
const currentScope = sourceCode.getScope(node);
|
|
113
|
+
const functionScope = findFunctionScope(currentScope);
|
|
114
|
+
if (!functionScope || !functionScope.block) return;
|
|
115
|
+
const usedProperties = getUsedProperties(functionScope.block, resultVarName);
|
|
116
|
+
const callNode = node;
|
|
117
|
+
const depsArg = callNode.arguments.length > 0 ? callNode.arguments[callNode.arguments.length - 1] : null;
|
|
118
|
+
if (depsArg && 'ArrayExpression' === depsArg.type) {
|
|
119
|
+
const arrayNode = depsArg;
|
|
120
|
+
for(let i = 0; i < deps.length; i++){
|
|
121
|
+
const dep = deps[i];
|
|
122
|
+
if (!usedProperties.has(dep)) {
|
|
123
|
+
const depElement = arrayNode.elements[i];
|
|
124
|
+
if (depElement) context.report({
|
|
125
|
+
node: depElement,
|
|
126
|
+
messageId: 'unusedDep',
|
|
127
|
+
data: {
|
|
128
|
+
property: dep
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const zeiger_deps = rule;
|
|
139
|
+
const src_plugin = {
|
|
140
|
+
meta: {
|
|
141
|
+
name: 'zeiger-eslint-plugin',
|
|
142
|
+
version: '1.0.0'
|
|
143
|
+
},
|
|
144
|
+
rules: {
|
|
145
|
+
'zeiger-deps': zeiger_deps
|
|
146
|
+
},
|
|
147
|
+
configs: {
|
|
148
|
+
recommended: {
|
|
149
|
+
plugins: [
|
|
150
|
+
'zeiger'
|
|
151
|
+
],
|
|
152
|
+
rules: {
|
|
153
|
+
'zeiger/zeiger-deps': 'error'
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const src = src_plugin;
|
|
159
|
+
export { src as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zeiger-deps.d.ts","sourceRoot":"","sources":["../../src/rules/zeiger-deps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UA2VhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "zeiger-eslint-plugin",
|
|
3
|
+
"description": "ESLint plugin for Zeiger library",
|
|
4
|
+
"homepage": "https://github.com/DNepovim/zeiger",
|
|
5
|
+
"repository": "https://github.com/DNepovim/zeiger",
|
|
6
|
+
"author": "Dominik Bláha <iam@dominikblaha.cz>",
|
|
7
|
+
"version": "0.1.0",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.cjs",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "rslib build",
|
|
23
|
+
"dev": "rslib build --watch",
|
|
24
|
+
"lint:check": "eslint .",
|
|
25
|
+
"lint:fix": "eslint --fix .",
|
|
26
|
+
"format:check": "prettier --check .",
|
|
27
|
+
"format:fix": "prettier --write .",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"knip": "knip"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"eslint",
|
|
34
|
+
"eslintplugin",
|
|
35
|
+
"zeiger"
|
|
36
|
+
],
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"eslint": ">=8.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@rslib/core": "^0.18.4",
|
|
42
|
+
"@types/estree": "^1.0.8",
|
|
43
|
+
"@types/node": "^24.10.1",
|
|
44
|
+
"knip": "^5.82.1",
|
|
45
|
+
"typescript": "^5.9.3",
|
|
46
|
+
"vitest": "^4.0.15"
|
|
47
|
+
}
|
|
48
|
+
}
|