Skip to content

Commit

Permalink
feat: add --verbose flag (#46)
Browse files Browse the repository at this point in the history
* added verbose flag functionality

* documentation for verbose flag

* remove onUnchangedFile, it seems redundant

* added tests for verbose flag
  • Loading branch information
flurmbo authored and azz committed Oct 12, 2018
1 parent a318e7e commit 851ddc1
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -88,6 +88,10 @@ Use with the `--staged` flag to skip re-staging files after formatting.

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

### `--verbose`

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.

<!-- Undocumented = Unsupported :D
### `--config`
Expand Down
4 changes: 4 additions & 0 deletions bin/pretty-quick.js
Expand Up @@ -37,6 +37,10 @@ prettyQuick(
onWriteFile: file => {
console.log(`✍️ Fixing up ${chalk.bold(file)}.`);
},

onExamineFile: file => {
console.log(`🔍 Examining ${chalk.bold(file)}.`);
},
})
);

Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/scm-git.test.js
Expand Up @@ -221,4 +221,24 @@ describe('with git', () => {
cwd: '/',
});
});

test('with --verbose calls onExamineFile', () => {
const onExamineFile = jest.fn();
mockGitFs();

prettyQuick('root', { since: 'banana', verbose: true, onExamineFile });

expect(onExamineFile).toHaveBeenCalledWith('./foo.js');
expect(onExamineFile).toHaveBeenCalledWith('./bar.md');
});

test('without --verbose does NOT call onExamineFile', () => {
const onExamineFile = jest.fn();
mockGitFs();

prettyQuick('root', { since: 'banana', onExamineFile });

expect(onExamineFile).not.toHaveBeenCalledWith('./foo.js');
expect(onExamineFile).not.toHaveBeenCalledWith('./bar.md');
});
});
18 changes: 18 additions & 0 deletions src/__tests__/scm-hg.test.js
Expand Up @@ -134,4 +134,22 @@ describe('with hg', () => {
cwd: '/',
});
});

test('with --verbose calls onExamineFile', () => {
const onExamineFile = jest.fn();
mockHgFs();
prettyQuick('root', { since: 'banana', verbose: true, onExamineFile });

expect(onExamineFile).toHaveBeenCalledWith('./foo.js');
expect(onExamineFile).toHaveBeenCalledWith('./bar.md');
});

test('without --verbose does NOT call onExamineFile', () => {
const onExamineFile = jest.fn();
mockHgFs();
prettyQuick('root', { since: 'banana', onExamineFile });

expect(onExamineFile).not.toHaveBeenCalledWith('./foo.js');
expect(onExamineFile).not.toHaveBeenCalledWith('./bar.md');
});
});
7 changes: 6 additions & 1 deletion src/formatFiles.js
Expand Up @@ -2,8 +2,13 @@ import { readFileSync, writeFileSync } from 'fs';
import { resolveConfig, format } from 'prettier';
import { join } from 'path';

export default (directory, files, { config, onWriteFile } = {}) => {
export default (
directory,
files,
{ config, onWriteFile, onExamineFile } = {}
) => {
for (const relative of files) {
onExamineFile && onExamineFile(relative);
const file = join(directory, relative);
const options = resolveConfig.sync(file, { config, editorconfig: true });
const input = readFileSync(file, 'utf8');
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Expand Up @@ -11,10 +11,12 @@ export default (
staged,
restage = true,
branch,
verbose,
onFoundSinceRevision,
onFoundChangedFiles,
onPartiallyStagedFile,
onWriteFile,
onExamineFile,
} = {}
) => {
const scm = scms(currentDirectory);
Expand Down Expand Up @@ -55,5 +57,6 @@ export default (
}
}
},
onExamineFile: verbose && onExamineFile,
});
};

0 comments on commit 851ddc1

Please sign in to comment.