Skip to content

Commit 851ddc1

Browse files
flurmboazz
authored andcommitted
feat: add --verbose flag (#46)
* added verbose flag functionality * documentation for verbose flag * remove onUnchangedFile, it seems redundant * added tests for verbose flag
1 parent a318e7e commit 851ddc1

File tree

6 files changed

+55
-1
lines changed

6 files changed

+55
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ Use with the `--staged` flag to skip re-staging files after formatting.
8888

8989
When not in `staged` pre-commit mode, use this flag to compare changes with the specified branch. Defaults to `master` (git) / `default` (hg) branch.
9090

91+
### `--verbose`
92+
93+
Outputs the name of each file right before it is proccessed. This can be useful if Prettier throws an error and you can't identify which file is causing the problem.
94+
9195
<!-- Undocumented = Unsupported :D
9296
9397
### `--config`

bin/pretty-quick.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ prettyQuick(
3737
onWriteFile: file => {
3838
console.log(`✍️ Fixing up ${chalk.bold(file)}.`);
3939
},
40+
41+
onExamineFile: file => {
42+
console.log(`🔍 Examining ${chalk.bold(file)}.`);
43+
},
4044
})
4145
);
4246

src/__tests__/scm-git.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,24 @@ describe('with git', () => {
221221
cwd: '/',
222222
});
223223
});
224+
225+
test('with --verbose calls onExamineFile', () => {
226+
const onExamineFile = jest.fn();
227+
mockGitFs();
228+
229+
prettyQuick('root', { since: 'banana', verbose: true, onExamineFile });
230+
231+
expect(onExamineFile).toHaveBeenCalledWith('./foo.js');
232+
expect(onExamineFile).toHaveBeenCalledWith('./bar.md');
233+
});
234+
235+
test('without --verbose does NOT call onExamineFile', () => {
236+
const onExamineFile = jest.fn();
237+
mockGitFs();
238+
239+
prettyQuick('root', { since: 'banana', onExamineFile });
240+
241+
expect(onExamineFile).not.toHaveBeenCalledWith('./foo.js');
242+
expect(onExamineFile).not.toHaveBeenCalledWith('./bar.md');
243+
});
224244
});

src/__tests__/scm-hg.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,22 @@ describe('with hg', () => {
134134
cwd: '/',
135135
});
136136
});
137+
138+
test('with --verbose calls onExamineFile', () => {
139+
const onExamineFile = jest.fn();
140+
mockHgFs();
141+
prettyQuick('root', { since: 'banana', verbose: true, onExamineFile });
142+
143+
expect(onExamineFile).toHaveBeenCalledWith('./foo.js');
144+
expect(onExamineFile).toHaveBeenCalledWith('./bar.md');
145+
});
146+
147+
test('without --verbose does NOT call onExamineFile', () => {
148+
const onExamineFile = jest.fn();
149+
mockHgFs();
150+
prettyQuick('root', { since: 'banana', onExamineFile });
151+
152+
expect(onExamineFile).not.toHaveBeenCalledWith('./foo.js');
153+
expect(onExamineFile).not.toHaveBeenCalledWith('./bar.md');
154+
});
137155
});

src/formatFiles.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import { readFileSync, writeFileSync } from 'fs';
22
import { resolveConfig, format } from 'prettier';
33
import { join } from 'path';
44

5-
export default (directory, files, { config, onWriteFile } = {}) => {
5+
export default (
6+
directory,
7+
files,
8+
{ config, onWriteFile, onExamineFile } = {}
9+
) => {
610
for (const relative of files) {
11+
onExamineFile && onExamineFile(relative);
712
const file = join(directory, relative);
813
const options = resolveConfig.sync(file, { config, editorconfig: true });
914
const input = readFileSync(file, 'utf8');

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ export default (
1111
staged,
1212
restage = true,
1313
branch,
14+
verbose,
1415
onFoundSinceRevision,
1516
onFoundChangedFiles,
1617
onPartiallyStagedFile,
1718
onWriteFile,
19+
onExamineFile,
1820
} = {}
1921
) => {
2022
const scm = scms(currentDirectory);
@@ -55,5 +57,6 @@ export default (
5557
}
5658
}
5759
},
60+
onExamineFile: verbose && onExamineFile,
5861
});
5962
};

0 commit comments

Comments
 (0)