Skip to content

Commit

Permalink
chore: eslint standardization for oclif-based packages (#2304)
Browse files Browse the repository at this point in the history
* chore: initial eslint consolidation

* chore: direct all oclif packages to use root .eslintrc

* chore: specify location of .eslintignore file in oclif packages

* chore: add rule for no-constant-condition

* chore: update eslint setup to work with typescript and in monorepo

* chore: eslint fixes for apps package

* chore: eslint fixes for auth package

* chore: eslint fixes for autocomplete package

* chore: eslint fixes for buildpacks package

* chore: eslint fixes for ci package

* chore: eslint fixes for cli package

* chore: eslint fixes for config package

* chore: eslint fixes for git package

* chore: eslint fixes for local package

* chore: eslint fixes for oauth package

* chore: eslint fixes for pipelines package

* chore: eslint fixes for ps package

* chore: eslint fixes for run package

* chore: eslint fixes for status package

* chore: eslint fixes for webhooks package
  • Loading branch information
k80bowman authored Apr 19, 2023
1 parent 5c7180b commit a94632b
Show file tree
Hide file tree
Showing 119 changed files with 1,378 additions and 2,177 deletions.
6 changes: 4 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules
packages/*/lib
packages/*/tmp
**/dist
**/tmp
**/lib
tmp
dst
packages/ci/src/interfaces/kolkrabbi.ts
34 changes: 31 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
{
"extends": "standard",
"env": {
"mocha": true
"plugins": ["import"],
"extends": [
"oclif",
"oclif-typescript"
],
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {
"project": "packages/*/tsconfig.json"
}
}
},
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off",
"camelcase":"off",
"import/no-unresolved": "error",
"no-constant-condition": ["error", {"checkLoops": false }],
"node/no-missing-import": "off", // using import/no-unresolved instead
"unicorn/better-regex": "off", // TODO: fix issues and turn this back on
"unicorn/import-style": "off",
"unicorn/no-abusive-eslint-disable": "off",
"unicorn/no-array-for-each": "off",
"unicorn/no-lonely-if":"off",
"unicorn/numeric-separators-style":"off",
"unicorn/prefer-module": "off",
"unicorn/prefer-node-protocol": "off",
"unicorn/prefer-regexp-test": "off",
"unicorn/prefer-spread": "off" // TODO: fix issues and turn this back on
}
}
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"devDependencies": {
"@oclif/tslint": "^3.1.1",
"eslint": "5.13.0",
"eslint-config-standard": "12.0.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"@typescript-eslint/eslint-plugin": "4.18.0",
"@typescript-eslint/parser": "4.18.0",
"eslint": "^7.32.0",
"eslint-config-oclif": "^4.0.0",
"eslint-config-oclif-typescript": "^1.0.2",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5",
"lerna": "^6.4.1",
"promise-request-retry": "^1.0.2",
"standard": "12.0.1",
Expand Down
1 change: 0 additions & 1 deletion packages/apps/.eslintignore

This file was deleted.

9 changes: 0 additions & 9 deletions packages/apps/.eslintrc

This file was deleted.

5 changes: 1 addition & 4 deletions packages/apps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
"@types/supports-color": "^5.3.0",
"@types/urijs": "^1.19.4",
"chai": "^4",
"eslint": "^6.7.1",
"eslint-config-oclif": "^3.1.0",
"eslint-config-oclif-typescript": "^0.1.0",
"globby": "^10",
"mocha": "^5",
"nock": "^13.0.1",
Expand Down Expand Up @@ -59,7 +56,7 @@
"repository": "heroku/heroku-cli-plugin-apps",
"scripts": {
"postpack": "rm -f oclif.manifest.json",
"lint": "eslint . --ext .ts --config .eslintrc",
"lint": "eslint . --ext .ts --config ../../.eslintrc --ignore-path ../../.eslintignore",
"pretest": "tsc -p test --noEmit",
"posttest": "yarn lint",
"prepack": "rm -rf lib && tsc -b && oclif manifest",
Expand Down
1 change: 1 addition & 0 deletions packages/apps/src/commands/domains/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class DomainsClear extends Command {
// eslint-disable-next-line no-await-in-loop
await this.heroku.delete(`/apps/${flags.app}/domains/${domain.hostname}`)
}

action.stop()
}
}
1 change: 0 additions & 1 deletion packages/auth/.eslintignore

This file was deleted.

9 changes: 0 additions & 9 deletions packages/auth/.eslintrc

This file was deleted.

5 changes: 1 addition & 4 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
"@types/nock": "^9.3.1",
"@types/supports-color": "^5.3.0",
"chai": "^4.2.0",
"eslint": "^6.7.2",
"eslint-config-oclif": "^3.1.0",
"eslint-config-oclif-typescript": "^0.1.0",
"globby": "^10.0.1",
"mocha": "^5.2.0",
"nock": "^10.0.6",
Expand Down Expand Up @@ -58,7 +55,7 @@
"postpack": "rm -f oclif.manifest.json",
"pretest": "tsc -p test --noEmit",
"posttest": "yarn lint",
"lint": "eslint . --ext .ts --config .eslintrc",
"lint": "eslint . --ext .ts --config ../../.eslintrc --ignore-path ../../.eslintignore",
"prepack": "rm -rf lib && tsc && oclif manifest",
"prepare": "rm -rf lib && tsc && oclif manifest",
"test": "nyc mocha --forbid-only \"test/**/*.test.ts\"",
Expand Down
1 change: 1 addition & 0 deletions packages/auth/src/commands/auth/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ By default, the CLI auth token is only valid for 1 year. To generate a long-live
} catch (error: any) {
this.warn(error)
}

this.log(this.heroku.auth)
}
}
1 change: 0 additions & 1 deletion packages/autocomplete/.eslintignore

This file was deleted.

10 changes: 0 additions & 10 deletions packages/autocomplete/.eslintrc

This file was deleted.

7 changes: 1 addition & 6 deletions packages/autocomplete/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
"@types/lodash.flatten": "^4.4.6",
"@types/mocha": "5.2.6",
"@types/nock": "^9.3.1",
"@typescript-eslint/eslint-plugin": "4.18.0",
"@typescript-eslint/parser": "4.18.0",
"chai": "4.2.0",
"eslint": "^6.7.2",
"eslint-config-oclif": "^3.1.0",
"eslint-config-oclif-typescript": "^0.1.0",
"globby": "9.0.0",
"mocha": "5.2.0",
"nock": "^10.0.6",
Expand Down Expand Up @@ -67,7 +62,7 @@
"postpublish": "rm -f oclif.manifest.json",
"pretest": "tsc -p test --noEmit",
"posttest": "yarn lint",
"lint": "eslint . --ext .ts --config .eslintrc",
"lint": "eslint . --ext .ts --config ../../.eslintrc --ignore-path ../../.eslintignore",
"prepack": "rm -rf lib && tsc && oclif manifest",
"test": "nyc mocha --forbid-only \"test/**/*.test.ts\"",
"version": "oclif readme && git add README.md"
Expand Down
1 change: 1 addition & 0 deletions packages/autocomplete/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export abstract class AutocompleteBase extends Command {
if (!shell) {
this.error('Missing required argument shell')
}

this.errorIfWindows()
if (!['bash', 'zsh'].includes(shell)) {
throw new Error(`${shell} is not a supported shell for autocomplete`)
Expand Down
1 change: 1 addition & 0 deletions packages/autocomplete/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function fetchCache(cachePath: string, cacheDuration: number, optio
if (cachePresent && !_isStale(cachePath, cacheDuration)) {
return fs.readJSON(cachePath)
}

const cache = await options.cacheFn()
// to-do: move this to a fork
await updateCache(cachePath, cache)
Expand Down
4 changes: 4 additions & 0 deletions packages/autocomplete/src/commands/autocomplete/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export default class Create extends AutocompleteBase {
const text = Command.description.split('\n')[0]
description = `:"${text}"`
}

return `"${Command.id.replace(/:/g, '\\:')}"${description}`
}

Expand All @@ -160,9 +161,11 @@ export default class Create extends AutocompleteBase {
if (hasCompletion) {
cachecompl = ': :_compadd_flag_options'
}

if (this.wantsLocalFiles(flag)) {
cachecompl = ': :_files'
}

const help = isBoolean ? '(switch) ' : (hasCompletion ? '(autocomplete) ' : '')
const completion = `--${name}[${help}${f.description}]${cachecompl}`
return `"${completion}"`
Expand All @@ -177,6 +180,7 @@ ${flagscompletions}
}
`
}

return `# no flags for ${id}`
}

Expand Down
2 changes: 2 additions & 0 deletions packages/autocomplete/src/commands/autocomplete/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class Doctor extends AutocompleteBase {
async run() {
const {args, flags} = await this.parse(Doctor)
const shell = args.shell || this.config.shell
// eslint-disable-next-line unicorn/consistent-function-scoping
const printLine: typeof this.log = (...args) => this.log(...args)
this.errorIfNotSupportedShell(shell)

Expand Down Expand Up @@ -90,6 +91,7 @@ export default class Doctor extends AutocompleteBase {
if (hasCompletion) {
out += '(c)'
}

if (flag.hidden) out += '(h)'
return out
})
Expand Down
2 changes: 2 additions & 0 deletions packages/autocomplete/src/commands/autocomplete/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default class Options extends AutocompleteBase {
const [argsIndex, curPositionIsFlag, curPositionIsFlagValue] = this.determineCmdState(slicedArgv, Klass)
return {id, Klass, argsIndex, curPositionIsFlag, curPositionIsFlagValue, slicedArgv}
}

this.throwError(`Command ${id} not found`)
}

Expand Down Expand Up @@ -98,6 +99,7 @@ export default class Options extends AutocompleteBase {
if (!cacheCompletion) {
cacheCompletion = this.findCompletion(cacheKey, id)
}

return {cacheKey, cacheCompletion}
}

Expand Down
7 changes: 5 additions & 2 deletions packages/autocomplete/src/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const AppCompletion: Interfaces.Completion = {
personal: await herokuGet('users/~/apps', ctx),
teams: flatten(await Promise.all(teams.map((team: string) => herokuGet(`teams/${team}/apps`, ctx)))),
}

return apps.personal.concat(apps.teams)
},
}
Expand Down Expand Up @@ -77,6 +78,7 @@ const ConfigCompletion: Interfaces.Completion = {
const {body: configs} = await heroku.get<{body: Record<string, any>}>(`/apps/${ctx.flags.app}/config-vars`, {retryAuth: false})
return Object.keys(configs)
}

return []
},
}
Expand All @@ -92,6 +94,7 @@ const ConfigSetCompletion: Interfaces.Completion = {
const {body: configs} = await heroku.get<{body: Record<string, any>}>(`/apps/${ctx.flags.app}/config-vars`, {retryAuth: false})
return Object.keys(configs).map(k => `${k}=`)
}

return []
},
}
Expand Down Expand Up @@ -142,6 +145,7 @@ export const ProcessTypeCompletion: Interfaces.Completion = {
} catch (error: any) {
if (error.code !== 'ENOENT') throw error
}

return types
},
}
Expand Down Expand Up @@ -254,8 +258,7 @@ export class CompletionLookup {
}

// eslint-disable-next-line no-useless-constructor
constructor(private readonly cmdId: string, private readonly name: string, private readonly description?: string) {
}
constructor(private readonly cmdId: string, private readonly name: string, private readonly description?: string) {}

run(): Interfaces.Completion | undefined {
if (this.blocklisted()) return
Expand Down
1 change: 1 addition & 0 deletions packages/autocomplete/src/hooks/recache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ export const completions: Interfaces.Hook<'app' | 'addon' | 'config' | 'login' |
} catch (error: any) {
this.debug(error.message)
}

CliUx.ux.action.stop()
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/* eslint-disable no-useless-escape */
import Nock from '@fancy-test/nock'
import * as Test from '@oclif/test'

const test = Test.test
.register('nock', Nock)
const expect = Test.expect
import {expect, test} from '@oclif/test'

// autocomplete will throw error on windows
const {default: runtest} = require('../../helpers/runtest')
Expand Down
1 change: 0 additions & 1 deletion packages/buildpacks/.eslintignore

This file was deleted.

10 changes: 0 additions & 10 deletions packages/buildpacks/.eslintrc

This file was deleted.

5 changes: 1 addition & 4 deletions packages/buildpacks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"@types/node-fetch": "^2.1.6",
"@types/supports-color": "^5.3.0",
"chai": "^4.2.0",
"eslint": "^6.7.2",
"eslint-config-oclif": "^3.1.0",
"eslint-config-oclif-typescript": "^0.1.0",
"globby": "^9.0.0",
"mocha": "^5",
"nock": "^10.0.6",
Expand Down Expand Up @@ -64,7 +61,7 @@
},
"repository": "heroku/cli",
"scripts": {
"lint": "eslint . --ext .ts --config .eslintrc",
"lint": "eslint . --ext .ts --config ../../.eslintrc --ignore-path ../../.eslintignore",
"postpack": "rm -f oclif.manifest.json npm-shrinkwrap.json",
"prepack": "rm -rf lib && tsc && oclif manifest",
"prepare": "rm -rf lib && tsc",
Expand Down
1 change: 1 addition & 0 deletions packages/buildpacks/src/buildpacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class BuildpackCommand {
return b.ordinal + 1 === index
})
}

return -1
}

Expand Down
1 change: 1 addition & 0 deletions packages/buildpacks/src/commands/buildpacks/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class Add extends Command {
if (flags.index === undefined) {
spliceIndex = buildpacks.length
} else {
// eslint-disable-next-line unicorn/no-array-callback-reference, unicorn/no-array-method-this-argument
const foundIndex = buildpackCommand.findIndex(buildpacks, flags.index)
spliceIndex = (foundIndex === -1) ? buildpacks.length : foundIndex
}
Expand Down
2 changes: 2 additions & 0 deletions packages/buildpacks/src/commands/buildpacks/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class Remove extends Command {
if (flags.index && args.buildpack) {
CliUx.ux.error('Please choose either index or Buildpack, but not both.', {exit: 1})
}

if (!flags.index && !args.buildpack) {
CliUx.ux.error('Usage: heroku buildpacks:remove [BUILDPACK_URL]. Must specify a buildpack to remove, either by index or URL.')
}
Expand All @@ -41,6 +42,7 @@ export default class Remove extends Command {
let spliceIndex: number
if (flags.index) {
buildpackCommand.validateIndexInRange(buildpacks, flags.index)
// eslint-disable-next-line unicorn/no-array-method-this-argument
spliceIndex = await buildpackCommand.findIndex(buildpacks, flags.index)
} else {
spliceIndex = await buildpackCommand.findUrl(buildpacks, args.buildpack)
Expand Down
2 changes: 2 additions & 0 deletions packages/buildpacks/src/commands/buildpacks/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export default class Search extends Command {

if (args.term) {
const uniqueBuildpacks = new Map<string, BuildpackBody>()
// eslint-disable-next-line unicorn/no-useless-undefined
const array = ((await registry.search(args.term, undefined, undefined)).unwrapOr([]))
// eslint-disable-next-line unicorn/no-useless-undefined
.concat((await registry.search(undefined, args.term, undefined)).unwrapOr([]))
.concat((await registry.search(undefined, undefined, args.term)).unwrapOr([]))
array
Expand Down
1 change: 1 addition & 0 deletions packages/buildpacks/src/commands/buildpacks/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class Set extends Command {
if (flags.index === undefined) {
spliceIndex = 0
} else {
// eslint-disable-next-line unicorn/no-array-callback-reference, unicorn/no-array-method-this-argument
const foundIndex = buildpackCommand.findIndex(buildpacks, flags.index)
spliceIndex = (foundIndex === -1) ? buildpacks.length : foundIndex
}
Expand Down
Loading

0 comments on commit a94632b

Please sign in to comment.