Skip to content

Commit

Permalink
fix: allow non-core file extensions (from plugins) (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
ustramooner authored Jun 17, 2021
1 parent 2972ade commit 262a02d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/__tests__/isSupportedExtension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

0 comments on commit 262a02d

Please sign in to comment.