diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2018-04-04 20:04:39 +0100 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2018-04-04 20:04:39 +0100 |
commit | 85b45ce94de94a85bb341d2978f1471a21b9a0ff (patch) | |
tree | ab65c6cfefc07fd2a65c20e15d7fda98047886bb /scripts/frontend | |
parent | dd3b1526af1675f7686f189ec41b8d919b6835a2 (diff) | |
parent | cb5bb4dbc67c5dd43bb7b27faf79ca79f8ae3e1f (diff) | |
download | gitlab-ce-85b45ce94de94a85bb341d2978f1471a21b9a0ff.tar.gz |
[ci skip] Merge branch 'master' into 44427-state-management-with-vuex
* master: (544 commits)
Bulk deleting refs is handled by Gitaly by default
Allow assigning and filtering issuables by ancestor group labels
Fix links to subdirectories of a directory with a plus character in its path
Add banzai filter to detect commit message trailers and properly link the users
Render MR commit SHA instead "diffs" when viable
Fix a transient failure by removing unneeded expectations
Revert changelog entry for removed feature
Revert "Allow CI/CD Jobs being grouped on version strings"
Add support for Sidekiq JSON logging
Resolve "Protected branches count is wrong when a wildcard includes several protected branches"
Remove unused form for admin application settings
Use standard codequality job
Resolve "Allow the configuration of a project's merge method via the API"
Move the rest of application settings to expandable blocks
[Rails5] Rename `sort` methods to `sort_by_attribute`
Add better LDAP connection handling
Updated components to PascalCase
Handle invalid params when trying update_username
Move network related app settings to expandable blocks
[Rails5] Update Gemfile.rails5.lock [ci skip]
...
Diffstat (limited to 'scripts/frontend')
-rw-r--r-- | scripts/frontend/frontend_script_utils.js | 8 | ||||
-rw-r--r-- | scripts/frontend/prettier.js | 40 |
2 files changed, 28 insertions, 20 deletions
diff --git a/scripts/frontend/frontend_script_utils.js b/scripts/frontend/frontend_script_utils.js index 2c06747255c..e42b912d359 100644 --- a/scripts/frontend/frontend_script_utils.js +++ b/scripts/frontend/frontend_script_utils.js @@ -1,4 +1,3 @@ -/* eslint import/no-commonjs: "off" */ const execFileSync = require('child_process').execFileSync; const exec = (command, args) => { @@ -18,12 +17,7 @@ const execGitCmd = args => module.exports = { getStagedFiles: fileExtensionFilter => { - const gitOptions = [ - 'diff', - '--name-only', - '--cached', - '--diff-filter=ACMRTUB', - ]; + const gitOptions = ['diff', '--name-only', '--cached', '--diff-filter=ACMRTUB']; if (fileExtensionFilter) gitOptions.push(...fileExtensionFilter); return execGitCmd(gitOptions); }, diff --git a/scripts/frontend/prettier.js b/scripts/frontend/prettier.js index 863572bf64d..39de77bc333 100644 --- a/scripts/frontend/prettier.js +++ b/scripts/frontend/prettier.js @@ -1,7 +1,8 @@ -/* eslint import/no-commonjs: "off", import/no-extraneous-dependencies: "off", no-console: "off" */ 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; @@ -11,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', @@ -18,13 +23,25 @@ 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 ...`); -const stagedFiles = allFiles - ? null - : getStagedFiles(availableExtensions.map(ext => `*.${ext}`)); +const stagedFiles = allFiles ? null : getStagedFiles(availableExtensions.map(ext => `*.${ext}`)); if (stagedFiles) { if (!stagedFiles.length || (stagedFiles.length === 1 && !stagedFiles[0])) { @@ -41,17 +58,14 @@ let files; if (allFiles) { const ignore = config.ignore; const patterns = config.patterns; - const globPattern = - patterns.length > 1 ? `{${patterns.join(',')}}` : `${patterns.join(',')}`; - files = glob - .sync(globPattern, { ignore }) - .filter(f => allFiles || stagedFiles.includes(f)); + const globPattern = patterns.length > 1 ? `{${patterns.join(',')}}` : `${patterns.join(',')}`; + files = glob.sync(globPattern, { ignore }).filter(f => allFiles || stagedFiles.includes(f)); } else { - files = stagedFiles.filter(f => - availableExtensions.includes(f.split('.').pop()), - ); + 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; @@ -81,7 +95,7 @@ prettier } else if (!prettier.check(input, options)) { if (!didWarn) { console.log( - '\n===============================\nGitLab uses Prettier to format all JavaScript code.\nPlease format each file listed below or run "yarn prettier-staged-save"\n===============================\n', + '\n===============================\nGitLab uses Prettier to format all JavaScript code.\nPlease format each file listed below or run "yarn prettier-staged-save"\n===============================\n' ); didWarn = true; } |