Skip to content

Commit 9fde3d1

Browse files
committed
feat: use separate commands for linting and formatting
Closes #190
1 parent a01a6ab commit 9fde3d1

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

Diff for: index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ async function init() {
450450
}
451451
console.log(` ${bold(green(getCommand(packageManager, 'install')))}`)
452452
if (needsPrettier) {
453-
console.log(` ${bold(green(getCommand(packageManager, 'lint')))}`)
453+
console.log(` ${bold(green(getCommand(packageManager, 'format')))}`)
454454
}
455455
console.log(` ${bold(green(getCommand(packageManager, 'dev')))}`)
456456
console.log()

Diff for: utils/renderEslint.ts

+18-10
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,27 @@ export default function renderEslint(
4545
additionalDependencies
4646
})
4747

48+
const scripts: Record<string, string> = {
49+
// Note that we reuse .gitignore here to avoid duplicating the configuration
50+
lint: needsTypeScript
51+
? 'eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore'
52+
: 'eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore'
53+
}
54+
55+
// Theoretically, we could add Prettier without requring ESLint.
56+
// But it doesn't seem to be a good practice, so we just leave it here.
57+
if (needsPrettier) {
58+
// Default to only format the `src/` directory to avoid too much noise, and
59+
// the need for a `.prettierignore` file.
60+
// Users can still append any paths they'd like to format to the command,
61+
// e.g. `npm run format cypress/`.
62+
scripts.format = 'prettier --write src/'
63+
}
64+
4865
// update package.json
4966
const packageJsonPath = path.resolve(rootDir, 'package.json')
5067
const existingPkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
51-
const updatedPkg = sortDependencies(
52-
deepMerge(deepMerge(existingPkg, pkg), {
53-
scripts: {
54-
// Note that we reuse .gitignore here to avoid duplicating the configuration
55-
lint: needsTypeScript
56-
? 'eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore'
57-
: 'eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore'
58-
}
59-
})
60-
)
68+
const updatedPkg = sortDependencies(deepMerge(deepMerge(existingPkg, pkg), { scripts }))
6169
fs.writeFileSync(packageJsonPath, JSON.stringify(updatedPkg, null, 2) + '\n', 'utf-8')
6270

6371
// write to .eslintrc.cjs, .prettierrc.json, etc.

0 commit comments

Comments
 (0)