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

Ignore Path flag #115

Merged
merged 4 commits into from
Oct 14, 2020
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ For example `pretty-quick --since HEAD` will format only staged files.

-->

### `--ignore-path`

Check an alternative file for ignoring files with the same format as [`.prettierignore`](https://prettier.io/docs/en/ignore#ignoring-files).
For example `pretty-quick --ignore-path=.gitignore`

## Configuration and Ignore Files

`pretty-quick` will respect your [`.prettierrc`](https://prettier.io/docs/en/configuration), [`.prettierignore`](https://prettier.io/docs/en/ignore#ignoring-files), and [`.editorconfig`](http://editorconfig.org/) files, so there's no additional setup required. Configuration files will be found by searching up the file system. `.prettierignore` files are only found from the repository root and the working directory that the command was executed from.
`pretty-quick` will respect your [`.prettierrc`](https://prettier.io/docs/en/configuration), [`.prettierignore`](https://prettier.io/docs/en/ignore#ignoring-files), and [`.editorconfig`](http://editorconfig.org/) files if you don't use `--ignore-path` . Configuration files will be found by searching up the file system. `.prettierignore` files are only found from the repository root and the working directory that the command was executed from.
1 change: 1 addition & 0 deletions bin/pretty-quick.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const prettyQuick = require('..').default;
const args = mri(process.argv.slice(2), {
alias: {
'resolve-config': 'resolveConfig',
'ignore-path': 'ignorePath',
},
});

Expand Down
26 changes: 26 additions & 0 deletions src/__tests__/scm-git.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,30 @@ describe('with git', () => {
prettyQuick('/sub-directory/', { since: 'banana', onWriteFile });
expect(onWriteFile.mock.calls).toEqual([['./foo.js']]);
});

test('with --ignore-path to ignore files matching patterns from the repositories root .ignorePath', () => {
const onWriteFile = jest.fn();
mockGitFs('', {
'/.ignorePath': '*.md',
});
prettyQuick('/sub-directory/', {
since: 'banana',
onWriteFile,
ignorePath: '/.ignorePath',
});
expect(onWriteFile.mock.calls).toEqual([['./foo.js']]);
});

test('with --ignore-path to ignore files matching patterns from the working directories .ignorePath', () => {
const onWriteFile = jest.fn();
mockGitFs('', {
'/sub-directory/.ignorePath': '*.md',
});
prettyQuick('/sub-directory/', {
since: 'banana',
onWriteFile,
ignorePath: '/.ignorePath',
});
expect(onWriteFile.mock.calls).toEqual([['./foo.js']]);
});
});
26 changes: 26 additions & 0 deletions src/__tests__/scm-hg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,30 @@ describe('with hg', () => {
prettyQuick('/sub-directory/', { since: 'banana', onWriteFile });
expect(onWriteFile.mock.calls).toEqual([['./foo.js']]);
});

test('with --ignore-path to ignore files matching patterns from the repositories root .ignorePath', () => {
const onWriteFile = jest.fn();
mockHgFs({
'/.ignorePath': '*.md',
});
prettyQuick('/sub-directory/', {
since: 'banana',
onWriteFile,
ignorePath: '/.ignorePath',
});
expect(onWriteFile.mock.calls).toEqual([['./foo.js']]);
});

test('with --ignore-path to ignore files matching patterns from the working directories .ignorePath', () => {
const onWriteFile = jest.fn();
mockHgFs({
'/.ignorePath': '*.md',
});
prettyQuick('/sub-directory/', {
since: 'banana',
onWriteFile,
ignorePath: '/.ignorePath',
});
expect(onWriteFile.mock.calls).toEqual([['./foo.js']]);
});
});
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default (
branch,
bail,
check,
ignorePath,
verbose,
onFoundSinceRevision,
onFoundChangedFiles,
Expand All @@ -35,10 +36,10 @@ export default (

onFoundSinceRevision && onFoundSinceRevision(scm.name, revision);

const rootIgnorer = createIgnorer(directory);
const rootIgnorer = createIgnorer(directory, ignorePath);
const cwdIgnorer =
currentDirectory !== directory
? createIgnorer(currentDirectory)
? createIgnorer(currentDirectory, ignorePath)
: () => true;

const changedFiles = scm
Expand Down