Skip to content

Commit

Permalink
feat: shebang support
Browse files Browse the repository at this point in the history
- rename "isSupportedExtension" function to "isFileSupported"
- use `prettier.getFileInfo` to detect shebangs
- upgrade prettier to 1.15.0+ (where shebang support was added)
  • Loading branch information
aleclarson committed Dec 27, 2018
1 parent f1d88ae commit 829524a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"precommit": "./bin/pretty-quick.js --staged"
},
"peerDependencies": {
"prettier": ">=1.13.0"
"prettier": ">=1.15.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
Expand All @@ -53,7 +53,7 @@
"husky": "^0.14.3",
"jest": "^23.6.0",
"mock-fs": "^4.4.2",
"prettier": "1.13.0",
"prettier": "1.15.0",
"semantic-release": "^11.0.2"
}
}
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import scms from './scms';
import formatFiles from './formatFiles';
import createIgnorer from './createIgnorer';
import isSupportedExtension from './isSupportedExtension';
import isFileSupported from './isFileSupported';

export default (
currentDirectory,
Expand Down Expand Up @@ -32,13 +32,13 @@ export default (

const changedFiles = scm
.getChangedFiles(rootDirectory, revision, staged)
.filter(isSupportedExtension)
.filter(isFileSupported)
.filter(createIgnorer(rootDirectory));

const unstagedFiles = staged
? scm
.getUnstagedChangedFiles(rootDirectory, revision)
.filter(isSupportedExtension)
.filter(isFileSupported)
.filter(createIgnorer(rootDirectory))
: [];

Expand Down
11 changes: 11 additions & 0 deletions src/isFileSupported.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { extname } from 'path';
import { getFileInfo, getSupportInfo } from 'prettier';

const extensions = getSupportInfo().languages.reduce(
(prev, language) => prev.concat(language.extensions || []),
[]
);

export default file =>
extensions.includes(extname(file)) ||
getFileInfo.sync(file).inferredParser !== null;
9 changes: 0 additions & 9 deletions src/isSupportedExtension.js

This file was deleted.

8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4549,10 +4549,10 @@ preserve@^0.2.0:
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
integrity sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks=

prettier@1.13.0:
version "1.13.0"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.13.0.tgz#054de8d5fb1a4405c845d16183f58a2c301f6f16"
integrity sha512-ubNahzMwHtdrSVGMMNabOHSeBKvZu+N5Z7Tu2CvbTexffL6aHwwOc7/fvEaWYTtvu4CtXnniHGA2vxV/NIH6KQ==
prettier@1.15.0:
version "1.15.0"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.15.0.tgz#c6191a50fbc9056ff770577d64ebd9987cca1dd7"
integrity sha512-NtSOnDRmJaNuruoX0KhDdQ3UGyLNJaSuP2eJn6Q6uSvzQBAJQHZbXgraFPbv8sYbNaMR9nz7scMy55WC+78E6w==

pretty-format@^23.6.0:
version "23.6.0"
Expand Down

0 comments on commit 829524a

Please sign in to comment.