Skip to content

refactor: use @typescript-eslint/types instead of estree #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"docs:build": "yarn svelte-kit build",
"docs:preview": "yarn svelte-kit preview",
"docs:watch": "yarn svelte-kit dev",
"format-for-gen-file": "eslint src/types-for-node.ts src/utils/rules.ts src/configs --fix",
"format-for-gen-file": "eslint src/types-for-node.ts src/utils/rules.ts src/configs typings/estree/index.d.ts --fix",
"install-with-ignore-engines": "yarn --ignore-engines",
"lint": "run-p lint:*",
"lint-fix": "yarn lint:es --fix && yarn lint:style --fix",
Expand Down Expand Up @@ -100,7 +100,6 @@
"@types/eslint-scope": "^3.7.0",
"@types/eslint-utils": "^3.0.1",
"@types/eslint-visitor-keys": "^1.0.0",
"@types/estree": "^1.0.0",
"@types/esutils": "^2.0.0",
"@types/less": "^3.0.3",
"@types/markdown-it": "^12.2.3",
Expand Down
5 changes: 2 additions & 3 deletions src/rules/@typescript-eslint/no-unnecessary-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts
import type { TSESTree } from "@typescript-eslint/types"
import type { AST } from "svelte-eslint-parser"
import type * as ESTree from "estree"
import { createRule } from "../../utils"
import {
isFalsyType,
Expand Down Expand Up @@ -183,7 +182,7 @@ export default createRule("@typescript-eslint/no-unnecessary-condition", {
})
}

const mutableVarReferenceIds: ESTree.Identifier[] = []
const mutableVarReferenceIds: TSESTree.Identifier[] = []
const scriptElements: AST.SvelteScriptElement[] = []
let inSvelteReactiveStatement = false

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

return mutableVarReferenceIds.some(
(id) => node.range[0] <= id.range![0] && id.range![1] <= node.range[1],
(id) => node.range[0] <= id.range[0] && id.range[1] <= node.range[1],
)
}

Expand Down
20 changes: 10 additions & 10 deletions src/rules/derived-has-same-inputs-outputs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type * as ESTree from "estree"
import type { TSESTree } from "@typescript-eslint/types"
import { createRule } from "../utils"
import type { RuleContext } from "../types"
import { extractStoreReferences } from "./reference-helpers/svelte-store"
Expand All @@ -21,18 +21,18 @@ export default createRule("derived-has-same-inputs-outputs", {
create(context) {
/** check node type */
function isIdentifierOrArrayExpression(
node: ESTree.SpreadElement | ESTree.Expression,
): node is ESTree.Identifier | ESTree.ArrayExpression {
node: TSESTree.SpreadElement | TSESTree.Expression,
): node is TSESTree.Identifier | TSESTree.ArrayExpression {
return ["Identifier", "ArrayExpression"].includes(node.type)
}

type ArrowFunctionExpressionOrFunctionExpression =
| ESTree.ArrowFunctionExpression
| ESTree.FunctionExpression
| TSESTree.ArrowFunctionExpression
| TSESTree.FunctionExpression

/** check node type */
function isFunctionExpression(
node: ESTree.SpreadElement | ESTree.Expression,
node: TSESTree.SpreadElement | TSESTree.Expression,
): node is ArrowFunctionExpressionOrFunctionExpression {
return ["ArrowFunctionExpression", "FunctionExpression"].includes(
node.type,
Expand All @@ -45,7 +45,7 @@ export default createRule("derived-has-same-inputs-outputs", {
*/
function checkIdentifier(
context: RuleContext,
args: ESTree.Identifier,
args: TSESTree.Identifier,
fn: ArrowFunctionExpressionOrFunctionExpression,
) {
const fnParam = fn.params[0]
Expand All @@ -54,7 +54,7 @@ export default createRule("derived-has-same-inputs-outputs", {
if (expectedName !== fnParam.name) {
context.report({
node: fn,
loc: fnParam.loc!,
loc: fnParam.loc,
messageId: "unexpected",
data: { name: expectedName },
})
Expand All @@ -67,7 +67,7 @@ export default createRule("derived-has-same-inputs-outputs", {
*/
function checkArrayExpression(
context: RuleContext,
args: ESTree.ArrayExpression,
args: TSESTree.ArrayExpression,
fn: ArrowFunctionExpressionOrFunctionExpression,
) {
const fnParam = fn.params[0]
Expand All @@ -82,7 +82,7 @@ export default createRule("derived-has-same-inputs-outputs", {
if (expectedName !== element.name) {
context.report({
node: fn,
loc: element.loc!,
loc: element.loc,
messageId: "unexpected",
data: { name: expectedName },
})
Expand Down
6 changes: 2 additions & 4 deletions src/rules/first-attribute-linebreak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,11 @@ export default createRule("first-attribute-linebreak", {
: multiline

if (location === "beside") {
if (
node.parent.name.loc!.end.line === firstAttribute.loc.start.line
) {
if (node.parent.name.loc.end.line === firstAttribute.loc.start.line) {
return
}
} else {
if (node.parent.name.loc!.end.line < firstAttribute.loc.start.line) {
if (node.parent.name.loc.end.line < firstAttribute.loc.start.line) {
return
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/rules/indent-helpers/ast.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { AST } from "svelte-eslint-parser"
import type * as ESTree from "estree"
import type { TSESTree } from "@typescript-eslint/types"
type AnyToken = AST.Token | AST.Comment
/**
* Check whether the given token is a whitespace.
*/
export function isWhitespace(
token: AnyToken | ESTree.Comment | null | undefined,
token: AnyToken | TSESTree.Comment | null | undefined,
): boolean {
return (
token != null &&
Expand All @@ -18,7 +18,7 @@ export function isWhitespace(
* Check whether the given token is a not whitespace.
*/
export function isNotWhitespace(
token: AnyToken | ESTree.Comment | null | undefined,
token: AnyToken | TSESTree.Comment | null | undefined,
): boolean {
return (
token != null &&
Expand Down
2 changes: 1 addition & 1 deletion src/rules/indent-helpers/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function isBeginningOfLine(
filter: isNotWhitespace,
})

return !prevToken || prevToken.loc.end.line < node.loc!.start.line
return !prevToken || prevToken.loc.end.line < node.loc.start.line
}

/**
Expand Down
Loading