Skip to content

Commit

Permalink
refactor: move typescript-eslint types to dev dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Aug 6, 2023
1 parent b0b52b0 commit 3210ff3
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 100 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"svelte-eslint-parser": "^0.32.0"
},
"dependencies": {
"@typescript-eslint/types": "^5.62.0",
"@typescript-eslint/utils": "^5.62.0",
"is-core-module": "^2.13.0",
"minimatch": "^9.0.3",
Expand All @@ -84,6 +83,7 @@
"@types/node": "^20.4.8",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/types": "^5.62.0",
"@vitest/coverage-v8": "^0.34.1",
"astro-eslint-parser": "^0.14.0",
"changelogen": "^0.5.4",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 10 additions & 15 deletions rules/sort-array-includes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { TSESTree } from '@typescript-eslint/types'

import { AST_NODE_TYPES } from '@typescript-eslint/types'

import type { SortingNode } from '../typings'

import { createEslintRule } from '../utils/create-eslint-rule'
Expand Down Expand Up @@ -78,13 +76,13 @@ export default createEslintRule<Options, MESSAGE_ID>({
create: context => ({
MemberExpression: node => {
if (
(node.object.type === AST_NODE_TYPES.ArrayExpression ||
node.object.type === AST_NODE_TYPES.NewExpression) &&
node.property.type === AST_NODE_TYPES.Identifier &&
(node.object.type === 'ArrayExpression' ||
node.object.type === 'NewExpression') &&
node.property.type === 'Identifier' &&
node.property.name === 'includes'
) {
let elements =
node.object.type === AST_NODE_TYPES.ArrayExpression
node.object.type === 'ArrayExpression'
? node.object.elements
: node.object.arguments

Expand All @@ -107,7 +105,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
if (element !== null) {
accumulator.at(0)!.push({
name:
element.type === AST_NODE_TYPES.Literal
element.type === 'Literal'
? `${element.value}`
: source.text.slice(...element.range),
size: rangeToDiff(element.range),
Expand All @@ -127,14 +125,14 @@ export default createEslintRule<Options, MESSAGE_ID>({

if (
options['spread-last'] &&
left.node.type === AST_NODE_TYPES.Literal &&
right.node.type === AST_NODE_TYPES.SpreadElement
left.node.type === 'Literal' &&
right.node.type === 'SpreadElement'
) {
compareValue = false
} else if (
options['spread-last'] &&
left.node.type === AST_NODE_TYPES.SpreadElement &&
right.node.type === AST_NODE_TYPES.Literal
left.node.type === 'SpreadElement' &&
right.node.type === 'Literal'
) {
compareValue = true
} else {
Expand All @@ -154,10 +152,7 @@ export default createEslintRule<Options, MESSAGE_ID>({

if (options['spread-last']) {
for (let i = 0, max = sortedNodes.length; i < max; i++) {
if (
sortedNodes.at(i)!.node.type ===
AST_NODE_TYPES.SpreadElement
) {
if (sortedNodes.at(i)!.node.type === 'SpreadElement') {
sortedNodes.push(sortedNodes.splice(i, 1).at(0)!)
}
}
Expand Down
12 changes: 5 additions & 7 deletions rules/sort-classes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { TSESLint } from '@typescript-eslint/utils'

import { AST_NODE_TYPES } from '@typescript-eslint/types'

import type { SortingNode } from '../typings'

import { createEslintRule } from '../utils/create-eslint-rule'
Expand Down Expand Up @@ -102,22 +100,22 @@ export default createEslintRule<Options, MESSAGE_ID>({
let name: string
let { getGroup, defineGroup } = useGroups(options.groups)

if (member.type === AST_NODE_TYPES.StaticBlock) {
if (member.type === 'StaticBlock') {
name = 'static'
} else if (member.type === AST_NODE_TYPES.TSIndexSignature) {
} else if (member.type === 'TSIndexSignature') {
name = source.text.slice(
member.range.at(0),
member.typeAnnotation?.range.at(0) ?? member.range.at(1),
)
} else {
if (member.key.type === AST_NODE_TYPES.Identifier) {
if (member.key.type === 'Identifier') {
;({ name } = member.key)
} else {
name = source.text.slice(...member.key.range)
}
}

if (member.type === AST_NODE_TYPES.MethodDefinition) {
if (member.type === 'MethodDefinition') {
if (member.kind === 'constructor') {
defineGroup('constructor')
}
Expand All @@ -131,7 +129,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
}

defineGroup('method')
} else if (member.type === AST_NODE_TYPES.PropertyDefinition) {
} else if (member.type === 'PropertyDefinition') {
if (member.static) {
defineGroup('static-property')
}
Expand Down
4 changes: 1 addition & 3 deletions rules/sort-enums.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { AST_NODE_TYPES } from '@typescript-eslint/types'

import type { SortingNode } from '../typings'

import { createEslintRule } from '../utils/create-eslint-rule'
Expand Down Expand Up @@ -83,7 +81,7 @@ export default createEslintRule<Options, MESSAGE_ID>({

let nodes: SortingNode[] = node.members.map(member => ({
name:
member.id.type === AST_NODE_TYPES.Literal
member.id.type === 'Literal'
? `${member.id.value}`
: `${source.text.slice(...member.id.range)}`,
size: rangeToDiff(member.range),
Expand Down
7 changes: 1 addition & 6 deletions rules/sort-exports.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { TSESTree } from '@typescript-eslint/types'

import { AST_NODE_TYPES } from '@typescript-eslint/types'

import type { SortingNode } from '../typings'

import { createEslintRule } from '../utils/create-eslint-rule'
Expand Down Expand Up @@ -82,10 +80,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
| TSESTree.ExportNamedDeclarationWithSource
| TSESTree.ExportAllDeclaration,
) => {
if (
node.type === AST_NODE_TYPES.ExportAllDeclaration &&
node.exported === null
) {
if (node.type === 'ExportAllDeclaration' && node.exported === null) {
parts.push([])
} else {
parts.at(-1)!.push({
Expand Down
15 changes: 6 additions & 9 deletions rules/sort-imports.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { TSESTree } from '@typescript-eslint/types'
import type { TSESLint } from '@typescript-eslint/utils'

import { AST_NODE_TYPES } from '@typescript-eslint/types'
import isCoreModule from 'is-core-module'
import { minimatch } from 'minimatch'

Expand Down Expand Up @@ -164,8 +163,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
let nodes: SortingNode[] = []

let isSideEffectImport = (node: TSESTree.Node) =>
node.type === AST_NODE_TYPES.ImportDeclaration &&
node.specifiers.length === 0
node.type === 'ImportDeclaration' && node.specifiers.length === 0

let computeGroup = (node: ModuleDeclaration): Group<string[]> => {
let isStyle = (value: string) =>
Expand Down Expand Up @@ -198,7 +196,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
tsPaths.some(pattern => minimatch(nodeElement.source.value, pattern))

if (node.importKind === 'type') {
if (node.type === AST_NODE_TYPES.ImportDeclaration) {
if (node.type === 'ImportDeclaration') {
setCustomGroups(options['custom-groups'].type, node.source.value)

if (isCoreModule(node.source.value)) {
Expand Down Expand Up @@ -226,7 +224,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
defineGroup('type')
}

if (node.type === AST_NODE_TYPES.ImportDeclaration) {
if (node.type === 'ImportDeclaration') {
setCustomGroups(options['custom-groups'].value, node.source.value)

if (isCoreModule(node.source.value)) {
Expand Down Expand Up @@ -266,13 +264,12 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
let registerNode = (node: ModuleDeclaration) => {
let name: string

if (node.type === AST_NODE_TYPES.ImportDeclaration) {
if (node.type === 'ImportDeclaration') {
name = node.source.value
} else {
if (
node.moduleReference.type ===
AST_NODE_TYPES.TSExternalModuleReference &&
node.moduleReference.expression.type === AST_NODE_TYPES.Literal
node.moduleReference.type === 'TSExternalModuleReference' &&
node.moduleReference.expression.type === 'Literal'
) {
name = `${node.moduleReference.expression.value}`
} else {
Expand Down
11 changes: 5 additions & 6 deletions rules/sort-interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AST_NODE_TYPES } from '@typescript-eslint/types'
import { minimatch } from 'minimatch'

import type { SortingNode } from '../typings'
Expand Down Expand Up @@ -93,17 +92,17 @@ export default createEslintRule<Options, MESSAGE_ID>({

let formattedMembers: SortingNode[][] = node.body.body.reduce(
(accumulator: SortingNode[][], element) => {
if (element.type === AST_NODE_TYPES.TSCallSignatureDeclaration) {
if (element.type === 'TSCallSignatureDeclaration') {
accumulator.push([])
return accumulator
}

let name: string

if (element.type === AST_NODE_TYPES.TSPropertySignature) {
if (element.key.type === AST_NODE_TYPES.Identifier) {
if (element.type === 'TSPropertySignature') {
if (element.key.type === 'Identifier') {
;({ name } = element.key)
} else if (element.key.type === AST_NODE_TYPES.Literal) {
} else if (element.key.type === 'Literal') {
name = `${element.key.value}`
} else {
let end: number =
Expand All @@ -112,7 +111,7 @@ export default createEslintRule<Options, MESSAGE_ID>({

name = source.text.slice(element.range.at(0), end)
}
} else if (element.type === AST_NODE_TYPES.TSIndexSignature) {
} else if (element.type === 'TSIndexSignature') {
let endIndex: number =
element.typeAnnotation?.range.at(0) ?? element.range.at(1)!

Expand Down
6 changes: 2 additions & 4 deletions rules/sort-jsx-props.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { TSESTree } from '@typescript-eslint/types'

import { AST_NODE_TYPES } from '@typescript-eslint/types'

import type { SortingNode } from '../typings'

import { createEslintRule } from '../utils/create-eslint-rule'
Expand Down Expand Up @@ -103,13 +101,13 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
accumulator: SortingNode[][],
attribute: TSESTree.JSXSpreadAttribute | TSESTree.JSXAttribute,
) => {
if (attribute.type === AST_NODE_TYPES.JSXSpreadAttribute) {
if (attribute.type === 'JSXSpreadAttribute') {
accumulator.push([])
return accumulator
}

let name =
attribute.name.type === AST_NODE_TYPES.JSXNamespacedName
attribute.name.type === 'JSXNamespacedName'
? `${attribute.name.namespace.name}:${attribute.name.name.name}`
: attribute.name.name

Expand Down
15 changes: 5 additions & 10 deletions rules/sort-maps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { TSESTree } from '@typescript-eslint/types'

import { AST_NODE_TYPES } from '@typescript-eslint/types'

import type { SortingNode } from '../typings'

import { createEslintRule } from '../utils/create-eslint-rule'
Expand Down Expand Up @@ -73,10 +71,10 @@ export default createEslintRule<Options, MESSAGE_ID>({
create: context => ({
NewExpression: node => {
if (
node.callee.type === AST_NODE_TYPES.Identifier &&
node.callee.type === 'Identifier' &&
node.callee.name === 'Map' &&
node.arguments.length &&
node.arguments[0].type === AST_NODE_TYPES.ArrayExpression
node.arguments[0].type === 'ArrayExpression'
) {
let [{ elements }] = node.arguments

Expand All @@ -94,10 +92,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
accumulator: TSESTree.Expression[][],
element: TSESTree.SpreadElement | TSESTree.Expression | null,
) => {
if (
element === null ||
element.type === AST_NODE_TYPES.SpreadElement
) {
if (element === null || element.type === 'SpreadElement') {
accumulator.push([])
} else {
accumulator.at(-1)!.push(element)
Expand All @@ -111,12 +106,12 @@ export default createEslintRule<Options, MESSAGE_ID>({
let nodes: SortingNode[] = part.map(element => {
let name: string

if (element.type === AST_NODE_TYPES.ArrayExpression) {
if (element.type === 'ArrayExpression') {
let [left] = element.elements

if (!left) {
name = `${left}`
} else if (left.type === AST_NODE_TYPES.Literal) {
} else if (left.type === 'Literal') {
name = left.raw
} else {
name = source.text.slice(...left.range)
Expand Down
4 changes: 1 addition & 3 deletions rules/sort-named-imports.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { AST_NODE_TYPES } from '@typescript-eslint/types'

import type { SortingNode } from '../typings'

import { createEslintRule } from '../utils/create-eslint-rule'
Expand Down Expand Up @@ -70,7 +68,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
create: context => ({
ImportDeclaration: node => {
let specifiers = node.specifiers.filter(
({ type }) => type === AST_NODE_TYPES.ImportSpecifier,
({ type }) => type === 'ImportSpecifier',
)

if (specifiers.length > 1) {
Expand Down
10 changes: 4 additions & 6 deletions rules/sort-object-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { AST_NODE_TYPES } from '@typescript-eslint/types'

import type { SortingNode } from '../typings'

import { createEslintRule } from '../utils/create-eslint-rule'
Expand Down Expand Up @@ -86,18 +84,18 @@ export default createEslintRule<Options, MESSAGE_ID>({
let formatName = (value: string): string =>
value.replace(/(,|;)$/, '')

if (member.type === AST_NODE_TYPES.TSPropertySignature) {
if (member.key.type === AST_NODE_TYPES.Identifier) {
if (member.type === 'TSPropertySignature') {
if (member.key.type === 'Identifier') {
;({ name } = member.key)
} else if (member.key.type === AST_NODE_TYPES.Literal) {
} else if (member.key.type === 'Literal') {
name = `${member.key.value}`
} else {
name = source.text.slice(
member.range.at(0),
member.typeAnnotation?.range.at(0),
)
}
} else if (member.type === AST_NODE_TYPES.TSIndexSignature) {
} else if (member.type === 'TSIndexSignature') {
let endIndex: number =
member.typeAnnotation?.range.at(0) ?? member.range.at(1)!

Expand Down
Loading

0 comments on commit 3210ff3

Please sign in to comment.