diff --git a/lib/src/verifiers/unicity/endpoints.spec.ts b/lib/src/verifiers/unicity/endpoints.spec.ts index bc20d9015..dbb0d714b 100644 --- a/lib/src/verifiers/unicity/endpoints.spec.ts +++ b/lib/src/verifiers/unicity/endpoints.spec.ts @@ -64,7 +64,7 @@ describe("unique endpoint names verifier", () => { }; expect(verifyUniqueEndpointNames(contractNode)).toMatchObject([ { - message: "endpoints must have unique names" + message: "endpoints must have unique names: EndpointOne" } ]); }); diff --git a/lib/src/verifiers/unicity/endpoints.ts b/lib/src/verifiers/unicity/endpoints.ts index 01ea658e9..93f8e02ab 100644 --- a/lib/src/verifiers/unicity/endpoints.ts +++ b/lib/src/verifiers/unicity/endpoints.ts @@ -1,4 +1,4 @@ -import { uniq } from "lodash"; +import { groupBy, keys, pickBy } from "lodash"; import { ContractNode } from "../../models/nodes"; import { VerificationError } from "../verification-error"; @@ -6,16 +6,25 @@ export function verifyUniqueEndpointNames( contract: ContractNode ): VerificationError[] { const errors: VerificationError[] = []; - const endpointNames = contract.endpoints.map( + + const endpointsByName = groupBy( + contract.endpoints, endpoint => endpoint.value.name.value ); - if (uniq(endpointNames).length !== endpointNames.length) { + + const duplicatedEndpoints = pickBy( + endpointsByName, + endpointCollection => endpointCollection.length > 1 + ); + + keys(duplicatedEndpoints).forEach(endpointName => { + const firstEndpointWithName = duplicatedEndpoints[endpointName][0]; errors.push({ - message: "endpoints must have unique names", - // TODO: use a duplicated endpoint location - location: contract.api.location, - line: contract.api.line + message: `endpoints must have unique names: ${endpointName}`, + location: firstEndpointWithName.value.name.location, + line: firstEndpointWithName.value.name.line }); - } + }); + return errors; } diff --git a/lib/src/verifiers/unicity/types.spec.ts b/lib/src/verifiers/unicity/types.spec.ts index 585530f5f..f934f85c0 100644 --- a/lib/src/verifiers/unicity/types.spec.ts +++ b/lib/src/verifiers/unicity/types.spec.ts @@ -39,7 +39,7 @@ describe("unique type names verifier", () => { }; expect(verifyUniqueTypeNames(contractNode)).toMatchObject([ { - message: "types must have unique names" + message: "types must have unique names: TypeOne" } ]); }); diff --git a/lib/src/verifiers/unicity/types.ts b/lib/src/verifiers/unicity/types.ts index 344566486..8db2b24ef 100644 --- a/lib/src/verifiers/unicity/types.ts +++ b/lib/src/verifiers/unicity/types.ts @@ -1,4 +1,4 @@ -import { uniq } from "lodash"; +import { groupBy, keys, pickBy } from "lodash"; import { ContractNode } from "../../models/nodes"; import { VerificationError } from "../verification-error"; @@ -6,14 +6,21 @@ export function verifyUniqueTypeNames( contract: ContractNode ): VerificationError[] { const errors: VerificationError[] = []; - const typeNames = contract.types.map(type => type.name); - if (uniq(typeNames).length !== typeNames.length) { + + const typesByName = groupBy(contract.types, type => type.name); + const duplicatedTypes = pickBy( + typesByName, + typeCollection => typeCollection.length > 1 + ); + + keys(duplicatedTypes).forEach(typeName => { errors.push({ - message: "types must have unique names", + message: `types must have unique names: ${typeName}`, // TODO: use a duplicated type location location: contract.api.location, line: contract.api.line }); - } + }); + return errors; }