Skip to content

Commit 7a61f0e

Browse files
committed
refactor: use @typescript-eslint/types instead of estree
1 parent 27be352 commit 7a61f0e

34 files changed

+471
-373
lines changed

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"docs:build": "yarn svelte-kit build",
3535
"docs:preview": "yarn svelte-kit preview",
3636
"docs:watch": "yarn svelte-kit dev",
37-
"format-for-gen-file": "eslint src/types-for-node.ts src/utils/rules.ts src/configs --fix",
37+
"format-for-gen-file": "eslint src/types-for-node.ts src/utils/rules.ts src/configs typings/estree/index.d.ts --fix",
3838
"install-with-ignore-engines": "yarn --ignore-engines",
3939
"lint": "run-p lint:*",
4040
"lint-fix": "yarn lint:es --fix && yarn lint:style --fix",
@@ -100,7 +100,6 @@
100100
"@types/eslint-scope": "^3.7.0",
101101
"@types/eslint-utils": "^3.0.1",
102102
"@types/eslint-visitor-keys": "^1.0.0",
103-
"@types/estree": "^1.0.0",
104103
"@types/esutils": "^2.0.0",
105104
"@types/less": "^3.0.3",
106105
"@types/markdown-it": "^12.2.3",
@@ -175,7 +174,7 @@
175174
"access": "public"
176175
},
177176
"typeCoverage": {
178-
"atLeast": 98.69,
177+
"atLeast": 98.72,
179178
"cache": true,
180179
"detail": true,
181180
"ignoreAsAssertion": true,

src/rules/@typescript-eslint/no-unnecessary-condition.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts
44
import type { TSESTree } from "@typescript-eslint/types"
55
import type { AST } from "svelte-eslint-parser"
6-
import type * as ESTree from "estree"
76
import { createRule } from "../../utils"
87
import {
98
isFalsyType,
@@ -183,7 +182,7 @@ export default createRule("@typescript-eslint/no-unnecessary-condition", {
183182
})
184183
}
185184

186-
const mutableVarReferenceIds: ESTree.Identifier[] = []
185+
const mutableVarReferenceIds: TSESTree.Identifier[] = []
187186
const scriptElements: AST.SvelteScriptElement[] = []
188187
let inSvelteReactiveStatement = false
189188

@@ -238,7 +237,7 @@ export default createRule("@typescript-eslint/no-unnecessary-condition", {
238237
}
239238

240239
return mutableVarReferenceIds.some(
241-
(id) => node.range[0] <= id.range![0] && id.range![1] <= node.range[1],
240+
(id) => node.range[0] <= id.range[0] && id.range[1] <= node.range[1],
242241
)
243242
}
244243

src/rules/derived-has-same-inputs-outputs.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type * as ESTree from "estree"
1+
import type { TSESTree } from "@typescript-eslint/types"
22
import { createRule } from "../utils"
33
import type { RuleContext } from "../types"
44
import { extractStoreReferences } from "./reference-helpers/svelte-store"
@@ -21,18 +21,18 @@ export default createRule("derived-has-same-inputs-outputs", {
2121
create(context) {
2222
/** check node type */
2323
function isIdentifierOrArrayExpression(
24-
node: ESTree.SpreadElement | ESTree.Expression,
25-
): node is ESTree.Identifier | ESTree.ArrayExpression {
24+
node: TSESTree.SpreadElement | TSESTree.Expression,
25+
): node is TSESTree.Identifier | TSESTree.ArrayExpression {
2626
return ["Identifier", "ArrayExpression"].includes(node.type)
2727
}
2828

2929
type ArrowFunctionExpressionOrFunctionExpression =
30-
| ESTree.ArrowFunctionExpression
31-
| ESTree.FunctionExpression
30+
| TSESTree.ArrowFunctionExpression
31+
| TSESTree.FunctionExpression
3232

3333
/** check node type */
3434
function isFunctionExpression(
35-
node: ESTree.SpreadElement | ESTree.Expression,
35+
node: TSESTree.SpreadElement | TSESTree.Expression,
3636
): node is ArrowFunctionExpressionOrFunctionExpression {
3737
return ["ArrowFunctionExpression", "FunctionExpression"].includes(
3838
node.type,
@@ -45,7 +45,7 @@ export default createRule("derived-has-same-inputs-outputs", {
4545
*/
4646
function checkIdentifier(
4747
context: RuleContext,
48-
args: ESTree.Identifier,
48+
args: TSESTree.Identifier,
4949
fn: ArrowFunctionExpressionOrFunctionExpression,
5050
) {
5151
const fnParam = fn.params[0]
@@ -54,7 +54,7 @@ export default createRule("derived-has-same-inputs-outputs", {
5454
if (expectedName !== fnParam.name) {
5555
context.report({
5656
node: fn,
57-
loc: fnParam.loc!,
57+
loc: fnParam.loc,
5858
messageId: "unexpected",
5959
data: { name: expectedName },
6060
})
@@ -67,7 +67,7 @@ export default createRule("derived-has-same-inputs-outputs", {
6767
*/
6868
function checkArrayExpression(
6969
context: RuleContext,
70-
args: ESTree.ArrayExpression,
70+
args: TSESTree.ArrayExpression,
7171
fn: ArrowFunctionExpressionOrFunctionExpression,
7272
) {
7373
const fnParam = fn.params[0]
@@ -82,7 +82,7 @@ export default createRule("derived-has-same-inputs-outputs", {
8282
if (expectedName !== element.name) {
8383
context.report({
8484
node: fn,
85-
loc: element.loc!,
85+
loc: element.loc,
8686
messageId: "unexpected",
8787
data: { name: expectedName },
8888
})

src/rules/first-attribute-linebreak.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,11 @@ export default createRule("first-attribute-linebreak", {
6868
: multiline
6969

7070
if (location === "beside") {
71-
if (
72-
node.parent.name.loc!.end.line === firstAttribute.loc.start.line
73-
) {
71+
if (node.parent.name.loc.end.line === firstAttribute.loc.start.line) {
7472
return
7573
}
7674
} else {
77-
if (node.parent.name.loc!.end.line < firstAttribute.loc.start.line) {
75+
if (node.parent.name.loc.end.line < firstAttribute.loc.start.line) {
7876
return
7977
}
8078
}

src/rules/indent-helpers/ast.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { AST } from "svelte-eslint-parser"
2-
import type * as ESTree from "estree"
2+
import type { TSESTree } from "@typescript-eslint/types"
33
type AnyToken = AST.Token | AST.Comment
44
/**
55
* Check whether the given token is a whitespace.
66
*/
77
export function isWhitespace(
8-
token: AnyToken | ESTree.Comment | null | undefined,
8+
token: AnyToken | TSESTree.Comment | null | undefined,
99
): boolean {
1010
return (
1111
token != null &&
@@ -18,7 +18,7 @@ export function isWhitespace(
1818
* Check whether the given token is a not whitespace.
1919
*/
2020
export function isNotWhitespace(
21-
token: AnyToken | ESTree.Comment | null | undefined,
21+
token: AnyToken | TSESTree.Comment | null | undefined,
2222
): boolean {
2323
return (
2424
token != null &&

src/rules/indent-helpers/commons.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function isBeginningOfLine(
7474
filter: isNotWhitespace,
7575
})
7676

77-
return !prevToken || prevToken.loc.end.line < node.loc!.start.line
77+
return !prevToken || prevToken.loc.end.line < node.loc.start.line
7878
}
7979

8080
/**

0 commit comments

Comments
 (0)