Skip to content

Commit eaf29e2

Browse files
authoredOct 14, 2020
feat: add an --ignore-path flag (#115)
* feat(ignore-path): define new flag for ignore files * refactor: addressing comments * test: adding --ignore-path cases * test: adding scm-hg tests
1 parent 8c994bc commit eaf29e2

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed
 

‎README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ For example `pretty-quick --since HEAD` will format only staged files.
142142
143143
-->
144144

145+
### `--ignore-path`
146+
147+
Check an alternative file for ignoring files with the same format as [`.prettierignore`](https://prettier.io/docs/en/ignore#ignoring-files).
148+
For example `pretty-quick --ignore-path=.gitignore`
149+
145150
## Configuration and Ignore Files
146151

147-
`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.
152+
`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.

‎bin/pretty-quick.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const prettyQuick = require('..').default;
1010
const args = mri(process.argv.slice(2), {
1111
alias: {
1212
'resolve-config': 'resolveConfig',
13+
'ignore-path': 'ignorePath',
1314
},
1415
});
1516

‎src/__tests__/scm-git.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,30 @@ describe('with git', () => {
332332
prettyQuick('/sub-directory/', { since: 'banana', onWriteFile });
333333
expect(onWriteFile.mock.calls).toEqual([['./foo.js']]);
334334
});
335+
336+
test('with --ignore-path to ignore files matching patterns from the repositories root .ignorePath', () => {
337+
const onWriteFile = jest.fn();
338+
mockGitFs('', {
339+
'/.ignorePath': '*.md',
340+
});
341+
prettyQuick('/sub-directory/', {
342+
since: 'banana',
343+
onWriteFile,
344+
ignorePath: '/.ignorePath',
345+
});
346+
expect(onWriteFile.mock.calls).toEqual([['./foo.js']]);
347+
});
348+
349+
test('with --ignore-path to ignore files matching patterns from the working directories .ignorePath', () => {
350+
const onWriteFile = jest.fn();
351+
mockGitFs('', {
352+
'/sub-directory/.ignorePath': '*.md',
353+
});
354+
prettyQuick('/sub-directory/', {
355+
since: 'banana',
356+
onWriteFile,
357+
ignorePath: '/.ignorePath',
358+
});
359+
expect(onWriteFile.mock.calls).toEqual([['./foo.js']]);
360+
});
335361
});

‎src/__tests__/scm-hg.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,30 @@ describe('with hg', () => {
231231
prettyQuick('/sub-directory/', { since: 'banana', onWriteFile });
232232
expect(onWriteFile.mock.calls).toEqual([['./foo.js']]);
233233
});
234+
235+
test('with --ignore-path to ignore files matching patterns from the repositories root .ignorePath', () => {
236+
const onWriteFile = jest.fn();
237+
mockHgFs({
238+
'/.ignorePath': '*.md',
239+
});
240+
prettyQuick('/sub-directory/', {
241+
since: 'banana',
242+
onWriteFile,
243+
ignorePath: '/.ignorePath',
244+
});
245+
expect(onWriteFile.mock.calls).toEqual([['./foo.js']]);
246+
});
247+
248+
test('with --ignore-path to ignore files matching patterns from the working directories .ignorePath', () => {
249+
const onWriteFile = jest.fn();
250+
mockHgFs({
251+
'/.ignorePath': '*.md',
252+
});
253+
prettyQuick('/sub-directory/', {
254+
since: 'banana',
255+
onWriteFile,
256+
ignorePath: '/.ignorePath',
257+
});
258+
expect(onWriteFile.mock.calls).toEqual([['./foo.js']]);
259+
});
234260
});

‎src/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default (
1515
branch,
1616
bail,
1717
check,
18+
ignorePath,
1819
verbose,
1920
onFoundSinceRevision,
2021
onFoundChangedFiles,
@@ -35,10 +36,10 @@ export default (
3536

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

38-
const rootIgnorer = createIgnorer(directory);
39+
const rootIgnorer = createIgnorer(directory, ignorePath);
3940
const cwdIgnorer =
4041
currentDirectory !== directory
41-
? createIgnorer(currentDirectory)
42+
? createIgnorer(currentDirectory, ignorePath)
4243
: () => true;
4344

4445
const changedFiles = scm

0 commit comments

Comments
 (0)
Please sign in to comment.