Skip to content

Commit

Permalink
refactor: enable and fix class-methods-use-this
Browse files Browse the repository at this point in the history
  • Loading branch information
tinfoil-knight committed Jul 5, 2021
1 parent 886c1b7 commit b467e68
Show file tree
Hide file tree
Showing 39 changed files with 238 additions and 209 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = {
rules: {
// Those rules from @netlify/eslint-config-node are currently disabled
// TODO: remove, so those rules are enabled
'class-methods-use-this': 0,
complexity: 0,
'max-depth': 0,
'max-lines': 0,
Expand Down
13 changes: 7 additions & 6 deletions src/commands/addons/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const openBrowser = require('../../utils/open-browser')
class AddonsAuthCommand extends Command {
async run() {
const { args } = this.parse(AddonsAuthCommand)
const { log } = Command

const addonName = args.name
const { addon } = await prepareAddonCommand({
Expand All @@ -18,12 +19,12 @@ class AddonsAuthCommand extends Command {
return false
}

this.log()
this.log(`Opening ${addonName} add-on admin URL:`)
this.log()
this.log(addon.auth_url)
this.log()
await openBrowser({ url: addon.auth_url, log: this.log })
log()
log(`Opening ${addonName} add-on admin URL:`)
log()
log(addon.auth_url)
log()
await openBrowser({ url: addon.auth_url, log })
this.exit()
}
}
Expand Down
41 changes: 21 additions & 20 deletions src/commands/addons/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { parseRawFlags } = require('../../utils/parse-raw-flags')
class AddonsConfigCommand extends Command {
async run() {
const { args, raw } = this.parse(AddonsConfigCommand)
const { log } = Command

const addonName = args.name
const { manifest, addon, siteData } = await prepareAddonCommand({
Expand All @@ -33,15 +34,15 @@ class AddonsConfigCommand extends Command {
const currentConfig = addon.config || {}

const words = `Current "${addonName} add-on" Settings:`
this.log(` ${chalk.yellowBright.bold(words)}`)
log(` ${chalk.yellowBright.bold(words)}`)
if (hasConfig) {
if (!rawFlags.silent) {
render.configValues(addonName, manifest.config, currentConfig)
}
} else {
// For addons without manifest. TODO remove once we enfore manifests
Object.keys(currentConfig).forEach((key) => {
this.log(`${key} - ${currentConfig[key]}`)
log(`${key} - ${currentConfig[key]}`)
})
}

Expand All @@ -61,7 +62,7 @@ class AddonsConfigCommand extends Command {
instanceId: addon.id,
api,
error: this.error,
log: this.log,
log,
})
return false
}
Expand All @@ -75,16 +76,16 @@ class AddonsConfigCommand extends Command {
},
])
if (!updatePrompt.updateNow) {
this.log('Sounds good! Exiting configuration...')
log('Sounds good! Exiting configuration...')
return false
}
this.log()
this.log(` - Hit ${chalk.white.bold('enter')} to keep the existing value in (parentheses)`)
this.log(` - Hit ${chalk.white.bold('down arrow')} to remove the value`)
this.log(` - Hit ${chalk.white.bold('ctrl + C')} to cancel & exit configuration`)
this.log()
this.log(` You will need to verify the changed before we push them to your live site!`)
this.log()
log()
log(` - Hit ${chalk.white.bold('enter')} to keep the existing value in (parentheses)`)
log(` - Hit ${chalk.white.bold('down arrow')} to remove the value`)
log(` - Hit ${chalk.white.bold('ctrl + C')} to cancel & exit configuration`)
log()
log(` You will need to verify the changed before we push them to your live site!`)
log()
const prompts = generatePrompts({
config: manifest.config,
configValues: currentConfig,
Expand All @@ -94,20 +95,20 @@ class AddonsConfigCommand extends Command {
const newConfig = updateConfigValues(manifest.config, currentConfig, userInput)

const diffs = compare(currentConfig, newConfig)
// this.log('compare', diffs)
// log('compare', diffs)
if (diffs.isEqual) {
this.log(`No changes. exiting early`)
log(`No changes. exiting early`)
return false
}
this.log()
this.log(`${chalk.yellowBright.bold.underline('Confirm your updates:')}`)
this.log()
log()
log(`${chalk.yellowBright.bold.underline('Confirm your updates:')}`)
log()
diffs.keys.forEach((key) => {
const { newValue, oldValue } = diffs.diffs[key]
const oldVal = oldValue || 'NO VALUE'
this.log(`${chalk.cyan(key)} changed from ${chalk.whiteBright(oldVal)} to ${chalk.green(newValue)}`)
log(`${chalk.cyan(key)} changed from ${chalk.whiteBright(oldVal)} to ${chalk.green(newValue)}`)
})
this.log()
log()

const confirmPrompt = await inquirer.prompt([
{
Expand All @@ -121,7 +122,7 @@ class AddonsConfigCommand extends Command {
])

if (!confirmPrompt.confirmChange) {
this.log('Canceling changes... You are good to go!')
log('Canceling changes... You are good to go!')
return false
}

Expand All @@ -133,7 +134,7 @@ class AddonsConfigCommand extends Command {
instanceId: addon.id,
api,
error: this.error,
log: this.log,
log,
})
}
}
Expand Down
39 changes: 19 additions & 20 deletions src/commands/addons/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class AddonsCreateCommand extends Command {
validation: ADDON_VALIDATION.NOT_EXISTS,
})

const { log, error, netlify } = this
const { error, netlify } = this
const { log } = Command
const { api, site } = netlify
const siteId = site.id

Expand All @@ -50,25 +51,23 @@ class AddonsCreateCommand extends Command {
if (hasConfig) {
const required = requiredConfigValues(manifest.config)
const missingValues = missingConfigValues(required, rawFlags)
this.log(`Starting the setup for "${addonName} add-on"`)
this.log()
log(`Starting the setup for "${addonName} add-on"`)
log()

if (Object.keys(rawFlags).length !== 0) {
const newConfig = updateConfigValues(manifest.config, {}, rawFlags)

if (missingValues.length !== 0) {
/* Warn user of missing required values */
this.log(
`${chalk.redBright.underline.bold(`Error: Missing required configuration for "${addonName} add-on"`)}`,
)
this.log()
log(`${chalk.redBright.underline.bold(`Error: Missing required configuration for "${addonName} add-on"`)}`)
log()
render.missingValues(missingValues, manifest)
this.log()
log()
const msg = `netlify addons:create ${addonName}`
this.log(`Please supply the configuration values as CLI flags`)
this.log()
this.log(`Alternatively, you can run ${chalk.cyan(msg)} with no flags to walk through the setup steps`)
this.log()
log(`Please supply the configuration values as CLI flags`)
log()
log(`Alternatively, you can run ${chalk.cyan(msg)} with no flags to walk through the setup steps`)
log()
return false
}

Expand All @@ -78,15 +77,15 @@ class AddonsCreateCommand extends Command {
}

const words = `The ${addonName} add-on has the following configurable options:`
this.log(` ${chalk.yellowBright.bold(words)}`)
log(` ${chalk.yellowBright.bold(words)}`)
render.configValues(addonName, manifest.config)
this.log()
this.log(` ${chalk.greenBright.bold('Lets configure those!')}`)
log()
log(` ${chalk.greenBright.bold('Lets configure those!')}`)

this.log()
this.log(` - Hit ${chalk.white.bold('enter')} to confirm value or set empty value`)
this.log(` - Hit ${chalk.white.bold('ctrl + C')} to cancel & exit configuration`)
this.log()
log()
log(` - Hit ${chalk.white.bold('enter')} to confirm value or set empty value`)
log(` - Hit ${chalk.white.bold('ctrl + C')} to cancel & exit configuration`)
log()

const prompts = generatePrompts({
config: manifest.config,
Expand All @@ -99,7 +98,7 @@ class AddonsCreateCommand extends Command {
const missingRequiredValues = missingConfigValues(required, configValues)
if (missingRequiredValues && missingRequiredValues.length !== 0) {
missingRequiredValues.forEach((val) => {
this.log(`Missing required value "${val}". Please run the command again`)
log(`Missing required value "${val}". Please run the command again`)
})
return false
}
Expand Down
3 changes: 2 additions & 1 deletion src/commands/addons/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { parseRawFlags } = require('../../utils/parse-raw-flags')
class AddonsDeleteCommand extends Command {
async run() {
const { args, raw } = this.parse(AddonsDeleteCommand)
const { log } = Command

const addonName = args.name
const { addon } = await prepareAddonCommand({
Expand Down Expand Up @@ -35,7 +36,7 @@ class AddonsDeleteCommand extends Command {
addon: addonName,
instanceId: addon.id,
})
this.log(`Addon "${addonName}" deleted`)
log(`Addon "${addonName}" deleted`)
} catch (error) {
this.error(error.message)
}
Expand Down
12 changes: 6 additions & 6 deletions src/commands/addons/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ class AddonsListCommand extends Command {
const { flags } = this.parse(AddonsListCommand)

const { addons, siteData } = await prepareAddonCommand({ context: this })

const { logJson, log } = Command
// Return json response for piping commands
if (flags.json) {
this.logJson(addons)
logJson(addons)
return false
}

if (!addons || addons.length === 0) {
this.log(`No addons currently installed for ${siteData.name}`)
this.log(`> Run \`netlify addons:create addon-namespace\` to install an addon`)
log(`No addons currently installed for ${siteData.name}`)
log(`> Run \`netlify addons:create addon-namespace\` to install an addon`)
return false
}

Expand All @@ -29,7 +29,7 @@ class AddonsListCommand extends Command {
}))

// Build a table out of addons
this.log(`site: ${siteData.name}`)
log(`site: ${siteData.name}`)
const table = new AsciiTable(`Currently Installed addons`)

table.setHeading('NameSpace', 'Name', 'Instance Id')
Expand All @@ -38,7 +38,7 @@ class AddonsListCommand extends Command {
table.addRow(namespace, name, id)
})
// Log da addons
this.log(table.toString())
log(table.toString())
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/commands/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class APICommand extends Command {
async run() {
const { api } = this.netlify
const { args, flags } = this.parse(APICommand)
const { log, logJson } = Command

const { apiMethod } = args

Expand All @@ -20,10 +21,10 @@ class APICommand extends Command {
const { operationId } = method
table.addRow(operationId, `https://open-api.netlify.com/#operation/${operationId}`)
})
this.log(table.toString())
this.log()
this.log('Above is a list of available API methods')
this.log(`To run a method use "${chalk.cyanBright('netlify api methodName')}"`)
log(table.toString())
log()
log('Above is a list of available API methods')
log(`To run a method use "${chalk.cyanBright('netlify api methodName')}"`)
this.exit()
}

Expand All @@ -43,7 +44,7 @@ class APICommand extends Command {
}
try {
const apiResponse = await api[apiMethod](payload)
this.logJson(apiResponse)
logJson(apiResponse)
} catch (error) {
this.error(error)
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BuildCommand extends Command {
this.setAnalyticsPayload({ dry: flags.dry })

// Retrieve Netlify Build options
const [token] = await this.getConfigToken()
const [token] = await Command.getConfigToken()

const options = await getBuildOptions({
context: this,
Expand Down
6 changes: 4 additions & 2 deletions src/commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,12 @@ const printResults = ({ flags, results, deployToProduction, log, logJson, exit }
class DeployCommand extends Command {
async run() {
const { flags } = this.parse(DeployCommand)
const { log, logJson, warn, error, exit } = this
const { warn, error, exit } = this
const { api, site } = this.netlify
const alias = flags.alias || flags.branch

const { log, logJson } = Command

this.setAnalyticsPayload({ open: flags.open, prod: flags.prod, json: flags.json, alias: Boolean(alias) })

if (flags.branch) {
Expand All @@ -387,7 +389,7 @@ class DeployCommand extends Command {
}
}
} else {
this.log("This folder isn't linked to a site yet")
log("This folder isn't linked to a site yet")
const NEW_SITE = '+ Create & configure a new site'
const EXISTING_SITE = 'Link this directory to an existing site'

Expand Down
5 changes: 3 additions & 2 deletions src/commands/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ class DevCommand extends Command {
}

async run() {
this.log(`${NETLIFYDEV}`)
const { error: errorExit, log, warn, exit } = this
const { log } = Command
log(`${NETLIFYDEV}`)
const { error: errorExit, warn, exit } = this
const { flags } = this.parse(DevCommand)
const { api, site, config, siteInfo } = this.netlify
config.dev = { ...config.dev }
Expand Down
3 changes: 2 additions & 1 deletion src/commands/dev/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class TraceCommand extends Command {
this.parse(TraceCommand)

const args = ['trace'].concat(this.argv)
const { subprocess } = runProcess({ log: this.log, args })
const { log } = Command
const { subprocess } = runProcess({ log, args })
await subprocess
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/commands/env/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ class EnvGetCommand extends Command {
async run() {
const { args, flags } = this.parse(EnvGetCommand)
const { api, cachedConfig, site } = this.netlify
const { log, logJson } = Command
const siteId = site.id

if (!siteId) {
this.log('No site id found, please run inside a site folder or `netlify link`')
log('No site id found, please run inside a site folder or `netlify link`')
return false
}

Expand All @@ -18,16 +19,16 @@ class EnvGetCommand extends Command {

// Return json response for piping commands
if (flags.json) {
this.logJson(value ? { [name]: value } : {})
logJson(value ? { [name]: value } : {})
return false
}

if (!value) {
this.log(`Environment variable ${name} not set for site ${siteData.name}`)
log(`Environment variable ${name} not set for site ${siteData.name}`)
return false
}

this.log(value)
log(value)
}
}

Expand Down
Loading

0 comments on commit b467e68

Please sign in to comment.