Skip to content

Commit e42713c

Browse files
authored
fix(W-17692101): migrate to eslint 9 (#1305)
* chore: test files * chore: all the other files * chore: more eslint changes
1 parent 835d908 commit e42713c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+987
-656
lines changed

.eslintignore

-2
This file was deleted.

.eslintrc.json

-15
This file was deleted.

eslint.config.mjs

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
'@typescript-eslint/no-namespace': 'off',
17+
'@typescript-eslint/no-require-imports': 'off',
18+
'import/no-named-as-default-member': 'off',
19+
'no-useless-constructor': 'off',
20+
'perfectionist/sort-intersection-types': 'off',
21+
'perfectionist/sort-object-types': 'off',
22+
'perfectionist/sort-union-types': 'off',
23+
'unicorn/no-array-reduce': 'off',
24+
'unicorn/prefer-module': 'off',
25+
},
26+
},
27+
{
28+
files: ['test/**/*'],
29+
rules: {
30+
'@stylistic/lines-between-class-members': 'off',
31+
'@typescript-eslint/ban-ts-comment': 'off',
32+
'@typescript-eslint/ban-ts-ignore': 'off',
33+
'@typescript-eslint/no-empty-function': 'off',
34+
'max-lines': 'off',
35+
'mocha/max-top-level-suites': ['warn', {limit: 8}],
36+
'no-import-assign': 'off',
37+
'perfectionist/sort-classes': 'off',
38+
'perfectionist/sort-objects': 'off',
39+
'unicorn/consistent-function-scoping': 'off',
40+
'unicorn/no-abusive-eslint-disable': 'off',
41+
'unicorn/no-static-only-class': 'off',
42+
'unicorn/no-useless-undefined': 'off',
43+
},
44+
},
45+
{
46+
files: ['test/integration/*'],
47+
rules: {
48+
'@typescript-eslint/no-unused-expressions': 'off',
49+
'mocha/no-nested-tests': 'off',
50+
'mocha/no-sibling-hooks': 'off',
51+
'mocha/no-top-level-hooks': 'off',
52+
'unicorn/prefer-object-from-entries': 'off',
53+
'unicorn/prefer-top-level-await': 'off',
54+
},
55+
},
56+
{
57+
files: ['test/module-loader/fixtures/**/*'],
58+
rules: {
59+
'@typescript-eslint/no-unused-expressions': 'off',
60+
camelcase: 'off',
61+
'no-undef': 'off',
62+
'unicorn/filename-case': 'off',
63+
},
64+
},
65+
]

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"devDependencies": {
2828
"@commitlint/config-conventional": "^19",
29+
"@eslint/compat": "^1.2.5",
2930
"@oclif/plugin-help": "^6",
3031
"@oclif/plugin-plugins": "^5",
3132
"@oclif/prettier-config": "^0.2.1",
@@ -49,10 +50,9 @@
4950
"chai-as-promised": "^7.1.2",
5051
"commitlint": "^19",
5152
"cross-env": "^7.0.3",
52-
"eslint": "^8.57.1",
53-
"eslint-config-oclif": "^5.2.2",
54-
"eslint-config-oclif-typescript": "^3.1.13",
55-
"eslint-config-prettier": "^9.1.0",
53+
"eslint": "^9",
54+
"eslint-config-oclif": "^6",
55+
"eslint-config-prettier": "^10",
5656
"husky": "^9.1.7",
5757
"lint-staged": "^15",
5858
"madge": "^6.1.0",
@@ -96,6 +96,7 @@
9696
"./hooks": "./lib/interfaces/hooks.js",
9797
"./interfaces": "./lib/interfaces/index.js",
9898
"./logger": "./lib/logger.js",
99+
"./package.json": "./package.json",
99100
"./parser": "./lib/parser/index.js",
100101
"./performance": "./lib/performance.js",
101102
"./run": "./lib/main.js",
@@ -118,7 +119,7 @@
118119
"build": "shx rm -rf lib && tsc",
119120
"compile": "tsc",
120121
"format": "prettier --write \"+(src|test)/**/*.+(ts|js|json)\"",
121-
"lint": "eslint . --ext .ts",
122+
"lint": "eslint",
122123
"posttest": "yarn lint && yarn test:circular-deps",
123124
"prepack": "yarn run build",
124125
"prepare": "husky",

src/args.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {isNotFalsy} from './util/util'
2222
* },
2323
* })
2424
*/
25-
export function custom<T = string, P = Record<string, unknown>>(defaults: Partial<Arg<T, P>>): ArgDefinition<T, P>
25+
export function custom<T = string, P = Record<string, unknown>>(_defaults: Partial<Arg<T, P>>): ArgDefinition<T, P>
2626
export function custom<T, P = Record<string, unknown>>(defaults: Partial<Arg<T, P>>): ArgDefinition<T, P> {
2727
return (options: any = {}) => ({
2828
parse: async (i: string, _context: Command, _opts: P) => i,

src/cache.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@ import {join} from 'node:path'
44
import {Config} from './config/config'
55
import {OclifConfiguration, Plugin} from './interfaces'
66

7-
type OclifCoreInfo = {name: string; version: string}
8-
97
type CacheContents = {
108
rootPlugin: Plugin
119
config: Config
1210
exitCodes: OclifConfiguration['exitCodes']
1311
'@oclif/core': OclifCoreInfo
1412
}
1513

14+
type OclifCoreInfo = {name: string; version: string}
15+
1616
type ValueOf<T> = T[keyof T]
1717

1818
/**
1919
* A simple cache for storing values that need to be accessed globally.
2020
*/
2121
export default class Cache extends Map<keyof CacheContents, ValueOf<CacheContents>> {
2222
static instance: Cache
23+
2324
public constructor() {
2425
super()
2526
this.set('@oclif/core', this.getOclifCoreMeta())
@@ -33,10 +34,10 @@ export default class Cache extends Map<keyof CacheContents, ValueOf<CacheContent
3334
return Cache.instance
3435
}
3536

36-
public get(key: 'config'): Config | undefined
37-
public get(key: '@oclif/core'): OclifCoreInfo
38-
public get(key: 'rootPlugin'): Plugin | undefined
39-
public get(key: 'exitCodes'): OclifConfiguration['exitCodes'] | undefined
37+
public get(_key: 'config'): Config | undefined
38+
public get(_key: '@oclif/core'): OclifCoreInfo
39+
public get(_key: 'rootPlugin'): Plugin | undefined
40+
public get(_key: 'exitCodes'): OclifConfiguration['exitCodes'] | undefined
4041
public get(key: keyof CacheContents): ValueOf<CacheContents> | undefined {
4142
return super.get(key)
4243
}

src/command.ts

+29-50
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,24 @@ process.stdout.on('error', (err: any) => {
4747
*/
4848

4949
export abstract class Command {
50+
private static readonly _base = `${pjson.name}@${pjson.version}`
5051
/** An array of aliases for this command. */
5152
public static aliases: string[] = []
52-
5353
/** An order-dependent object of arguments for the command */
5454
public static args: ArgInput = {}
55-
5655
public static baseFlags: FlagInput
57-
5856
/**
5957
* Emit deprecation warning when a command alias is used
6058
*/
6159
static deprecateAliases?: boolean
62-
6360
public static deprecationOptions?: Deprecation
64-
6561
/**
6662
* A full description of how to use the command.
6763
*
6864
* If no summary, the first line of the description will be used as the summary.
6965
*/
7066
public static description: string | undefined
71-
7267
public static enableJsonFlag = false
73-
7468
/**
7569
* An array of examples to show at the end of the command's help.
7670
*
@@ -86,35 +80,24 @@ export abstract class Command {
8680
* ```
8781
*/
8882
public static examples: Command.Example[]
89-
9083
/** A hash of flags for the command */
9184
public static flags: FlagInput
92-
9385
public static hasDynamicHelp = false
94-
9586
public static help: string | undefined
96-
9787
/** Hide the command from help */
9888
public static hidden: boolean
99-
10089
/** An array of aliases for this command that are hidden from help. */
10190
public static hiddenAliases: string[] = []
102-
10391
/** A command ID, used mostly in error or verbose reporting. */
10492
public static id: string
105-
10693
public static plugin: Plugin | undefined
107-
10894
public static readonly pluginAlias?: string
10995
public static readonly pluginName?: string
11096
public static readonly pluginType?: string
111-
11297
/** Mark the command as a given state (e.g. beta or deprecated) in help */
11398
public static state?: 'beta' | 'deprecated' | string
114-
11599
/** When set to false, allows a variable amount of arguments */
116100
public static strict = true
117-
118101
/**
119102
* The tweet-sized description for your class, used in a parent-commands
120103
* sub-command listing and as the header for the command help.
@@ -124,13 +107,9 @@ export abstract class Command {
124107
* An override string (or strings) for the default usage documentation.
125108
*/
126109
public static usage: string | string[] | undefined
127-
128110
protected debug: (...args: any[]) => void
129-
130111
public id: string | undefined
131112

132-
private static readonly _base = `${pjson.name}@${pjson.version}`
133-
134113
public constructor(
135114
public argv: string[],
136115
public config: Config,
@@ -145,11 +124,6 @@ export abstract class Command {
145124
}
146125
}
147126

148-
/**
149-
* actual command run code goes here
150-
*/
151-
public abstract run(): Promise<any>
152-
153127
/**
154128
* instantiate and run the command
155129
*
@@ -188,6 +162,26 @@ export abstract class Command {
188162
return this.constructor as typeof Command
189163
}
190164

165+
protected async _run<T>(): Promise<T> {
166+
let err: Error | undefined
167+
let result: T | undefined
168+
try {
169+
// remove redirected env var to allow subsessions to run autoupdated client
170+
this.removeEnvVar('REDIRECTED')
171+
await this.init()
172+
result = await this.run()
173+
} catch (error: any) {
174+
err = error
175+
await this.catch(error)
176+
} finally {
177+
await this.finally(err)
178+
}
179+
180+
if (result && this.jsonEnabled()) this.logJson(this.toSuccessJson(result))
181+
182+
return result as T
183+
}
184+
191185
protected async catch(err: CommandError): Promise<any> {
192186
process.exitCode = process.exitCode ?? err.exitCode ?? 1
193187
if (this.jsonEnabled()) {
@@ -221,7 +215,7 @@ export abstract class Command {
221215

222216
protected async init(): Promise<any> {
223217
this.debug('init version: %s argv: %o', this.ctor._base, this.argv)
224-
const g: any = global
218+
const g: any = globalThis
225219
g['http-call'] = g['http-call'] || {}
226220
g['http-call']!.userAgent = this.config.userAgent
227221
this.warnIfCommandDeprecated()
@@ -243,9 +237,9 @@ export abstract class Command {
243237
const jsonIndex = this.argv.indexOf('--json')
244238
return passThroughIndex === -1
245239
? // If '--' is not present, then check for `--json` in this.argv
246-
jsonIndex > -1
240+
jsonIndex !== -1
247241
: // If '--' is present, return true only the --json flag exists and is before the '--'
248-
jsonIndex > -1 && jsonIndex < passThroughIndex
242+
jsonIndex !== -1 && jsonIndex < passThroughIndex
249243
}
250244

251245
public log(message = '', ...args: any[]): void {
@@ -293,6 +287,11 @@ export abstract class Command {
293287
return results
294288
}
295289

290+
/**
291+
* actual command run code goes here
292+
*/
293+
public abstract run(): Promise<any>
294+
296295
protected toErrorJson(err: unknown): any {
297296
return {error: err}
298297
}
@@ -350,26 +349,6 @@ export abstract class Command {
350349
}
351350
}
352351

353-
protected async _run<T>(): Promise<T> {
354-
let err: Error | undefined
355-
let result: T | undefined
356-
try {
357-
// remove redirected env var to allow subsessions to run autoupdated client
358-
this.removeEnvVar('REDIRECTED')
359-
await this.init()
360-
result = await this.run()
361-
} catch (error: any) {
362-
err = error
363-
await this.catch(error)
364-
} finally {
365-
await this.finally(err)
366-
}
367-
368-
if (result && this.jsonEnabled()) this.logJson(this.toSuccessJson(result))
369-
370-
return result as T
371-
}
372-
373352
private removeEnvVar(envVar: string): void {
374353
const keys: string[] = []
375354
try {

0 commit comments

Comments
 (0)