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.1.0
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.1
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Apr 14, 2021

  1. docs: fix ignore-path description (#119)

    * feat(ignore-path): define new flag for ignore files
    
    * refactor: addressing comments
    
    * test: adding --ignore-path cases
    
    * test: adding scm-hg tests
    
    * docs(readme): fix ignore-path description
    roggervalf authored Apr 14, 2021
    Copy the full SHA
    2972ade View commit details

Commits on Jun 17, 2021

  1. Copy the full SHA
    262a02d View commit details
Showing with 15 additions and 3 deletions.
  1. +1 −1 README.md
  2. +3 −0 src/__tests__/isSupportedExtension.test.js
  3. +11 −2 src/isSupportedExtension.js
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -145,7 +145,7 @@ 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`
For example `pretty-quick --ignore-path .gitignore`

## Configuration and Ignore Files

3 changes: 3 additions & 0 deletions src/__tests__/isSupportedExtension.test.js
Original file line number Diff line number Diff line change
@@ -6,20 +6,23 @@ afterEach(() => jest.clearAllMocks());
test('return true when file with supported extension passed in', () => {
expect(isSupportedExtension(true)('banana.js')).toEqual(true);
expect(prettier.getFileInfo.sync).toHaveBeenCalledWith('banana.js', {
file: 'banana.js',
resolveConfig: true,
});
});

test('return false when file with not supported extension passed in', () => {
expect(isSupportedExtension(true)('banana.txt')).toEqual(false);
expect(prettier.getFileInfo.sync).toHaveBeenCalledWith('banana.txt', {
file: 'banana.txt',
resolveConfig: true,
});
});

test('do not resolve config when false passed', () => {
expect(isSupportedExtension(false)('banana.txt')).toEqual(false);
expect(prettier.getFileInfo.sync).toHaveBeenCalledWith('banana.txt', {
file: 'banana.txt',
resolveConfig: false,
});
});
13 changes: 11 additions & 2 deletions src/isSupportedExtension.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { getFileInfo } from 'prettier';
import { getFileInfo, resolveConfig as prettierResolveConfig } from 'prettier';

export default (resolveConfig) => (file) =>
Boolean(getFileInfo.sync(file, { resolveConfig }).inferredParser);
Boolean(
getFileInfo.sync(file, {
resolveConfig,
...prettierResolveConfig.sync(
file,
{ editorconfig: true },
{ filepath: file },
),
}).inferredParser,
);