diff options
author | Sean McGivern <sean@gitlab.com> | 2018-03-30 12:58:20 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2018-03-30 12:58:20 +0100 |
commit | 6412c4c54a7a824e108899a34b1ecec5cbdcec4b (patch) | |
tree | afe9fa7485520c60d91315d8f73c6f1d64108c8c /scripts/frontend/prettier.js | |
parent | ddb23d3b2ba7c646cff6a5d21957194fc3474418 (diff) | |
parent | fa1eabe8e82f7635f2aa51733c727728577c7644 (diff) | |
download | gitlab-ce-6412c4c54a7a824e108899a34b1ecec5cbdcec4b.tar.gz |
Merge branch 'master' into stuartnelson3/gitlab-ce-stn/issue-due-email
Diffstat (limited to 'scripts/frontend/prettier.js')
-rw-r--r-- | scripts/frontend/prettier.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/scripts/frontend/prettier.js b/scripts/frontend/prettier.js index 2708340b48e..39de77bc333 100644 --- a/scripts/frontend/prettier.js +++ b/scripts/frontend/prettier.js @@ -1,6 +1,8 @@ const glob = require('glob'); const prettier = require('prettier'); const fs = require('fs'); +const path = require('path'); +const prettierIgnore = require('ignore')(); const getStagedFiles = require('./frontend_script_utils').getStagedFiles; @@ -10,6 +12,10 @@ const allFiles = mode === 'check-all' || mode === 'save-all'; const config = { patterns: ['**/*.js', '**/*.vue', '**/*.scss'], + /* + * The ignore patterns below are just to reduce search time with glob, as it includes the + * folders with the most ignored assets, the actual `.prettierignore` will be used later on + */ ignore: ['**/node_modules/**', '**/vendor/**', '**/public/**'], parsers: { js: 'babylon', @@ -17,6 +23,20 @@ const config = { scss: 'css', }, }; + +/* + * Unfortunately the prettier API does not expose support for `.prettierignore` files, they however + * use the ignore package, so we do the same. We simply cannot use the glob package, because + * gitignore style is not compatible with globs ignore style. + */ +prettierIgnore.add( + fs + .readFileSync(path.join(__dirname, '../../', '.prettierignore')) + .toString() + .trim() + .split(/\r?\n/) +); + const availableExtensions = Object.keys(config.parsers); console.log(`Loading ${allFiles ? 'All' : 'Staged'} Files ...`); @@ -44,6 +64,8 @@ if (allFiles) { files = stagedFiles.filter(f => availableExtensions.includes(f.split('.').pop())); } +files = prettierIgnore.filter(files); + if (!files.length) { console.log('No Files found to process with Prettier'); return; |