Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verbose #46

Merged
merged 4 commits into from Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
});
};