@clarusjs/eslint-plugin 0.2.1 → 0.2.3

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.
Files changed (2) hide show
  1. package/dist/index.js +10 -7
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ import { declarations, fromTypescriptEslint, loadTypeScript, typeProgram } from
14
14
  const fromEslint = createRequire(createRequire(import.meta.url).resolve('eslint'));
15
15
  const espree = fromEslint('espree');
16
16
  const eslintScope = fromEslint('eslint-scope');
17
- const RUNTIME = ['state', 'derived', 'shared']; // what a script uses without importing (see the compiler's script.ts)
17
+ const RUNTIME = ['state', 'derived', 'shared', 'effect']; // what a script uses without importing (see the compiler's script.ts)
18
18
  /** Every expression a template reads, as text. */
19
19
  function* expressions(nodes) {
20
20
  for (const n of nodes) {
@@ -100,8 +100,8 @@ export const parser = {
100
100
  return { ...result, scopeManager };
101
101
  },
102
102
  };
103
- /** The file's own globals: inputs, imported data, and the runtime's signal functions. */
104
- 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))];
105
105
  /**
106
106
  * typescript-eslint's parse of the script followed by declarations for what it uses without importing, with the types
107
107
  * of a program that has them; the declarations are then cut from the tree, so ESLint sees the file as it is.
@@ -143,14 +143,17 @@ const usesVars = {
143
143
  const { sourceCode } = context;
144
144
  return {
145
145
  Program(node) {
146
- let nodes;
146
+ let parsed;
147
147
  try {
148
- nodes = parse(sourceCode.text, context.filename).nodes;
148
+ parsed = parse(sourceCode.text, context.filename);
149
149
  }
150
150
  catch {
151
151
  return;
152
152
  }
153
- const corpus = [...expressions(nodes)].join('\n');
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');
154
157
  const scope = sourceCode.getScope(node);
155
158
  // The module scope's names (a script is a module), and the global scope's for scripts parsed as scripts.
156
159
  for (const variable of [...scope.variables, ...(scope.childScopes[0]?.variables ?? [])]) {
@@ -203,7 +206,7 @@ const processor = {
203
206
  postprocess(messages, filename) {
204
207
  const lines = (texts.get(filename) ?? '').split('\n');
205
208
  texts.delete(filename);
206
- 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
207
210
  },
208
211
  };
209
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.1",
3
+ "version": "0.2.3",
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.17.0",
31
+ "clarusjs": ">=0.21.0",
32
32
  "eslint": "^9.0.0 || ^10.0.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@types/node": "^26.6.6",
35
+ "@types/node": "^26.6.11",
36
36
  "@typescript/native": "npm:typescript@^7.0.2",
37
- "clarusjs": "0.17.0",
38
- "eslint": "10.15.0",
37
+ "clarusjs": "0.21.0",
38
+ "eslint": "10.16.0",
39
39
  "typescript": "npm:@typescript/typescript6@6.0.2",
40
- "typescript-eslint": "8.73.0",
41
- "vitest": "^5.1.1"
40
+ "typescript-eslint": "8.74.0",
41
+ "vitest": "^5.1.2"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"