astro-eslint-parser 0.0.17 → 0.0.18
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/lib/ast/astro.d.ts +49 -0
- package/lib/{ast.js → ast/astro.js} +0 -0
- package/lib/ast/base.d.ts +6 -0
- package/lib/ast/base.js +2 -0
- package/lib/ast/index.d.ts +2 -0
- package/lib/ast/index.js +18 -0
- package/lib/ast/jsx.d.ts +91 -0
- package/lib/ast/jsx.js +2 -0
- package/package.json +9 -8
- package/lib/ast.d.ts +0 -48
package/README.md
CHANGED
|
@@ -145,7 +145,7 @@ Example **.vscode/settings.json**:
|
|
|
145
145
|
}
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
-
## :
|
|
148
|
+
## :handshake: Compatibility With Existing ESLint Rules
|
|
149
149
|
|
|
150
150
|
Most of the rules in the ESLint core work for the script part, but some rules are incompatible.
|
|
151
151
|
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.
|
|
@@ -154,7 +154,7 @@ For example, the [react/jsx-no-target-blank] rule works fine.
|
|
|
154
154
|
[eslint-plugin-react]: https://github.com/jsx-eslint/eslint-plugin-react/
|
|
155
155
|
[react/jsx-no-target-blank]: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md
|
|
156
156
|
|
|
157
|
-
## :
|
|
157
|
+
## :hammer_and_wrench: Usage for Custom Rules / Plugins
|
|
158
158
|
|
|
159
159
|
- TBA
|
|
160
160
|
- You can check the AST in the [Online DEMO](https://ota-meshi.github.io/astro-eslint-parser/). However, AST is subject to major changes in the future.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { JSXAttribute, JSXElement, JSXExpression, JSXExpressionContainer, JSXFragment, JSXText } from "./jsx";
|
|
2
|
+
import type { TSESTree as ES } from "@typescript-eslint/types";
|
|
3
|
+
import type { BaseNode } from "./base";
|
|
4
|
+
export declare type AstroNode = AstroProgram | AstroFragment | AstroHTMLComment | AstroDoctype | AstroShorthandAttribute | AstroTemplateLiteralAttribute | AstroRawText;
|
|
5
|
+
export declare type AstroChild = JSXElement | JSXFragment | JSXExpression | JSXText | AstroHTMLComment;
|
|
6
|
+
export declare type AstroParentNode = JSXElement | JSXFragment | AstroFragment;
|
|
7
|
+
/** Node of Astro program root */
|
|
8
|
+
export interface AstroProgram extends Omit<ES.Program, "type" | "body"> {
|
|
9
|
+
type: "Program";
|
|
10
|
+
body: (ES.Program["body"][number] | AstroFragment)[];
|
|
11
|
+
sourceType: "script" | "module";
|
|
12
|
+
comments: ES.Comment[];
|
|
13
|
+
tokens: ES.Token[];
|
|
14
|
+
parent?: undefined;
|
|
15
|
+
}
|
|
16
|
+
/** Node of Astro fragment */
|
|
17
|
+
export interface AstroFragment extends BaseNode {
|
|
18
|
+
type: "AstroFragment";
|
|
19
|
+
children: AstroChild[];
|
|
20
|
+
parent?: AstroParentNode;
|
|
21
|
+
}
|
|
22
|
+
/** Node of Astro html comment */
|
|
23
|
+
export interface AstroHTMLComment extends BaseNode {
|
|
24
|
+
type: "AstroHTMLComment";
|
|
25
|
+
value: string;
|
|
26
|
+
parent?: AstroParentNode;
|
|
27
|
+
}
|
|
28
|
+
/** Node of Astro doctype */
|
|
29
|
+
export interface AstroDoctype extends BaseNode {
|
|
30
|
+
type: "AstroDoctype";
|
|
31
|
+
parent?: AstroFragment;
|
|
32
|
+
}
|
|
33
|
+
/** Node of Astro shorthand attribute */
|
|
34
|
+
export interface AstroShorthandAttribute extends Omit<JSXAttribute, "type"> {
|
|
35
|
+
type: "AstroShorthandAttribute";
|
|
36
|
+
value: JSXExpressionContainer;
|
|
37
|
+
}
|
|
38
|
+
/** Node of Astro template-literal attribute */
|
|
39
|
+
export interface AstroTemplateLiteralAttribute extends Omit<JSXAttribute, "type"> {
|
|
40
|
+
type: "AstroTemplateLiteralAttribute";
|
|
41
|
+
value: JSXExpressionContainer & {
|
|
42
|
+
expression: ES.TemplateLiteral;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** Node of Astro raw text */
|
|
46
|
+
export interface AstroRawText extends Omit<JSXText, "type"> {
|
|
47
|
+
type: "AstroRawText";
|
|
48
|
+
parent?: JSXElement;
|
|
49
|
+
}
|
|
File without changes
|
package/lib/ast/base.js
ADDED
package/lib/ast/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./astro"), exports);
|
|
18
|
+
__exportStar(require("./jsx"), exports);
|
package/lib/ast/jsx.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { TSESTree as ES, AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
2
|
+
import type { AstroFragment, AstroHTMLComment, AstroShorthandAttribute, AstroTemplateLiteralAttribute } from "./astro";
|
|
3
|
+
import type { BaseNode } from "./base";
|
|
4
|
+
export declare type JSXNode = JSXAttribute | JSXClosingElement | JSXClosingFragment | JSXElement | JSXEmptyExpression | JSXExpressionContainer | JSXFragment | JSXIdentifier | JSXMemberExpression | JSXNamespacedName | JSXOpeningElement | JSXOpeningFragment | JSXSpreadAttribute | JSXSpreadChild | JSXText;
|
|
5
|
+
export declare type JSXChild = JSXElement | JSXFragment | JSXExpression | JSXText | AstroHTMLComment;
|
|
6
|
+
export declare type JSXParentNode = JSXElement | JSXFragment | AstroFragment;
|
|
7
|
+
export interface JSXElement extends BaseNode {
|
|
8
|
+
type: AST_NODE_TYPES.JSXElement;
|
|
9
|
+
openingElement: JSXOpeningElement;
|
|
10
|
+
closingElement: JSXClosingElement | null;
|
|
11
|
+
children: JSXChild[];
|
|
12
|
+
parent?: JSXParentNode;
|
|
13
|
+
}
|
|
14
|
+
export interface JSXFragment extends BaseNode {
|
|
15
|
+
type: AST_NODE_TYPES.JSXFragment;
|
|
16
|
+
openingFragment: JSXOpeningFragment;
|
|
17
|
+
closingFragment: JSXClosingFragment;
|
|
18
|
+
children: JSXChild[];
|
|
19
|
+
parent?: JSXParentNode;
|
|
20
|
+
}
|
|
21
|
+
export interface JSXOpeningElement extends BaseNode {
|
|
22
|
+
type: AST_NODE_TYPES.JSXOpeningElement;
|
|
23
|
+
typeParameters?: ES.TSTypeParameterInstantiation;
|
|
24
|
+
selfClosing: boolean;
|
|
25
|
+
name: JSXTagNameExpression;
|
|
26
|
+
attributes: (JSXAttribute | JSXSpreadAttribute | AstroShorthandAttribute | AstroTemplateLiteralAttribute)[];
|
|
27
|
+
parent?: JSXElement;
|
|
28
|
+
}
|
|
29
|
+
export interface JSXClosingElement extends BaseNode {
|
|
30
|
+
type: AST_NODE_TYPES.JSXClosingElement;
|
|
31
|
+
name: JSXTagNameExpression;
|
|
32
|
+
parent?: JSXElement;
|
|
33
|
+
}
|
|
34
|
+
export interface JSXClosingFragment extends BaseNode {
|
|
35
|
+
type: AST_NODE_TYPES.JSXClosingFragment;
|
|
36
|
+
parent?: JSXFragment;
|
|
37
|
+
}
|
|
38
|
+
export interface JSXOpeningFragment extends BaseNode {
|
|
39
|
+
type: AST_NODE_TYPES.JSXOpeningFragment;
|
|
40
|
+
parent?: JSXFragment;
|
|
41
|
+
}
|
|
42
|
+
export interface JSXAttribute extends BaseNode {
|
|
43
|
+
type: AST_NODE_TYPES.JSXAttribute;
|
|
44
|
+
name: JSXIdentifier | JSXNamespacedName;
|
|
45
|
+
value: JSXExpression | ES.Literal | null;
|
|
46
|
+
parent?: JSXOpeningElement;
|
|
47
|
+
}
|
|
48
|
+
export interface JSXSpreadAttribute extends BaseNode {
|
|
49
|
+
type: AST_NODE_TYPES.JSXSpreadAttribute;
|
|
50
|
+
argument: ES.Expression;
|
|
51
|
+
parent?: JSXOpeningElement;
|
|
52
|
+
}
|
|
53
|
+
export declare type JSXTagNameExpression = JSXIdentifier | JSXMemberExpression | JSXNamespacedName;
|
|
54
|
+
export interface JSXIdentifier extends BaseNode {
|
|
55
|
+
type: AST_NODE_TYPES.JSXIdentifier;
|
|
56
|
+
name: string;
|
|
57
|
+
parent?: JSXAttribute | AstroShorthandAttribute | AstroTemplateLiteralAttribute | JSXMemberExpression | JSXNamespacedName | JSXOpeningElement | JSXClosingElement;
|
|
58
|
+
}
|
|
59
|
+
export interface JSXMemberExpression extends BaseNode {
|
|
60
|
+
type: AST_NODE_TYPES.JSXMemberExpression;
|
|
61
|
+
object: JSXTagNameExpression;
|
|
62
|
+
property: JSXIdentifier;
|
|
63
|
+
parent?: JSXMemberExpression | JSXOpeningElement | JSXClosingElement;
|
|
64
|
+
}
|
|
65
|
+
export interface JSXNamespacedName extends BaseNode {
|
|
66
|
+
type: AST_NODE_TYPES.JSXNamespacedName;
|
|
67
|
+
namespace: JSXIdentifier;
|
|
68
|
+
name: JSXIdentifier;
|
|
69
|
+
parent?: JSXAttribute | AstroShorthandAttribute | AstroTemplateLiteralAttribute | JSXMemberExpression | JSXOpeningElement | JSXClosingElement;
|
|
70
|
+
}
|
|
71
|
+
export declare type JSXExpression = JSXExpressionContainer | JSXSpreadChild;
|
|
72
|
+
export interface JSXExpressionContainer extends BaseNode {
|
|
73
|
+
type: AST_NODE_TYPES.JSXExpressionContainer;
|
|
74
|
+
expression: ES.Expression | JSXEmptyExpression;
|
|
75
|
+
parent?: JSXAttribute | AstroShorthandAttribute | AstroTemplateLiteralAttribute | JSXParentNode;
|
|
76
|
+
}
|
|
77
|
+
export interface JSXSpreadChild extends BaseNode {
|
|
78
|
+
type: AST_NODE_TYPES.JSXSpreadChild;
|
|
79
|
+
expression: ES.Expression;
|
|
80
|
+
parent?: JSXAttribute | JSXParentNode;
|
|
81
|
+
}
|
|
82
|
+
export interface JSXEmptyExpression extends BaseNode {
|
|
83
|
+
type: AST_NODE_TYPES.JSXEmptyExpression;
|
|
84
|
+
parent?: JSXExpressionContainer;
|
|
85
|
+
}
|
|
86
|
+
export interface JSXText extends BaseNode {
|
|
87
|
+
type: AST_NODE_TYPES.JSXText;
|
|
88
|
+
value: string;
|
|
89
|
+
raw: string;
|
|
90
|
+
parent?: JSXParentNode;
|
|
91
|
+
}
|
package/lib/ast/jsx.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-eslint-parser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "Astro component parser for ESLint",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"prebuild": "npm run -s clean",
|
|
14
14
|
"build": "tsc --project ./tsconfig.build.json",
|
|
15
15
|
"clean": "rimraf .nyc_output lib coverage",
|
|
16
|
-
"lint": "eslint . --ext .js,.ts,.json",
|
|
16
|
+
"lint": "eslint . --ext .js,.ts,.json,.astro,.svelte",
|
|
17
17
|
"eslint-fix": "npm run lint -- --fix",
|
|
18
18
|
"test": "mocha --require ts-node/register \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
|
|
19
19
|
"cover": "nyc --reporter=lcov npm run test",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@ota-meshi/eslint-plugin": "^0.10.0",
|
|
52
|
+
"@ota-meshi/eslint-plugin-svelte": "^0.34.0",
|
|
52
53
|
"@types/benchmark": "^2.1.1",
|
|
53
54
|
"@types/chai": "^4.3.0",
|
|
54
55
|
"@types/debug": "^4.1.7",
|
|
@@ -64,18 +65,17 @@
|
|
|
64
65
|
"benchmark": "^2.1.4",
|
|
65
66
|
"chai": "^4.3.4",
|
|
66
67
|
"code-red": "^0.2.3",
|
|
67
|
-
"eslint": "^8.
|
|
68
|
+
"eslint": "^8.15.0",
|
|
68
69
|
"eslint-config-prettier": "^8.3.0",
|
|
69
70
|
"eslint-formatter-codeframe": "^7.32.1",
|
|
70
71
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
71
|
-
"eslint-plugin-json-schema-validator": "^
|
|
72
|
+
"eslint-plugin-json-schema-validator": "^3.0.0",
|
|
72
73
|
"eslint-plugin-jsonc": "^2.0.0",
|
|
73
74
|
"eslint-plugin-node": "^11.1.0",
|
|
74
75
|
"eslint-plugin-node-dependencies": "^0.8.0",
|
|
75
76
|
"eslint-plugin-prettier": "^4.0.0",
|
|
76
77
|
"eslint-plugin-react": "^7.29.4",
|
|
77
78
|
"eslint-plugin-regexp": "^1.5.0",
|
|
78
|
-
"eslint-plugin-vue": "^8.0.3",
|
|
79
79
|
"estree-walker": "^3.0.0",
|
|
80
80
|
"locate-character": "^2.0.5",
|
|
81
81
|
"magic-string": "^0.26.0",
|
|
@@ -83,11 +83,12 @@
|
|
|
83
83
|
"mocha-chai-jest-snapshot": "^1.1.3",
|
|
84
84
|
"nyc": "^15.1.0",
|
|
85
85
|
"prettier": "^2.0.5",
|
|
86
|
-
"prettier-plugin-astro": "^0.0
|
|
86
|
+
"prettier-plugin-astro": "^0.1.0-0",
|
|
87
|
+
"prettier-plugin-svelte": "^2.7.0",
|
|
87
88
|
"semver": "^7.3.5",
|
|
88
89
|
"string-replace-loader": "^3.0.3",
|
|
90
|
+
"svelte": "^3.48.0",
|
|
89
91
|
"ts-node": "^10.4.0",
|
|
90
|
-
"typescript": "~4.6.0"
|
|
91
|
-
"vue-eslint-parser": "^9.0.0"
|
|
92
|
+
"typescript": "~4.6.0"
|
|
92
93
|
}
|
|
93
94
|
}
|
package/lib/ast.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { TSESTree } from "@typescript-eslint/types";
|
|
2
|
-
export declare type AstroNode = AstroProgram | AstroFragment | AstroHTMLComment | AstroDoctype | AstroShorthandAttribute | AstroTemplateLiteralAttribute | AstroRawText;
|
|
3
|
-
export declare type AstroChild = TSESTree.JSXFragment["children"][number] | AstroHTMLComment;
|
|
4
|
-
/** Node of Astro program root */
|
|
5
|
-
export interface AstroProgram extends Omit<TSESTree.Program, "type" | "body"> {
|
|
6
|
-
type: "Program";
|
|
7
|
-
body: (TSESTree.Program["body"][number] | AstroFragment)[];
|
|
8
|
-
sourceType: "script" | "module";
|
|
9
|
-
comments: TSESTree.Comment[];
|
|
10
|
-
tokens: TSESTree.Token[];
|
|
11
|
-
parent: undefined;
|
|
12
|
-
}
|
|
13
|
-
/** Node of Astro fragment */
|
|
14
|
-
export interface AstroFragment extends Omit<TSESTree.BaseNode, "type" | "parent"> {
|
|
15
|
-
type: "AstroFragment";
|
|
16
|
-
children: AstroChild[];
|
|
17
|
-
parent: TSESTree.JSXFragment["parent"];
|
|
18
|
-
}
|
|
19
|
-
/** Node of Astro html comment */
|
|
20
|
-
export interface AstroHTMLComment extends Omit<TSESTree.BaseNode, "type" | "parent"> {
|
|
21
|
-
type: "AstroHTMLComment";
|
|
22
|
-
value: string;
|
|
23
|
-
parent: AstroFragment | AstroFragment | TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
24
|
-
}
|
|
25
|
-
/** Node of Astro doctype */
|
|
26
|
-
export interface AstroDoctype extends Omit<TSESTree.BaseNode, "type" | "parent"> {
|
|
27
|
-
type: "AstroDoctype";
|
|
28
|
-
parent: AstroFragment | AstroFragment;
|
|
29
|
-
}
|
|
30
|
-
/** Node of Astro shorthand attribute */
|
|
31
|
-
export interface AstroShorthandAttribute extends Omit<TSESTree.JSXAttribute, "type" | "parent"> {
|
|
32
|
-
type: "AstroShorthandAttribute";
|
|
33
|
-
value: TSESTree.JSXExpressionContainer;
|
|
34
|
-
parent: TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
35
|
-
}
|
|
36
|
-
/** Node of Astro template-literal attribute */
|
|
37
|
-
export interface AstroTemplateLiteralAttribute extends Omit<TSESTree.JSXAttribute, "type" | "parent"> {
|
|
38
|
-
type: "AstroTemplateLiteralAttribute";
|
|
39
|
-
value: TSESTree.JSXExpressionContainer & {
|
|
40
|
-
expression: TSESTree.TemplateLiteral;
|
|
41
|
-
};
|
|
42
|
-
parent: TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
43
|
-
}
|
|
44
|
-
/** Node of Astro raw text */
|
|
45
|
-
export interface AstroRawText extends Omit<TSESTree.JSXText, "type" | "parent"> {
|
|
46
|
-
type: "AstroRawText";
|
|
47
|
-
parent: AstroFragment | TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
48
|
-
}
|