Skip to content

Commit d6f8261

Browse files
author
linfeng
committed
fix: add prettier format to lint
1 parent bc216db commit d6f8261

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/utils/lint.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export async function lint(options?: Partial<DefaultOptions>) {
4545
});
4646

4747
let lintFiles: string[] = [];
48+
let prettierFiles: string[] = [];
4849

4950
if (mergedOptions.lintAll) {
5051
if (globalState.selectedSourceType === 'root') {
@@ -73,6 +74,10 @@ export async function lint(options?: Partial<DefaultOptions>) {
7374
const lintResult = await spinner(
7475
`Lint ${mergedOptions.lintAll ? 'all' : ''} ${lintFiles.length} files.`,
7576
async () => {
77+
const files = execSync(
78+
`${globalState.projectRootPath}/node_modules/.bin/prettier --list-different --write ${lintFiles.join(' ')}`,
79+
);
80+
prettierFiles = _.compact(files.toString().split('\n'));
7681
return cli.executeOnFiles(lintFiles);
7782
},
7883
);
@@ -150,15 +155,21 @@ export async function lint(options?: Partial<DefaultOptions>) {
150155
}
151156
}
152157

153-
if (mergedOptions.needFix && lintResult.results.some(each => each.output)) {
154-
const fixedFiles = lintResult.results.filter(each => each.output);
158+
if (mergedOptions.needFix && (lintResult.results.some(each => each.output) || prettierFiles.length > 0)) {
159+
const fixedFiles = _.uniq(
160+
lintResult.results
161+
.filter(each => each.output)
162+
.map(item => item.filePath)
163+
.concat(prettierFiles),
164+
);
165+
155166
// eslint-disable-next-line no-console
156167
console.log(colors.yellow(`${fixedFiles.length} files autofixed, please recheck your code.`));
157-
execSync(`git add ${fixedFiles.map(file => file.filePath).join(' ')}`);
158-
process.exit(1);
168+
execSync(`git add ${fixedFiles.join(' ')}`);
159169
}
160170

161171
if (mergedOptions.typeCheck) {
162172
typeChecker();
173+
process.exit(1);
163174
}
164175
}

0 commit comments

Comments
 (0)