Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: prettier/pretty-quick
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.0.2
Choose a base ref
...
head repository: prettier/pretty-quick
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.1.0
Choose a head ref
  • 2 commits
  • 5 files changed
  • 2 contributors

Commits on Sep 16, 2020

  1. doc: update npx usage for v3

    azz authored Sep 16, 2020
    Copy the full SHA
    8c994bc View commit details

Commits on Oct 14, 2020

  1. 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
    roggervalf authored Oct 14, 2020
    1
    Copy the full SHA
    eaf29e2 View commit details
Showing with 66 additions and 5 deletions.
  1. +10 −3 README.md
  2. +1 −0 bin/pretty-quick.js
  3. +26 −0 src/__tests__/scm-git.test.js
  4. +26 −0 src/__tests__/scm-hg.test.js
  5. +3 −2 src/index.js
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -42,9 +42,11 @@ yarn pretty-quick
With [`npx`](https://npm.im/npx):

```shellsession
npx pretty-quick
npx -p prettier@latest -p pretty-quick pretty-quick
```

> Note: You can (_should_) change `latest` to a specific version of Prettier.
With `npm`:

1. Add `"pretty-quick": "pretty-quick"` to the `"scripts"` section of `package.json`.
@@ -62,7 +64,7 @@ yarn add --dev husky

In `package.json`, add:

```
```json
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
@@ -140,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
@@ -10,6 +10,7 @@ const prettyQuick = require('..').default;
const args = mri(process.argv.slice(2), {
alias: {
'resolve-config': 'resolveConfig',
'ignore-path': 'ignorePath',
},
});

26 changes: 26 additions & 0 deletions src/__tests__/scm-git.test.js
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -15,6 +15,7 @@ export default (
branch,
bail,
check,
ignorePath,
verbose,
onFoundSinceRevision,
onFoundChangedFiles,
@@ -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