@lumiose/eslint-plugin 0.0.0-stage → 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/dist/index.d.ts +86 -0
- package/dist/index.js +117 -0
- package/package.json +27 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Javi Aguilar
|
|
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/dist/index.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type Diagnostic } from "@lumiose/compiler";
|
|
2
|
+
/** The parts of ESLint's rule context the rules use (oxlint implements the same API). */
|
|
3
|
+
interface RuleContext {
|
|
4
|
+
filename: string;
|
|
5
|
+
physicalFilename?: string;
|
|
6
|
+
sourceCode: {
|
|
7
|
+
text: string;
|
|
8
|
+
};
|
|
9
|
+
report(descriptor: {
|
|
10
|
+
loc: {
|
|
11
|
+
start: Position;
|
|
12
|
+
end: Position;
|
|
13
|
+
};
|
|
14
|
+
message: string;
|
|
15
|
+
fix?: (fixer: Fixer) => unknown;
|
|
16
|
+
}): void;
|
|
17
|
+
}
|
|
18
|
+
interface Position {
|
|
19
|
+
/** 1-based. */
|
|
20
|
+
line: number;
|
|
21
|
+
/** 0-based. */
|
|
22
|
+
column: number;
|
|
23
|
+
}
|
|
24
|
+
interface Fixer {
|
|
25
|
+
replaceTextRange(range: [number, number], text: string): unknown;
|
|
26
|
+
}
|
|
27
|
+
interface Message {
|
|
28
|
+
ruleId: string | null;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}
|
|
31
|
+
/** The compiler's diagnostics for a `.stsx` or `.tsx` file (none for other files). */
|
|
32
|
+
export declare function lumioseDiagnostics(text: string, filename: string): Diagnostic[];
|
|
33
|
+
declare const plugin: {
|
|
34
|
+
meta: {
|
|
35
|
+
name: string;
|
|
36
|
+
version: string;
|
|
37
|
+
};
|
|
38
|
+
rules: {
|
|
39
|
+
/** The compiler's errors (reactivity, styles, islands, …). */
|
|
40
|
+
compiler: {
|
|
41
|
+
meta: {
|
|
42
|
+
type: "problem";
|
|
43
|
+
docs: {
|
|
44
|
+
description: string;
|
|
45
|
+
url: string;
|
|
46
|
+
};
|
|
47
|
+
fixable: "code";
|
|
48
|
+
schema: never[];
|
|
49
|
+
};
|
|
50
|
+
create(context: RuleContext): {
|
|
51
|
+
Program(): void;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/** The compiler's warnings and hints. */
|
|
55
|
+
"compiler-warnings": {
|
|
56
|
+
meta: {
|
|
57
|
+
type: "problem";
|
|
58
|
+
docs: {
|
|
59
|
+
description: string;
|
|
60
|
+
url: string;
|
|
61
|
+
};
|
|
62
|
+
fixable: "code";
|
|
63
|
+
schema: never[];
|
|
64
|
+
};
|
|
65
|
+
create(context: RuleContext): {
|
|
66
|
+
Program(): void;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
processors: {
|
|
71
|
+
stsx: {
|
|
72
|
+
meta: {
|
|
73
|
+
name: string;
|
|
74
|
+
version: string;
|
|
75
|
+
};
|
|
76
|
+
supportsAutofix: boolean;
|
|
77
|
+
preprocess(text: string, filename: string): {
|
|
78
|
+
text: string;
|
|
79
|
+
filename: string;
|
|
80
|
+
}[];
|
|
81
|
+
postprocess(messages: Message[][], filename: string): Message[];
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
configs: Record<string, unknown>;
|
|
85
|
+
};
|
|
86
|
+
export default plugin;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// `@lumiose/eslint-plugin` (TASK-41): the Lumiose compiler's diagnostics as lint rules. The compiler is
|
|
2
|
+
// the single source of truth: these rules only report what `compile()` reports (`LUMxxxx`, with
|
|
3
|
+
// help and fixes), so oxlint, ESLint, `lumiose check` and the editor agree.
|
|
4
|
+
//
|
|
5
|
+
// - oxlint (JS plugins): `"jsPlugins": ["@lumiose/eslint-plugin"]` lints `.tsx` files. oxlint cannot
|
|
6
|
+
// parse `.stsx` (no custom file formats yet): `lumiose lint` covers those.
|
|
7
|
+
// - ESLint 9 (flat config): `configs.recommended` also lints `.stsx` files through the `stsx`
|
|
8
|
+
// processor, which hands ESLint the scanner's masked TSX (offset-identical, so positions and
|
|
9
|
+
// fixes apply to the source). Parse `.tsx` with a TypeScript parser (typescript-eslint).
|
|
10
|
+
//
|
|
11
|
+
// Not covered: project-wide checks (LUM4003, LUM3012) and `$` constants imported from other
|
|
12
|
+
// modules, whose style diagnostics need the module graph: `lumiose check` reports those.
|
|
13
|
+
import { compile, scan } from "@lumiose/compiler";
|
|
14
|
+
/** TypeScript (and ESLint's parser) report syntax errors themselves. */
|
|
15
|
+
const REPORTED_BY_PARSERS = new Set(["LUM1001"]);
|
|
16
|
+
/** The original text of `.stsx` files being linted through the processor, by physical path. */
|
|
17
|
+
const stsxSources = new Map();
|
|
18
|
+
/** The compiler's diagnostics for a `.stsx` or `.tsx` file (none for other files). */
|
|
19
|
+
export function lumioseDiagnostics(text, filename) {
|
|
20
|
+
if (!/\.(?:stsx|tsx)$/.test(filename))
|
|
21
|
+
return [];
|
|
22
|
+
let diagnostics;
|
|
23
|
+
try {
|
|
24
|
+
diagnostics = compile(text, filename, { target: "client", sourceMap: false }).diagnostics;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
return diagnostics.filter((diagnostic) => !REPORTED_BY_PARSERS.has(diagnostic.code));
|
|
30
|
+
}
|
|
31
|
+
/** 1-based line and 0-based column (UTF-16) of `offset` in `text`. */
|
|
32
|
+
function position(text, offset) {
|
|
33
|
+
let line = 1;
|
|
34
|
+
let start = 0;
|
|
35
|
+
for (let at = text.indexOf("\n"); at !== -1 && at < offset; at = text.indexOf("\n", at + 1)) {
|
|
36
|
+
line++;
|
|
37
|
+
start = at + 1;
|
|
38
|
+
}
|
|
39
|
+
return { line, column: offset - start };
|
|
40
|
+
}
|
|
41
|
+
/** `LUM2001: message`, then the help and the docs topic on a line of their own. */
|
|
42
|
+
function message(diagnostic) {
|
|
43
|
+
const help = diagnostic.help === undefined ? "" : `${diagnostic.help} `;
|
|
44
|
+
return `${diagnostic.code}: ${diagnostic.message}\n${help}(lumiose docs ${diagnostic.docs})`;
|
|
45
|
+
}
|
|
46
|
+
function compilerRule(severities, description) {
|
|
47
|
+
return {
|
|
48
|
+
meta: {
|
|
49
|
+
type: "problem",
|
|
50
|
+
docs: {
|
|
51
|
+
description,
|
|
52
|
+
url: "https://github.com/itsjavi/lumiose/tree/main/packages/lumiose/docs/errors",
|
|
53
|
+
},
|
|
54
|
+
fixable: "code",
|
|
55
|
+
schema: [],
|
|
56
|
+
},
|
|
57
|
+
create(context) {
|
|
58
|
+
const file = context.physicalFilename ?? context.filename;
|
|
59
|
+
const text = stsxSources.get(file) ?? context.sourceCode.text;
|
|
60
|
+
return {
|
|
61
|
+
Program() {
|
|
62
|
+
for (const diagnostic of lumioseDiagnostics(text, file)) {
|
|
63
|
+
if (!severities.has(diagnostic.severity))
|
|
64
|
+
continue;
|
|
65
|
+
const { fix } = diagnostic;
|
|
66
|
+
context.report({
|
|
67
|
+
loc: {
|
|
68
|
+
start: position(text, diagnostic.span.start),
|
|
69
|
+
end: position(text, Math.max(diagnostic.span.start, diagnostic.span.end)),
|
|
70
|
+
},
|
|
71
|
+
message: message(diagnostic),
|
|
72
|
+
...(fix === undefined
|
|
73
|
+
? {}
|
|
74
|
+
: {
|
|
75
|
+
fix: (fixer) => fix.edits.map((edit) => fixer.replaceTextRange([edit.span.start, edit.span.end], edit.text)),
|
|
76
|
+
}),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** ESLint processor for `.stsx`: lint the masked TSX, which keeps every offset of the source. */
|
|
85
|
+
const stsxProcessor = {
|
|
86
|
+
meta: { name: "lumiose/stsx", version: "0.0.0" },
|
|
87
|
+
supportsAutofix: true,
|
|
88
|
+
preprocess(text, filename) {
|
|
89
|
+
stsxSources.set(filename, text);
|
|
90
|
+
return [{ text: scan(text, filename).masked, filename: "component.tsx" }];
|
|
91
|
+
},
|
|
92
|
+
postprocess(messages, filename) {
|
|
93
|
+
stsxSources.delete(filename);
|
|
94
|
+
return messages.flat();
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
const plugin = {
|
|
98
|
+
meta: { name: "lumiose", version: "0.0.0" },
|
|
99
|
+
rules: {
|
|
100
|
+
/** The compiler's errors (reactivity, styles, islands, …). */
|
|
101
|
+
compiler: compilerRule(new Set(["error"]), "Lumiose compiler errors (LUMxxxx)"),
|
|
102
|
+
/** The compiler's warnings and hints. */
|
|
103
|
+
"compiler-warnings": compilerRule(new Set(["warning", "hint"]), "Lumiose compiler warnings and hints (LUMxxxx)"),
|
|
104
|
+
},
|
|
105
|
+
processors: { stsx: stsxProcessor },
|
|
106
|
+
configs: {},
|
|
107
|
+
};
|
|
108
|
+
/** ESLint 9 flat config: `.stsx` through the processor, compiler rules on `.tsx` and `.stsx`. */
|
|
109
|
+
plugin.configs["recommended"] = [
|
|
110
|
+
{ files: ["**/*.stsx"], plugins: { lumiose: plugin }, processor: "lumiose/stsx" },
|
|
111
|
+
{
|
|
112
|
+
files: ["**/*.tsx", "**/*.stsx/*.tsx"],
|
|
113
|
+
plugins: { lumiose: plugin },
|
|
114
|
+
rules: { "lumiose/compiler": "error", "lumiose/compiler-warnings": "warn" },
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
export default plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumiose/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Lumiose's compiler diagnostics (LUMxxxx) as lint rules for oxlint (JS plugins) and ESLint, plus a .stsx processor for ESLint.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/itsjavi/lumiose.git",
|
|
9
|
+
"directory": "packages/eslint-plugin"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@lumiose/compiler": "0.1.0"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"build": "node ../../scripts/build-package.ts"
|
|
29
|
+
}
|
|
6
30
|
}
|
package/README.md
DELETED