Skip to content

Commit 82f7bd3

Browse files
authored
Implement parser (#1)
1 parent 20b0674 commit 82f7bd3

File tree

663 files changed

+583725
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

663 files changed

+583725
-1
lines changed

.eslintignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/.nyc_output
2+
/coverage
3+
/lib
4+
/node_modules
5+
/tests/fixtures/**/*.json

.eslintrc.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"use strict"
2+
3+
// const version = require("./package.json").version
4+
5+
module.exports = {
6+
parserOptions: {
7+
sourceType: "script",
8+
ecmaVersion: 2020,
9+
},
10+
extends: [
11+
"plugin:@ota-meshi/recommended",
12+
"plugin:@ota-meshi/+node",
13+
"plugin:@ota-meshi/+typescript",
14+
"plugin:@ota-meshi/+prettier",
15+
"plugin:@ota-meshi/+json",
16+
],
17+
rules: {
18+
"require-jsdoc": "error",
19+
"no-warning-comments": "warn",
20+
"no-lonely-if": "off",
21+
},
22+
overrides: [
23+
{
24+
files: ["*.ts"],
25+
parser: "@typescript-eslint/parser",
26+
parserOptions: {
27+
sourceType: "module",
28+
project: "./tsconfig.json",
29+
},
30+
rules: {
31+
"@typescript-eslint/naming-convention": [
32+
"error",
33+
{
34+
selector: "default",
35+
format: ["camelCase"],
36+
leadingUnderscore: "allow",
37+
trailingUnderscore: "allow",
38+
},
39+
{
40+
selector: "variable",
41+
format: ["camelCase", "UPPER_CASE"],
42+
leadingUnderscore: "allow",
43+
trailingUnderscore: "allow",
44+
},
45+
{
46+
selector: "typeLike",
47+
format: ["PascalCase"],
48+
},
49+
{
50+
selector: "property",
51+
format: null,
52+
},
53+
{
54+
selector: "method",
55+
format: null,
56+
},
57+
],
58+
"no-implicit-globals": "off",
59+
"@typescript-eslint/no-non-null-assertion": "off",
60+
"@typescript-eslint/no-use-before-define": "off",
61+
"@typescript-eslint/no-explicit-any": "off",
62+
},
63+
},
64+
{
65+
files: ["scripts/**/*.ts", "tests/**/*.ts"],
66+
rules: {
67+
"require-jsdoc": "off",
68+
"no-console": "off",
69+
},
70+
},
71+
],
72+
}

.github/workflows/GHPages.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: GHPages
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
deploy-docs:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: actions/setup-node@v2
13+
- name: Install And Build
14+
run: |+
15+
npm install
16+
npm run build
17+
cd explorer
18+
npm install
19+
npm run build
20+
- name: Deploy
21+
uses: peaceiris/actions-gh-pages@v3
22+
with:
23+
github_token: ${{ secrets.GITHUB_TOKEN }}
24+
publish_dir: ./explorer/dist
25+
force_orphan: true

.github/workflows/NodeCI.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-node@v2
15+
with:
16+
node-version: 14
17+
- name: Install Packages
18+
run: npm install
19+
- name: Lint
20+
run: npm run lint
21+
test:
22+
runs-on: ubuntu-latest
23+
strategy:
24+
matrix:
25+
node-version: [12.x, 13.x, 14.x]
26+
steps:
27+
- uses: actions/checkout@v2
28+
- name: Use Node.js ${{ matrix.node-version }}
29+
uses: actions/setup-node@v2
30+
with:
31+
node-version: ${{ matrix.node-version }}
32+
- name: Install Packages
33+
run: npm install
34+
- name: Test
35+
run: npm test
36+
test-and-coverage:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v2
40+
- uses: actions/setup-node@v2
41+
- name: Install Packages
42+
run: npm install
43+
- name: Test
44+
run: npm run cover
45+
- name: Coveralls GitHub Action
46+
uses: coverallsapp/github-action@v1.1.2
47+
with:
48+
github-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/NpmPublish.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: publish
2+
on:
3+
push:
4+
tags:
5+
- "*"
6+
jobs:
7+
release:
8+
name: check version, and release
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: checkout
12+
uses: actions/checkout@v2
13+
- name: setup Node
14+
uses: actions/setup-node@v2
15+
with:
16+
registry-url: 'https://registry.npmjs.org'
17+
- name: Install Packages
18+
run: npm install
19+
- name: test and build
20+
run: |
21+
npm run build
22+
npm run test
23+
- name: check can npm-publish
24+
run: npx can-npm-publish
25+
- name: release
26+
run: npm publish
27+
env:
28+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,8 @@ dist
102102

103103
# TernJS port file
104104
.tern-port
105+
106+
# repo
107+
/lib
108+
/.nyc_output
109+
/coverage

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.vscode/settings.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"eslint.validate": [
3+
"javascript",
4+
"javascriptreact",
5+
"vue",
6+
"typescript",
7+
"json",
8+
"jsonc"
9+
],
10+
"typescript.validate.enable": true,
11+
"javascript.validate.enable": false,
12+
"typescript.tsdk": "node_modules/typescript/lib",
13+
"editor.codeActionsOnSave": {
14+
"source.fixAll.eslint": true,
15+
},
16+
"vetur.validation.template": false
17+
}

README.md

+109-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,110 @@
11
# svelte-eslint-parser
2-
Svelte parser for ESLint
2+
3+
[Svelte] parser for [ESLint]
4+
5+
***Works In Progress***
6+
***This parser is still in an EXPERIMENTAL STATE***
7+
8+
## ❓ Why?
9+
10+
[Svelte] has the official ESLint plugin [eslint-plugin-svelte3]. [eslint-plugin-svelte3] works well enough to check scripts. However, it does not handle the AST of the template, which makes it very difficult for third parties to create their own [ESLint] rules for [Svelte].
11+
12+
The `svelte-eslint-parser` aims to make it easy to create your own rules for [Svelte] by allowing the template AST to be used in the rules.
13+
14+
## 💿 Installation
15+
16+
```bash
17+
npm install --save-dev eslint svelte-eslint-parser
18+
```
19+
20+
## 📖 Usage
21+
22+
1. Write `overrides.parser` option into your `.eslintrc.*` file.
23+
2. Use glob patterns or `--ext .vue` CLI option.
24+
25+
```json
26+
{
27+
"extends": "eslint:recommended",
28+
"overrides": [
29+
{
30+
"files": ["*.svelte"],
31+
"parser": "svelte-eslint-parser"
32+
}
33+
]
34+
}
35+
```
36+
37+
```console
38+
$ eslint "src/**/*.{js,svelte}"
39+
# or
40+
$ eslint src --ext .svelte
41+
```
42+
43+
## 🔧 Options
44+
45+
`parserOptions` has the same properties as what [espree](https://github.com/eslint/espree#usage), the default parser of ESLint, is supporting.
46+
For example:
47+
48+
```json
49+
{
50+
"parser": "svelte-eslint-parser",
51+
"parserOptions": {
52+
"sourceType": "module",
53+
"ecmaVersion": 2021,
54+
"ecmaFeatures": {
55+
"globalReturn": false,
56+
"impliedStrict": false,
57+
"jsx": false
58+
}
59+
}
60+
}
61+
```
62+
63+
### parserOptions.parser
64+
65+
You can use `parserOptions.parser` property to specify a custom parser to parse `<script>` tags.
66+
Other properties than parser would be given to the specified parser.
67+
For example:
68+
69+
```json
70+
{
71+
"parser": "svelte-eslint-parser",
72+
"parserOptions": {
73+
"parser": "@typescript-eslint/parser"
74+
}
75+
}
76+
```
77+
78+
## :computer: Editor Integrations
79+
80+
### Visual Studio Code
81+
82+
Use the [dbaeumer.vscode-eslint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) extension that Microsoft provides officially.
83+
84+
You have to configure the `eslint.validate` option of the extension to check `.svelte` files, because the extension targets only `*.js` or `*.jsx` files by default.
85+
86+
Example **.vscode/settings.json**:
87+
88+
```json
89+
{
90+
"eslint.validate": [
91+
"javascript",
92+
"javascriptreact",
93+
"svelte"
94+
]
95+
}
96+
```
97+
98+
## :beers: Contributing
99+
100+
Welcome contributing!
101+
102+
Please use GitHub's Issues/PRs.
103+
104+
## :lock: License
105+
106+
See the [LICENSE](LICENSE) file for license rights and limitations (MIT).
107+
108+
[Svelte]: https://svelte.dev/
109+
[ESLint]: https://eslint.org/
110+
[eslint-plugin-svelte3]: https://github.com/sveltejs/eslint-plugin-svelte3

docs/AST.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# AST for Svelte
2+
3+
See details: [../src/ast.ts](../src/ast.ts)
4+
5+
### Program
6+
7+
```js
8+
extend interface Program {
9+
body: TODO[]
10+
}
11+
```
12+
13+
[ESLint - The AST specification]: https://eslint.org/docs/developer-guide/working-with-custom-parsers#the-ast-specification

explorer/.eslintrc.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
parserOptions: {
3+
sourceType: "module",
4+
ecmaVersion: 2020,
5+
},
6+
extends: [
7+
"plugin:@ota-meshi/+vue3",
8+
"plugin:@ota-meshi/+prettier",
9+
"plugin:@ota-meshi/+json",
10+
],
11+
rules: {
12+
"node/no-unsupported-features/es-syntax": "off",
13+
"node/no-missing-import": "off",
14+
},
15+
}

explorer/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

explorer/babel.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: ["@vue/cli-plugin-babel/preset"],
3+
}

explorer/package.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "svelte-eslint-parser-ast-explorer",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"serve": "vue-cli-service serve",
7+
"build": "vue-cli-service build"
8+
},
9+
"dependencies": {
10+
"core-js": "^3.6.5",
11+
"vue": "^3.0.0"
12+
},
13+
"devDependencies": {
14+
"@vue/cli-plugin-babel": "~4.5.0",
15+
"@vue/cli-service": "~4.5.0",
16+
"@vue/compiler-sfc": "^3.0.0"
17+
},
18+
"browserslist": [
19+
"> 1%",
20+
"last 2 versions",
21+
"not dead"
22+
]
23+
}

0 commit comments

Comments
 (0)