From 3be3d088dd33d884f4a51d0bf129fe5a917926e6 Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Tue, 15 Jan 2019 11:52:29 +0100 Subject: [PATCH] fix: also use .prettierignore from current working directory (#14) --- README.md | 2 +- src/index.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c80287c..ac4f328 100644 --- a/README.md +++ b/README.md @@ -108,4 +108,4 @@ For example `pretty-quick --since HEAD` will format only staged files. ## 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 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, 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. diff --git a/src/index.js b/src/index.js index f1fb2d5..8300cb9 100644 --- a/src/index.js +++ b/src/index.js @@ -29,16 +29,22 @@ export default ( onFoundSinceRevision && onFoundSinceRevision(scm.name, revision); + const rootIgnorer = createIgnorer(directory); + const cwdIgnorer = + process.cwd() !== directory ? createIgnorer(process.cwd()) : () => true; + const changedFiles = scm .getChangedFiles(directory, revision, staged) .filter(isSupportedExtension) - .filter(createIgnorer(directory)); + .filter(rootIgnorer) + .filter(cwdIgnorer); const unstagedFiles = staged ? scm .getUnstagedChangedFiles(directory, revision) .filter(isSupportedExtension) - .filter(createIgnorer(directory)) + .filter(rootIgnorer) + .filter(cwdIgnorer) : []; const wasFullyStaged = f => unstagedFiles.indexOf(f) < 0;