Skip to content

Commit

Permalink
test: use AST_NODE_TYPES directlyinstead of reading from TSESTree
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalexiei committed Nov 20, 2024
1 parent 8dcd3cd commit 511bcfe
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 267 deletions.
113 changes: 23 additions & 90 deletions test/rules/consistent-type-specifier-style.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RuleTester as TSESLintRuleTester } from '@typescript-eslint/rule-tester'
import { TSESTree } from '@typescript-eslint/utils'
import { AST_NODE_TYPES } from '@typescript-eslint/utils'

import { parsers, createRuleTestCaseFunctions } from '../utils'
import type { RuleRunTests } from '../utils'
Expand Down Expand Up @@ -120,7 +120,7 @@ const COMMON_TESTS: RuleRunTests<typeof rule> = {
data: {
kind: 'type',
},
type: TSESTree.AST_NODE_TYPES.ImportDeclaration,
type: AST_NODE_TYPES.ImportDeclaration,
},
],
},
Expand All @@ -129,66 +129,40 @@ const COMMON_TESTS: RuleRunTests<typeof rule> = {
output: "import type {Foo as Bar} from 'Foo';",
options: ['prefer-top-level'],
errors: [
{
messageId: 'topLevel',
type: TSESTree.AST_NODE_TYPES.ImportDeclaration,
},
{ messageId: 'topLevel', type: AST_NODE_TYPES.ImportDeclaration },
],
},
{
code: "import { type Foo, type Bar } from 'Foo';",
output: "import type {Foo, Bar} from 'Foo';",
options: ['prefer-top-level'],
errors: [
{
messageId: 'topLevel',
type: TSESTree.AST_NODE_TYPES.ImportDeclaration,
},
{ messageId: 'topLevel', type: AST_NODE_TYPES.ImportDeclaration },
],
},
{
code: "import { Foo, type Bar } from 'Foo';",
output: "import { Foo } from 'Foo';\nimport type {Bar} from 'Foo';",
options: ['prefer-top-level'],
errors: [
{
messageId: 'topLevel',
type: TSESTree.AST_NODE_TYPES.ImportSpecifier,
},
],
errors: [{ messageId: 'topLevel', type: AST_NODE_TYPES.ImportSpecifier }],
},
{
code: "import { type Foo, Bar } from 'Foo';",
output: "import { Bar } from 'Foo';\nimport type {Foo} from 'Foo';",
options: ['prefer-top-level'],
errors: [
{
messageId: 'topLevel',
type: TSESTree.AST_NODE_TYPES.ImportSpecifier,
},
],
errors: [{ messageId: 'topLevel', type: AST_NODE_TYPES.ImportSpecifier }],
},
{
code: "import Foo, { type Bar } from 'Foo';",
output: "import Foo from 'Foo';\nimport type {Bar} from 'Foo';",
options: ['prefer-top-level'],
errors: [
{
messageId: 'topLevel',
type: TSESTree.AST_NODE_TYPES.ImportSpecifier,
},
],
errors: [{ messageId: 'topLevel', type: AST_NODE_TYPES.ImportSpecifier }],
},
{
code: "import Foo, { type Bar, Baz } from 'Foo';",
output: "import Foo, { Baz } from 'Foo';\nimport type {Bar} from 'Foo';",
options: ['prefer-top-level'],
errors: [
{
messageId: 'topLevel',
type: TSESTree.AST_NODE_TYPES.ImportSpecifier,
},
],
errors: [{ messageId: 'topLevel', type: AST_NODE_TYPES.ImportSpecifier }],
},
// https://github.com/import-js/eslint-plugin-import-x/issues/2753
{
Expand All @@ -212,12 +186,7 @@ import {
Component5,
} from "package-2";`,
options: ['prefer-top-level'],
errors: [
{
messageId: 'topLevel',
type: TSESTree.AST_NODE_TYPES.ImportSpecifier,
},
],
errors: [{ messageId: 'topLevel', type: AST_NODE_TYPES.ImportSpecifier }],
},

//
Expand All @@ -233,20 +202,15 @@ import {
data: {
kind: 'type',
},
type: TSESTree.AST_NODE_TYPES.ImportDeclaration,
type: AST_NODE_TYPES.ImportDeclaration,
},
],
},
{
code: "import type { Foo, Bar, Baz } from 'Foo';",
output: "import { type Foo, type Bar, type Baz } from 'Foo';",
options: ['prefer-inline'],
errors: [
{
messageId: 'inline',
type: TSESTree.AST_NODE_TYPES.ImportDeclaration,
},
],
errors: [{ messageId: 'inline', type: AST_NODE_TYPES.ImportDeclaration }],
},
],
} as const
Expand Down Expand Up @@ -309,7 +273,7 @@ const FLOW_ONLY: RuleRunTests<typeof rule> = {
data: {
kind: 'typeof',
},
type: TSESTree.AST_NODE_TYPES.ImportDeclaration,
type: AST_NODE_TYPES.ImportDeclaration,
},
],
},
Expand All @@ -318,10 +282,7 @@ const FLOW_ONLY: RuleRunTests<typeof rule> = {
output: "import typeof {Foo as Bar} from 'Foo';",
options: ['prefer-top-level'],
errors: [
{
messageId: 'topLevel',
type: TSESTree.AST_NODE_TYPES.ImportDeclaration,
},
{ messageId: 'topLevel', type: AST_NODE_TYPES.ImportDeclaration },
],
},
{
Expand All @@ -334,7 +295,7 @@ const FLOW_ONLY: RuleRunTests<typeof rule> = {
data: {
kind: 'type/typeof',
},
type: TSESTree.AST_NODE_TYPES.ImportDeclaration,
type: AST_NODE_TYPES.ImportDeclaration,
},
],
},
Expand All @@ -343,33 +304,20 @@ const FLOW_ONLY: RuleRunTests<typeof rule> = {
output: "import typeof {Foo, Bar} from 'Foo';",
options: ['prefer-top-level'],
errors: [
{
messageId: 'topLevel',
type: TSESTree.AST_NODE_TYPES.ImportDeclaration,
},
{ messageId: 'topLevel', type: AST_NODE_TYPES.ImportDeclaration },
],
},
{
code: "import { Foo, typeof Bar } from 'Foo';",
output: "import { Foo } from 'Foo';\nimport typeof {Bar} from 'Foo';",
options: ['prefer-top-level'],
errors: [
{
messageId: 'topLevel',
type: TSESTree.AST_NODE_TYPES.ImportSpecifier,
},
],
errors: [{ messageId: 'topLevel', type: AST_NODE_TYPES.ImportSpecifier }],
},
{
code: "import { typeof Foo, Bar } from 'Foo';",
output: "import { Bar } from 'Foo';\nimport typeof {Foo} from 'Foo';",
options: ['prefer-top-level'],
errors: [
{
messageId: 'topLevel',
type: TSESTree.AST_NODE_TYPES.ImportSpecifier,
},
],
errors: [{ messageId: 'topLevel', type: AST_NODE_TYPES.ImportSpecifier }],
},
{
code: "import { Foo, type Bar, typeof Baz } from 'Foo';",
Expand All @@ -382,39 +330,29 @@ const FLOW_ONLY: RuleRunTests<typeof rule> = {
data: {
kind: 'type',
},
type: TSESTree.AST_NODE_TYPES.ImportSpecifier,
type: AST_NODE_TYPES.ImportSpecifier,
},
{
messageId: 'topLevel',
data: {
kind: 'typeof',
},
type: TSESTree.AST_NODE_TYPES.ImportSpecifier,
type: AST_NODE_TYPES.ImportSpecifier,
},
],
},
{
code: "import Foo, { typeof Bar } from 'Foo';",
output: "import Foo from 'Foo';\nimport typeof {Bar} from 'Foo';",
options: ['prefer-top-level'],
errors: [
{
messageId: 'topLevel',
type: TSESTree.AST_NODE_TYPES.ImportSpecifier,
},
],
errors: [{ messageId: 'topLevel', type: AST_NODE_TYPES.ImportSpecifier }],
},
{
code: "import Foo, { typeof Bar, Baz } from 'Foo';",
output:
"import Foo, { Baz } from 'Foo';\nimport typeof {Bar} from 'Foo';",
options: ['prefer-top-level'],
errors: [
{
messageId: 'topLevel',
type: TSESTree.AST_NODE_TYPES.ImportSpecifier,
},
],
errors: [{ messageId: 'topLevel', type: AST_NODE_TYPES.ImportSpecifier }],
},

//
Expand All @@ -430,20 +368,15 @@ const FLOW_ONLY: RuleRunTests<typeof rule> = {
data: {
kind: 'typeof',
},
type: TSESTree.AST_NODE_TYPES.ImportDeclaration,
type: AST_NODE_TYPES.ImportDeclaration,
},
],
},
{
code: "import typeof { Foo, Bar, Baz } from 'Foo';",
output: "import { typeof Foo, typeof Bar, typeof Baz } from 'Foo';",
options: ['prefer-inline'],
errors: [
{
messageId: 'inline',
type: TSESTree.AST_NODE_TYPES.ImportDeclaration,
},
],
errors: [{ messageId: 'inline', type: AST_NODE_TYPES.ImportDeclaration }],
},
],
} as const
Expand Down
Loading

0 comments on commit 511bcfe

Please sign in to comment.