Skip to content

Commit

Permalink
chore(prettier/eslint): Add consistency in the use of Prettier and es…
Browse files Browse the repository at this point in the history
…lint
  • Loading branch information
PaulRosset committed Oct 6, 2018
1 parent 062d5b3 commit 820dd82
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 35 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ module.exports = {
semi: false,
},
],
'comma-dangle': ["error", "always-multiline"],
},
};
6 changes: 6 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
trailingComma: 'es5',
tabWidth: 2,
semi: false,
singleQuote: true,
}
4 changes: 1 addition & 3 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,8 +24,8 @@ if (program.files) {
{
path: program.files,
maxSize: program.maxSize,
compression: program.compression || 'gzip'
}
compression: program.compression || 'gzip',
},
]
}

Expand Down
2 changes: 1 addition & 1 deletion src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
27 changes: 8 additions & 19 deletions src/reporter.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -12,7 +12,7 @@ const setBuildStatus = ({
globalMessage,
fail,
event: currentEvent,
branch: currentBranch
branch: currentBranch,
}) => {
if (fail) build.fail(globalMessage || 'bundle size > maxSize', url)
else {
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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})`
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/shortener.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const shorten = longUrl =>
method: 'POST',
url: `${url}?key=${googleApiKey}`,
data: {
longUrl
}
longUrl,
},
})

const shortener = { shorten }
Expand Down
4 changes: 2 additions & 2 deletions store/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion store/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
2 changes: 1 addition & 1 deletion store/newrelic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
}

0 comments on commit 820dd82

Please sign in to comment.