Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 14 additions & 139 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -28,9 +22,6 @@
"@typescript-eslint/prefer-nullish-coalescing": {
"count": 1
},
"@typescript-eslint/prefer-readonly": {
"count": 2
},
"unicorn/consistent-class-member-order": {
"count": 1
},
Expand All @@ -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
},
Expand All @@ -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": {
Expand All @@ -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
},
Expand All @@ -138,146 +96,88 @@
},
"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
},
"unicorn/consistent-class-member-order": {
"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
},
"@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
},
"@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
},
"@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
}
},
"test/commands/autocomplete/create.test.ts": {
"@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
},
Expand All @@ -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": {
Expand All @@ -330,4 +205,4 @@
"count": 1
}
}
}
}
54 changes: 26 additions & 28 deletions src/autocomplete/powershell.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -9,9 +9,7 @@ type CommandCompletion = {
summary: string
}

type CommandFlags = {
[name: string]: Command.Flag.Cached
}
type CommandFlags = Record<string, Command.Flag.Cached>

type Topic = {
description: string
Expand All @@ -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
Expand Down Expand Up @@ -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[] = []
Expand Down Expand Up @@ -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'))

Expand Down Expand Up @@ -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,
Expand Down
Loading
Loading