Skip to content

Commit

Permalink
Merge pull request #5472 from NomicFoundation/rename-parameterType
Browse files Browse the repository at this point in the history
Normalize naming of parameter type
  • Loading branch information
schaable authored Jul 4, 2024
2 parents 2962472 + 0771f21 commit 74fb192
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 100 deletions.
4 changes: 2 additions & 2 deletions v-next/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function overrideTask(
export function globalOption<T extends ParameterType>(options: {
name: string;
description: string;
parameterType?: T;
type?: T;
defaultValue: ParameterTypeToValueType<T>;
}): GlobalOption {
return buildGlobalOptionDefinition(options);
Expand All @@ -76,7 +76,7 @@ export function globalFlag(options: {
}): GlobalOption {
return buildGlobalOptionDefinition({
...options,
parameterType: ParameterType.BOOLEAN,
type: ParameterType.BOOLEAN,
defaultValue: false,
});
}
14 changes: 7 additions & 7 deletions v-next/core/src/internal/global-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ export function buildGlobalOptionsMap(
export function buildGlobalOptionDefinition<T extends ParameterType>({
name,
description,
parameterType,
type,
defaultValue,
}: {
name: string;
description: string;
parameterType?: T;
type?: T;
defaultValue: ParameterTypeToValueType<T>;
}): GlobalOption {
const type = parameterType ?? ParameterType.STRING;
const parameterType = type ?? ParameterType.STRING;

if (!isValidParamNameCasing(name)) {
throw new HardhatError(HardhatError.ERRORS.ARGUMENTS.INVALID_NAME, {
Expand All @@ -95,21 +95,21 @@ export function buildGlobalOptionDefinition<T extends ParameterType>({
});
}

if (!isParameterValueValid(type, defaultValue)) {
if (!isParameterValueValid(parameterType, defaultValue)) {
throw new HardhatError(
HardhatError.ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE,
{
value: defaultValue,
name: "defaultValue",
type: parameterType,
type,
},
);
}

return {
name,
description,
parameterType: type,
type: parameterType,
defaultValue,
};
}
Expand Down Expand Up @@ -155,7 +155,7 @@ export function resolveGlobalOptions(
value = process.env[`HARDHAT_${camelToSnakeCase(name).toUpperCase()}`];
if (value !== undefined) {
// if the value is provided via an env var, it needs to be parsed
parsedValue = parseParameterValue(value, option.parameterType, name);
parsedValue = parseParameterValue(value, option.type, name);
} else {
// if the value is not provided by the user or env var, use the default
parsedValue = option.defaultValue;
Expand Down
6 changes: 3 additions & 3 deletions v-next/core/src/internal/tasks/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class NewTaskDefinitionBuilderImplementation
this.#options[name] = {
name,
description,
parameterType,
type: parameterType,
defaultValue,
};

Expand Down Expand Up @@ -300,7 +300,7 @@ export class NewTaskDefinitionBuilderImplementation
this.#positionalParams.push({
name,
description,
parameterType,
type: parameterType,
defaultValue,
isVariadic,
});
Expand Down Expand Up @@ -399,7 +399,7 @@ export class TaskOverrideDefinitionBuilderImplementation
this.#options[name] = {
name,
description,
parameterType,
type: parameterType,
defaultValue,
};

Expand Down
4 changes: 2 additions & 2 deletions v-next/core/src/internal/tasks/resolved-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ export class ResolvedTask implements Task {
const isVariadic = isPositionalParameter(parameter) && parameter.isVariadic;

// check if the value is valid for the parameter type
if (!isParameterValueValid(parameter.parameterType, value, isVariadic)) {
if (!isParameterValueValid(parameter.type, value, isVariadic)) {
throw new HardhatError(
HardhatError.ERRORS.TASK_DEFINITIONS.INVALID_VALUE_FOR_TYPE,
{
value,
name: parameter.name,
type: parameter.parameterType,
type: parameter.type,
task: formatTaskId(this.id),
},
);
Expand Down
2 changes: 1 addition & 1 deletion v-next/core/src/types/global-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { ParameterType, ParameterTypeToValueType } from "./common.js";
export interface GlobalOption<T extends ParameterType = ParameterType> {
name: string;
description: string;
parameterType: ParameterType;
type: ParameterType;
defaultValue: ParameterTypeToValueType<T>;
}

Expand Down
2 changes: 1 addition & 1 deletion v-next/core/src/types/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ declare module "./config.js" {
export interface TaskParameter<T extends ParameterType = ParameterType> {
name: string;
description: string;
parameterType: T;
type: T;
defaultValue?:
| ParameterTypeToValueType<T>
| Array<ParameterTypeToValueType<T>>;
Expand Down
64 changes: 32 additions & 32 deletions v-next/core/test/internal/global-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { after, before, describe, it } from "node:test";

import { HardhatError } from "@ignored/hardhat-vnext-errors";

import { ParameterType } from "../../src/config.js";
import { globalOption, ParameterType } from "../../src/config.js";
import {
buildGlobalOptionsMap,
buildGlobalOptionDefinition,
Expand Down Expand Up @@ -45,12 +45,12 @@ describe("Global Options", () => {
});

it("should build a map of global options", () => {
const globalOptionDefinition = {
const globalOptionDefinition = globalOption({
name: "param1",
description: "param1 description",
parameterType: ParameterType.BOOLEAN,
type: ParameterType.BOOLEAN,
defaultValue: true,
};
});
const globalOptionsMap = buildGlobalOptionsMap([
{
id: "plugin1",
Expand All @@ -70,18 +70,18 @@ describe("Global Options", () => {
});

it("should throw if a global option is already defined by another plugin", () => {
const globalOptionDefinition = {
const globalOptionDefinition = globalOption({
name: "param1",
description: "param1 description",
parameterType: ParameterType.BOOLEAN,
type: ParameterType.BOOLEAN,
defaultValue: true,
};
const globalOptionDefinition2 = {
});
const globalOptionDefinition2 = globalOption({
name: "param1",
description: "param1 description 2",
parameterType: ParameterType.BOOLEAN,
type: ParameterType.BOOLEAN,
defaultValue: false,
};
});

assert.throws(
() =>
Expand Down Expand Up @@ -113,12 +113,12 @@ describe("Global Options", () => {
{
id: "plugin1",
globalOptions: [
{
globalOption({
name: "foo bar",
description: "Foo description",
parameterType: ParameterType.STRING,
type: ParameterType.STRING,
defaultValue: "bar",
},
}),
],
},
]),
Expand All @@ -136,12 +136,12 @@ describe("Global Options", () => {
{
id: "plugin1",
globalOptions: [
{
globalOption({
name,
description: "Foo description",
parameterType: ParameterType.STRING,
type: ParameterType.STRING,
defaultValue: "bar",
},
}),
],
},
]),
Expand All @@ -159,14 +159,14 @@ describe("Global Options", () => {
{
id: "plugin1",
globalOptions: [
{
globalOption({
name: "foo",
description: "Foo description",
parameterType: ParameterType.BOOLEAN,
type: ParameterType.BOOLEAN,
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions --
Intentionally testing an invalid type */
defaultValue: "bar" as any,
},
}),
],
},
]),
Expand All @@ -184,12 +184,12 @@ describe("Global Options", () => {
const options = {
name: "foo",
description: "Foo description",
parameterType: ParameterType.BOOLEAN,
type: ParameterType.BOOLEAN,
defaultValue: true,
};
const globalOption = buildGlobalOptionDefinition(options);
const globalOptionDefinition = buildGlobalOptionDefinition(options);

assert.deepEqual(globalOption, options);
assert.deepEqual(globalOptionDefinition, options);
});

it("should build a global option definition with a default type of STRING", () => {
Expand All @@ -198,11 +198,11 @@ describe("Global Options", () => {
description: "Foo description",
defaultValue: "bar",
};
const globalOption = buildGlobalOptionDefinition(options);
const globalOptionDefinition = buildGlobalOptionDefinition(options);

assert.deepEqual(globalOption, {
assert.deepEqual(globalOptionDefinition, {
...options,
parameterType: ParameterType.STRING,
type: ParameterType.STRING,
});
});

Expand Down Expand Up @@ -242,7 +242,7 @@ describe("Global Options", () => {
buildGlobalOptionDefinition({
name: "foo",
description: "Foo description",
parameterType: ParameterType.BOOLEAN,
type: ParameterType.BOOLEAN,
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions --
Intentionally testing an invalid type */
defaultValue: "bar" as any,
Expand All @@ -267,7 +267,7 @@ describe("Global Options", () => {
buildGlobalOptionDefinition({
name: "param1",
description: "param1 description",
parameterType: ParameterType.BOOLEAN,
type: ParameterType.BOOLEAN,
defaultValue: true,
}),
buildGlobalOptionDefinition({
Expand Down Expand Up @@ -295,7 +295,7 @@ describe("Global Options", () => {
buildGlobalOptionDefinition({
name: "param1",
description: "param1 description",
parameterType: ParameterType.BOOLEAN,
type: ParameterType.BOOLEAN,
defaultValue: true,
}),
buildGlobalOptionDefinition({
Expand All @@ -306,7 +306,7 @@ describe("Global Options", () => {
buildGlobalOptionDefinition({
name: "param3",
description: "param3 description",
parameterType: ParameterType.BIGINT,
type: ParameterType.BIGINT,
defaultValue: 0n,
}),
],
Expand Down Expand Up @@ -338,7 +338,7 @@ describe("Global Options", () => {
buildGlobalOptionDefinition({
name: "param1",
description: "param1 description",
parameterType: ParameterType.BOOLEAN,
type: ParameterType.BOOLEAN,
defaultValue: true,
}),
buildGlobalOptionDefinition({
Expand Down Expand Up @@ -374,7 +374,7 @@ describe("Global Options", () => {
buildGlobalOptionDefinition({
name: "param1",
description: "param1 description",
parameterType: ParameterType.BOOLEAN,
type: ParameterType.BOOLEAN,
defaultValue: true,
}),
],
Expand Down Expand Up @@ -404,7 +404,7 @@ describe("Global Options", () => {
buildGlobalOptionDefinition({
name: "param1",
description: "param1 description",
parameterType: ParameterType.BOOLEAN,
type: ParameterType.BOOLEAN,
defaultValue: true,
}),
],
Expand Down
Loading

0 comments on commit 74fb192

Please sign in to comment.