@@ -8,14 +8,7 @@ import c from 'picocolors'
88
99// @ts -expect-error missing types
1010import 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'
1912import { isGitClean } from './utils'
2013
2114export interface RuleOptions {
@@ -36,19 +29,14 @@ export async function run(options: RuleOptions = {}) {
3629 const pathESLintIngore = path . join ( cwd , '.eslintignore' )
3730
3831 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.` ) )
4433 return process . exit ( 1 )
4534 }
4635
4736 if ( ! SKIP_GIT_CHECK && ! isGitClean ( ) ) {
4837 const { confirmed } = await prompts ( {
4938 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?' ,
5240 name : 'confirmed' ,
5341 type : 'confirm' ,
5442 } )
@@ -79,18 +67,13 @@ export async function run(options: RuleOptions = {}) {
7967
8068 for ( const glob of globs ) {
8169 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 } ` ) )
8671 }
8772 }
8873
8974 let eslintConfigContent : string = ''
9075
91- const coderwydConfig = `${
92- eslintIgnores . length ? `ignores: ${ JSON . stringify ( eslintIgnores ) } ` : ''
93- } `
76+ const coderwydConfig = `${ eslintIgnores . length ? `ignores: ${ JSON . stringify ( eslintIgnores ) } ` : '' } `
9477 if ( pkg . type === 'module' ) {
9578 eslintConfigContent = `
9679import { defineConfig } from '@coderwyd/eslint-config'
@@ -111,8 +94,7 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
11194 const files = fs . readdirSync ( cwd )
11295 const legacyConfig : string [ ] = [ ]
11396 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 )
11698 } )
11799 if ( legacyConfig . length ) {
118100 console . log ( `${ WARN } you can now remove those files manually:` )
@@ -130,8 +112,7 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
130112 promptResult = await prompts (
131113 {
132114 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?' ,
135116 name : 'updateVscodeSettings' ,
136117 type : 'confirm' ,
137118 } ,
@@ -151,8 +132,7 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
151132 const dotVscodePath : string = path . join ( cwd , '.vscode' )
152133 const settingsPath : string = path . join ( dotVscodePath , 'settings.json' )
153134
154- if ( ! fs . existsSync ( dotVscodePath ) )
155- await fsp . mkdir ( dotVscodePath , { recursive : true } )
135+ if ( ! fs . existsSync ( dotVscodePath ) ) await fsp . mkdir ( dotVscodePath , { recursive : true } )
156136
157137 if ( ! fs . existsSync ( settingsPath ) ) {
158138 await fsp . writeFile ( settingsPath , `{${ vscodeSettingsString } }\n` , 'utf-8' )
@@ -161,10 +141,7 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
161141 let settingsContent = await fsp . readFile ( settingsPath , 'utf8' )
162142
163143 settingsContent = settingsContent . trim ( ) . replace ( / \s * } $ / , '' )
164- settingsContent +=
165- settingsContent . endsWith ( ',' ) || settingsContent . endsWith ( '{' )
166- ? ''
167- : ','
144+ settingsContent += settingsContent . endsWith ( ',' ) || settingsContent . endsWith ( '{' ) ? '' : ','
168145 settingsContent += `${ vscodeSettingsString } }\n`
169146
170147 await fsp . writeFile ( settingsPath , settingsContent , 'utf-8' )
@@ -174,7 +151,5 @@ module.exports = defineConfig({\n${coderwydConfig}\n})
174151
175152 // End update .vscode/settings.json
176153 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` )
180155}
0 commit comments