@clarusjs/eslint-plugin 0.2.0 → 0.2.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/dist/index.js +20 -7
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -32,13 +32,23 @@ function* expressions(nodes) {
|
|
|
32
32
|
}
|
|
33
33
|
yield* expressions(n.children);
|
|
34
34
|
}
|
|
35
|
-
else if (n.type === 'if')
|
|
35
|
+
else if (n.type === 'if') {
|
|
36
|
+
// @transition (name, options) around it: its arguments read script names too.
|
|
37
|
+
if (n.transition?.name)
|
|
38
|
+
yield n.transition.name;
|
|
39
|
+
if (n.transition?.options)
|
|
40
|
+
yield n.transition.options;
|
|
36
41
|
for (const b of n.branches) {
|
|
37
42
|
if (b.cond)
|
|
38
43
|
yield b.cond;
|
|
39
44
|
yield* expressions(b.children);
|
|
40
45
|
}
|
|
46
|
+
}
|
|
41
47
|
else if (n.type === 'for') {
|
|
48
|
+
if (n.transition?.name)
|
|
49
|
+
yield n.transition.name;
|
|
50
|
+
if (n.transition?.options)
|
|
51
|
+
yield n.transition.options;
|
|
42
52
|
yield n.list;
|
|
43
53
|
if (n.track)
|
|
44
54
|
yield n.track;
|
|
@@ -90,8 +100,8 @@ export const parser = {
|
|
|
90
100
|
return { ...result, scopeManager };
|
|
91
101
|
},
|
|
92
102
|
};
|
|
93
|
-
/** The file's own globals: inputs, imported data, and the runtime's signal functions. */
|
|
94
|
-
const globalsOf = (parsed) => [...RUNTIME, ...parsed.inputs.map((i) => i.name), ...parsed.dataImports.flatMap((d) => importNames(d.clause))];
|
|
103
|
+
/** The file's own globals: inputs (and props()'s object), imported data, and the runtime's signal functions. */
|
|
104
|
+
const globalsOf = (parsed) => [...RUNTIME, ...parsed.inputs.map((i) => i.name), ...parsed.contexts.map((c) => c.name), ...(parsed.props ? [parsed.props.name] : []), ...(parsed.events.length ? ['emit'] : []), ...parsed.dataImports.flatMap((d) => importNames(d.clause))];
|
|
95
105
|
/**
|
|
96
106
|
* typescript-eslint's parse of the script followed by declarations for what it uses without importing, with the types
|
|
97
107
|
* of a program that has them; the declarations are then cut from the tree, so ESLint sees the file as it is.
|
|
@@ -133,14 +143,17 @@ const usesVars = {
|
|
|
133
143
|
const { sourceCode } = context;
|
|
134
144
|
return {
|
|
135
145
|
Program(node) {
|
|
136
|
-
let
|
|
146
|
+
let parsed;
|
|
137
147
|
try {
|
|
138
|
-
|
|
148
|
+
parsed = parse(sourceCode.text, context.filename);
|
|
139
149
|
}
|
|
140
150
|
catch {
|
|
141
151
|
return;
|
|
142
152
|
}
|
|
143
|
-
|
|
153
|
+
// the template's expressions, and the names the props()/model()/events()/context() arguments use (spaces in
|
|
154
|
+
// what ESLint parses, but context(themeKey) uses themeKey; a type member named like a variable doesn't)
|
|
155
|
+
const factories = [parsed.script, parsed.serverScript].flatMap((s) => s?.factoryRefs ?? []);
|
|
156
|
+
const corpus = [...expressions(parsed.nodes), ...factories].join('\n');
|
|
144
157
|
const scope = sourceCode.getScope(node);
|
|
145
158
|
// The module scope's names (a script is a module), and the global scope's for scripts parsed as scripts.
|
|
146
159
|
for (const variable of [...scope.variables, ...(scope.childScopes[0]?.variables ?? [])]) {
|
|
@@ -193,7 +206,7 @@ const processor = {
|
|
|
193
206
|
postprocess(messages, filename) {
|
|
194
207
|
const lines = (texts.get(filename) ?? '').split('\n');
|
|
195
208
|
texts.delete(filename);
|
|
196
|
-
return messages.flat().filter((m) => m.ruleId !== 'prefer-const' || !/^[\w$]+\s*=\s*(state|shared)\s*\(/.test(lines[m.line - 1]?.slice(m.column - 1) ?? ''));
|
|
209
|
+
return messages.flat().filter((m) => m.ruleId !== 'prefer-const' || !/^[\w$]+\s*=\s*(state|shared)\s*(<.*>)?\s*\(/.test(lines[m.line - 1]?.slice(m.column - 1) ?? '')); // state<T>(…) too
|
|
197
210
|
},
|
|
198
211
|
};
|
|
199
212
|
/** The plugin: its parser, the .tscl processor, its rules, and `configs.recommended`. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clarusjs/eslint-plugin",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Lint clarusjs .tscl components with ESLint: their <script> blocks with your rules, and the template rules of clarusjs check",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -28,17 +28,17 @@
|
|
|
28
28
|
"README.md"
|
|
29
29
|
],
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"clarusjs": ">=0.
|
|
31
|
+
"clarusjs": ">=0.20.0",
|
|
32
32
|
"eslint": "^9.0.0 || ^10.0.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@types/node": "^26.6.
|
|
35
|
+
"@types/node": "^26.6.11",
|
|
36
36
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
37
|
-
"clarusjs": "0.
|
|
38
|
-
"eslint": "10.
|
|
37
|
+
"clarusjs": "0.20.0",
|
|
38
|
+
"eslint": "10.16.0",
|
|
39
39
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
40
|
-
"typescript-eslint": "8.
|
|
41
|
-
"vitest": "^5.1.
|
|
40
|
+
"typescript-eslint": "8.74.0",
|
|
41
|
+
"vitest": "^5.1.2"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|