Skip to content

Commit a5ca777

Browse files
authored
Merge pull request #5378 from NomicFoundation/eslint-rules
Added eslint rules
2 parents 6f33944 + cb4a841 commit a5ca777

Some content is hidden

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

52 files changed

+349
-240
lines changed

config-v-next/eslint.cjs

+26
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ function createConfig(configFilePath, packageEntryPoints = []) {
9999
{ assertionStyle: "never" },
100100
],
101101
"@typescript-eslint/consistent-type-definitions": "error",
102+
"@typescript-eslint/consistent-type-imports": [
103+
"error",
104+
{
105+
prefer: "type-imports",
106+
disallowTypeAnnotations: true,
107+
},
108+
],
102109
"@typescript-eslint/dot-notation": "error",
103110
"@typescript-eslint/explicit-member-accessibility": [
104111
"error",
@@ -214,6 +221,25 @@ function createConfig(configFilePath, packageEntryPoints = []) {
214221
message:
215222
"Use ensureError() or HardhatError.isHardhatError instead of casting the error",
216223
},
224+
{
225+
selector:
226+
"CallExpression[callee.object.name='assert'][callee.property.name=/strict/i]",
227+
message:
228+
"Use non-strict methods when importing from 'node:assert/strict'",
229+
},
230+
// We forbid using assert.ok and assert directly without a message
231+
// as this may cause a bug. See: https://github.com/nodejs/node/issues/52962
232+
{
233+
selector: "CallExpression[callee.name='assert'][arguments.length<2]",
234+
message:
235+
"assert should provide an error message as the second argument",
236+
},
237+
{
238+
selector:
239+
"CallExpression[callee.object.name='assert'][callee.property.name='ok'][arguments.length<2]",
240+
message:
241+
"assert.ok should provide an error message as the second argument",
242+
},
217243
],
218244
"@typescript-eslint/restrict-plus-operands": "error",
219245
"@typescript-eslint/restrict-template-expressions": [

v-next/core/src/config.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
import type { ConfigurationVariable } from "./types/config.js";
2+
import type { GlobalParameter } from "./types/global-parameters.js";
3+
import type {
4+
EmptyTaskDefinitionBuilder,
5+
NewTaskDefinitionBuilder,
6+
TaskOverrideDefinitionBuilder,
7+
} from "./types/tasks.js";
8+
19
import { buildGlobalParameterDefinition } from "./internal/global-parameters.js";
210
import {
311
EmptyTaskDefinitionBuilderImplementation,
412
NewTaskDefinitionBuilderImplementation,
513
TaskOverrideDefinitionBuilderImplementation,
614
} from "./internal/tasks/builders.js";
715
import { ParameterType } from "./types/common.js";
8-
import { ConfigurationVariable } from "./types/config.js";
9-
import { GlobalParameter } from "./types/global-parameters.js";
10-
import {
11-
EmptyTaskDefinitionBuilder,
12-
NewTaskDefinitionBuilder,
13-
TaskOverrideDefinitionBuilder,
14-
} from "./types/tasks.js";
1516

1617
export type { HardhatUserConfig } from "./types/config.js";
1718

v-next/core/src/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import type { UnsafeHardhatRuntimeEnvironmentOptions } from "./types/cli.js";
2+
import type { HardhatUserConfig } from "./types/config.js";
3+
import type { GlobalArguments } from "./types/global-parameters.js";
4+
import type { HardhatRuntimeEnvironment } from "./types/hre.js";
5+
16
import { HardhatRuntimeEnvironmentImplementation } from "./internal/hre.js";
2-
import { UnsafeHardhatRuntimeEnvironmentOptions } from "./types/cli.js";
3-
import { HardhatUserConfig } from "./types/config.js";
4-
import { GlobalArguments } from "./types/global-parameters.js";
5-
import { HardhatRuntimeEnvironment } from "./types/hre.js";
67

78
/**
89
* Creates an instances of the Hardhat Runtime Environment.

v-next/core/src/internal/configuration-variables.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { HardhatError } from "@nomicfoundation/hardhat-errors";
2-
3-
import {
1+
import type {
42
ConfigurationVariable,
53
ResolvedConfigurationVariable,
64
} from "../types/config.js";
7-
import { HookManager } from "../types/hooks.js";
5+
import type { HookManager } from "../types/hooks.js";
6+
7+
import { HardhatError } from "@nomicfoundation/hardhat-errors";
88

99
export class ResolvedConfigurationVariableImplementation
1010
implements ResolvedConfigurationVariable

v-next/core/src/internal/global-parameters.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { ParameterType } from "../types/common.js";
2-
import {
1+
import type { ParameterType } from "../types/common.js";
2+
import type {
33
GlobalArguments,
44
GlobalParameter,
55
GlobalParameterMap,
66
} from "../types/global-parameters.js";
7-
import { HardhatPlugin } from "../types/plugins.js";
7+
import type { HardhatPlugin } from "../types/plugins.js";
88

99
/**
1010
* Builds a map of the global parameters, validating them.

v-next/core/src/internal/hook-manager.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Typescript
22
can handle the generic types in this file correctly. It can do it for function
33
signatures, but not for function bodies. */
4-
import {
4+
import type {
55
ChainedHook,
66
HookContext,
77
HookManager,
88
InitialHookParams as InitialHookParams,
99
InitialChainedHookParams,
1010
HardhatHooks,
1111
} from "../types/hooks.js";
12-
import { HardhatPlugin } from "../types/plugins.js";
13-
import { LastParameter, Return } from "../types/utils.js";
12+
import type { HardhatPlugin } from "../types/plugins.js";
13+
import type { LastParameter, Return } from "../types/utils.js";
1414

1515
export class HookManagerImplementation implements HookManager {
1616
readonly #pluginsInReverseOrder: HardhatPlugin[];

v-next/core/src/internal/hre.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import type { HardhatRuntimeEnvironment } from "../types/hre.js";
2-
3-
import { UnsafeHardhatRuntimeEnvironmentOptions } from "../types/cli.js";
4-
import { HardhatUserConfig, HardhatConfig } from "../types/config.js";
5-
import {
1+
import type { UnsafeHardhatRuntimeEnvironmentOptions } from "../types/cli.js";
2+
import type { HardhatUserConfig, HardhatConfig } from "../types/config.js";
3+
import type {
64
GlobalArguments,
75
GlobalParameterMap,
86
} from "../types/global-parameters.js";
9-
import {
7+
import type {
108
HardhatUserConfigValidationError,
119
HookContext,
1210
HookManager,
1311
} from "../types/hooks.js";
14-
import { HardhatPlugin } from "../types/plugins.js";
15-
import { TaskManager } from "../types/tasks.js";
16-
import { UserInterruptionManager } from "../types/user-interruptions.js";
12+
import type { HardhatRuntimeEnvironment } from "../types/hre.js";
13+
import type { HardhatPlugin } from "../types/plugins.js";
14+
import type { TaskManager } from "../types/tasks.js";
15+
import type { UserInterruptionManager } from "../types/user-interruptions.js";
1716

1817
import { ResolvedConfigurationVariableImplementation } from "./configuration-variables.js";
1918
import {

v-next/core/src/internal/plugins/detect-plugin-npm-dependency-problems.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import type { HardhatPlugin } from "../../types/plugins.js";
2+
import type { PackageJson } from "@nomicfoundation/hardhat-utils/package";
3+
14
import { createRequire } from "node:module";
25
import path from "node:path";
36

47
import { HardhatError } from "@nomicfoundation/hardhat-errors";
5-
import { PackageJson } from "@nomicfoundation/hardhat-utils/package";
68
import semver from "semver";
79

8-
import { HardhatPlugin } from "../../types/plugins.js";
9-
1010
/**
1111
* Validate that a plugin is installed and that its peer dependencies are installed and satisfy the version constraints.
1212
*

v-next/core/src/internal/tasks/task-manager.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import {
2-
HardhatError,
3-
assertHardhatInvariant,
4-
} from "@nomicfoundation/hardhat-errors";
5-
6-
import { GlobalParameterMap } from "../../types/global-parameters.js";
7-
import { HardhatRuntimeEnvironment } from "../../types/hre.js";
8-
import {
1+
import type { GlobalParameterMap } from "../../types/global-parameters.js";
2+
import type { HardhatRuntimeEnvironment } from "../../types/hre.js";
3+
import type {
94
Task,
105
TaskDefinition,
11-
TaskDefinitionType,
126
TaskManager,
137
NewTaskDefinition,
148
TaskOverrideDefinition,
159
} from "../../types/tasks.js";
1610

11+
import {
12+
HardhatError,
13+
assertHardhatInvariant,
14+
} from "@nomicfoundation/hardhat-errors";
15+
16+
import { TaskDefinitionType } from "../../types/tasks.js";
17+
1718
import { ResolvedTask } from "./resolved-task.js";
1819
import { formatTaskId, getActorFragment } from "./utils.js";
1920

v-next/core/src/internal/user-interruptions.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
1+
import type { HookContext, HookManager } from "../types/hooks.js";
2+
import type { UserInterruptionManager } from "../types/user-interruptions.js";
23

3-
import { HookContext, HookManager } from "../types/hooks.js";
4-
import { UserInterruptionManager } from "../types/user-interruptions.js";
4+
import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
55

66
import { AsyncMutex } from "./async-mutex.js";
77

v-next/core/src/types/cli.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { GlobalParameterMap } from "./global-parameters.js";
2-
import { HardhatPlugin } from "./plugins.js";
1+
import type { GlobalParameterMap } from "./global-parameters.js";
2+
import type { HardhatPlugin } from "./plugins.js";
33

44
/**
55
* An object that contains options to bypass some initialization, to avoid

v-next/core/src/types/global-parameters.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ParameterType } from "./common.js";
1+
import type { ParameterType } from "./common.js";
22

33
/**
44
* A global parameter with an associated value and a default if not provided by

v-next/core/src/types/hooks.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import {
1+
import type {
22
ConfigurationVariable,
33
HardhatConfig,
44
HardhatUserConfig,
55
ResolvedConfigurationVariable,
66
} from "./config.js";
7-
import { GlobalArguments } from "./global-parameters.js";
8-
import { HardhatRuntimeEnvironment } from "./hre.js";
9-
import { UserInterruptionManager } from "./user-interruptions.js";
10-
import {
7+
import type { GlobalArguments } from "./global-parameters.js";
8+
import type { HardhatRuntimeEnvironment } from "./hre.js";
9+
import type { UserInterruptionManager } from "./user-interruptions.js";
10+
import type {
1111
LastParameter,
1212
ParametersExceptFirst,
1313
ParametersExceptFirstAndLast,

v-next/core/src/types/hre.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { HardhatConfig } from "../types/config.js";
2-
3-
import { GlobalArguments } from "./global-parameters.js";
4-
import { UserInterruptionManager } from "./user-interruptions.js";
1+
import type { GlobalArguments } from "./global-parameters.js";
2+
import type { UserInterruptionManager } from "./user-interruptions.js";
3+
import type { HardhatConfig } from "../types/config.js";
54

65
/**
76
* The Hardhat Runtime Environment (HRE) is an object that exposes

v-next/core/src/types/plugins.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { GlobalParameter } from "./global-parameters.js";
2-
import { HardhatHooks } from "./hooks.js";
3-
import { TaskDefinition } from "./tasks.js";
1+
import type { GlobalParameter } from "./global-parameters.js";
2+
import type { HardhatHooks } from "./hooks.js";
3+
import type { TaskDefinition } from "./tasks.js";
44

55
// We add the plugins to the config types with a module augmentation to avoid
66
// introducing a circular dependency that would look like this:

v-next/core/test/internal/plugins/detect-plugin-npm-dependency-problems.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import type { HardhatPlugin } from "../../../src/types/plugins.js";
2+
13
import assert from "node:assert/strict";
24
import { describe, it } from "node:test";
35

46
import { detectPluginNpmDependencyProblems } from "../../../src/internal/plugins/detect-plugin-npm-dependency-problems.js";
5-
import { HardhatPlugin } from "../../../src/types/plugins.js";
67

78
describe("Plugins - detect npm dependency problems", () => {
89
const plugin: HardhatPlugin = {

v-next/core/test/internal/plugins/resolve-plugin-list.ts

+23-19
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1+
import type { HardhatPlugin } from "../../../src/types/plugins.js";
2+
13
import assert from "node:assert/strict";
24
import { describe, it } from "node:test";
35

46
import { resolvePluginList } from "../../../src/internal/plugins/resolve-plugin-list.js";
5-
import { HardhatPlugin } from "../../../src/types/plugins.js";
67

78
describe("Plugins - resolve plugin list", () => {
89
const installedPackageFixture = import.meta.resolve(
910
"./fixture-projects/installed-package",
1011
);
1112

1213
it("should return empty on an empty plugin list", async () => {
13-
assert.deepStrictEqual(
14-
await resolvePluginList([], installedPackageFixture),
15-
[],
16-
);
14+
assert.deepEqual(await resolvePluginList([], installedPackageFixture), []);
1715
});
1816

1917
it("should return empty on an undefined plugin list", async () => {
20-
assert.deepStrictEqual(
18+
assert.deepEqual(
2119
await resolvePluginList(undefined, installedPackageFixture),
2220
[],
2321
);
@@ -28,7 +26,7 @@ describe("Plugins - resolve plugin list", () => {
2826
id: "example-plugin",
2927
};
3028

31-
assert.deepStrictEqual(
29+
assert.deepEqual(
3230
await resolvePluginList([plugin], installedPackageFixture),
3331
[plugin],
3432
);
@@ -40,9 +38,10 @@ describe("Plugins - resolve plugin list", () => {
4038
const b: HardhatPlugin = { id: "b", dependencies: [async () => c] };
4139
const a: HardhatPlugin = { id: "a", dependencies: [async () => b] };
4240

43-
assert.deepStrictEqual(
41+
const expected = [c, b, a];
42+
assert.deepEqual(
4443
await resolvePluginList([a], installedPackageFixture),
45-
[c, b, a],
44+
expected,
4645
);
4746
});
4847

@@ -52,9 +51,10 @@ describe("Plugins - resolve plugin list", () => {
5251
const b: HardhatPlugin = { id: "b" };
5352
const a: HardhatPlugin = { id: "a" };
5453

55-
assert.deepStrictEqual(
54+
const expected = [a, b, c];
55+
assert.deepEqual(
5656
await resolvePluginList([a, b, c], installedPackageFixture),
57-
[a, b, c],
57+
expected,
5858
);
5959
});
6060

@@ -69,9 +69,10 @@ describe("Plugins - resolve plugin list", () => {
6969
dependencies: [async () => b, async () => c],
7070
};
7171

72-
assert.deepStrictEqual(
72+
const expected = [b, c, a];
73+
assert.deepEqual(
7374
await resolvePluginList([a], installedPackageFixture),
74-
[b, c, a],
75+
expected,
7576
);
7677
});
7778

@@ -83,9 +84,10 @@ describe("Plugins - resolve plugin list", () => {
8384
const b: HardhatPlugin = { id: "b", dependencies: [async () => c] };
8485
const a: HardhatPlugin = { id: "a", dependencies: [async () => c] };
8586

86-
assert.deepStrictEqual(
87+
const expected = [c, a, b];
88+
assert.deepEqual(
8789
await resolvePluginList([a, b], installedPackageFixture),
88-
[c, a, b],
90+
expected,
8991
);
9092
});
9193

@@ -103,9 +105,10 @@ describe("Plugins - resolve plugin list", () => {
103105
dependencies: [async () => b, async () => c],
104106
};
105107

106-
assert.deepStrictEqual(
108+
const expected = [d, b, c, a];
109+
assert.deepEqual(
107110
await resolvePluginList([a], installedPackageFixture),
108-
[d, b, c, a],
111+
expected,
109112
);
110113
});
111114

@@ -133,9 +136,10 @@ describe("Plugins - resolve plugin list", () => {
133136
dependencies: [async () => c, async () => d],
134137
};
135138

136-
assert.deepStrictEqual(
139+
const expected = [i, g, c, d, a, h, e, f, b];
140+
assert.deepEqual(
137141
await resolvePluginList([a, b], installedPackageFixture),
138-
[i, g, c, d, a, h, e, f, b],
142+
expected,
139143
);
140144
});
141145

0 commit comments

Comments
 (0)