@@ -8,14 +8,7 @@ import c from 'picocolors'
8
8
9
9
// @ts -expect-error missing types
10
10
import parse from 'parse-gitignore'
11
- import {
12
- ARROW ,
13
- CHECK ,
14
- WARN ,
15
- eslintVersion ,
16
- version ,
17
- vscodeSettingsString ,
18
- } from './constants'
11
+ import { ARROW , CHECK , WARN , eslintVersion , version , vscodeSettingsString } from './constants'
19
12
import { isGitClean } from './utils'
20
13
21
14
export interface RuleOptions {
@@ -36,19 +29,14 @@ export async function run(options: RuleOptions = {}) {
36
29
const pathESLintIngore = path . join ( cwd , '.eslintignore' )
37
30
38
31
if ( fs . existsSync ( pathFlatConfig ) ) {
39
- console . log (
40
- c . yellow (
41
- `${ WARN } eslint.config.js already exists, migration wizard exited.` ,
42
- ) ,
43
- )
32
+ console . log ( c . yellow ( `${ WARN } eslint.config.js already exists, migration wizard exited.` ) )
44
33
return process . exit ( 1 )
45
34
}
46
35
47
36
if ( ! SKIP_GIT_CHECK && ! isGitClean ( ) ) {
48
37
const { confirmed } = await prompts ( {
49
38
initial : false ,
50
- message :
51
- 'There are uncommitted changes in the current repository, are you sure to continue?' ,
39
+ message : 'There are uncommitted changes in the current repository, are you sure to continue?' ,
52
40
name : 'confirmed' ,
53
41
type : 'confirm' ,
54
42
} )
@@ -79,18 +67,13 @@ export async function run(options: RuleOptions = {}) {
79
67
80
68
for ( const glob of globs ) {
81
69
if ( glob . type === 'ignore' ) eslintIgnores . push ( ...glob . patterns )
82
- else if ( glob . type === 'unignore' )
83
- eslintIgnores . push (
84
- ...glob . patterns . map ( ( pattern : string ) => `!${ pattern } ` ) ,
85
- )
70
+ else if ( glob . type === 'unignore' ) eslintIgnores . push ( ...glob . patterns . map ( ( pattern : string ) => `!${ pattern } ` ) )
86
71
}
87
72
}
88
73
89
74
let eslintConfigContent : string = ''
90
75
91
- const coderwydConfig = `${
92
- eslintIgnores . length ? `ignores: ${ JSON . stringify ( eslintIgnores ) } ` : ''
93
- } `
76
+ const coderwydConfig = `${ eslintIgnores . length ? `ignores: ${ JSON . stringify ( eslintIgnores ) } ` : '' } `
94
77
if ( pkg . type === 'module' ) {
95
78
eslintConfigContent = `
96
79
import { defineConfig } from '@coderwyd/eslint-config'
@@ -111,8 +94,7 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
111
94
const files = fs . readdirSync ( cwd )
112
95
const legacyConfig : string [ ] = [ ]
113
96
files . forEach ( file => {
114
- if ( file . includes ( 'eslint' ) || file . includes ( 'prettier' ) )
115
- legacyConfig . push ( file )
97
+ if ( file . includes ( 'eslint' ) || file . includes ( 'prettier' ) ) legacyConfig . push ( file )
116
98
} )
117
99
if ( legacyConfig . length ) {
118
100
console . log ( `${ WARN } you can now remove those files manually:` )
@@ -130,8 +112,7 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
130
112
promptResult = await prompts (
131
113
{
132
114
initial : true ,
133
- message :
134
- 'Update .vscode/settings.json for better VS Code experience?' ,
115
+ message : 'Update .vscode/settings.json for better VS Code experience?' ,
135
116
name : 'updateVscodeSettings' ,
136
117
type : 'confirm' ,
137
118
} ,
@@ -151,8 +132,7 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
151
132
const dotVscodePath : string = path . join ( cwd , '.vscode' )
152
133
const settingsPath : string = path . join ( dotVscodePath , 'settings.json' )
153
134
154
- if ( ! fs . existsSync ( dotVscodePath ) )
155
- await fsp . mkdir ( dotVscodePath , { recursive : true } )
135
+ if ( ! fs . existsSync ( dotVscodePath ) ) await fsp . mkdir ( dotVscodePath , { recursive : true } )
156
136
157
137
if ( ! fs . existsSync ( settingsPath ) ) {
158
138
await fsp . writeFile ( settingsPath , `{${ vscodeSettingsString } }\n` , 'utf-8' )
@@ -161,10 +141,7 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
161
141
let settingsContent = await fsp . readFile ( settingsPath , 'utf8' )
162
142
163
143
settingsContent = settingsContent . trim ( ) . replace ( / \s * } $ / , '' )
164
- settingsContent +=
165
- settingsContent . endsWith ( ',' ) || settingsContent . endsWith ( '{' )
166
- ? ''
167
- : ','
144
+ settingsContent += settingsContent . endsWith ( ',' ) || settingsContent . endsWith ( '{' ) ? '' : ','
168
145
settingsContent += `${ vscodeSettingsString } }\n`
169
146
170
147
await fsp . writeFile ( settingsPath , settingsContent , 'utf-8' )
@@ -174,7 +151,5 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
174
151
175
152
// End update .vscode/settings.json
176
153
console . log ( c . green ( `${ CHECK } migration completed` ) )
177
- console . log (
178
- `Now you can update the dependencies and run ${ c . blue ( 'eslint . --fix' ) } \n` ,
179
- )
154
+ console . log ( `Now you can update the dependencies and run ${ c . blue ( 'eslint . --fix' ) } \n` )
180
155
}
0 commit comments