summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Eipert <git@leipert.io>2018-03-26 07:39:14 +0000
committerPhil Hughes <me@iamphill.com>2018-03-26 07:39:14 +0000
commitd023244aa5a71c9cf0e68f196c0a402a8ccc951f (patch)
treee49b6311e720191c1fbf4113bfb144f54cceca55
parent391732a2c1b04baf565c77f2788a1ec035b1d85e (diff)
downloadgitlab-ce-d023244aa5a71c9cf0e68f196c0a402a8ccc951f.tar.gz
Make use of the prettier ignore file during our save script
-rw-r--r--package.json1
-rw-r--r--scripts/frontend/prettier.js22
-rw-r--r--yarn.lock2
3 files changed, 24 insertions, 1 deletions
diff --git a/package.json b/package.json
index c81020f631e..56fd2575e91 100644
--- a/package.json
+++ b/package.json
@@ -107,6 +107,7 @@
"eslint-plugin-jasmine": "^2.1.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-vue": "^4.0.1",
+ "ignore": "^3.3.7",
"istanbul": "^0.4.5",
"jasmine-core": "^2.9.0",
"jasmine-jquery": "^2.1.1",
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;
diff --git a/yarn.lock b/yarn.lock
index 36683a2a480..af7bda5d562 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4232,7 +4232,7 @@ ignore@^3.2.0:
version "3.3.3"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.3.tgz#432352e57accd87ab3110e82d3fea0e47812156d"
-ignore@^3.3.5:
+ignore@^3.3.5, ignore@^3.3.7:
version "3.3.7"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.7.tgz#612289bfb3c220e186a58118618d5be8c1bab021"