Skip to content

Commit f3f67de

Browse files
committed
chore: enhance type definition
1 parent 8099d38 commit f3f67de

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

test/integrations.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const FIXTURE_DIR = path.join(__dirname, "fixtures/integrations")
2222

2323
describe("Integration tests", () => {
2424
beforeAll(async () => {
25+
// @ts-expect-error -- ignore
2526
await import("ts-node/register")
2627
})
2728
for (const target of fs.readdirSync(FIXTURE_DIR)) {
@@ -75,8 +76,11 @@ describe("Integration tests", () => {
7576
throw e
7677
}
7778

78-
function normalizeReport(report, option = {}) {
79-
return report
79+
function normalizeReport(
80+
result: ESLintRaw.ESLint.LintResult[],
81+
option: { withoutMessage?: boolean } = {},
82+
) {
83+
return result
8084
.filter((res) => res.messages.length)
8185
.map((res) => ({
8286
filePath: res.filePath

test/lib/eslint-compat.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1-
import type { ESLint } from "eslint"
1+
import type { ESLint, Linter, RuleTester } from "eslint"
22

3-
export default function compat(eslint: any) {
3+
export default function compat(eslint: any): {
4+
ESLint: typeof ESLint
5+
RuleTester: typeof RuleTester
6+
Linter: typeof Linter
7+
} {
48
return {
59
ESLint: eslint.ESLint || getESLintClassForV6(eslint),
610
RuleTester: eslint.RuleTester,
711
Linter: eslint.Linter,
812
}
913
}
1014

11-
function getESLintClassForV6(eslint: any): ESLint {
15+
function getESLintClassForV6(eslint: any): typeof ESLint {
1216
class ESLintForV6 {
1317
public engine
1418

19+
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
1520
static get version() {
1621
return eslint.CLIEngine.version
1722
}
1823

1924
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
20-
constructor(options: ESLint.Options) {
25+
constructor(options: any) {
2126
const {
2227
overrideConfig: {
2328
plugins,
@@ -29,14 +34,14 @@ function getESLintClassForV6(eslint: any): ESLint {
2934
plugins: [],
3035
globals: {},
3136
rules: {},
32-
},
37+
} as any,
3338
overrideConfigFile,
3439
fix,
3540
reportUnusedDisableDirectives,
3641
plugins: pluginsMap,
3742
...otherOptions
3843
} = options || {}
39-
const newOptions: CLIEngine.Options = {
44+
const newOptions = {
4045
fix: Boolean(fix),
4146
reportUnusedDisableDirectives: reportUnusedDisableDirectives
4247
? reportUnusedDisableDirectives !== "off"
@@ -59,7 +64,7 @@ function getESLintClassForV6(eslint: any): ESLint {
5964
}
6065
return o
6166
},
62-
{} satisfies NonNullable<CLIEngine.Options["rules"]>,
67+
{} as Record<string, any>,
6368
)
6469
: undefined,
6570
...overrideConfig,
@@ -71,29 +76,33 @@ function getESLintClassForV6(eslint: any): ESLint {
7176
}
7277
}
7378

79+
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
7480
async lintText(
7581
...params: Parameters<ESLint["lintText"]>
7682
): ReturnType<ESLint["lintText"]> {
77-
const result = this.engine.executeOnText(
83+
const result = await this.engine.executeOnText(
7884
params[0],
7985
params[1]!.filePath,
8086
)
8187
return result.results
8288
}
8389

90+
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
8491
async lintFiles(
8592
...params: Parameters<ESLint["lintFiles"]>
8693
): ReturnType<ESLint["lintFiles"]> {
87-
const result = this.engine.executeOnFiles(
94+
const result = await this.engine.executeOnFiles(
8895
Array.isArray(params[0]) ? params[0] : [params[0]],
8996
)
9097
return result.results
9198
}
9299

100+
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
93101
static async outputFixes(
94-
...params: Parameters<ESLint["outputFixes"]>
95-
): ReturnType<ESLint["outputFixes"]> {
96-
return eslint.CLIEngine.outputFixes({
102+
...params: Parameters<typeof ESLint.outputFixes>
103+
): ReturnType<typeof ESLint.outputFixes> {
104+
// eslint-disable-next-line no-return-await
105+
return await eslint.CLIEngine.outputFixes({
97106
results: params[0],
98107
})
99108
}

0 commit comments

Comments
 (0)