diff --git a/src/validator.ts b/src/validator.ts index e83b81f..8540968 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -19,9 +19,9 @@ export class Validator { } validate(node: NodeToProcess, natspec: Natspec): string[] { - // Proccess contract-level natspec + // Process contract-level natspec if (node instanceof ContractDefinition) { - return this.config.contractNatspec ? this.validateContractNatspec(node, natspec) : []; + return this.config.contractNatspec ? this.validateContractNatspec(natspec) : []; } // Ignore fallback and receive @@ -141,17 +141,10 @@ export class Validator { /** * Validate the natspec of a contract - * @param {ContractDefinition} node - The contract node * @param {Natspec} natspec - The natspec of the contract * @returns {string[]} - The list of alerts */ - private validateContractNatspec(node: ContractDefinition, natspec: Natspec): string[] { - let alerts: string[] = []; - - if (!natspec.tags.map((t) => t.name).includes('notice')) { - alerts.push(`Contract @notice is missing`); - } - - return alerts; + private validateContractNatspec(natspec: Natspec): string[] { + return natspec.tags.some((t) => t.name === 'notice') ? [] : [`@notice is missing`]; } } diff --git a/test/validator.test.ts b/test/validator.test.ts index 9e7efc7..0273af6 100644 --- a/test/validator.test.ts +++ b/test/validator.test.ts @@ -420,20 +420,24 @@ describe('Validator', () => { }); }); - describe('with enforeced contract-level natspec', () => { + describe('with enforced contract-level natspec', () => { beforeAll(() => { validator = new Validator(mockConfig({ contractNatspec: true })); - node = contract; }); it('should reveal missing natspec for a contract if enabled', () => { - const result = validator.validate(node, mockNatspec({})); - expect(result).toContainEqual(`Contract @notice is missing`); + const result = validator.validate(contract, mockNatspec({})); + expect(result).toContainEqual(`@notice is missing`); }); it('should pay attention only to the @notice tag', () => { - const result = validator.validate(node, mockNatspec({ tags: [{ name: 'author', content: 'Some author' }] })); - expect(result).toContainEqual(`Contract @notice is missing`); + const result = validator.validate( + contract, + mockNatspec({ + tags: [{ name: 'author', content: 'Some author' }], + }) + ); + expect(result).toContainEqual(`@notice is missing`); expect(result.length).toBe(1); }); }); @@ -441,11 +445,10 @@ describe('Validator', () => { describe('with disabled contract-level natspec', () => { beforeAll(async () => { validator = new Validator(mockConfig({ contractNatspec: false })); - node = contract; }); it('should ignore missing natspec for a contract if disabled (by default)', () => { - const result = validator.validate(node, mockNatspec({})); + const result = validator.validate(contract, mockNatspec({})); expect(result).toEqual([]); }); });