diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 4f253484..086779e5 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -10,12 +10,6 @@ } }, "src/autocomplete/powershell.ts": { - "@typescript-eslint/consistent-indexed-object-style": { - "count": 1 - }, - "@typescript-eslint/consistent-type-imports": { - "count": 1 - }, "@typescript-eslint/no-loop-func": { "count": 1 }, @@ -28,9 +22,6 @@ "@typescript-eslint/prefer-nullish-coalescing": { "count": 1 }, - "@typescript-eslint/prefer-readonly": { - "count": 2 - }, "unicorn/consistent-class-member-order": { "count": 1 }, @@ -43,35 +34,14 @@ "unicorn/no-break-in-nested-loop": { "count": 1 }, - "unicorn/no-negated-array-predicate": { - "count": 1 - }, - "unicorn/prefer-array-from-map": { - "count": 1 - }, - "unicorn/prefer-continue": { - "count": 2 - }, "unicorn/prefer-simple-sort-comparator": { "count": 1 } }, "src/autocomplete/zsh.ts": { - "@typescript-eslint/array-type": { - "count": 4 - }, - "@typescript-eslint/consistent-indexed-object-style": { - "count": 1 - }, - "@typescript-eslint/consistent-type-imports": { - "count": 1 - }, "@typescript-eslint/no-loop-func": { "count": 1 }, - "@typescript-eslint/prefer-readonly": { - "count": 2 - }, "require-unicode-regexp": { "count": 2 }, @@ -87,14 +57,8 @@ "unicorn/no-duplicate-loops": { "count": 4 }, - "unicorn/no-negated-array-predicate": { - "count": 2 - }, "unicorn/prefer-simple-sort-comparator": { "count": 1 - }, - "unicorn/prefer-split-limit": { - "count": 1 } }, "src/base.ts": { @@ -110,20 +74,14 @@ "count": 2 }, "@typescript-eslint/no-unsafe-member-access": { - "count": 13 + "count": 12 }, "@typescript-eslint/prefer-nullish-coalescing": { "count": 5 }, - "@typescript-eslint/prefer-optional-chain": { - "count": 1 - }, "require-unicode-regexp": { "count": 2 }, - "unicorn/consistent-boolean-name": { - "count": 2 - }, "unicorn/consistent-class-member-order": { "count": 1 }, @@ -138,18 +96,9 @@ }, "unicorn/prefer-simple-condition-first": { "count": 2 - }, - "unicorn/prefer-split-limit": { - "count": 1 } }, "src/commands/autocomplete/index.ts": { - "@stylistic/lines-between-class-members": { - "count": 2 - }, - "@typescript-eslint/no-unnecessary-template-expression": { - "count": 1 - }, "@typescript-eslint/switch-exhaustiveness-check": { "count": 1 }, @@ -157,33 +106,17 @@ "count": 1 } }, - "src/commands/autocomplete/script.ts": { - "@stylistic/lines-between-class-members": { - "count": 1 - } - }, - "src/hooks/refresh-cache.ts": { - "@typescript-eslint/consistent-type-imports": { - "count": 1 - } - }, "src/index.ts": { "import-x/no-anonymous-default-export": { "count": 1 } }, "test/autocomplete/bash.test.ts": { - "@typescript-eslint/consistent-indexed-object-style": { + "@typescript-eslint/class-literal-property-style": { "count": 1 }, - "@typescript-eslint/consistent-type-imports": { - "count": 2 - }, "@typescript-eslint/no-empty-function": { - "count": 1 - }, - "@typescript-eslint/no-unnecessary-template-expression": { - "count": 6 + "count": 2 }, "@typescript-eslint/no-unsafe-assignment": { "count": 1 @@ -191,34 +124,19 @@ "@typescript-eslint/no-unsafe-call": { "count": 2 }, - "@typescript-eslint/promise-function-async": { + "@typescript-eslint/no-unused-private-class-members": { "count": 1 }, - "import-x/no-named-default": { - "count": 1 - }, - "unicorn/consistent-template-literal-escape": { - "count": 6 - }, - "unicorn/no-named-default": { - "count": 1 - }, - "unicorn/prefer-private-class-fields": { + "unicorn/consistent-class-member-order": { "count": 1 } }, "test/autocomplete/powershell.test.ts": { - "@typescript-eslint/consistent-indexed-object-style": { + "@typescript-eslint/class-literal-property-style": { "count": 1 }, - "@typescript-eslint/consistent-type-imports": { - "count": 2 - }, "@typescript-eslint/no-empty-function": { - "count": 1 - }, - "@typescript-eslint/no-unnecessary-type-assertion": { - "count": 3 + "count": 2 }, "@typescript-eslint/no-unsafe-assignment": { "count": 1 @@ -226,25 +144,19 @@ "@typescript-eslint/no-unsafe-call": { "count": 2 }, - "@typescript-eslint/promise-function-async": { + "@typescript-eslint/no-unused-private-class-members": { "count": 1 }, - "unicorn/prefer-private-class-fields": { + "unicorn/consistent-class-member-order": { "count": 1 } }, "test/autocomplete/zsh.test.ts": { - "@typescript-eslint/consistent-indexed-object-style": { + "@typescript-eslint/class-literal-property-style": { "count": 1 }, - "@typescript-eslint/consistent-type-imports": { - "count": 2 - }, "@typescript-eslint/no-empty-function": { - "count": 1 - }, - "@typescript-eslint/no-unnecessary-type-assertion": { - "count": 3 + "count": 2 }, "@typescript-eslint/no-unsafe-assignment": { "count": 1 @@ -252,16 +164,10 @@ "@typescript-eslint/no-unsafe-call": { "count": 2 }, - "@typescript-eslint/promise-function-async": { - "count": 1 - }, - "import-x/no-named-default": { - "count": 1 - }, - "unicorn/no-named-default": { + "@typescript-eslint/no-unused-private-class-members": { "count": 1 }, - "unicorn/prefer-private-class-fields": { + "unicorn/consistent-class-member-order": { "count": 1 } }, @@ -269,15 +175,9 @@ "@eslint-community/eslint-comments/require-description": { "count": 1 }, - "@typescript-eslint/consistent-type-imports": { - "count": 1 - }, "@typescript-eslint/no-shadow": { "count": 1 }, - "@typescript-eslint/no-unnecessary-template-expression": { - "count": 1 - }, "@typescript-eslint/no-unsafe-assignment": { "count": 1 }, @@ -290,36 +190,11 @@ "@typescript-eslint/no-unsafe-return": { "count": 1 }, - "@typescript-eslint/promise-function-async": { - "count": 2 - }, - "import-x/no-named-default": { - "count": 1 - }, "unicorn/max-nested-calls": { "count": 2 }, "unicorn/no-incorrect-template-string-interpolation": { "count": 1 - }, - "unicorn/no-named-default": { - "count": 1 - } - }, - "test/commands/autocomplete/index.test.ts": { - "import-x/no-named-default": { - "count": 1 - }, - "unicorn/no-named-default": { - "count": 1 - } - }, - "test/commands/autocomplete/script.test.ts": { - "import-x/no-named-default": { - "count": 1 - }, - "unicorn/no-named-default": { - "count": 1 } }, "test/helpers/runtest.ts": { @@ -330,4 +205,4 @@ "count": 1 } } -} \ No newline at end of file +} diff --git a/src/autocomplete/powershell.ts b/src/autocomplete/powershell.ts index 46b8b582..269ab050 100644 --- a/src/autocomplete/powershell.ts +++ b/src/autocomplete/powershell.ts @@ -1,4 +1,4 @@ -import {Command, Config, Interfaces} from '@oclif/core' +import {type Command, type Config, type Interfaces} from '@oclif/core' import * as ejs from 'ejs' import {EOL} from 'node:os' import {format} from 'node:util' @@ -9,9 +9,7 @@ type CommandCompletion = { summary: string } -type CommandFlags = { - [name: string]: Command.Flag.Cached -} +type CommandFlags = Record type Topic = { description: string @@ -21,8 +19,8 @@ type Topic = { export default class PowerShellComp { protected config: Config private _coTopics?: string[] - private commands: CommandCompletion[] - private topics: Topic[] + private readonly commands: CommandCompletion[] + private readonly topics: Topic[] constructor(config: Config) { this.config = config @@ -100,29 +98,33 @@ export default class PowerShellComp { // Collect top-level topics and generate a cmd tree node for each one of them. for (const t of this.topics) { - if (!t.name.includes(':')) { - commandTree[t.name] = this.coTopics.includes(t.name) - ? { - ...genNode(t.name), - } - : { - _summary: t.description, - ...genNode(t.name), - } - - topLevelArgs.push(t.name) + if (t.name.includes(':')) { + continue } + + commandTree[t.name] = this.coTopics.includes(t.name) + ? { + ...genNode(t.name), + } + : { + _summary: t.description, + ...genNode(t.name), + } + + topLevelArgs.push(t.name) } // Collect top-level commands and add a cmd tree node with the command ID. for (const c of this.commands) { - if (!c.id.includes(':') && !this.coTopics.includes(c.id)) { - commandTree[c.id] = { - _command: c.id, - } + if (c.id.includes(':') || this.coTopics.includes(c.id)) { + continue + } - topLevelArgs.push(c.id) + commandTree[c.id] = { + _command: c.id, } + + topLevelArgs.push(c.id) } const hashtables: string[] = [] @@ -325,11 +327,7 @@ ${flaghHashtables.join('\n')} const newKeys = nodeKeys.filter((k) => k !== '_summary') if (newKeys.length > 0) { - const childNodes: string[] = [] - - for (const newKey of newKeys) { - childNodes.push(this.genHashtable(newKey, node[key])) - } + const childNodes: string[] = Array.from(newKeys, (newKey) => this.genHashtable(newKey, node[key])) childTpl = format(childTpl, childNodes.join('\n')) @@ -396,7 +394,7 @@ ${flaghHashtables.join('\n')} // but aliases aren't guaranteed to follow the plugin command tree // so we need to add any missing topic between the starting point and the alias. for (let i = 0; i < split.length - 1; i++) { - if (!this.topics.some((t) => t.name === topic)) { + if (this.topics.every((t) => t.name !== topic)) { this.topics.push({ description: `${topic.replaceAll(':', ' ')} commands`, name: topic, diff --git a/src/autocomplete/zsh.ts b/src/autocomplete/zsh.ts index 115dca9f..72b84759 100644 --- a/src/autocomplete/zsh.ts +++ b/src/autocomplete/zsh.ts @@ -1,4 +1,4 @@ -import {Command, Config, Interfaces} from '@oclif/core' +import {type Command, type Config, type Interfaces} from '@oclif/core' import * as ejs from 'ejs' import {format} from 'node:util' @@ -10,9 +10,7 @@ type CommandCompletion = { summary: string } -type CommandFlags = { - [name: string]: Command.Flag.Cached -} +type CommandFlags = Record type Topic = { description: string @@ -22,8 +20,8 @@ type Topic = { export default class ZshCompWithSpaces { protected config: Config private _coTopics?: string[] - private commands: CommandCompletion[] - private topics: Topic[] + private readonly commands: CommandCompletion[] + private readonly topics: Topic[] constructor(config: Config) { this.config = config @@ -50,7 +48,7 @@ export default class ZshCompWithSpaces { } public generate(): string { - const firstArgs: {id: string; summary?: string}[] = [] + const firstArgs: Array<{id: string; summary?: string}> = [] for (const t of this.topics) { if (!t.name.includes(':')) @@ -61,7 +59,7 @@ export default class ZshCompWithSpaces { } for (const c of this.commands) { - if (!firstArgs.some((a) => a.id === c.id) && !c.id.includes(':')) + if (firstArgs.every((a) => a.id !== c.id) && !c.id.includes(':')) firstArgs.push({ id: c.id, summary: c.summary, @@ -240,7 +238,7 @@ _${this.config.bin} esac } ` - const subArgs: {id: string; summary?: string}[] = [] + const subArgs: Array<{id: string; summary?: string}> = [] let argsBlock = '' @@ -274,7 +272,7 @@ _${this.config.bin} let argsBlock = '' - const subArgs: {id: string; summary?: string}[] = [] + const subArgs: Array<{id: string; summary?: string}> = [] for (const t of this.topics.filter((t) => t.name.startsWith(id + ':') && t.name.split(':').length === depth + 1)) { const subArg = t.name.split(':')[depth] @@ -319,7 +317,7 @@ _${this.config.bin} return format(topicCompFunc, this.genZshValuesBlock(subArgs), argsBlock) } - private genZshValuesBlock(subArgs: {id: string; summary?: string}[]): string { + private genZshValuesBlock(subArgs: Array<{id: string; summary?: string}>): string { let valuesBlock = '_values "completions" \\\n' for (const subArg of subArgs) { @@ -360,7 +358,7 @@ _${this.config.bin} // but aliases aren't guaranteed to follow the plugin command tree // so we need to add any missing topic between the starting point and the alias. for (let i = 0; i < split.length - 1; i++) { - if (!this.topics.some((t) => t.name === topic)) { + if (this.topics.every((t) => t.name !== topic)) { this.topics.push({ description: `${topic.replaceAll(':', ' ')} commands`, name: topic, @@ -418,6 +416,6 @@ _${this.config.bin} .replaceAll(/(["`])/g, '\\\\\\$1') // backticks and double-quotes require triple-backslashes .replaceAll(/([[\]])/g, '\\\\$1') // square brackets require double-backslashes - .split('\n')[0] // only use the first line + .split('\n', 1)[0] // only use the first line } } diff --git a/src/commands/autocomplete/create.ts b/src/commands/autocomplete/create.ts index a815f9cb..5baf2ff8 100644 --- a/src/commands/autocomplete/create.ts +++ b/src/commands/autocomplete/create.ts @@ -25,7 +25,7 @@ function sanitizeDescription(description?: string): string { .replaceAll(/(["`])/g, '\\\\\\$1') // backticks and double-quotes require triple-backslashes .replaceAll(/([[\]])/g, '\\\\$1') // square brackets require double-backslashes - .split('\n')[0] // only use the first line + .split('\n', 1)[0] // only use the first line } export default class Create extends AutocompleteBase { @@ -44,19 +44,17 @@ export default class Create extends AutocompleteBase { private get bashCompletionFunction(): string { const {cliBin} = this - const supportSpaces = this.config.topicSeparator === ' ' + const isSupportSpaces = this.config.topicSeparator === ' ' const bashScript = - process.env.OCLIF_AUTOCOMPLETE_TOPIC_SEPARATOR === 'colon' || !supportSpaces + process.env.OCLIF_AUTOCOMPLETE_TOPIC_SEPARATOR === 'colon' || !isSupportSpaces ? bashAutocomplete : bashAutocompleteWithSpaces - return ( - bashScript - .concat( - ...(this.config.binAliases?.map((alias) => `complete -F __autocomplete ${alias}`).join('\n') ?? []), - ) - .replaceAll('', cliBin) - .replaceAll('', this.bashCommandsWithFlagsList) - ) + return bashScript + .concat( + ...(this.config.binAliases?.map((alias) => `complete -F __autocomplete ${alias}`).join('\n') ?? []), + ) + .replaceAll('', cliBin) + .replaceAll('', this.bashCommandsWithFlagsList) } private get bashCompletionFunctionPath(): string { @@ -230,7 +228,7 @@ compinit;\n` private async createFiles() { // zsh - const supportSpaces = this.config.topicSeparator === ' ' + const isSupportSpaces = this.config.topicSeparator === ' ' await Promise.all( [ @@ -239,7 +237,7 @@ compinit;\n` writeFile(this.zshSetupScriptPath, this.zshSetupScript), // eslint-disable-next-line unicorn/prefer-spread ].concat( - process.env.OCLIF_AUTOCOMPLETE_TOPIC_SEPARATOR === 'colon' || !supportSpaces + process.env.OCLIF_AUTOCOMPLETE_TOPIC_SEPARATOR === 'colon' || !isSupportSpaces ? [writeFile(this.zshCompletionFunctionPath, this.zshCompletionFunction)] : [ writeFile(this.zshCompletionFunctionPath, new ZshCompWithSpaces(this.config).generate()), @@ -271,7 +269,7 @@ compinit;\n` return Object.keys(Klass.flags || {}) .filter((flag) => Klass.flags && !Klass.flags[flag].hidden) .map((flag) => { - const f = (Klass.flags && Klass.flags[flag]) || {description: ''} + const f = Klass.flags?.[flag] || {description: ''} const isBoolean = f.type === 'boolean' const isOption = f.type === 'option' const name = isBoolean ? flag : `${flag}=-` diff --git a/src/commands/autocomplete/index.ts b/src/commands/autocomplete/index.ts index 3d3a7a9d..db140664 100644 --- a/src/commands/autocomplete/index.ts +++ b/src/commands/autocomplete/index.ts @@ -13,6 +13,7 @@ export default class Index extends AutocompleteBase { required: false, }), } + static description = 'Display autocomplete installation instructions.' static examples = [ '$ <%= config.bin %> autocomplete', @@ -21,6 +22,7 @@ export default class Index extends AutocompleteBase { '$ <%= config.bin %> autocomplete powershell', '$ <%= config.bin %> autocomplete --refresh-cache', ] + static flags = { 'refresh-cache': Flags.boolean({char: 'r', description: 'Refresh cache (ignores displaying instructions)'}), } @@ -35,7 +37,7 @@ export default class Index extends AutocompleteBase { ) } - ux.action.start(`${bold('Building the autocomplete cache')}`) + ux.action.start(bold('Building the autocomplete cache')) await Create.run([], this.config) ux.action.stop() diff --git a/src/commands/autocomplete/script.ts b/src/commands/autocomplete/script.ts index 284dbfba..68675dab 100644 --- a/src/commands/autocomplete/script.ts +++ b/src/commands/autocomplete/script.ts @@ -11,6 +11,7 @@ export default class Script extends AutocompleteBase { required: false, }), } + static description = 'outputs autocomplete config script for shells' static hidden = true diff --git a/src/hooks/refresh-cache.ts b/src/hooks/refresh-cache.ts index f4f2f45e..725376d0 100644 --- a/src/hooks/refresh-cache.ts +++ b/src/hooks/refresh-cache.ts @@ -1,4 +1,4 @@ -import {Hook} from '@oclif/core' +import {type Hook} from '@oclif/core' const hook: Hook<'refresh'> = async function (opts) { // this `config` instance already have installed/uninstalled plugins loaded diff --git a/test/autocomplete/bash.test.ts b/test/autocomplete/bash.test.ts index 7c93b680..98709e4d 100644 --- a/test/autocomplete/bash.test.ts +++ b/test/autocomplete/bash.test.ts @@ -1,30 +1,28 @@ -import {Command, Config} from '@oclif/core' -import {Plugin as IPlugin} from '@oclif/core/interfaces' +import {type Command, Config} from '@oclif/core' +import {type Plugin as IPlugin} from '@oclif/core/interfaces' import {expect} from 'chai' import path from 'node:path' import {fileURLToPath} from 'node:url' import Create from '../../src/commands/autocomplete/create.js' // autocomplete will throw error on windows ci -import {default as skipWindows} from '../helpers/runtest.js' +import skipWindows from '../helpers/runtest.js' class MyCommandClass implements Command.Cached { [key: string]: unknown - _base = '' aliases: string[] = [] - args: {[name: string]: Command.Arg.Cached} = {} + args: Record = {} flags = {} hidden = false hiddenAliases!: string[] id = 'foo:bar' + readonly #base = '' new(): Command.Cached { // @ts-expect-error this is not the full interface but enough for testing return { - _run(): Promise { - return Promise.resolve() - }, + async _run(): Promise {}, } } @@ -190,32 +188,32 @@ skipWindows('bash comp', () => { _test-cli_autocomplete() { - local cur="$\{COMP_WORDS[COMP_CWORD]}" opts IFS=$' \\t\\n' + local cur="\${COMP_WORDS[COMP_CWORD]}" opts IFS=$' \\t\\n' COMPREPLY=() local commands=" autocomplete --refresh-cache deploy --api-version --ignore-errors --json --metadata deploy:functions --branch -${'search '} -${'app:execute:code '} +search +app:execute:code " if [[ "$cur" != "-"* ]]; then opts=$(printf "$commands" | grep -Eo '^[a-zA-Z0-9:_-]+') else local __COMP_WORDS - if [[ $\{COMP_WORDS[2]} == ":" ]]; then + if [[ \${COMP_WORDS[2]} == ":" ]]; then #subcommand - __COMP_WORDS=$(printf "%s" "$\{COMP_WORDS[@]:1:3}") + __COMP_WORDS=$(printf "%s" "\${COMP_WORDS[@]:1:3}") else #simple command - __COMP_WORDS="$\{COMP_WORDS[@]:1:1}" + __COMP_WORDS="\${COMP_WORDS[@]:1:1}" fi - opts=$(printf "$commands" | grep "$\{__COMP_WORDS}" | sed -n "s/^$\{__COMP_WORDS} //p") + opts=$(printf "$commands" | grep "\${__COMP_WORDS}" | sed -n "s/^\${__COMP_WORDS} //p") fi _get_comp_words_by_ref -n : cur - COMPREPLY=( $(compgen -W "$\{opts}" -- $\{cur}) ) + COMPREPLY=( $(compgen -W "\${opts}" -- \${cur}) ) __ltrim_colon_completions "$cur" return 0 @@ -234,32 +232,32 @@ complete -o default -F _test-cli_autocomplete test-cli`) _test-cli_autocomplete() { - local cur="$\{COMP_WORDS[COMP_CWORD]}" opts IFS=$' \\t\\n' + local cur="\${COMP_WORDS[COMP_CWORD]}" opts IFS=$' \\t\\n' COMPREPLY=() local commands=" autocomplete --refresh-cache deploy --api-version --ignore-errors --json --metadata deploy:functions --branch -${'search '} -${'app:execute:code '} +search +app:execute:code " if [[ "$cur" != "-"* ]]; then opts=$(printf "$commands" | grep -Eo '^[a-zA-Z0-9:_-]+') else local __COMP_WORDS - if [[ $\{COMP_WORDS[2]} == ":" ]]; then + if [[ \${COMP_WORDS[2]} == ":" ]]; then #subcommand - __COMP_WORDS=$(printf "%s" "$\{COMP_WORDS[@]:1:3}") + __COMP_WORDS=$(printf "%s" "\${COMP_WORDS[@]:1:3}") else #simple command - __COMP_WORDS="$\{COMP_WORDS[@]:1:1}" + __COMP_WORDS="\${COMP_WORDS[@]:1:1}" fi - opts=$(printf "$commands" | grep "$\{__COMP_WORDS}" | sed -n "s/^$\{__COMP_WORDS} //p") + opts=$(printf "$commands" | grep "\${__COMP_WORDS}" | sed -n "s/^\${__COMP_WORDS} //p") fi _get_comp_words_by_ref -n : cur - COMPREPLY=( $(compgen -W "$\{opts}" -- $\{cur}) ) + COMPREPLY=( $(compgen -W "\${opts}" -- \${cur}) ) __ltrim_colon_completions "$cur" return 0 @@ -279,32 +277,32 @@ complete -F _test-cli_autocomplete alias`) _test-cli_autocomplete() { - local cur="$\{COMP_WORDS[COMP_CWORD]}" opts IFS=$' \\t\\n' + local cur="\${COMP_WORDS[COMP_CWORD]}" opts IFS=$' \\t\\n' COMPREPLY=() local commands=" autocomplete --refresh-cache deploy --api-version --ignore-errors --json --metadata deploy:functions --branch -${'search '} -${'app:execute:code '} +search +app:execute:code " if [[ "$cur" != "-"* ]]; then opts=$(printf "$commands" | grep -Eo '^[a-zA-Z0-9:_-]+') else local __COMP_WORDS - if [[ $\{COMP_WORDS[2]} == ":" ]]; then + if [[ \${COMP_WORDS[2]} == ":" ]]; then #subcommand - __COMP_WORDS=$(printf "%s" "$\{COMP_WORDS[@]:1:3}") + __COMP_WORDS=$(printf "%s" "\${COMP_WORDS[@]:1:3}") else #simple command - __COMP_WORDS="$\{COMP_WORDS[@]:1:1}" + __COMP_WORDS="\${COMP_WORDS[@]:1:1}" fi - opts=$(printf "$commands" | grep "$\{__COMP_WORDS}" | sed -n "s/^$\{__COMP_WORDS} //p") + opts=$(printf "$commands" | grep "\${__COMP_WORDS}" | sed -n "s/^\${__COMP_WORDS} //p") fi _get_comp_words_by_ref -n : cur - COMPREPLY=( $(compgen -W "$\{opts}" -- $\{cur}) ) + COMPREPLY=( $(compgen -W "\${opts}" -- \${cur}) ) __ltrim_colon_completions "$cur" return 0 diff --git a/test/autocomplete/powershell.test.ts b/test/autocomplete/powershell.test.ts index 25283d0e..d6e14c96 100644 --- a/test/autocomplete/powershell.test.ts +++ b/test/autocomplete/powershell.test.ts @@ -1,5 +1,5 @@ -import {Command, Config} from '@oclif/core' -import {Deprecation, Plugin as IPlugin} from '@oclif/core/interfaces' +import {type Command, Config} from '@oclif/core' +import {type Deprecation, type Plugin as IPlugin} from '@oclif/core/interfaces' import {expect} from 'chai' import path from 'node:path' import {fileURLToPath} from 'node:url' @@ -8,10 +8,9 @@ import PowerShellComp from '../../src/autocomplete/powershell.js' class MyCommandClass implements Command.Cached { [key: string]: unknown - _base = '' aliases: string[] = [] aliasPermutations?: string[] | undefined - args: {[name: string]: Command.Arg.Cached} = {} + args: Record = {} deprecateAliases?: boolean | undefined deprecationOptions?: Deprecation | undefined description?: string | undefined @@ -32,13 +31,12 @@ class MyCommandClass implements Command.Cached { summary?: string | undefined type?: string | undefined usage?: string | string[] | undefined + readonly #base = '' new(): Command.Cached { // @ts-expect-error this is not the full interface but enough for testing return { - _run(): Promise { - return Promise.resolve() - }, + async _run(): Promise {}, } } @@ -196,7 +194,7 @@ describe('powershell completion', () => { it('generates a valid completion file.', () => { config.bin = 'test-cli' - const powerShellComp = new PowerShellComp(config as Config) + const powerShellComp = new PowerShellComp(config) expect(powerShellComp.generate()).to.equal(` using namespace System.Management.Automation using namespace System.Management.Automation.Language @@ -389,7 +387,7 @@ Register-ArgumentCompleter -Native -CommandName test-cli -ScriptBlock $scriptblo it('generates a valid completion file with a bin alias.', () => { config.bin = 'test-cli' config.binAliases = ['test'] - const powerShellComp = new PowerShellComp(config as Config) + const powerShellComp = new PowerShellComp(config) expect(powerShellComp.generate()).to.equal(` using namespace System.Management.Automation using namespace System.Management.Automation.Language @@ -582,7 +580,7 @@ Register-ArgumentCompleter -Native -CommandName @("test","test-cli") -ScriptBloc it('generates a valid completion file with multiple bin aliases.', () => { config.bin = 'test-cli' config.binAliases = ['test', 'test1'] - const powerShellComp = new PowerShellComp(config as Config) + const powerShellComp = new PowerShellComp(config) expect(powerShellComp.generate()).to.equal(` using namespace System.Management.Automation using namespace System.Management.Automation.Language diff --git a/test/autocomplete/zsh.test.ts b/test/autocomplete/zsh.test.ts index df92261a..bcd3c579 100644 --- a/test/autocomplete/zsh.test.ts +++ b/test/autocomplete/zsh.test.ts @@ -1,19 +1,18 @@ -import {Command, Config} from '@oclif/core' -import {Deprecation, Plugin as IPlugin} from '@oclif/core/interfaces' +import {type Command, Config} from '@oclif/core' +import {type Deprecation, type Plugin as IPlugin} from '@oclif/core/interfaces' import {expect} from 'chai' import path from 'node:path' import {fileURLToPath} from 'node:url' import ZshCompWithSpaces from '../../src/autocomplete/zsh.js' // autocomplete will throw error on windows ci -import {default as skipWindows} from '../helpers/runtest.js' +import skipWindows from '../helpers/runtest.js' class MyCommandClass implements Command.Cached { [key: string]: unknown - _base = '' aliases: string[] = [] aliasPermutations?: string[] | undefined - args: {[name: string]: Command.Arg.Cached} = {} + args: Record = {} deprecateAliases?: boolean | undefined deprecationOptions?: Deprecation | undefined description?: string | undefined @@ -34,13 +33,12 @@ class MyCommandClass implements Command.Cached { summary?: string | undefined type?: string | undefined usage?: string | string[] | undefined + readonly #base = '' new(): Command.Cached { // @ts-expect-error this is not the full interface but enough for testing return { - _run(): Promise { - return Promise.resolve() - }, + async _run(): Promise {}, } } @@ -202,7 +200,7 @@ skipWindows('zsh comp', () => { it('generates a valid completion file.', () => { config.bin = 'test-cli' - const zshCompWithSpaces = new ZshCompWithSpaces(config as Config) + const zshCompWithSpaces = new ZshCompWithSpaces(config) expect(zshCompWithSpaces.generate()).to.equal(`#compdef test-cli @@ -336,7 +334,7 @@ _test-cli it('generates a valid completion file with a bin alias.', () => { config.bin = 'test-cli' config.binAliases = ['testing'] - const zshCompWithSpaces = new ZshCompWithSpaces(config as Config) + const zshCompWithSpaces = new ZshCompWithSpaces(config) expect(zshCompWithSpaces.generate()).to.equal(`#compdef test-cli compdef testing=test-cli @@ -470,7 +468,7 @@ _test-cli it('generates a valid completion file with multiple bin aliases.', () => { config.bin = 'test-cli' config.binAliases = ['testing', 'testing2'] - const zshCompWithSpaces = new ZshCompWithSpaces(config as Config) + const zshCompWithSpaces = new ZshCompWithSpaces(config) expect(zshCompWithSpaces.generate()).to.equal(`#compdef test-cli compdef testing=test-cli compdef testing2=test-cli diff --git a/test/commands/autocomplete/create.test.ts b/test/commands/autocomplete/create.test.ts index c4455ce3..1b904d85 100644 --- a/test/commands/autocomplete/create.test.ts +++ b/test/commands/autocomplete/create.test.ts @@ -1,4 +1,4 @@ -import {Config, Interfaces, Plugin} from '@oclif/core' +import {Config, type Interfaces, Plugin} from '@oclif/core' import {expect} from 'chai' import {readFile} from 'node:fs/promises' import path from 'node:path' @@ -6,7 +6,7 @@ import {fileURLToPath} from 'node:url' import Create from '../../../src/commands/autocomplete/create.js' // autocomplete will throw error on windows ci -import {default as skipWindows} from '../../helpers/runtest.js' +import skipWindows from '../../helpers/runtest.js' const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../package.json') const config = new Config({root}) @@ -27,7 +27,7 @@ skipWindows('Create', () => { cmd = new Create([], config) plugin = new Plugin({root}) cmd.config.plugins = [plugin] - plugin._manifest = () => + plugin._manifest = async () => readJson(path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../test.oclif.manifest.json')) await plugin.load() }) @@ -114,7 +114,7 @@ complete -o default -F _oclif-example_autocomplete oclif-example\n`) const spacedCmd: any = new Create([], spacedConfig) const spacedPlugin: any = new Plugin({root}) spacedCmd.config.plugins = [spacedPlugin] - spacedPlugin._manifest = () => + spacedPlugin._manifest = async () => readJson(path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../test.oclif.manifest.json')) await spacedPlugin.load() @@ -181,7 +181,7 @@ foo --bar --baz --dangerous --brackets --double-quotes --multi-line --json opts=$(printf "%s " "\${commands[@]}") # | grep -Eo '^[a-zA-Z0-9_-]+' fi - ${'else '} + else # Flag # The full CLI command separated by colons (e.g. "mycli command subcommand --fl" -> "command:subcommand") diff --git a/test/commands/autocomplete/index.test.ts b/test/commands/autocomplete/index.test.ts index a172a221..94938d91 100644 --- a/test/commands/autocomplete/index.test.ts +++ b/test/commands/autocomplete/index.test.ts @@ -2,7 +2,7 @@ import {runCommand} from '@oclif/test' import {expect} from 'chai' // autocomplete will throw error on windows ci -import {default as skipWindows} from '../../helpers/runtest.js' +import skipWindows from '../../helpers/runtest.js' skipWindows('autocomplete index', () => { it('provides bash instructions', async () => { diff --git a/test/commands/autocomplete/script.test.ts b/test/commands/autocomplete/script.test.ts index 5dfeab8c..7c1cdae5 100644 --- a/test/commands/autocomplete/script.test.ts +++ b/test/commands/autocomplete/script.test.ts @@ -3,7 +3,7 @@ import {runCommand} from '@oclif/test' import {expect} from 'chai' // autocomplete will throw error on windows ci -import {default as skipWindows} from '../../helpers/runtest.js' +import skipWindows from '../../helpers/runtest.js' skipWindows('autocomplete:script', () => { it('provides bash profile config', async () => {