Skip to content

Commit 6e165f6

Browse files
authored
Merge pull request #888 from oclif/mdonnalley/eslint-9
chore(W-17692101): eslint 9
2 parents 9c580ac + adc7fd3 commit 6e165f6

File tree

18 files changed

+705
-466
lines changed

18 files changed

+705
-466
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

bin/dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning
2-
// eslint-disable-next-line node/shebang
2+
33
async function main() {
44
const {execute} = await import('@oclif/core')
55
await execute({development: true, dir: import.meta.url})

bin/run.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env node
22

3-
// eslint-disable-next-line node/shebang
43
async function main() {
54
const {execute} = await import('@oclif/core')
65
await execute({dir: import.meta.url})

eslint.config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {includeIgnoreFile} from '@eslint/compat'
2+
import oclif from 'eslint-config-oclif'
3+
import prettier from 'eslint-config-prettier'
4+
import path from 'node:path'
5+
import {fileURLToPath} from 'node:url'
6+
7+
const gitignorePath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '.gitignore')
8+
9+
export default [
10+
includeIgnoreFile(gitignorePath),
11+
...oclif,
12+
prettier,
13+
{
14+
rules: {
15+
'@typescript-eslint/no-explicit-any': 'off',
16+
'max-depth': ['warn', 5],
17+
'unicorn/consistent-destructuring': 'off',
18+
'unicorn/prefer-string-raw': 'off',
19+
},
20+
},
21+
]

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"devDependencies": {
1414
"@commitlint/config-conventional": "^19",
15+
"@eslint/compat": "^1.2.5",
1516
"@oclif/plugin-help": "^6",
1617
"@oclif/prettier-config": "^0.2.1",
1718
"@oclif/test": "^4",
@@ -23,10 +24,9 @@
2324
"@types/node": "^18",
2425
"chai": "^4",
2526
"commitlint": "^19",
26-
"eslint": "^8.57.1",
27-
"eslint-config-oclif": "^5.2.2",
28-
"eslint-config-oclif-typescript": "^3.1.13",
29-
"eslint-config-prettier": "^9.1.0",
27+
"eslint": "^9.19.0",
28+
"eslint-config-oclif": "^6.0.0",
29+
"eslint-config-prettier": "^10.0.1",
3030
"husky": "^9.1.7",
3131
"lint-staged": "^15.4.1",
3232
"mocha": "^10.8.2",
@@ -68,7 +68,7 @@
6868
"build": "shx rm -rf lib && tsc",
6969
"clean": "shx rm -f oclif.manifest.json",
7070
"compile": "tsc",
71-
"lint": "eslint . --ext .ts",
71+
"lint": "eslint",
7272
"postpack": "yarn run clean",
7373
"posttest": "yarn lint",
7474
"prepack": "yarn build && oclif manifest && oclif readme",

src/autocomplete/powershell.ts

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Command, Config, Interfaces} from '@oclif/core'
22
import * as ejs from 'ejs'
33
import {EOL} from 'node:os'
4-
import * as util from 'node:util'
4+
import {format} from 'node:util'
55

66
type CommandCompletion = {
77
flags: CommandFlags
@@ -20,11 +20,8 @@ type Topic = {
2020

2121
export default class PowerShellComp {
2222
protected config: Config
23-
2423
private _coTopics?: string[]
25-
2624
private commands: CommandCompletion[]
27-
2825
private topics: Topic[]
2926

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

33+
private get coTopics(): string[] {
34+
if (this._coTopics) return this._coTopics
35+
36+
const coTopics: string[] = []
37+
38+
for (const topic of this.topics) {
39+
for (const cmd of this.commands) {
40+
if (topic.name === cmd.id) {
41+
coTopics.push(topic.name)
42+
}
43+
}
44+
}
45+
46+
this._coTopics = coTopics
47+
48+
return this._coTopics
49+
}
50+
3651
public generate(): string {
3752
const genNode = (partialId: string): Record<string, any> => {
3853
const node: Record<string, any> = {}
@@ -254,24 +269,6 @@ Register-ArgumentCompleter -Native -CommandName ${
254269
return compRegister
255270
}
256271

257-
private get coTopics(): string[] {
258-
if (this._coTopics) return this._coTopics
259-
260-
const coTopics: string[] = []
261-
262-
for (const topic of this.topics) {
263-
for (const cmd of this.commands) {
264-
if (topic.name === cmd.id) {
265-
coTopics.push(topic.name)
266-
}
267-
}
268-
}
269-
270-
this._coTopics = coTopics
271-
272-
return this._coTopics
273-
}
274-
275272
private genCmdHashtable(cmd: CommandCompletion): string {
276273
const flaghHashtables: string[] = []
277274

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

337-
childTpl = util.format(childTpl, childNodes.join('\n'))
334+
childTpl = format(childTpl, childNodes.join('\n'))
338335

339-
return util.format(leafTpl, childTpl)
336+
return format(leafTpl, childTpl)
340337
}
341338

342339
// last node
343-
return util.format(leafTpl, childTpl)
340+
return format(leafTpl, childTpl)
344341
}
345342

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

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

357-
childNodes.push(util.format(`"${k}" = @{\n"_command" = %s\n}`, this.genCmdHashtable(cmd)))
354+
childNodes.push(format(`"${k}" = @{\n"_command" = %s\n}`, this.genCmdHashtable(cmd)))
358355
} else {
359356
const childTpl = `"summary" = "${node[key][k]._summary}"\n"${k}" = @{ \n %s\n }`
360357
childNodes.push(this.genHashtable(k, node[key], childTpl))
361358
}
362359
}
363360

364361
if (childNodes.length > 0) {
365-
return util.format(leafTpl, childNodes.join('\n'))
362+
return format(leafTpl, childNodes.join('\n'))
366363
}
367364

368365
return leafTpl

src/autocomplete/zsh.ts

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Command, Config, Interfaces} from '@oclif/core'
22
import * as ejs from 'ejs'
3-
import * as util from 'node:util'
3+
import {format} from 'node:util'
44

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

@@ -21,11 +21,8 @@ type Topic = {
2121

2222
export default class ZshCompWithSpaces {
2323
protected config: Config
24-
2524
private _coTopics?: string[]
26-
2725
private commands: CommandCompletion[]
28-
2926
private topics: Topic[]
3027

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

34+
private get coTopics(): string[] {
35+
if (this._coTopics) return this._coTopics
36+
37+
const coTopics: string[] = []
38+
39+
for (const topic of this.topics) {
40+
for (const cmd of this.commands) {
41+
if (topic.name === cmd.id) {
42+
coTopics.push(topic.name)
43+
}
44+
}
45+
}
46+
47+
this._coTopics = coTopics
48+
49+
return this._coTopics
50+
}
51+
3752
public generate(): string {
3853
const firstArgs: {id: string; summary?: string}[] = []
3954

@@ -106,24 +121,6 @@ _${this.config.bin}
106121
`
107122
}
108123

109-
private get coTopics(): string[] {
110-
if (this._coTopics) return this._coTopics
111-
112-
const coTopics: string[] = []
113-
114-
for (const topic of this.topics) {
115-
for (const cmd of this.commands) {
116-
if (topic.name === cmd.id) {
117-
coTopics.push(topic.name)
118-
}
119-
}
120-
}
121-
122-
this._coTopics = coTopics
123-
124-
return this._coTopics
125-
}
126-
127124
private genZshFlagArgumentsBlock(flags?: CommandFlags): string {
128125
// if a command doesn't have flags make it only complete files
129126
// also add comp for the global `--help` flag.
@@ -257,7 +254,7 @@ _${this.config.bin}
257254
summary: t.description,
258255
})
259256

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

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

272-
argsBlock += util.format(flagArgsTemplate, subArg, this.genZshFlagArgumentsBlock(c.flags))
269+
argsBlock += format(flagArgsTemplate, subArg, this.genZshFlagArgumentsBlock(c.flags))
273270
}
274271

275-
return util.format(coTopicCompFunc, this.genZshValuesBlock(subArgs), argsBlock)
272+
return format(coTopicCompFunc, this.genZshValuesBlock(subArgs), argsBlock)
276273
}
277274

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

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

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

301-
argsBlock += util.format(flagArgsTemplate, subArg, this.genZshFlagArgumentsBlock(c.flags))
298+
argsBlock += format(flagArgsTemplate, subArg, this.genZshFlagArgumentsBlock(c.flags))
302299
}
303300

304301
const topicCompFunc = `_${this.config.bin}_${underscoreSepId}() {
@@ -319,7 +316,7 @@ _${this.config.bin}
319316
esac
320317
}
321318
`
322-
return util.format(topicCompFunc, this.genZshValuesBlock(subArgs), argsBlock)
319+
return format(topicCompFunc, this.genZshValuesBlock(subArgs), argsBlock)
323320
}
324321

325322
private genZshValuesBlock(subArgs: {id: string; summary?: string}[]): string {

src/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Command} from '@oclif/core'
22
import {mkdirSync, openSync, writeSync} from 'node:fs'
3-
import * as path from 'node:path'
3+
import path from 'node:path'
44

55
export abstract class AutocompleteBase extends Command {
66
public get acLogfilePath(): string {

0 commit comments

Comments
 (0)