File tree Expand file tree Collapse file tree 3 files changed +44
-5
lines changed Expand file tree Collapse file tree 3 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,16 @@ console.log("hi");
35
35
import { createSignal , Component } from " solid-js" ;
36
36
console .log (" hi" );
37
37
38
+ import { createSignal } from " solid-js/web" ;
39
+ import " solid-js" ;
40
+ // after eslint --fix:
41
+ import { createSignal } from " solid-js" ;
42
+
43
+ import { createSignal } from " solid-js/web" ;
44
+ import {} from " solid-js" ;
45
+ // after eslint --fix:
46
+ import { createSignal } from " solid-js" ;
47
+
38
48
import { createEffect } from " solid-js/web" ;
39
49
import { render } from " solid-js" ;
40
50
// after eslint --fix:
Original file line number Diff line number Diff line change @@ -127,11 +127,16 @@ export function appendImports(
127
127
return fixer . insertTextAfter ( otherSpecifier , `, { ${ identifiersString } }` ) ;
128
128
}
129
129
if ( importNode . specifiers . length === 0 ) {
130
- // import 'source' => import { B, C, D } from 'source'
131
- const importToken = sourceCode . getFirstToken ( importNode ) ;
132
- return importToken
133
- ? fixer . insertTextAfter ( importToken , ` { ${ identifiersString } } from` )
134
- : null ;
130
+ const [ importToken , maybeBrace ] = sourceCode . getFirstTokens ( importNode , { count : 2 } ) ;
131
+ if ( maybeBrace ?. value === "{" ) {
132
+ // import {} from 'source' => import { B, C, D } from 'source'
133
+ return fixer . insertTextAfter ( maybeBrace , ` ${ identifiersString } ` ) ;
134
+ } else {
135
+ // import 'source' => import { B, C, D } from 'source'
136
+ return importToken
137
+ ? fixer . insertTextAfter ( importToken , ` { ${ identifiersString } } from` )
138
+ : null ;
139
+ }
135
140
}
136
141
return null ;
137
142
}
Original file line number Diff line number Diff line change @@ -58,6 +58,30 @@ import { createSignal, Component } from "solid-js";
58
58
console.log('hi');` ,
59
59
parser : require . resolve ( "@typescript-eslint/parser" ) ,
60
60
} ,
61
+ {
62
+ code : `import { createSignal } from "solid-js/web";
63
+ import "solid-js";` ,
64
+ errors : [
65
+ {
66
+ messageId : "prefer-source" ,
67
+ data : { name : "createSignal" , source : "solid-js" } ,
68
+ } ,
69
+ ] ,
70
+ output : `
71
+ import { createSignal } from "solid-js";` ,
72
+ } ,
73
+ {
74
+ code : `import { createSignal } from "solid-js/web";
75
+ import {} from "solid-js";` ,
76
+ errors : [
77
+ {
78
+ messageId : "prefer-source" ,
79
+ data : { name : "createSignal" , source : "solid-js" } ,
80
+ } ,
81
+ ] ,
82
+ output : `
83
+ import { createSignal } from "solid-js";` ,
84
+ } ,
61
85
// Two-part fix, output here is first pass...
62
86
{
63
87
code : `import { createEffect } from "solid-js/web";
You can’t perform that action at this time.
0 commit comments