Avoid func declarations using function keyword (#2813)

We had only a few function expressions declared with the function keyword; almost everything is using function declarations.

This came up after this discussion: https://github.com/badges/shields/pull/2803#discussion_r249011621 though is actually not related ot that example.

What’s being removed is a third option, which is assigning to a variable a function expression using the `function` keyword. There’s still room for the programmer to choose between arrow function expressions and function declarations.
This commit is contained in:
Paul Melnikow
2019-01-21 15:33:43 -05:00
committed by GitHub
parent 18a65fc69c
commit 8dc8afeb55
6 changed files with 16 additions and 17 deletions

View File

@@ -38,6 +38,7 @@ rules:
object-shorthand: ['error', 'properties']
prefer-template: 'error'
promise/prefer-await-to-then: 'error'
func-style: ['error', 'declaration', { 'allowArrowFunctions': true }]
# Mocha-related.
mocha/no-exclusive-tests: 'error'

View File

@@ -9,7 +9,7 @@ const defaultErrorMessages = {
404: 'not found',
}
const checkErrorResponse = function(badgeData, err, res, errorMessages = {}) {
function checkErrorResponse(badgeData, err, res, errorMessages = {}) {
errorMessages = { ...defaultErrorMessages, ...errorMessages }
if (err != null) {
badgeData.text[1] = 'inaccessible'

View File

@@ -2,14 +2,14 @@
const dockerBlue = '066da5' // see https://github.com/badges/shields/pull/1690
const buildDockerUrl = function(badgeName) {
function buildDockerUrl(badgeName) {
return {
base: `docker/${badgeName}`,
pattern: ':user/:repo',
}
}
const getDockerHubUser = function(user) {
function getDockerHubUser(user) {
return user === '_' ? 'library' : user
}

View File

@@ -59,15 +59,13 @@ module.exports = class PackagistLicense extends LegacyService {
// Note: if you change the latest version detection algorithm here,
// change it above (for the actual version badge).
let version
const unstable = function(ver) {
return /dev/.test(ver)
}
const isUnstable = ({ version }) => version.includes('dev')
// Grab the latest stable version, or an unstable
for (const versionName in data.package.versions) {
const current = data.package.versions[versionName]
if (version !== undefined) {
if (unstable(version.version) && !unstable(current.version)) {
if (isUnstable(version) && !isUnstable(current)) {
version = current
} else if (
version.version_normalized < current.version_normalized

View File

@@ -8,7 +8,7 @@
our own functions to parse and sort django versions
*/
const parseDjangoVersionString = function(str) {
function parseDjangoVersionString(str) {
if (typeof str !== 'string') {
return false
}
@@ -21,8 +21,8 @@ const parseDjangoVersionString = function(str) {
}
}
// sort an array of django versions low to high
const sortDjangoVersions = function(versions) {
// Sort an array of django versions low to high.
function sortDjangoVersions(versions) {
return versions.sort((a, b) => {
if (
parseDjangoVersionString(a).major === parseDjangoVersionString(b).major
@@ -38,8 +38,8 @@ const sortDjangoVersions = function(versions) {
})
}
// extract classifiers from a pypi json response based on a regex
const parseClassifiers = function(parsedData, pattern) {
// Extract classifiers from a pypi json response based on a regex.
function parseClassifiers(parsedData, pattern) {
const results = []
for (let i = 0; i < parsedData.info.classifiers.length; i++) {
const matched = pattern.exec(parsedData.info.classifiers[i])

View File

@@ -1,9 +1,9 @@
'use strict'
const invalidJSON = function() {
return [200, '{{{{{invalid json}}', { 'Content-Type': 'application/json' }]
}
module.exports = {
invalidJSON,
invalidJSON: () => [
200,
'{{{{{invalid json}}',
{ 'Content-Type': 'application/json' },
],
}