From cefc966d8021d0dadecb701eb2dc5f13d52da8c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rogger=20andr=C3=A9=20valverde=20flores?= Date: Sun, 27 Sep 2020 01:17:05 -0500 Subject: [PATCH 1/4] feat(ignore-path): define new flag for ignore files --- README.md | 7 ++++++- bin/pretty-quick.js | 1 + src/index.js | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fde34e8..aa3fdd3 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/bin/pretty-quick.js b/bin/pretty-quick.js index 92ad1a1..541745c 100755 --- a/bin/pretty-quick.js +++ b/bin/pretty-quick.js @@ -10,6 +10,7 @@ const prettyQuick = require('..').default; const args = mri(process.argv.slice(2), { alias: { 'resolve-config': 'resolveConfig', + 'ignore-path': 'ignorePath', }, }); diff --git a/src/index.js b/src/index.js index 4aa5889..1455a4b 100644 --- a/src/index.js +++ b/src/index.js @@ -15,6 +15,7 @@ export default ( branch, bail, check, + ignorePath = '.prettierignore', verbose, onFoundSinceRevision, onFoundChangedFiles, @@ -35,7 +36,7 @@ export default ( onFoundSinceRevision && onFoundSinceRevision(scm.name, revision); - const rootIgnorer = createIgnorer(directory); + const rootIgnorer = createIgnorer(directory, ignorePath); const cwdIgnorer = currentDirectory !== directory ? createIgnorer(currentDirectory) From d43d0fc27213e3e53d3a14b2788b68815dc9c22e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rogger=20andr=C3=A9=20valverde=20flores?= Date: Tue, 13 Oct 2020 08:06:11 -0500 Subject: [PATCH 2/4] refactor: addressing comments --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 1455a4b..88aff35 100644 --- a/src/index.js +++ b/src/index.js @@ -15,7 +15,7 @@ export default ( branch, bail, check, - ignorePath = '.prettierignore', + ignorePath, verbose, onFoundSinceRevision, onFoundChangedFiles, @@ -39,7 +39,7 @@ export default ( const rootIgnorer = createIgnorer(directory, ignorePath); const cwdIgnorer = currentDirectory !== directory - ? createIgnorer(currentDirectory) + ? createIgnorer(currentDirectory, ignorePath) : () => true; const changedFiles = scm From 895564c26b16e15d9f2b47b9d693499f30f14302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rogger=20andr=C3=A9=20valverde=20flores?= Date: Tue, 13 Oct 2020 08:47:07 -0500 Subject: [PATCH 3/4] test: adding --ignore-path cases --- src/__tests__/scm-git.test.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/__tests__/scm-git.test.js b/src/__tests__/scm-git.test.js index ac8e9a9..0b864aa 100644 --- a/src/__tests__/scm-git.test.js +++ b/src/__tests__/scm-git.test.js @@ -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']]); + }); }); From c52346b72f93942ee033715dee89dbe544e64f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rogger=20andr=C3=A9=20valverde=20flores?= Date: Tue, 13 Oct 2020 20:44:01 -0500 Subject: [PATCH 4/4] test: adding scm-hg tests --- src/__tests__/scm-hg.test.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/__tests__/scm-hg.test.js b/src/__tests__/scm-hg.test.js index 0de70da..61dd3bc 100644 --- a/src/__tests__/scm-hg.test.js +++ b/src/__tests__/scm-hg.test.js @@ -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']]); + }); });