astro-eslint-parser 0.0.3 → 0.0.4
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 +10 -6
- package/lib/ast.d.ts +6 -1
- package/lib/parser/process-template.js +4 -2
- package/lib/visitor-keys.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,6 +15,10 @@ You can check it on [Online DEMO](https://ota-meshi.github.io/astro-eslint-parse
|
|
|
15
15
|
|
|
16
16
|
This parser is in the ***experimental stages*** of development.
|
|
17
17
|
|
|
18
|
+
Currently this parser relies heavily on the internal API of [@astrojs/compiler]. It may stop working in a future update of [@astrojs/compiler].
|
|
19
|
+
|
|
20
|
+
[@astrojs/compiler]: https://github.com/withastro/compiler
|
|
21
|
+
|
|
18
22
|
<!--
|
|
19
23
|
### ESLint Plugins Using astro-eslint-parser
|
|
20
24
|
|
|
@@ -75,7 +79,7 @@ For example:
|
|
|
75
79
|
|
|
76
80
|
### parserOptions.parser
|
|
77
81
|
|
|
78
|
-
You can use `parserOptions.parser` property to specify a custom parser to parse
|
|
82
|
+
You can use `parserOptions.parser` property to specify a custom parser to parse scripts.
|
|
79
83
|
Other properties than parser would be given to the specified parser.
|
|
80
84
|
For example:
|
|
81
85
|
|
|
@@ -88,7 +92,7 @@ For example:
|
|
|
88
92
|
}
|
|
89
93
|
```
|
|
90
94
|
|
|
91
|
-
For example, if you are using the `"@typescript-eslint/parser"`, and if you want to use TypeScript in
|
|
95
|
+
For example, if you are using the `"@typescript-eslint/parser"`, and if you want to use TypeScript in `.astro`, you need to add more `parserOptions` configuration.
|
|
92
96
|
|
|
93
97
|
```js
|
|
94
98
|
module.exports = {
|
|
@@ -97,13 +101,13 @@ module.exports = {
|
|
|
97
101
|
parserOptions: {
|
|
98
102
|
// ...
|
|
99
103
|
project: "path/to/your/tsconfig.json",
|
|
100
|
-
extraFileExtensions: [".astro"], // This is a required setting in `@typescript-eslint/parser`
|
|
104
|
+
extraFileExtensions: [".astro"], // This is a required setting in `@typescript-eslint/parser` v5.
|
|
101
105
|
},
|
|
102
106
|
overrides: [
|
|
103
107
|
{
|
|
104
108
|
files: ["*.astro"],
|
|
105
109
|
parser: "astro-eslint-parser",
|
|
106
|
-
// Parse the
|
|
110
|
+
// Parse the script in `.astro` as TypeScript by adding the following configuration.
|
|
107
111
|
parserOptions: {
|
|
108
112
|
parser: "@typescript-eslint/parser",
|
|
109
113
|
},
|
|
@@ -136,8 +140,7 @@ Example **.vscode/settings.json**:
|
|
|
136
140
|
|
|
137
141
|
## Compatibility With Existing ESLint Rules
|
|
138
142
|
|
|
139
|
-
Most of the rules in the ESLint core work for the script part, but some rules are incompatible.
|
|
140
|
-
For example, the [semi] rule doesn't work.
|
|
143
|
+
Most of the rules in the ESLint core work for the script part, but some rules are incompatible.
|
|
141
144
|
This parser will generate a JSX compatible AST for most of the HTML part of the Astro component. Therefore, some rules of [eslint-plugin-react] may work.
|
|
142
145
|
For example, the [react/jsx-no-target-blank] rule works fine.
|
|
143
146
|
|
|
@@ -148,6 +151,7 @@ For example, the [react/jsx-no-target-blank] rule works fine.
|
|
|
148
151
|
## Usage for Custom Rules / Plugins
|
|
149
152
|
|
|
150
153
|
- TBA
|
|
154
|
+
- You can check it on the [Online DEMO](https://ota-meshi.github.io/astro-eslint-parser/). However, AST is subject to major changes in the future.
|
|
151
155
|
|
|
152
156
|
<!-- - [AST.md](./docs/AST.md) is AST specification. You can check it on the [Online DEMO](https://ota-meshi.github.io/astro-eslint-parser/). -->
|
|
153
157
|
<!-- - I have already [implemented some rules] in the [`@ota-meshi/eslint-plugin-astro`]. The source code for these rules will be helpful to you. -->
|
package/lib/ast.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TSESTree } from "@typescript-eslint/types";
|
|
2
|
-
export declare type AstroNode = AstroProgram | AstroRootFragment | AstroHTMLComment | AstroDoctype | AstroShorthandAttribute | AstroTemplateLiteralAttribute;
|
|
2
|
+
export declare type AstroNode = AstroProgram | AstroRootFragment | AstroHTMLComment | AstroDoctype | AstroShorthandAttribute | AstroTemplateLiteralAttribute | AstroRawText;
|
|
3
3
|
/** Node of Astro program root */
|
|
4
4
|
export interface AstroProgram extends Omit<TSESTree.Program, "type" | "body"> {
|
|
5
5
|
type: "Program";
|
|
@@ -40,3 +40,8 @@ export interface AstroTemplateLiteralAttribute extends Omit<TSESTree.JSXAttribut
|
|
|
40
40
|
};
|
|
41
41
|
parent: TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
42
42
|
}
|
|
43
|
+
/** Node of Astro raw text */
|
|
44
|
+
export interface AstroRawText extends Omit<TSESTree.JSXText, "type" | "parent"> {
|
|
45
|
+
type: "AstroRawText";
|
|
46
|
+
parent: AstroRootFragment | TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
47
|
+
}
|
|
@@ -147,8 +147,10 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
147
147
|
script.addRestoreNodeProcess((scriptNode) => {
|
|
148
148
|
if (scriptNode.type === types_1.AST_NODE_TYPES.JSXElement &&
|
|
149
149
|
scriptNode.range[0] === styleNodeStart) {
|
|
150
|
-
const textNode = Object.assign({ type:
|
|
151
|
-
scriptNode.children = [
|
|
150
|
+
const textNode = Object.assign({ type: "AstroRawText", value: text.value, raw: text.value, parent: scriptNode }, ctx.getLocations(start, start + text.value.length));
|
|
151
|
+
scriptNode.children = [
|
|
152
|
+
textNode,
|
|
153
|
+
];
|
|
152
154
|
return true;
|
|
153
155
|
}
|
|
154
156
|
return false;
|
package/lib/visitor-keys.js
CHANGED