Skip to content

Commit

Permalink
Merge pull request #888 from oclif/mdonnalley/eslint-9
Browse files Browse the repository at this point in the history
chore(W-17692101): eslint 9
  • Loading branch information
mdonnalley authored Jan 29, 2025
2 parents 9c580ac + adc7fd3 commit 6e165f6
Show file tree
Hide file tree
Showing 18 changed files with 705 additions and 466 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

8 changes: 0 additions & 8 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion bin/dev.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning
// eslint-disable-next-line node/shebang

async function main() {
const {execute} = await import('@oclif/core')
await execute({development: true, dir: import.meta.url})
Expand Down
1 change: 0 additions & 1 deletion bin/run.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node

// eslint-disable-next-line node/shebang
async function main() {
const {execute} = await import('@oclif/core')
await execute({dir: import.meta.url})
Expand Down
21 changes: 21 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {includeIgnoreFile} from '@eslint/compat'
import oclif from 'eslint-config-oclif'
import prettier from 'eslint-config-prettier'
import path from 'node:path'
import {fileURLToPath} from 'node:url'

const gitignorePath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '.gitignore')

export default [
includeIgnoreFile(gitignorePath),
...oclif,
prettier,
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'max-depth': ['warn', 5],
'unicorn/consistent-destructuring': 'off',
'unicorn/prefer-string-raw': 'off',
},
},
]
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"devDependencies": {
"@commitlint/config-conventional": "^19",
"@eslint/compat": "^1.2.5",
"@oclif/plugin-help": "^6",
"@oclif/prettier-config": "^0.2.1",
"@oclif/test": "^4",
Expand All @@ -23,10 +24,9 @@
"@types/node": "^18",
"chai": "^4",
"commitlint": "^19",
"eslint": "^8.57.1",
"eslint-config-oclif": "^5.2.2",
"eslint-config-oclif-typescript": "^3.1.13",
"eslint-config-prettier": "^9.1.0",
"eslint": "^9.19.0",
"eslint-config-oclif": "^6.0.0",
"eslint-config-prettier": "^10.0.1",
"husky": "^9.1.7",
"lint-staged": "^15.4.1",
"mocha": "^10.8.2",
Expand Down Expand Up @@ -68,7 +68,7 @@
"build": "shx rm -rf lib && tsc",
"clean": "shx rm -f oclif.manifest.json",
"compile": "tsc",
"lint": "eslint . --ext .ts",
"lint": "eslint",
"postpack": "yarn run clean",
"posttest": "yarn lint",
"prepack": "yarn build && oclif manifest && oclif readme",
Expand Down
53 changes: 25 additions & 28 deletions src/autocomplete/powershell.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Command, Config, Interfaces} from '@oclif/core'
import * as ejs from 'ejs'
import {EOL} from 'node:os'
import * as util from 'node:util'
import {format} from 'node:util'

type CommandCompletion = {
flags: CommandFlags
Expand All @@ -20,11 +20,8 @@ type Topic = {

export default class PowerShellComp {
protected config: Config

private _coTopics?: string[]

private commands: CommandCompletion[]

private topics: Topic[]

constructor(config: Config) {
Expand All @@ -33,6 +30,24 @@ export default class PowerShellComp {
this.commands = this.getCommands()
}

private get coTopics(): string[] {
if (this._coTopics) return this._coTopics

const coTopics: string[] = []

for (const topic of this.topics) {
for (const cmd of this.commands) {
if (topic.name === cmd.id) {
coTopics.push(topic.name)
}
}
}

this._coTopics = coTopics

return this._coTopics
}

public generate(): string {
const genNode = (partialId: string): Record<string, any> => {
const node: Record<string, any> = {}
Expand Down Expand Up @@ -254,24 +269,6 @@ Register-ArgumentCompleter -Native -CommandName ${
return compRegister
}

private get coTopics(): string[] {
if (this._coTopics) return this._coTopics

const coTopics: string[] = []

for (const topic of this.topics) {
for (const cmd of this.commands) {
if (topic.name === cmd.id) {
coTopics.push(topic.name)
}
}
}

this._coTopics = coTopics

return this._coTopics
}

private genCmdHashtable(cmd: CommandCompletion): string {
const flaghHashtables: string[] = []

Expand Down Expand Up @@ -334,13 +331,13 @@ ${flaghHashtables.join('\n')}
childNodes.push(this.genHashtable(newKey, node[key]))
}

childTpl = util.format(childTpl, childNodes.join('\n'))
childTpl = format(childTpl, childNodes.join('\n'))

return util.format(leafTpl, childTpl)
return format(leafTpl, childTpl)
}

// last node
return util.format(leafTpl, childTpl)
return format(leafTpl, childTpl)
}

const childNodes: string[] = []
Expand All @@ -349,20 +346,20 @@ ${flaghHashtables.join('\n')}
const cmd = this.commands.find((c) => c.id === node[key][k])
if (!cmd) throw new Error('no command')

childNodes.push(util.format('"_command" = %s', this.genCmdHashtable(cmd)))
childNodes.push(format('"_command" = %s', this.genCmdHashtable(cmd)))
} else if (node[key][k]._command) {
const cmd = this.commands.find((c) => c.id === node[key][k]._command)
if (!cmd) throw new Error('no command')

childNodes.push(util.format(`"${k}" = @{\n"_command" = %s\n}`, this.genCmdHashtable(cmd)))
childNodes.push(format(`"${k}" = @{\n"_command" = %s\n}`, this.genCmdHashtable(cmd)))
} else {
const childTpl = `"summary" = "${node[key][k]._summary}"\n"${k}" = @{ \n %s\n }`
childNodes.push(this.genHashtable(k, node[key], childTpl))
}
}

if (childNodes.length > 0) {
return util.format(leafTpl, childNodes.join('\n'))
return format(leafTpl, childNodes.join('\n'))
}

return leafTpl
Expand Down
53 changes: 25 additions & 28 deletions src/autocomplete/zsh.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Command, Config, Interfaces} from '@oclif/core'
import * as ejs from 'ejs'
import * as util from 'node:util'
import {format} from 'node:util'

const argTemplate = ' "%s")\n %s\n ;;\n'

Expand All @@ -21,11 +21,8 @@ type Topic = {

export default class ZshCompWithSpaces {
protected config: Config

private _coTopics?: string[]

private commands: CommandCompletion[]

private topics: Topic[]

constructor(config: Config) {
Expand All @@ -34,6 +31,24 @@ export default class ZshCompWithSpaces {
this.commands = this.getCommands()
}

private get coTopics(): string[] {
if (this._coTopics) return this._coTopics

const coTopics: string[] = []

for (const topic of this.topics) {
for (const cmd of this.commands) {
if (topic.name === cmd.id) {
coTopics.push(topic.name)
}
}
}

this._coTopics = coTopics

return this._coTopics
}

public generate(): string {
const firstArgs: {id: string; summary?: string}[] = []

Expand Down Expand Up @@ -106,24 +121,6 @@ _${this.config.bin}
`
}

private get coTopics(): string[] {
if (this._coTopics) return this._coTopics

const coTopics: string[] = []

for (const topic of this.topics) {
for (const cmd of this.commands) {
if (topic.name === cmd.id) {
coTopics.push(topic.name)
}
}
}

this._coTopics = coTopics

return this._coTopics
}

private genZshFlagArgumentsBlock(flags?: CommandFlags): string {
// if a command doesn't have flags make it only complete files
// also add comp for the global `--help` flag.
Expand Down Expand Up @@ -257,7 +254,7 @@ _${this.config.bin}
summary: t.description,
})

argsBlock += util.format(argTemplate, subArg, `_${this.config.bin}_${underscoreSepId}_${subArg}`)
argsBlock += format(argTemplate, subArg, `_${this.config.bin}_${underscoreSepId}_${subArg}`)
}

for (const c of this.commands.filter((c) => c.id.startsWith(id + ':') && c.id.split(':').length === depth + 1)) {
Expand All @@ -269,10 +266,10 @@ _${this.config.bin}
summary: c.summary,
})

argsBlock += util.format(flagArgsTemplate, subArg, this.genZshFlagArgumentsBlock(c.flags))
argsBlock += format(flagArgsTemplate, subArg, this.genZshFlagArgumentsBlock(c.flags))
}

return util.format(coTopicCompFunc, this.genZshValuesBlock(subArgs), argsBlock)
return format(coTopicCompFunc, this.genZshValuesBlock(subArgs), argsBlock)
}

let argsBlock = ''
Expand All @@ -286,7 +283,7 @@ _${this.config.bin}
summary: t.description,
})

argsBlock += util.format(argTemplate, subArg, `_${this.config.bin}_${underscoreSepId}_${subArg}`)
argsBlock += format(argTemplate, subArg, `_${this.config.bin}_${underscoreSepId}_${subArg}`)
}

for (const c of this.commands.filter((c) => c.id.startsWith(id + ':') && c.id.split(':').length === depth + 1)) {
Expand All @@ -298,7 +295,7 @@ _${this.config.bin}
summary: c.summary,
})

argsBlock += util.format(flagArgsTemplate, subArg, this.genZshFlagArgumentsBlock(c.flags))
argsBlock += format(flagArgsTemplate, subArg, this.genZshFlagArgumentsBlock(c.flags))
}

const topicCompFunc = `_${this.config.bin}_${underscoreSepId}() {
Expand All @@ -319,7 +316,7 @@ _${this.config.bin}
esac
}
`
return util.format(topicCompFunc, this.genZshValuesBlock(subArgs), argsBlock)
return format(topicCompFunc, this.genZshValuesBlock(subArgs), argsBlock)
}

private genZshValuesBlock(subArgs: {id: string; summary?: string}[]): string {
Expand Down
2 changes: 1 addition & 1 deletion src/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Command} from '@oclif/core'
import {mkdirSync, openSync, writeSync} from 'node:fs'
import * as path from 'node:path'
import path from 'node:path'

export abstract class AutocompleteBase extends Command {
public get acLogfilePath(): string {
Expand Down
Loading

0 comments on commit 6e165f6

Please sign in to comment.