eslint-plugin-templ 0.0.1 → 0.0.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/README.md +2 -2
- package/dist/configs/recommended.d.ts +57 -0
- package/dist/configs/recommended.d.ts.map +1 -0
- package/dist/configs/recommended.js +49 -0
- package/dist/configs/recommended.js.map +1 -0
- package/dist/html-source-code.d.ts +65 -39
- package/dist/html-source-code.d.ts.map +1 -1
- package/dist/html-source-code.js +112 -60
- package/dist/html-source-code.js.map +1 -1
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/parse-for-eslint.d.ts.map +1 -1
- package/dist/parse-for-eslint.js +163 -25
- package/dist/parse-for-eslint.js.map +1 -1
- package/dist/run-templ-ast-to-json-binary.js +5 -3
- package/dist/run-templ-ast-to-json-binary.js.map +1 -1
- package/dist/templ-ast-to-eslint-ast.d.ts +16 -1
- package/dist/templ-ast-to-eslint-ast.d.ts.map +1 -1
- package/dist/templ-ast-to-eslint-ast.js +475 -117
- package/dist/templ-ast-to-eslint-ast.js.map +1 -1
- package/dist/templ-ast.d.ts +1564 -384
- package/dist/templ-ast.d.ts.map +1 -1
- package/dist/templ-ast.js +146 -48
- package/dist/templ-ast.js.map +1 -1
- package/dist/templ-language.d.ts +16 -3
- package/dist/templ-language.d.ts.map +1 -1
- package/dist/templ-language.js +9 -3
- package/dist/templ-language.js.map +1 -1
- package/package.json +27 -23
package/dist/parse-for-eslint.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { parse as parseCSS, toPlainObject } from "css-tree";
|
|
2
|
+
import { NodeTypes } from "es-html-parser";
|
|
1
3
|
import { runTemplAstToJsonBinary } from "./run-templ-ast-to-json-binary.js";
|
|
2
|
-
import { convertToESLintAST } from "./templ-ast-to-eslint-ast.js";
|
|
4
|
+
import { convertToESLintAST, TemplASTConversionError, } from "./templ-ast-to-eslint-ast.js";
|
|
3
5
|
import { validateTemplAST } from "./templ-ast.js";
|
|
4
6
|
export function parseForESLint(code) {
|
|
5
7
|
let stdout;
|
|
@@ -18,37 +20,50 @@ export function parseForESLint(code) {
|
|
|
18
20
|
parsedJSON = JSON.parse(stdout);
|
|
19
21
|
}
|
|
20
22
|
catch (error) {
|
|
21
|
-
|
|
22
|
-
return createFatalError(`Failed to parse JSON output from templ-ast-to-json: ${message}`);
|
|
23
|
+
return createFatalError(`Failed to parse JSON output from templ-ast-to-json: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
23
24
|
}
|
|
24
25
|
try {
|
|
25
26
|
validateTemplAST(parsedJSON);
|
|
27
|
+
const documentNode = convertToESLintAST(parsedJSON);
|
|
28
|
+
// Following html-eslint's approach: the Program body contains the DocumentNode
|
|
29
|
+
// instead of ESLint Statement nodes. This is the standard pattern for HTML parsers.
|
|
30
|
+
// See: https://github.com/yeonjuan/html-eslint/blob/main/packages/parser/lib/parser.js
|
|
31
|
+
const ast = {
|
|
32
|
+
type: "Program",
|
|
33
|
+
sourceType: "module",
|
|
34
|
+
// @ts-expect-error - html-eslint pattern: body contains DocumentNode, not Statement[]
|
|
35
|
+
body: [documentNode],
|
|
36
|
+
loc: documentNode.loc,
|
|
37
|
+
range: documentNode.range,
|
|
38
|
+
tokens: [],
|
|
39
|
+
comments: [],
|
|
40
|
+
};
|
|
41
|
+
attachStylesheets(ast);
|
|
42
|
+
return {
|
|
43
|
+
ok: true,
|
|
44
|
+
ast,
|
|
45
|
+
comments: [],
|
|
46
|
+
};
|
|
26
47
|
}
|
|
27
48
|
catch (error) {
|
|
28
|
-
if (
|
|
29
|
-
|
|
49
|
+
if (error instanceof TemplASTConversionError) {
|
|
50
|
+
const serializedNode = JSON.stringify(error.node, null, 2);
|
|
51
|
+
const messageWithNode = serializedNode === undefined
|
|
52
|
+
? error.message
|
|
53
|
+
: `${error.message}\nProblematic node:\n${serializedNode}`;
|
|
54
|
+
return {
|
|
55
|
+
ok: false,
|
|
56
|
+
errors: [
|
|
57
|
+
{
|
|
58
|
+
message: messageWithNode,
|
|
59
|
+
line: error.line,
|
|
60
|
+
column: error.column,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
};
|
|
30
64
|
}
|
|
31
|
-
return createFatalError(error.message);
|
|
65
|
+
return createFatalError(error instanceof Error ? error.message : "Unknown error");
|
|
32
66
|
}
|
|
33
|
-
const documentNode = convertToESLintAST(parsedJSON);
|
|
34
|
-
// Following html-eslint's approach: the Program body contains the DocumentNode
|
|
35
|
-
// instead of ESLint Statement nodes. This is the standard pattern for HTML parsers.
|
|
36
|
-
// See: https://github.com/yeonjuan/html-eslint/blob/main/packages/parser/lib/parser.js
|
|
37
|
-
const ast = {
|
|
38
|
-
type: "Program",
|
|
39
|
-
sourceType: "module",
|
|
40
|
-
// @ts-expect-error - html-eslint pattern: body contains DocumentNode, not Statement[]
|
|
41
|
-
body: [documentNode],
|
|
42
|
-
loc: documentNode.loc,
|
|
43
|
-
range: documentNode.range,
|
|
44
|
-
tokens: [],
|
|
45
|
-
comments: [],
|
|
46
|
-
};
|
|
47
|
-
return {
|
|
48
|
-
ok: true,
|
|
49
|
-
ast,
|
|
50
|
-
comments: [],
|
|
51
|
-
};
|
|
52
67
|
}
|
|
53
68
|
/**
|
|
54
69
|
* Creates a fatal error result for errors that prevent parsing
|
|
@@ -67,4 +82,127 @@ function createFatalError(message) {
|
|
|
67
82
|
],
|
|
68
83
|
};
|
|
69
84
|
}
|
|
85
|
+
function attachStylesheets(ast) {
|
|
86
|
+
const visit = (node) => {
|
|
87
|
+
if (!node || typeof node !== "object" || !("type" in node)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (node.type === NodeTypes.StyleTag) {
|
|
91
|
+
const styleNode = node;
|
|
92
|
+
if (styleNode.value?.type === NodeTypes.StyleTagContent) {
|
|
93
|
+
const cssNode = toPlainObject(parseCSS(styleNode.value.value, {
|
|
94
|
+
context: "stylesheet",
|
|
95
|
+
offset: styleNode.value.range[0],
|
|
96
|
+
positions: true,
|
|
97
|
+
line: styleNode.value.loc.start.line,
|
|
98
|
+
// css-tree uses 1-based columns.
|
|
99
|
+
column: styleNode.value.loc.start.column + 1,
|
|
100
|
+
}));
|
|
101
|
+
assertIsCssTraversalNode(cssNode);
|
|
102
|
+
traverseCss(cssNode, (cssChild) => {
|
|
103
|
+
cssChild.type = `Css${cssChild.type}`;
|
|
104
|
+
if (cssChild.loc) {
|
|
105
|
+
cssChild.range = [
|
|
106
|
+
cssChild.loc.start.offset,
|
|
107
|
+
cssChild.loc.end.offset,
|
|
108
|
+
];
|
|
109
|
+
cssChild.loc.start.column -= 1;
|
|
110
|
+
cssChild.loc.end.column -= 1;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
styleNode.value.stylesheet = cssNode;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
for (const value of Object.values(node)) {
|
|
117
|
+
if (Array.isArray(value)) {
|
|
118
|
+
for (const child of value) {
|
|
119
|
+
visit(child);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
visit(value);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
visit(ast);
|
|
128
|
+
}
|
|
129
|
+
function assertIsCssTraversalNode(value) {
|
|
130
|
+
if (!value || typeof value !== "object") {
|
|
131
|
+
throw new TypeError("Expected css-tree to produce an object node");
|
|
132
|
+
}
|
|
133
|
+
if (!("type" in value) || typeof value.type !== "string") {
|
|
134
|
+
throw new TypeError("Expected css-tree node to have a string type");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function traverseCss(node, visitor) {
|
|
138
|
+
if (!node) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const cssVisitorKeys = {
|
|
142
|
+
CssAnPlusB: [],
|
|
143
|
+
CssAtrule: ["prelude", "block"],
|
|
144
|
+
CssAtrulePrelude: ["children"],
|
|
145
|
+
CssAttributeSelector: ["name", "value"],
|
|
146
|
+
CssBlock: ["children"],
|
|
147
|
+
CssBrackets: ["children"],
|
|
148
|
+
CssCDC: [],
|
|
149
|
+
CssCDO: [],
|
|
150
|
+
CssClassSelector: [],
|
|
151
|
+
CssCombinator: [],
|
|
152
|
+
CssCondition: ["children"],
|
|
153
|
+
CssDeclaration: ["value"],
|
|
154
|
+
CssDeclarationList: ["children"],
|
|
155
|
+
CssDimension: [],
|
|
156
|
+
CssFeature: ["value"],
|
|
157
|
+
CssFeatureFunction: ["value"],
|
|
158
|
+
CssFeatureRange: ["left", "middle", "right"],
|
|
159
|
+
CssFunction: ["children"],
|
|
160
|
+
CssGeneralEnclosed: ["children"],
|
|
161
|
+
CssHash: [],
|
|
162
|
+
CssIdSelector: [],
|
|
163
|
+
CssIdentifier: [],
|
|
164
|
+
CssLayer: [],
|
|
165
|
+
CssLayerList: ["children"],
|
|
166
|
+
CssMediaQuery: ["condition"],
|
|
167
|
+
CssMediaQueryList: ["children"],
|
|
168
|
+
CssNestingSelector: [],
|
|
169
|
+
CssNth: ["nth", "selector"],
|
|
170
|
+
CssNumber: [],
|
|
171
|
+
CssOperator: [],
|
|
172
|
+
CssParentheses: ["children"],
|
|
173
|
+
CssPercentage: [],
|
|
174
|
+
CssPseudoClassSelector: ["children"],
|
|
175
|
+
CssPseudoElementSelector: ["children"],
|
|
176
|
+
CssRatio: ["left", "right"],
|
|
177
|
+
CssRaw: [],
|
|
178
|
+
CssRule: ["prelude", "block"],
|
|
179
|
+
CssScope: ["root", "limit"],
|
|
180
|
+
CssSelector: ["children"],
|
|
181
|
+
CssSelectorList: ["children"],
|
|
182
|
+
CssString: [],
|
|
183
|
+
CssStyleSheet: ["children"],
|
|
184
|
+
CssSupportsDeclaration: ["declaration"],
|
|
185
|
+
CssTypeSelector: [],
|
|
186
|
+
CssUnicodeRange: [],
|
|
187
|
+
CssUrl: [],
|
|
188
|
+
CssValue: ["children"],
|
|
189
|
+
CssWhiteSpace: [],
|
|
190
|
+
};
|
|
191
|
+
visitor(node);
|
|
192
|
+
const keys = cssVisitorKeys[node.type];
|
|
193
|
+
if (!keys) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
for (const key of keys) {
|
|
197
|
+
const value = node[key];
|
|
198
|
+
if (Array.isArray(value)) {
|
|
199
|
+
for (const child of value) {
|
|
200
|
+
traverseCss(child, visitor);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
traverseCss(value, visitor);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
70
208
|
//# sourceMappingURL=parse-for-eslint.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-for-eslint.js","sourceRoot":"","sources":["../src/parse-for-eslint.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,
|
|
1
|
+
{"version":3,"file":"parse-for-eslint.js","sourceRoot":"","sources":["../src/parse-for-eslint.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EACL,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAWlD,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,IAAI,MAAc,CAAC;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;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AC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -8,16 +8,18 @@ export function runTemplAstToJsonBinary(code) {
|
|
|
8
8
|
encoding: "utf8",
|
|
9
9
|
maxBuffer: 10 * 1024 * 1024, // 10MB
|
|
10
10
|
timeout: 2000, // 2 seconds
|
|
11
|
+
// Suppress stderr output in console
|
|
12
|
+
stdio: "pipe",
|
|
11
13
|
});
|
|
12
14
|
}
|
|
13
15
|
catch (error) {
|
|
14
16
|
if (error instanceof Error) {
|
|
15
17
|
const message = "code" in error && error.code === "ENOENT"
|
|
16
18
|
? `templ-ast-to-json binary not found at ${binaryPath}. Please ensure the binary is built.`
|
|
17
|
-
:
|
|
19
|
+
: "stderr" in error && typeof error.stderr === "string"
|
|
18
20
|
? error.stderr.trim()
|
|
19
|
-
: error.message
|
|
20
|
-
throw new Error(message);
|
|
21
|
+
: error.message;
|
|
22
|
+
throw new Error(message, { cause: error });
|
|
21
23
|
}
|
|
22
24
|
throw error;
|
|
23
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-templ-ast-to-json-binary.js","sourceRoot":"","sources":["../src/run-templ-ast-to-json-binary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAClD,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IAEnC,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,UAAU,EAAE,EAAE,EAAE;YAClC,KAAK,EAAE,IAAI;YACX,QAAQ,EAAE,MAAM;YAChB,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,OAAO;YACpC,OAAO,EAAE,IAAI,EAAE,YAAY;
|
|
1
|
+
{"version":3,"file":"run-templ-ast-to-json-binary.js","sourceRoot":"","sources":["../src/run-templ-ast-to-json-binary.ts"],"names":[],"mappings":"AAAA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AI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
* Conversion utilities for transforming templ AST to ESLint-compatible HTML AST
|
|
3
3
|
*/
|
|
4
4
|
import type { DocumentNode } from "es-html-parser";
|
|
5
|
-
import type { TemplAST } from "./templ-ast.ts";
|
|
5
|
+
import type { TemplAST, TemplAttribute, TemplChild } from "./templ-ast.ts";
|
|
6
|
+
/**
|
|
7
|
+
* Converts a templ AST to an ESLint-compatible HTML AST (DocumentNode).
|
|
8
|
+
*
|
|
9
|
+
* This function is a pure converter — it consumes only the templ AST and does
|
|
10
|
+
* not accept or use source text. All information needed for the conversion must
|
|
11
|
+
* be present in the AST. If something is missing, the fix belongs in the templ
|
|
12
|
+
* parser (github.com/AdamVig/templ), not here.
|
|
13
|
+
*/
|
|
6
14
|
export declare function convertToESLintAST(templAST: TemplAST): DocumentNode;
|
|
15
|
+
export declare class TemplASTConversionError extends SyntaxError {
|
|
16
|
+
name: string;
|
|
17
|
+
line: number;
|
|
18
|
+
column: number;
|
|
19
|
+
node: TemplChild | TemplAttribute;
|
|
20
|
+
constructor(message: string, node: TemplChild | TemplAttribute, options?: ErrorOptions);
|
|
21
|
+
}
|
|
7
22
|
//# sourceMappingURL=templ-ast-to-eslint-ast.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templ-ast-to-eslint-ast.d.ts","sourceRoot":"","sources":["../src/templ-ast-to-eslint-ast.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"templ-ast-to-eslint-ast.d.ts","sourceRoot":"","sources":["../src/templ-ast-to-eslint-ast.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAUV,YAAY,EAab,MAAM,gBAAgB,CAAC;AAGxB,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAEd,UAAU,EASX,MAAM,gBAAgB,CAAC;AAExB;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,GAAG,YAAY,CAoDnE;AAwmBD,qBAAa,uBAAwB,SAAQ,WAAW;IAC7C,IAAI,SAA6B;IAE1C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,GAAG,cAAc,CAAC;gBAGhC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,UAAU,GAAG,cAAc,EACjC,OAAO,CAAC,EAAE,YAAY;CAezB"}
|