summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Zallmann <tzallmann@gitlab.com>2018-03-14 10:17:15 +0100
committerTim Zallmann <tzallmann@gitlab.com>2018-03-14 10:17:15 +0100
commit551dcb5cc09d2f400783183b42c32acd48bef5c7 (patch)
tree970db5561a0ab3a7830419728b6f43023bdd29dc
parent535f9b5be9bc05f517070f9e6800c906b61c9543 (diff)
downloadgitlab-ce-tz-prettier-base.tar.gz
Made speed optimisations to the scripttz-prettier-base
Documentation updates Reverted config prettifiying
-rw-r--r--.eslintrc12
-rw-r--r--doc/development/new_fe_guide/style/index.md2
-rw-r--r--doc/development/new_fe_guide/style/prettier.md40
-rw-r--r--scripts/frontend/frontend_script_utils.js11
-rw-r--r--scripts/frontend/prettier.js10
5 files changed, 52 insertions, 23 deletions
diff --git a/.eslintrc b/.eslintrc
index fda31a27158..263372497b2 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -4,7 +4,10 @@
"browser": true,
"es6": true
},
- "extends": ["airbnb-base", "plugin:vue/recommended"],
+ "extends": [
+ "airbnb-base",
+ "plugin:vue/recommended"
+ ],
"globals": {
"__webpack_public_path__": true,
"gl": false,
@@ -14,7 +17,12 @@
"parserOptions": {
"parser": "babel-eslint"
},
- "plugins": ["filenames", "import", "html", "promise"],
+ "plugins": [
+ "filenames",
+ "import",
+ "html",
+ "promise"
+ ],
"settings": {
"html/html-extensions": [".html", ".html.raw"],
"import/resolver": {
diff --git a/doc/development/new_fe_guide/style/index.md b/doc/development/new_fe_guide/style/index.md
index 2cea04f8f22..ebee57bebbf 100644
--- a/doc/development/new_fe_guide/style/index.md
+++ b/doc/development/new_fe_guide/style/index.md
@@ -8,6 +8,8 @@
## [Vue style guide](vue.md)
+# Tooling
+
## [Prettier](prettier.md)
Our code is automatically formatted with [Prettier](https://prettier.io) to follow our guidelines.
diff --git a/doc/development/new_fe_guide/style/prettier.md b/doc/development/new_fe_guide/style/prettier.md
index 4330335af25..6a80ae6f2e8 100644
--- a/doc/development/new_fe_guide/style/prettier.md
+++ b/doc/development/new_fe_guide/style/prettier.md
@@ -1,29 +1,45 @@
# Formatting with Prettier
-Our code is automatically formatted with [Prettier](https://prettier.io) to follow our guidelines. Prettier is taking care of formatting .js, .vue and .scss files based on the standard prettier rules. You can find all settings for Prettier in `.prettierrc`.
+Our code is automatically formatted with [Prettier](https://prettier.io) to follow our style guides. Prettier is taking care of formatting .js, .vue, and .scss files based on the standard prettier rules. You can find all settings for Prettier in `.prettierrc`.
## Editor
-The easiest way to include prettier in your workflow is by setting up your preferred editor (all major editors are supported) accordingly. We suggest setting it up to run automatically on save of each file. Find [here](https://prettier.io/docs/en/editors.html) the best way to set it up in your preferred editor.
+The easiest way to include prettier in your workflow is by setting up your preferred editor (all major editors are supported) accordingly. We suggest setting up prettier to run automatically when each file is saved. Find [here](https://prettier.io/docs/en/editors.html) the best way to set it up in your preferred editor.
+
+Please take care that you only let Prettier format the same file types as the global Yarn script does (.js, .vue, and .scss). In VSCode by example you can easily exclude file formats in your settings file:
+
+```
+ "prettier.disableLanguages": [
+ "json",
+ "markdown"
+ ],
+```
## Yarn Script
-There are the following yarn scripts available to do global formatting:
+The following yarn scripts are available to do global formatting:
-> yarn prettier-changed-save
+```
+yarn prettier-changed-save
+```
Updates all currently changed files (based on git) with Prettier and saves the needed changes.
-> yarn prettier-changed
-
-Checks all currently changed files (based on git) with Prettier and writes in the console which files would need manual updating.
+```
+yarn prettier-changed
+```
+Checks all currently modified files (based on `git diff`) with Prettier and log which files would need manual updating to the console.
-> yarn prettier-all
+```
+yarn prettier-all
+```
-Checks all files with Prettier and writes in the console which files would need manual updating.
+Checks all files with Prettier and logs which files need manual updating to the console.
-> yarn prettier-all-save
+```
+yarn prettier-all-save
+```
-Updates all files through Prettier. (Should only be used to test global rule updates to not end up with huge MR's).
+Formats all files in the repository with Prettier. (This should only be used to test global rule updates otherwise you would end up with huge MR's).
-The actual logic of these Yarn scripts can be found in `/scripts/frontend/prettier.js`.
+The source of these Yarn scripts can be found in `/scripts/frontend/prettier.js`.
diff --git a/scripts/frontend/frontend_script_utils.js b/scripts/frontend/frontend_script_utils.js
index c942812ca74..99628ba428d 100644
--- a/scripts/frontend/frontend_script_utils.js
+++ b/scripts/frontend/frontend_script_utils.js
@@ -5,7 +5,6 @@ const exec = (command, args) => {
const options = {
cwd: process.cwd(),
env: process.env,
- stdio: 'pipe',
encoding: 'utf-8',
};
return execFileSync(command, args, options);
@@ -18,12 +17,14 @@ const execGitCmd = args =>
.split('\n');
module.exports = {
- getChangedFiles: () =>
- execGitCmd([
+ getChangedFiles: fileExtensionFilter => {
+ const gitOptions = [
'diff',
'--name-only',
- '--no-renames',
'--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 c191dcc2a98..3df9d7c2bb5 100644
--- a/scripts/frontend/prettier.js
+++ b/scripts/frontend/prettier.js
@@ -11,17 +11,20 @@ const allFiles = mode === 'check-all' || mode === 'save-all';
const config = {
patterns: ['**/*.js', '**/*.vue', '**/*.scss'],
- ignore: ['**/node_modules/**', '**/vendor/**'],
+ ignore: ['**/node_modules/**', '**/vendor/**', '**/public/**'],
parsers: {
js: 'babylon',
vue: 'vue',
scss: 'css',
},
};
+const availableExtensions = Object.keys(config.parsers);
console.log(`Loading ${allFiles ? 'All' : 'Changed'} Files ...`);
-const changedFiles = allFiles ? null : getChangedFiles();
+const changedFiles = allFiles
+ ? null
+ : getChangedFiles(availableExtensions.map(ext => `*.${ext}`));
if (changedFiles) {
if (!changedFiles.length || (changedFiles.length === 1 && !changedFiles[0])) {
@@ -44,7 +47,6 @@ if (allFiles) {
.sync(globPattern, { ignore })
.filter(f => allFiles || changedFiles.includes(f));
} else {
- const availableExtensions = Object.keys(config.parsers);
files = changedFiles.filter(f =>
availableExtensions.includes(f.split('.').pop()),
);
@@ -79,7 +81,7 @@ prettier
} else if (!prettier.check(input, options)) {
if (!didWarn) {
console.log(
- '\n===============================\nGitLab CE uses Prettier to format all JavaScript code.\nPlease format each file listed below or run "yarn prettier-changed-save"\n===============================\n',
+ '\n===============================\nGitLab uses Prettier to format all JavaScript code.\nPlease format each file listed below or run "yarn prettier-changed-save"\n===============================\n',
);
didWarn = true;
}