Skip to content

Commit 3da39e3

Browse files
committed
style: format
1 parent 1f3e747 commit 3da39e3

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

bin/create-eslint-config.js

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ const require = createRequire(import.meta.url)
1111
const Enquirer = require('enquirer')
1212
const enquirer = new Enquirer()
1313

14-
function abort () {
14+
function abort() {
1515
console.error(red('✖') + ' Operation cancelled')
1616
process.exit(1)
1717
}
1818

19-
function prompt (questions) {
19+
function prompt(questions) {
2020
return enquirer.prompt(questions).catch(abort)
2121
}
2222

@@ -26,16 +26,22 @@ const requireInCwd = createRequire(path.resolve(cwd, 'index.cjs'))
2626
// Only works in directories that has a `package.json`
2727
const pkgJsonPath = path.resolve(cwd, 'package.json')
2828
if (!existsSync(pkgJsonPath)) {
29-
console.error(`${bold(yellow('package.json'))} not found in the current directory.`)
29+
console.error(
30+
`${bold(yellow('package.json'))} not found in the current directory.`,
31+
)
3032
abort()
3133
}
3234

3335
const rawPkgJson = readFileSync(pkgJsonPath, 'utf-8')
34-
function inferIndent (rawJson) {
36+
function inferIndent(rawJson) {
3537
const lines = rawJson.split('\n')
36-
const firstLineWithIndent = lines.find(l => l.startsWith(' ') || l.startsWith('\t'))
38+
const firstLineWithIndent = lines.find(
39+
l => l.startsWith(' ') || l.startsWith('\t'),
40+
)
3741

38-
if (!firstLineWithIndent) { return '' }
42+
if (!firstLineWithIndent) {
43+
return ''
44+
}
3945
return /^\s+/.exec(firstLineWithIndent)[0]
4046
}
4147
const indent = inferIndent(rawPkgJson)
@@ -61,7 +67,7 @@ for (const fmt of eslintConfigFormats) {
6167
message:
6268
`Found existing ESLint config file: ${bold(blue(configFileName))}.\n` +
6369
'Do you want to remove the config file and continue?',
64-
initial: false
70+
initial: false,
6571
})
6672

6773
if (shouldRemove) {
@@ -81,7 +87,7 @@ if (pkg.eslintConfig) {
8187
message:
8288
`Found existing ${bold(blue('eslintConfig'))} field in ${bold(yellow('package.json'))}.\n` +
8389
'Do you want to remove the config field and continue?',
84-
initial: false
90+
initial: false,
8591
})
8692

8793
if (shouldRemoveConfigField) {
@@ -105,9 +111,11 @@ if (!vueVersion || !/^3/.test(vueVersion)) {
105111
enabled: 'Yes',
106112
name: 'continueAnyway',
107113
message: 'Vue 3.x is required but not detected. Continue anyway?',
108-
initial: false
114+
initial: false,
109115
})
110-
if (!continueAnyway) { abort() }
116+
if (!continueAnyway) {
117+
abort()
118+
}
111119
}
112120

113121
// 4. Check TypeScript
@@ -126,7 +134,7 @@ const { hasTypeScript } = await prompt({
126134
enabled: 'Yes',
127135
name: 'hasTypeScript',
128136
message: 'Does your project use TypeScript?',
129-
initial: detectedTypeScript
137+
initial: detectedTypeScript,
130138
})
131139

132140
const supportedScriptLangs = {}
@@ -182,15 +190,16 @@ const { needsPrettier } = await prompt({
182190
disabled: 'No',
183191
enabled: 'Yes',
184192
name: 'needsPrettier',
185-
message: 'Do you need Prettier to format your code?'
193+
message: 'Do you need Prettier to format your code?',
186194
})
187195

188196
const { needsOxlint } = await prompt({
189197
type: 'toggle',
190198
disabled: 'No',
191199
enabled: 'Yes',
192200
name: 'needsOxlint',
193-
message: 'Would you like to supplement ESLint with Oxlint for faster linting (experimental)?'
201+
message:
202+
'Would you like to supplement ESLint with Oxlint for faster linting (experimental)?',
194203
})
195204

196205
const { pkg: pkgToExtend, files } = createConfig({
@@ -212,14 +221,20 @@ for (const [name, content] of Object.entries(files)) {
212221

213222
// Prompt: Run `npm install` or `yarn` or `pnpm install`
214223
const userAgent = process.env.npm_config_user_agent ?? ''
215-
const packageManager = /pnpm/.test(userAgent) ? 'pnpm' : /yarn/.test(userAgent) ? 'yarn' : 'npm'
224+
const packageManager = /pnpm/.test(userAgent)
225+
? 'pnpm'
226+
: /yarn/.test(userAgent)
227+
? 'yarn'
228+
: 'npm'
216229

217-
const installCommand = packageManager === 'yarn' ? 'yarn' : `${packageManager} install`
218-
const lintCommand = packageManager === 'npm' ? 'npm run lint' : `${packageManager} lint`
230+
const installCommand =
231+
packageManager === 'yarn' ? 'yarn' : `${packageManager} install`
232+
const lintCommand =
233+
packageManager === 'npm' ? 'npm run lint' : `${packageManager} lint`
219234

220235
console.info(
221236
'\n' +
222-
`${bold(yellow('package.json'))} and ${bold(blue('eslint.config.js'))} have been updated.\n` +
223-
`Now please run ${bold(green(installCommand))} to re-install the dependencies.\n` +
224-
`Then you can run ${bold(green(lintCommand))} to lint your files.`
237+
`${bold(yellow('package.json'))} and ${bold(blue('eslint.config.js'))} have been updated.\n` +
238+
`Now please run ${bold(green(installCommand))} to re-install the dependencies.\n` +
239+
`Then you can run ${bold(green(lintCommand))} to lint your files.`,
225240
)

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function createConfig({
2020

2121
const pkg = {
2222
devDependencies: pickDependencies(['eslint', 'eslint-plugin-vue']),
23-
scripts: {}
23+
scripts: {},
2424
}
2525

2626
const fileExtensions = ['vue']
@@ -55,7 +55,11 @@ export default function createConfig({
5555

5656
if (needsOxlint) {
5757
additionalConfigs.push({
58-
devDependencies: pickDependencies(['oxlint', 'eslint-plugin-oxlint', 'npm-run-all2']),
58+
devDependencies: pickDependencies([
59+
'oxlint',
60+
'eslint-plugin-oxlint',
61+
'npm-run-all2',
62+
]),
5963
afterVuePlugin: [
6064
{
6165
importer: "import oxlint from 'eslint-plugin-oxlint'",

0 commit comments

Comments
 (0)