1- import { RuleTester } from 'eslint'
2- import * as tsParser from '@typescript-eslint/parser'
3- import { createRuleWithCommands } from '../rule'
41import { toDynamicImport as command } from './to-dynamic-import'
5- import { d } from './_test-utils'
2+ import { d , run } from './_test-utils'
63
7- const valids = [
8- 'const foo = function () {}' ,
9- ]
10-
11- const invalids = [
4+ run (
5+ command ,
126 // Named import
137 {
148 code : d `
159 /// to-dynamic-import
1610 import { foo } from 'bar'` ,
1711 output : d `
1812 const { foo } = await import('bar')` ,
19- messageId : [ 'command-removal' , 'command-fix' ] ,
13+ errors : [ 'command-removal' , 'command-fix' ] ,
2014 } ,
2115 // Default import
2216 {
@@ -25,7 +19,7 @@ const invalids = [
2519 import foo from 'bar'` ,
2620 output : d `
2721 const { default: foo } = await import('bar')` ,
28- messageId : [ 'command-removal' , 'command-fix' ] ,
22+ errors : [ 'command-removal' , 'command-fix' ] ,
2923 } ,
3024 // Namespace
3125 {
@@ -34,7 +28,7 @@ const invalids = [
3428 import * as foo from 'bar'` ,
3529 output : d `
3630 const foo = await import('bar')` ,
37- messageId : [ 'command-removal' , 'command-fix' ] ,
31+ errors : [ 'command-removal' , 'command-fix' ] ,
3832 } ,
3933 // Mixed
4034 {
@@ -43,15 +37,14 @@ const invalids = [
4337 import foo, { bar, baz as tex } from 'bar'` ,
4438 output : d `
4539 const { default: foo, bar, baz: tex } = await import('bar')` ,
46- messageId : [ 'command-removal' , 'command-fix' ] ,
40+ errors : [ 'command-removal' , 'command-fix' ] ,
4741 } ,
4842 // Type import (error)
4943 {
5044 code : d `
5145 /// to-dynamic-import
5246 import type { Type } from 'baz'` ,
53- output : null ,
54- messageId : [ 'command-error' ] ,
47+ errors : [ 'command-error' ] ,
5548 } ,
5649 // Mixed with type import
5750 {
@@ -61,22 +54,6 @@ const invalids = [
6154 output : d `
6255 import { type Type } from 'bar'
6356 const { default: foo, bar } = await import('bar')` ,
64- messageId : [ 'command-removal' , 'command-fix' ] ,
65- } ,
66- ]
67-
68- const ruleTester : RuleTester = new RuleTester ( {
69- languageOptions : {
70- parser : tsParser ,
57+ errors : [ 'command-removal' , 'command-fix' ] ,
7158 } ,
72- } )
73-
74- ruleTester . run ( command . name , createRuleWithCommands ( [ command ] ) as any , {
75- valid : valids ,
76- invalid : invalids . map ( i => ( {
77- code : i . code ,
78- output : i . output ,
79- errors : ( Array . isArray ( i . messageId ) ? i . messageId : [ i . messageId ] )
80- . map ( id => ( { messageId : id } ) ) ,
81- } ) ) ,
82- } )
59+ )
0 commit comments