Skip to content

Commit

Permalink
feat: add an --ignore-path flag (#115)
Browse files Browse the repository at this point in the history
* feat(ignore-path): define new flag for ignore files

* refactor: addressing comments

* test: adding --ignore-path cases

* test: adding scm-hg tests
  • Loading branch information
roggervalf authored Oct 14, 2020
1 parent 8c994bc commit eaf29e2
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
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

0 comments on commit eaf29e2

Please sign in to comment.