Skip to content

Commit

Permalink
fix: enable and fix class-methods-use-this (#2827)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinfoil-knight authored Jul 26, 2021
1 parent c2ab2f0 commit 5c5c69b
Show file tree
Hide file tree
Showing 63 changed files with 559 additions and 537 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
15 changes: 8 additions & 7 deletions src/commands/addons/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { prepareAddonCommand, ADDON_VALIDATION } = require('../../utils/addons/prepare')
const Command = require('../../utils/command')
const { log } = require('../../utils/command-helpers')
const openBrowser = require('../../utils/open-browser')

class AddonsAuthCommand extends Command {
Expand All @@ -14,16 +15,16 @@ class AddonsAuthCommand extends Command {
})

if (!addon.auth_url) {
console.log(`No Admin URL found for the "${addonName} add-on"`)
log(`No Admin URL found for the "${addonName} add-on"`)
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 })
this.exit()
}
}
Expand Down
41 changes: 20 additions & 21 deletions src/commands/addons/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const generatePrompts = require('../../utils/addons/prompts')
const render = require('../../utils/addons/render')
const { requiredConfigValues, missingConfigValues, updateConfigValues } = require('../../utils/addons/validation')
const Command = require('../../utils/command')
const { log } = require('../../utils/command-helpers')
const { parseRawFlags } = require('../../utils/parse-raw-flags')

class AddonsConfigCommand extends Command {
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,6 @@ class AddonsConfigCommand extends Command {
instanceId: addon.id,
api,
error: this.error,
log: this.log,
})
return false
}
Expand All @@ -75,16 +75,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 +94,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 +121,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,13 +133,12 @@ class AddonsConfigCommand extends Command {
instanceId: addon.id,
api,
error: this.error,
log: this.log,
})
}
}
}

const update = async function ({ addonName, currentConfig, newConfig, siteId, instanceId, api, error, log }) {
const update = async function ({ addonName, currentConfig, newConfig, siteId, instanceId, api, error }) {
const codeDiff = diffValues(currentConfig, newConfig)
if (!codeDiff) {
log('No changes, exiting early')
Expand Down
45 changes: 22 additions & 23 deletions src/commands/addons/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const generatePrompts = require('../../utils/addons/prompts')
const render = require('../../utils/addons/render')
const { requiredConfigValues, missingConfigValues, updateConfigValues } = require('../../utils/addons/validation')
const Command = require('../../utils/command')
const { log } = require('../../utils/command-helpers')
const { parseRawFlags } = require('../../utils/parse-raw-flags')

const createAddon = async ({ api, siteId, addonName, config, siteData, log, error }) => {
const createAddon = async ({ api, siteId, addonName, config, siteData, error }) => {
try {
const response = await api.createServiceInstance({
siteId,
Expand Down Expand Up @@ -37,7 +38,7 @@ class AddonsCreateCommand extends Command {
validation: ADDON_VALIDATION.NOT_EXISTS,
})

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

Expand All @@ -50,43 +51,41 @@ 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
}

await createAddon({ api, siteId, addonName, config: newConfig, siteData, log, error })
await createAddon({ api, siteId, addonName, config: newConfig, siteData, error })

return false
}

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,13 +98,13 @@ 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
}
}

await createAddon({ api, siteId, addonName, config: configValues, siteData, log, error })
await createAddon({ api, siteId, addonName, config: configValues, siteData, error })
}
}

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 @@ -3,6 +3,7 @@ const inquirer = require('inquirer')

const { prepareAddonCommand, ADDON_VALIDATION } = require('../../utils/addons/prepare')
const Command = require('../../utils/command')
const { log } = require('../../utils/command-helpers')
const { parseRawFlags } = require('../../utils/parse-raw-flags')

class AddonsDeleteCommand extends Command {
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 @@ -3,22 +3,22 @@ const AsciiTable = require('ascii-table')

const { prepareAddonCommand } = require('../../utils/addons/prepare')
const Command = require('../../utils/command')
const { log, logJson } = require('../../utils/command-helpers')

class AddonsListCommand extends Command {
async run() {
const { flags } = this.parse(AddonsListCommand)

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

// 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 @@ -5,6 +5,7 @@ const { methods } = require('netlify')

const { isEmptyCommand } = require('../utils/check-command-inputs')
const Command = require('../utils/command')
const { log, logJson } = require('../utils/command-helpers')

class APICommand extends Command {
async run() {
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
3 changes: 2 additions & 1 deletion src/commands/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { flags: flagsLib } = require('@oclif/command')

const { getBuildOptions, runBuild } = require('../../lib/build')
const Command = require('../../utils/command')
const { getToken } = require('../../utils/command-helpers')

class BuildCommand extends Command {
// Run Netlify Build
Expand All @@ -11,7 +12,7 @@ class BuildCommand extends Command {
this.setAnalyticsPayload({ dry: flags.dry })

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

const options = await getBuildOptions({
context: this,
Expand Down
Loading

1 comment on commit 5c5c69b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 331 MB

Please sign in to comment.