Skip to content

Commit

Permalink
chore: more eslint changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jan 28, 2025
1 parent 4619e06 commit b69040a
Show file tree
Hide file tree
Showing 23 changed files with 462 additions and 201 deletions.
6 changes: 6 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export default [
'perfectionist/sort-classes': 'off',
'perfectionist/sort-objects': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/no-abusive-eslint-disable': 'off',
'unicorn/no-static-only-class': 'off',
'unicorn/no-useless-undefined': 'off',
},
},
{
Expand All @@ -46,6 +49,8 @@ export default [
'mocha/no-nested-tests': 'off',
'mocha/no-sibling-hooks': 'off',
'mocha/no-top-level-hooks': 'off',
'unicorn/prefer-object-from-entries': 'off',
'unicorn/prefer-top-level-await': 'off',
},
},
{
Expand All @@ -54,6 +59,7 @@ export default [
'@typescript-eslint/no-unused-expressions': 'off',
camelcase: 'off',
'no-undef': 'off',
'unicorn/filename-case': 'off',
},
},
]
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
"commitlint": "^19",
"cross-env": "^7.0.3",
"eslint": "^9",
"eslint-config-oclif": "^5.2.2",
"eslint-config-oclif-typescript": "^3.1.13",
"eslint-config-oclif": "^6",
"eslint-config-prettier": "^10",
"husky": "^9.1.7",
"lint-staged": "^15",
Expand Down
6 changes: 3 additions & 3 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export abstract class Command {

protected async init(): Promise<any> {
this.debug('init version: %s argv: %o', this.ctor._base, this.argv)
const g: any = global
const g: any = globalThis
g['http-call'] = g['http-call'] || {}
g['http-call']!.userAgent = this.config.userAgent
this.warnIfCommandDeprecated()
Expand All @@ -237,9 +237,9 @@ export abstract class Command {
const jsonIndex = this.argv.indexOf('--json')
return passThroughIndex === -1
? // If '--' is not present, then check for `--json` in this.argv
jsonIndex > -1
jsonIndex !== -1
: // If '--' is present, return true only the --json flag exists and is before the '--'
jsonIndex > -1 && jsonIndex < passThroughIndex
jsonIndex !== -1 && jsonIndex < passThroughIndex
}

public log(message = '', ...args: any[]): void {
Expand Down
4 changes: 2 additions & 2 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ export class Config implements IConfig {
}

const [defaultTheme, userTheme] = await Promise.all([
await getDefaultTheme(),
await safeReadJson<Record<string, string>>(userThemeFile),
getDefaultTheme(),
safeReadJson<Record<string, string>>(userThemeFile),
])

// Merge the default theme with the user theme, giving the user theme precedence.
Expand Down
2 changes: 1 addition & 1 deletion src/config/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export class Plugin implements IPlugin {
}),
)
)

// eslint-disable-next-line unicorn/prefer-native-coercion-functions
.filter((f): f is [string, Command.Cached] => Boolean(f))
.reduce<{[k: string]: Command.Cached}>((commands, [id, c]) => {
commands[id] = c
Expand Down
2 changes: 1 addition & 1 deletion src/errors/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import prettyPrint from './errors/pretty-print'
*/
export const Exit = {
exit(code = 0) {
// eslint-disable-next-line n/no-process-exit
// eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
process.exit(code)
},
}
Expand Down
8 changes: 4 additions & 4 deletions src/parser/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ export const readStdin = async (): Promise<null | string> => {

if (stdin.isTTY) return null

if (global.oclif?.stdinCache) {
debug('resolved stdin from global cache', global.oclif.stdinCache)
return global.oclif.stdinCache
if (globalThis.oclif?.stdinCache) {
debug('resolved stdin from global cache', globalThis.oclif.stdinCache)
return globalThis.oclif.stdinCache
}

return new Promise((resolve) => {
Expand All @@ -86,7 +86,7 @@ export const readStdin = async (): Promise<null | string> => {
rl.once('close', () => {
clearTimeout(timeout)
debug('resolved from stdin', result)
global.oclif = {...global.oclif, stdinCache: result}
globalThis.oclif = {...globalThis.oclif, stdinCache: result}
resolve(result)
})

Expand Down
4 changes: 2 additions & 2 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ export type Settings = {
}

// Set global.oclif to the new object if it wasn't set before
if (!(global as any).oclif) (global as any).oclif = {}
if (!(globalThis as any).oclif) (globalThis as any).oclif = {}

export const settings: Settings = (global as any).oclif as Settings
export const settings: Settings = (globalThis as any).oclif as Settings
4 changes: 2 additions & 2 deletions src/util/cache-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ export async function cacheCommand(
const uncachedBaseFlags = cmd.baseFlags ?? cmd._baseFlags

const [flags, args] = await Promise.all([
await cacheFlags(aggregateFlags(uncachedFlags, uncachedBaseFlags, cmd.enableJsonFlag), respectNoCacheDefault),
await cacheArgs(ensureArgObject(cmd.args), respectNoCacheDefault),
cacheFlags(aggregateFlags(uncachedFlags, uncachedBaseFlags, cmd.enableJsonFlag), respectNoCacheDefault),
cacheArgs(ensureArgObject(cmd.args), respectNoCacheDefault),
])

const stdProperties = {
Expand Down
1 change: 1 addition & 0 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function pickBy<T extends {[s: string]: T[keyof T]} | ArrayLike<T[keyof T
}

export function compact<T>(a: (T | undefined)[]): T[] {
// eslint-disable-next-line unicorn/prefer-native-coercion-functions
return a.filter((a): a is T => Boolean(a))
}

Expand Down
4 changes: 2 additions & 2 deletions src/ux/action/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export class ActionBase {
}

private get globals(): {action: {task?: Task | undefined}; output: string | undefined} {
;(global as any).ux = (global as any).ux || {}
const globals = (global as any).ux
;(globalThis as any).ux = (globalThis as any).ux || {}
const globals = (globalThis as any).ux
globals.action = globals.action || {}
return globals
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {HelpBase, Interfaces} from '../../../../../src'

export type TestHelpClassConfig = Interfaces.Config & {showCommandHelpSpy?: SinonSpy; showHelpSpy?: SinonSpy}

export default class extends HelpBase {
export default class CustomHelp extends HelpBase {
showCommandHelp = spy(async () => {
console.log('hello from test-help-plugin #showCommandHelp')
})
Expand Down
3 changes: 3 additions & 0 deletions test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ describe('Config', () => {
process.env.LOCALAPPDATA = '/my/home/localappdata'
const config = await Config.load()

// eslint-disable-next-line unicorn/prefer-string-raw
expect(config).to.have.property('cacheDir', join('/my/home/localappdata/@oclif\\core'))
// eslint-disable-next-line unicorn/prefer-string-raw
expect(config).to.have.property('configDir', join('/my/home/localappdata/@oclif\\core'))
// eslint-disable-next-line unicorn/prefer-string-raw
expect(config).to.have.property('dataDir', join('/my/home/localappdata/@oclif\\core'))
expect(config).to.have.property('home', join('/my/home'))
})
Expand Down
2 changes: 1 addition & 1 deletion test/help/_test-help-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import {HelpBase} from '../../src'

export default class extends HelpBase {
export default class CustomHelp extends HelpBase {
getCommandHelpForReadme(): string {
return 'help for readme'
}
Expand Down
4 changes: 2 additions & 2 deletions test/help/format-command-with-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {expect} from 'chai'
import {Args, Config, Flags as flags} from '../../src'
import {makeCommandClass, makeLoadable, TestHelpWithOptions as TestHelp} from './help-test-utils'

const g: any = global
const g: any = globalThis
g.oclif.columns = 80

describe('formatCommand', () => {
Expand Down Expand Up @@ -178,7 +178,7 @@ ALIASES
})

describe('description', () => {
it('should output command description with values after a \\n newline character', async () => {
it(`should output command description with values after a \n newline character`, async () => {
const cmd = await makeLoadable(
makeCommandClass({
aliases: ['app:init', 'create'],
Expand Down
4 changes: 2 additions & 2 deletions test/help/format-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {expect} from 'chai'
import {Args, Config, Flags as flags} from '../../src'
import {makeCommandClass, makeLoadable, TestHelp} from './help-test-utils'

const g: any = global
const g: any = globalThis
g.oclif.columns = 80

describe('formatCommand', () => {
Expand Down Expand Up @@ -235,7 +235,7 @@ DESCRIPTION
})

describe('description', () => {
it('should output the command description with the values after a \\n newline character', async () => {
it(`should output the command description with the values after a \n newline character`, async () => {
const cmd = await makeLoadable(
makeCommandClass({
id: 'apps:create',
Expand Down
2 changes: 1 addition & 1 deletion test/help/format-commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {expect} from 'chai'

import {Command} from '../../src/command'

const g: any = global
const g: any = globalThis
g.oclif.columns = 80
import {Config} from '../../src'
import {Help} from '../../src/help'
Expand Down
2 changes: 1 addition & 1 deletion test/help/format-root.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ USAGE
})

describe('description', () => {
it('splits on \\n for the description into the top-level and description sections', () => {
it(`splits on \n for the description into the top-level and description sections`, () => {
sinon
.stub(config.pjson, 'description')
.value(
Expand Down
4 changes: 2 additions & 2 deletions test/help/format-topic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ USAGE
`)
})

it('shows topic descriptions split from \\n for top-level and description section descriptions', () => {
it(`shows topic descriptions split from \n for top-level and description section descriptions`, () => {
const topic = {
name: 'topic',
hidden: false,
Expand All @@ -63,7 +63,7 @@ DESCRIPTION
`)
})

it('shows templated topic descriptions split from \\n for top-level and description section descriptions', () => {
it(`shows templated topic descriptions split from \n for top-level and description section descriptions`, () => {
const topic = {
name: 'topic',
hidden: false,
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ const chaiAsPromised = require('chai-as-promised')

chai.use(chaiAsPromised)

global.oclif = global.oclif || {}
global.oclif.columns = 80
global.columns = '80'
globalThis.oclif = globalThis.oclif || {}
globalThis.oclif.columns = 80
globalThis.columns = '80'
16 changes: 8 additions & 8 deletions test/parser/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,13 @@ See more help with --help`)
expect(out.flags).to.deep.include({foo: ['a', 'b']})
})

it('parses single flag starting with with \\ escape char', async () => {
const out = await parse(['--foo', '\\file:foo'], {
it(`parses single flag starting with with escape char`, async () => {
const out = await parse(['--foo', String.raw`\file:foo`], {
flags: {
foo: Flags.custom({multiple: true})(),
},
})
expect(out.flags).to.deep.include({foo: ['\\file:foo']})
expect(out.flags).to.deep.include({foo: [String.raw`\file:foo`]})
})

it('parses multiple space-delimited flags', async () => {
Expand All @@ -540,14 +540,14 @@ See more help with --help`)
expect(out.flags).to.deep.include({foo: ['a', 'b', 'c']})
})

it('parses multiple space-delimited flags ending with with \\ escape char', async () => {
it(`parses multiple space-delimited flags ending with with escape char`, async () => {
const out = await parse(['--foo', 'c:\\', 'd:\\'], {
flags: {foo: Flags.string({multiple: true})},
})
expect(out.flags).to.deep.include({foo: ['c:\\', 'd:\\']})
})

it('parses multiple space-delimited flags ending with with \\ escape char', async () => {
it(`parses multiple space-delimited flags ending with with escape char`, async () => {
const out = await parse(['--foo', 'c:\\', 'd:\\'], {
flags: {foo: Flags.string({multiple: true})},
})
Expand Down Expand Up @@ -703,7 +703,7 @@ See more help with --help`)
})

it('does not split on escaped delimiter', async () => {
const out = await parse(['--foo', 'a\\,b,c'], {
const out = await parse(['--foo', String.raw`a\,b,c`], {
flags: {
foo: Flags.string({multiple: true, delimiter: ','}),
},
Expand All @@ -712,7 +712,7 @@ See more help with --help`)
})

it('escapes with multiple invocation', async () => {
const out = await parse(['--foo', 'a\\,b', '--foo', 'b'], {
const out = await parse(['--foo', String.raw`a\,b`, '--foo', 'b'], {
flags: {
foo: Flags.string({multiple: true, delimiter: ','}),
},
Expand All @@ -721,7 +721,7 @@ See more help with --help`)
})

it('comma-escaped stringified json', async () => {
const val = '{"a":"b"\\,"c":"d"}'
const val = String.raw`{"a":"b"\,"c":"d"}`
const expected = '{"a":"b","c":"d"}'
const out = await parse(['--foo', val], {
flags: {
Expand Down
4 changes: 2 additions & 2 deletions test/ux/colorize-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ describe('colorizeJson', () => {
})

it('tokenizes a string literal with an escaped quote', () => {
const result = tokenize('"a\\"b"')
expect(result).to.deep.equal([{type: 'string', value: '"a\\"b"'}])
const result = tokenize(String.raw`"a\"b"`)
expect(result).to.deep.equal([{type: 'string', value: String.raw`"a\"b"`}])
})

it('tokenizes a key-value pair with whitespace between the :', () => {
Expand Down
Loading

0 comments on commit b69040a

Please sign in to comment.