Commit c63e6801 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'ee-44589-problem-with-prettier-setting-trailingcomma-all' into 'master'

Port of Resolve "Problem with prettier setting trailingComma: all" to EE

See merge request gitlab-org/gitlab-ee!5101
parents eedc383f 72da358e
{ {
"presets": [ "presets": [["latest", { "es2015": { "modules": false } }], "stage-2"],
["latest", { "es2015": { "modules": false } }],
"stage-2"
],
"env": { "env": {
"coverage": { "coverage": {
"plugins": [ "plugins": [
["istanbul", { [
"exclude": [ "istanbul",
"spec/javascripts/**/*", {
"app/assets/javascripts/locale/**/app.js" "exclude": ["spec/javascripts/**/*", "app/assets/javascripts/locale/**/app.js"]
] }
}], ],
["transform-define", { [
"transform-define",
{
"process.env.BABEL_ENV": "coverage" "process.env.BABEL_ENV": "coverage"
}] }
]
] ]
} }
} }
......
/app/assets/javascripts/locale/**/app.js
/config/
/builds/ /builds/
/coverage/ /coverage/
/coverage-javascript/ /coverage-javascript/
/node_modules/ /node_modules/
/public/ /public/
/scripts/
/tmp/ /tmp/
/vendor/ /vendor/
karma.config.js karma.config.js
webpack.config.js webpack.config.js
svg.config.js
/app/assets/javascripts/locale/**/app.js
/config/ /app/assets/javascripts/locale/**/app.js
/node_modules/ /node_modules/
/public/ /public/
/vendor/ /vendor/
karma.config.js /tmp/
webpack.config.js
{ {
"printWidth": 100, "printWidth": 100,
"singleQuote": true, "singleQuote": true,
"trailingComma": "es5",
"overrides": [
{
"files": ["**/app/**/*", "**/spec/**/*"],
"options": {
"trailingComma": "all" "trailingComma": "all"
}
}
]
} }
...@@ -5,7 +5,7 @@ var ROOT_PATH = path.resolve(__dirname, '..'); ...@@ -5,7 +5,7 @@ var ROOT_PATH = path.resolve(__dirname, '..');
// remove problematic plugins // remove problematic plugins
if (webpackConfig.plugins) { if (webpackConfig.plugins) {
webpackConfig.plugins = webpackConfig.plugins.filter(function (plugin) { webpackConfig.plugins = webpackConfig.plugins.filter(function(plugin) {
return !( return !(
plugin instanceof webpack.optimize.CommonsChunkPlugin || plugin instanceof webpack.optimize.CommonsChunkPlugin ||
plugin instanceof webpack.optimize.ModuleConcatenationPlugin || plugin instanceof webpack.optimize.ModuleConcatenationPlugin ||
...@@ -34,7 +34,7 @@ module.exports = function(config) { ...@@ -34,7 +34,7 @@ module.exports = function(config) {
// escalated kernel privileges (e.g. docker run --cap-add=CAP_SYS_ADMIN) // escalated kernel privileges (e.g. docker run --cap-add=CAP_SYS_ADMIN)
'--no-sandbox', '--no-sandbox',
], ],
} },
}, },
frameworks: ['jasmine'], frameworks: ['jasmine'],
files: [ files: [
...@@ -55,7 +55,7 @@ module.exports = function(config) { ...@@ -55,7 +55,7 @@ module.exports = function(config) {
reports: ['html', 'text-summary'], reports: ['html', 'text-summary'],
dir: 'coverage-javascript/', dir: 'coverage-javascript/',
subdir: '.', subdir: '.',
fixWebpackSourcePaths: true fixWebpackSourcePaths: true,
}; };
karmaConfig.browserNoActivityTimeout = 60000; // 60 seconds karmaConfig.browserNoActivityTimeout = 60000; // 60 seconds
} }
......
'use strict';
const crypto = require('crypto'); const crypto = require('crypto');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
...@@ -27,10 +25,10 @@ let watchAutoEntries = []; ...@@ -27,10 +25,10 @@ let watchAutoEntries = [];
function generateEntries() { function generateEntries() {
// generate automatic entry points // generate automatic entry points
const autoEntries = {}; const autoEntries = {};
const pageEntries = glob.sync('pages/**/index.js', { cwd: path.join(ROOT_PATH, 'app/assets/javascripts') }); const pageEntries = glob.sync('pages/**/index.js', {
watchAutoEntries = [ cwd: path.join(ROOT_PATH, 'app/assets/javascripts'),
path.join(ROOT_PATH, 'app/assets/javascripts/pages/'), });
]; watchAutoEntries = [path.join(ROOT_PATH, 'app/assets/javascripts/pages/')];
function generateAutoEntries(path, prefix = '.') { function generateAutoEntries(path, prefix = '.') {
const chunkPath = path.replace(/\/index\.js$/, ''); const chunkPath = path.replace(/\/index\.js$/, '');
...@@ -38,7 +36,7 @@ function generateEntries() { ...@@ -38,7 +36,7 @@ function generateEntries() {
autoEntries[chunkName] = `${prefix}/${path}`; autoEntries[chunkName] = `${prefix}/${path}`;
} }
pageEntries.forEach(( path ) => generateAutoEntries(path)); pageEntries.forEach(path => generateAutoEntries(path));
// EE-specific auto entries // EE-specific auto entries
const eePageEntries = glob.sync('pages/**/index.js', { const eePageEntries = glob.sync('pages/**/index.js', {
...@@ -98,8 +96,8 @@ const config = { ...@@ -98,8 +96,8 @@ const config = {
{ {
loader: 'worker-loader', loader: 'worker-loader',
options: { options: {
inline: true inline: true,
} },
}, },
{ loader: 'babel-loader' }, { loader: 'babel-loader' },
], ],
...@@ -110,7 +108,7 @@ const config = { ...@@ -110,7 +108,7 @@ const config = {
loader: 'file-loader', loader: 'file-loader',
options: { options: {
name: '[name].[hash].[ext]', name: '[name].[hash].[ext]',
} },
}, },
{ {
test: /katex.css$/, test: /katex.css$/,
...@@ -120,8 +118,8 @@ const config = { ...@@ -120,8 +118,8 @@ const config = {
{ {
loader: 'css-loader', loader: 'css-loader',
options: { options: {
name: '[name].[hash].[ext]' name: '[name].[hash].[ext]',
} },
}, },
], ],
}, },
...@@ -131,7 +129,7 @@ const config = { ...@@ -131,7 +129,7 @@ const config = {
loader: 'file-loader', loader: 'file-loader',
options: { options: {
name: '[name].[hash].[ext]', name: '[name].[hash].[ext]',
} },
}, },
{ {
test: /monaco-editor\/\w+\/vs\/loader\.js$/, test: /monaco-editor\/\w+\/vs\/loader\.js$/,
...@@ -139,7 +137,7 @@ const config = { ...@@ -139,7 +137,7 @@ const config = {
{ loader: 'exports-loader', options: 'l.global' }, { loader: 'exports-loader', options: 'l.global' },
{ loader: 'imports-loader', options: 'l=>{},this=>l,AMDLoader=>this,module=>undefined' }, { loader: 'imports-loader', options: 'l=>{},this=>l,AMDLoader=>this,module=>undefined' },
], ],
} },
], ],
noParse: [/monaco-editor\/\w+\/vs\//], noParse: [/monaco-editor\/\w+\/vs\//],
...@@ -157,10 +155,10 @@ const config = { ...@@ -157,10 +155,10 @@ const config = {
source: false, source: false,
chunks: false, chunks: false,
modules: false, modules: false,
assets: true assets: true,
}); });
return JSON.stringify(stats, null, 2); return JSON.stringify(stats, null, 2);
} },
}), }),
// prevent pikaday from including moment.js // prevent pikaday from including moment.js
...@@ -177,7 +175,7 @@ const config = { ...@@ -177,7 +175,7 @@ const config = {
new NameAllModulesPlugin(), new NameAllModulesPlugin(),
// assign deterministic chunk ids // assign deterministic chunk ids
new webpack.NamedChunksPlugin((chunk) => { new webpack.NamedChunksPlugin(chunk => {
if (chunk.name) { if (chunk.name) {
return chunk.name; return chunk.name;
} }
...@@ -194,9 +192,12 @@ const config = { ...@@ -194,9 +192,12 @@ const config = {
const pagesBase = path.join(ROOT_PATH, 'app/assets/javascripts/pages'); const pagesBase = path.join(ROOT_PATH, 'app/assets/javascripts/pages');
if (m.resource.indexOf(pagesBase) === 0) { if (m.resource.indexOf(pagesBase) === 0) {
moduleNames.push(path.relative(pagesBase, m.resource) moduleNames.push(
path
.relative(pagesBase, m.resource)
.replace(/\/index\.[a-z]+$/, '') .replace(/\/index\.[a-z]+$/, '')
.replace(/\//g, '__')); .replace(/\//g, '__')
);
} else { } else {
moduleNames.push(path.relative(m.context, m.resource)); moduleNames.push(path.relative(m.context, m.resource));
} }
...@@ -204,7 +205,8 @@ const config = { ...@@ -204,7 +205,8 @@ const config = {
chunk.forEachModule(collectModuleNames); chunk.forEachModule(collectModuleNames);
const hash = crypto.createHash('sha256') const hash = crypto
.createHash('sha256')
.update(moduleNames.join('_')) .update(moduleNames.join('_'))
.digest('hex'); .digest('hex');
...@@ -219,7 +221,10 @@ const config = { ...@@ -219,7 +221,10 @@ const config = {
// copy pre-compiled vendor libraries verbatim // copy pre-compiled vendor libraries verbatim
new CopyWebpackPlugin([ new CopyWebpackPlugin([
{ {
from: path.join(ROOT_PATH, `node_modules/monaco-editor/${IS_PRODUCTION ? 'min' : 'dev'}/vs`), from: path.join(
ROOT_PATH,
`node_modules/monaco-editor/${IS_PRODUCTION ? 'min' : 'dev'}/vs`
),
to: 'monaco-editor/vs', to: 'monaco-editor/vs',
transform: function(content, path) { transform: function(content, path) {
if (/\.js$/.test(path) && !/worker/i.test(path) && !/typescript/i.test(path)) { if (/\.js$/.test(path) && !/worker/i.test(path) && !/typescript/i.test(path)) {
...@@ -232,8 +237,8 @@ const config = { ...@@ -232,8 +237,8 @@ const config = {
); );
} }
return content; return content;
} },
} },
]), ]),
], ],
...@@ -241,20 +246,20 @@ const config = { ...@@ -241,20 +246,20 @@ const config = {
extensions: ['.js'], extensions: ['.js'],
alias: { alias: {
'~': path.join(ROOT_PATH, 'app/assets/javascripts'), '~': path.join(ROOT_PATH, 'app/assets/javascripts'),
'emojis': path.join(ROOT_PATH, 'fixtures/emojis'), emojis: path.join(ROOT_PATH, 'fixtures/emojis'),
'empty_states': path.join(ROOT_PATH, 'app/views/shared/empty_states'), empty_states: path.join(ROOT_PATH, 'app/views/shared/empty_states'),
'icons': path.join(ROOT_PATH, 'app/views/shared/icons'), icons: path.join(ROOT_PATH, 'app/views/shared/icons'),
'images': path.join(ROOT_PATH, 'app/assets/images'), images: path.join(ROOT_PATH, 'app/assets/images'),
'vendor': path.join(ROOT_PATH, 'vendor/assets/javascripts'), vendor: path.join(ROOT_PATH, 'vendor/assets/javascripts'),
'vue$': 'vue/dist/vue.esm.js', vue$: 'vue/dist/vue.esm.js',
'spec': path.join(ROOT_PATH, 'spec/javascripts'), spec: path.join(ROOT_PATH, 'spec/javascripts'),
// EE-only // EE-only
ee: path.join(ROOT_PATH, 'ee/app/assets/javascripts'), ee: path.join(ROOT_PATH, 'ee/app/assets/javascripts'),
ee_empty_states: path.join(ROOT_PATH, 'ee/app/views/shared/empty_states'), ee_empty_states: path.join(ROOT_PATH, 'ee/app/views/shared/empty_states'),
ee_icons: path.join(ROOT_PATH, 'ee/app/views/shared/icons'), ee_icons: path.join(ROOT_PATH, 'ee/app/views/shared/icons'),
ee_images: path.join(ROOT_PATH, 'ee/app/assets/images'), ee_images: path.join(ROOT_PATH, 'ee/app/assets/images'),
} },
}, },
// sqljs requires fs // sqljs requires fs
...@@ -269,14 +274,14 @@ if (IS_PRODUCTION) { ...@@ -269,14 +274,14 @@ if (IS_PRODUCTION) {
new webpack.NoEmitOnErrorsPlugin(), new webpack.NoEmitOnErrorsPlugin(),
new webpack.LoaderOptionsPlugin({ new webpack.LoaderOptionsPlugin({
minimize: true, minimize: true,
debug: false debug: false,
}), }),
new webpack.optimize.ModuleConcatenationPlugin(), new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.optimize.UglifyJsPlugin({ new webpack.optimize.UglifyJsPlugin({
sourceMap: true sourceMap: true,
}), }),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env': { NODE_ENV: JSON.stringify('production') } 'process.env': { NODE_ENV: JSON.stringify('production') },
}) })
); );
...@@ -295,7 +300,7 @@ if (IS_DEV_SERVER) { ...@@ -295,7 +300,7 @@ if (IS_DEV_SERVER) {
headers: { 'Access-Control-Allow-Origin': '*' }, headers: { 'Access-Control-Allow-Origin': '*' },
stats: 'errors-only', stats: 'errors-only',
hot: DEV_SERVER_LIVERELOAD, hot: DEV_SERVER_LIVERELOAD,
inline: DEV_SERVER_LIVERELOAD inline: DEV_SERVER_LIVERELOAD,
}; };
config.plugins.push( config.plugins.push(
// watch node_modules for changes if we encounter a missing module compile error // watch node_modules for changes if we encounter a missing module compile error
...@@ -311,10 +316,12 @@ if (IS_DEV_SERVER) { ...@@ -311,10 +316,12 @@ if (IS_DEV_SERVER) {
]; ];
// report our auto-generated bundle count // report our auto-generated bundle count
console.log(`${autoEntriesCount} entries from '/pages' automatically added to webpack output.`); console.log(
`${autoEntriesCount} entries from '/pages' automatically added to webpack output.`
);
callback(); callback();
}) });
}, },
} }
); );
......
/* eslint import/no-commonjs: "off" */
const execFileSync = require('child_process').execFileSync; const execFileSync = require('child_process').execFileSync;
const exec = (command, args) => { const exec = (command, args) => {
...@@ -18,12 +17,7 @@ const execGitCmd = args => ...@@ -18,12 +17,7 @@ const execGitCmd = args =>
module.exports = { module.exports = {
getStagedFiles: fileExtensionFilter => { getStagedFiles: fileExtensionFilter => {
const gitOptions = [ const gitOptions = ['diff', '--name-only', '--cached', '--diff-filter=ACMRTUB'];
'diff',
'--name-only',
'--cached',
'--diff-filter=ACMRTUB',
];
if (fileExtensionFilter) gitOptions.push(...fileExtensionFilter); if (fileExtensionFilter) gitOptions.push(...fileExtensionFilter);
return execGitCmd(gitOptions); return execGitCmd(gitOptions);
}, },
......
/* eslint import/no-commonjs: "off", import/no-extraneous-dependencies: "off", no-console: "off" */
const glob = require('glob'); const glob = require('glob');
const prettier = require('prettier'); const prettier = require('prettier');
const fs = require('fs'); const fs = require('fs');
...@@ -22,9 +21,7 @@ const availableExtensions = Object.keys(config.parsers); ...@@ -22,9 +21,7 @@ const availableExtensions = Object.keys(config.parsers);
console.log(`Loading ${allFiles ? 'All' : 'Staged'} Files ...`); console.log(`Loading ${allFiles ? 'All' : 'Staged'} Files ...`);
const stagedFiles = allFiles const stagedFiles = allFiles ? null : getStagedFiles(availableExtensions.map(ext => `*.${ext}`));
? null
: getStagedFiles(availableExtensions.map(ext => `*.${ext}`));
if (stagedFiles) { if (stagedFiles) {
if (!stagedFiles.length || (stagedFiles.length === 1 && !stagedFiles[0])) { if (!stagedFiles.length || (stagedFiles.length === 1 && !stagedFiles[0])) {
...@@ -41,15 +38,10 @@ let files; ...@@ -41,15 +38,10 @@ let files;
if (allFiles) { if (allFiles) {
const ignore = config.ignore; const ignore = config.ignore;
const patterns = config.patterns; const patterns = config.patterns;
const globPattern = const globPattern = patterns.length > 1 ? `{${patterns.join(',')}}` : `${patterns.join(',')}`;
patterns.length > 1 ? `{${patterns.join(',')}}` : `${patterns.join(',')}`; files = glob.sync(globPattern, { ignore }).filter(f => allFiles || stagedFiles.includes(f));
files = glob
.sync(globPattern, { ignore })
.filter(f => allFiles || stagedFiles.includes(f));
} else { } else {
files = stagedFiles.filter(f => files = stagedFiles.filter(f => availableExtensions.includes(f.split('.').pop()));
availableExtensions.includes(f.split('.').pop()),
);
} }
if (!files.length) { if (!files.length) {
...@@ -81,7 +73,7 @@ prettier ...@@ -81,7 +73,7 @@ prettier
} else if (!prettier.check(input, options)) { } else if (!prettier.check(input, options)) {
if (!didWarn) { if (!didWarn) {
console.log( 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; didWarn = true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment