Skip to content

Commit 8fad01e

Browse files
committed
Refactor for types
1 parent ff6e037 commit 8fad01e

File tree

9 files changed

+862
-56
lines changed

9 files changed

+862
-56
lines changed

.github/workflows/NodeCI.yml

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ jobs:
1818
run: npm install
1919
- name: Lint
2020
run: npm run lint
21+
build:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v2
25+
- uses: actions/setup-node@v2
26+
with:
27+
node-version: 14
28+
- name: Install Packages
29+
run: npm install
30+
- name: Build
31+
run: |+
32+
npm run update
33+
npm run build
2134
test:
2235
name: "Test for ESLint ${{ matrix.eslint }} on ${{ matrix.node }} OS: ${{matrix.os}}"
2336
runs-on: ${{ matrix.os }}

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"debug": "mocha --require ts-node/register/transpile-only \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
2424
"lint": "eslint .",
2525
"eslint-fix": "eslint . --fix",
26-
"update": "ts-node --transpile-only ./tools/update.ts && npm run eslint-fix && npm run test",
26+
"update": "ts-node --transpile-only ./tools/update.ts && npm run format-for-gen-file",
27+
"format-for-gen-file": "eslint src/types-for-node.ts src/utils/rules.ts src/configs --fix",
2728
"new": "ts-node --transpile-only ./tools/new-rule.ts",
2829
"docs:watch": "svelte-kit dev",
2930
"docs:build": "node --experimental-loader ./svelte-kit-import-hook.mjs node_modules/@sveltejs/kit/svelte-kit.js build",
@@ -80,6 +81,7 @@
8081
"@types/eslint": "^8.0.0",
8182
"@types/eslint-scope": "^3.7.0",
8283
"@types/eslint-visitor-keys": "^1.0.0",
84+
"@types/estree": "^0.0.50",
8385
"@types/mocha": "^9.0.0",
8486
"@types/node": "^16.0.0",
8587
"@typescript-eslint/eslint-plugin": "^5.4.0",

src/rules/indent-helpers/es.ts

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { AST } from "svelte-eslint-parser"
22
import type * as ESTree from "estree"
33
import type { TSESTree } from "@typescript-eslint/types"
4-
import type { ASTNode } from "../../types"
54
import type { IndentContext } from "./commons"
65
import { getFirstAndLastTokens } from "./commons"
76
import {
@@ -17,17 +16,9 @@ import {
1716
isOpeningParenToken,
1817
isSemicolonToken,
1918
} from "eslint-utils"
19+
import type { ESNodeListener } from "../../types-for-node"
2020

21-
type NodeWithParent =
22-
| (Exclude<ESTree.Node, ESTree.Program> & { parent: ASTNode })
23-
| AST.SvelteProgram
24-
| AST.SvelteReactiveStatement
25-
26-
type NodeListener = {
27-
[key in NodeWithParent["type"]]: (
28-
node: NodeWithParent & { type: key },
29-
) => void
30-
}
21+
type NodeListener = ESNodeListener
3122

3223
/**
3324
* Creates AST event handlers for ES nodes.

src/rules/indent-helpers/svelte.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import type { AST } from "svelte-eslint-parser"
22
import type { ASTNode } from "../../types"
3+
import type { SvelteNodeListener } from "../../types-for-node"
34
import { isNotWhitespace } from "./ast"
45
import type { IndentContext } from "./commons"
56
import { isBeginningOfElement } from "./commons"
67
import { isBeginningOfLine } from "./commons"
78
import { getFirstAndLastTokens } from "./commons"
8-
type NodeWithoutES = Exclude<
9-
AST.SvelteNode,
10-
AST.SvelteProgram | AST.SvelteReactiveStatement
11-
>
129

13-
type NodeListener = {
14-
[key in NodeWithoutES["type"]]: (node: NodeWithoutES & { type: key }) => void
15-
}
10+
type NodeListener = SvelteNodeListener
1611
const PREFORMATTED_ELEMENT_NAMES = ["pre", "textarea", "template"]
1712

1813
/**

src/rules/indent-helpers/ts.ts

+2-22
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,9 @@ import {
1313
import type { AnyToken, IndentContext } from "./commons"
1414
import { isBeginningOfLine } from "./commons"
1515
import { getFirstAndLastTokens } from "./commons"
16+
import type { TSNodeListener } from "../../types-for-node"
1617

17-
type NodeWithoutES = Exclude<
18-
TSESTree.Node,
19-
| { type: ESTree.Node["type"] }
20-
| TSESTree.JSXAttribute
21-
| TSESTree.JSXClosingElement
22-
| TSESTree.JSXClosingFragment
23-
| TSESTree.JSXElement
24-
| TSESTree.JSXEmptyExpression
25-
| TSESTree.JSXExpressionContainer
26-
| TSESTree.JSXFragment
27-
| TSESTree.JSXIdentifier
28-
| TSESTree.JSXMemberExpression
29-
| TSESTree.JSXNamespacedName
30-
| TSESTree.JSXOpeningElement
31-
| TSESTree.JSXOpeningFragment
32-
| TSESTree.JSXSpreadAttribute
33-
| TSESTree.JSXSpreadChild
34-
| TSESTree.JSXText
35-
>
36-
type NodeListener = {
37-
[key in NodeWithoutES["type"]]: (node: NodeWithoutES & { type: key }) => void
38-
}
18+
type NodeListener = TSNodeListener
3919

4020
/**
4121
* Creates AST event handlers for svelte nodes.

0 commit comments

Comments
 (0)