From 820dd8271191d93a454aa04415e27a4369af391c Mon Sep 17 00:00:00 2001 From: Paul Rosset Date: Sat, 6 Oct 2018 20:10:31 +0100 Subject: [PATCH] chore(prettier/eslint): Add consistency in the use of Prettier and eslint --- .eslintrc.js | 1 + prettier.config.js | 6 ++++++ src/api.js | 4 +--- src/config.js | 9 +++------ src/files.js | 2 +- src/reporter.js | 27 ++++++++------------------- src/shortener.js | 4 ++-- store/github.js | 4 ++-- store/migrate.js | 2 +- store/newrelic.js | 2 +- 10 files changed, 26 insertions(+), 35 deletions(-) create mode 100644 prettier.config.js diff --git a/.eslintrc.js b/.eslintrc.js index e1a87002..9627975f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,5 +9,6 @@ module.exports = { semi: false, }, ], + 'comma-dangle': ["error", "always-multiline"], }, }; diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 00000000..0614ee70 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,6 @@ +module.exports = { + trailingComma: 'es5', + tabWidth: 2, + semi: false, + singleQuote: true, +} diff --git a/src/api.js b/src/api.js index 13e76fd9..e28fee06 100644 --- a/src/api.js +++ b/src/api.js @@ -46,9 +46,7 @@ const set = values => { repo = repo.replace(/\./g, '_') debug('saving values') - axios - .post(url, { repo, token, sha, values }) - .catch(error => console.log(error)) + axios.post(url, { repo, token, sha, values }).catch(error => console.log(error)) } } diff --git a/src/config.js b/src/config.js index ad6c87b1..d722e77c 100644 --- a/src/config.js +++ b/src/config.js @@ -14,10 +14,7 @@ program .option('-f, --files [files]', 'files to test against (dist/*.js)') .option('-s, --max-size [maxSize]', 'maximum size threshold (3Kb)') .option('--debug', 'run in debug mode') - .option( - '-c, --compression [compression]', - 'specify which compression algorithm to use' - ) + .option('-c, --compression [compression]', 'specify which compression algorithm to use') .parse(process.argv) let cliConfig @@ -27,8 +24,8 @@ if (program.files) { { path: program.files, maxSize: program.maxSize, - compression: program.compression || 'gzip' - } + compression: program.compression || 'gzip', + }, ] } diff --git a/src/files.js b/src/files.js index 586231fc..17df704a 100644 --- a/src/files.js +++ b/src/files.js @@ -11,7 +11,7 @@ config.map(file => { const paths = glob.sync(file.path) if (!paths.length) { error(`There is no matching file for ${file.path} in ${process.cwd()}`, { - silent: true + silent: true, }) } else { paths.map(path => { diff --git a/src/reporter.js b/src/reporter.js index 816c1a3a..f1669173 100644 --- a/src/reporter.js +++ b/src/reporter.js @@ -1,6 +1,6 @@ const bytes = require('bytes') const { error, warn, info } = require('prettycli') -const { event, repo, branch, commit_message, sha } = require('ci-env') +const { event, repo, branch, commit_message, sha } = require('ci-env') //eslint-disable-line const build = require('./build') const api = require('./api') const debug = require('./debug') @@ -12,7 +12,7 @@ const setBuildStatus = ({ globalMessage, fail, event: currentEvent, - branch: currentBranch + branch: currentBranch, }) => { if (fail) build.fail(globalMessage || 'bundle size > maxSize', url) else { @@ -28,12 +28,7 @@ const setBuildStatus = ({ } // Generate global message as per https://github.com/siddharthkp/bundlesize/issues/182#issuecomment-343274689 -const getGlobalMessage = ({ - results, - totalSize, - totalSizeMaster, - totalMaxSize -}) => { +const getGlobalMessage = ({ results, totalSize, totalSizeMaster, totalMaxSize }) => { let globalMessage let failures = results.filter(result => !!result.fail).length @@ -51,9 +46,7 @@ const getGlobalMessage = ({ // multiple files, multiple failures const change = totalSize - totalSizeMaster const prettyChange = - change === 0 - ? 'no change' - : change > 0 ? `+${bytes(change)}` : `-${bytes(Math.abs(change))}` + change === 0 ? 'no change' : change > 0 ? `+${bytes(change)}` : `-${bytes(Math.abs(change))}` globalMessage = `${failures} out of ${results.length} bundles are too big! (${prettyChange})` } else { @@ -62,9 +55,7 @@ const getGlobalMessage = ({ const prettyMaxSize = bytes(totalMaxSize) const change = totalSize - totalSizeMaster const prettyChange = - change === 0 - ? 'no change' - : change > 0 ? `+${bytes(change)}` : `-${bytes(Math.abs(change))}` + change === 0 ? 'no change' : change > 0 ? `+${bytes(change)}` : `-${bytes(Math.abs(change))}` globalMessage = `Total bundle size is ${prettySize}/${prettyMaxSize} (${prettyChange})` } @@ -122,16 +113,14 @@ const analyse = ({ files, masterValues }) => { fail, size, master, - maxSize + maxSize, } }) } const report = ({ files, globalMessage, fail }) => { /* prepare the build page */ - const params = encodeURIComponent( - JSON.stringify({ files, repo, branch, commit_message, sha }) - ) + const params = encodeURIComponent(JSON.stringify({ files, repo, branch, commit_message, sha })) //eslint-disable-line let url = `https://bundlesize-store.now.sh/build?info=${params}` debug('url before shortening', url) @@ -156,7 +145,7 @@ const compare = (files, masterValues = {}) => { results, totalSize: results.reduce((acc, result) => acc + result.size, 0), totalSizeMaster: results.reduce((acc, result) => acc + result.master, 0), - totalMaxSize: results.reduce((acc, result) => acc + result.maxSize, 0) + totalMaxSize: results.reduce((acc, result) => acc + result.maxSize, 0), }) let fail = results.filter(result => result.fail).length > 0 diff --git a/src/shortener.js b/src/shortener.js index 36cbc4c0..ada657e5 100644 --- a/src/shortener.js +++ b/src/shortener.js @@ -8,8 +8,8 @@ const shorten = longUrl => method: 'POST', url: `${url}?key=${googleApiKey}`, data: { - longUrl - } + longUrl, + }, }) const shortener = { shorten } diff --git a/store/github.js b/store/github.js index 09716065..dcbe31ae 100644 --- a/store/github.js +++ b/store/github.js @@ -12,8 +12,8 @@ const token = code => data: { code, client_id: process.env.githubId, - client_secret: process.env.githubSecret - } + client_secret: process.env.githubSecret, + }, }) .then(response => response.data) .catch(response => response.response.status) diff --git a/store/migrate.js b/store/migrate.js index 6ddd7ad6..eea62ab0 100644 --- a/store/migrate.js +++ b/store/migrate.js @@ -8,7 +8,7 @@ tokens.map(token => { const repos = Object.keys(initial[token][users]) repos.map(repo => { const future = { - '-Kp6JuK8QrSeYBh4g_0K': initial[token][users][repo] + '-Kp6JuK8QrSeYBh4g_0K': initial[token][users][repo], } initial[token][users][repo] = future }) diff --git a/store/newrelic.js b/store/newrelic.js index 5db7627e..7780dd86 100644 --- a/store/newrelic.js +++ b/store/newrelic.js @@ -5,5 +5,5 @@ if (process.env.dev) { exports.config = { app_name: ['bundlesize store'], license_key: process.env.newrelicKey, - logging: { level: 'info' } + logging: { level: 'info' }, }