diff --git a/lib/rules/security/mark-callable-contracts.js b/lib/rules/security/mark-callable-contracts.js index b9ec42fe..8673feed 100644 --- a/lib/rules/security/mark-callable-contracts.js +++ b/lib/rules/security/mark-callable-contracts.js @@ -25,11 +25,15 @@ class MarkCallableContractsChecker { this.reporter = reporter this.ruleId = ruleId this.meta = meta - this.structNames = [] + this.nonContractNames = [] } enterStructDefinition(ctx) { - this.gatherStructNames(ctx) + this.gatherNonContractNames(ctx) + } + + enterEventDefinition(ctx) { + this.gatherNonContractNames(ctx) } exitIdentifier(ctx) { @@ -42,7 +46,7 @@ class MarkCallableContractsChecker { isFirstCharUpper && !containsTrustInfo && isStatement && - !this.structNames.includes(identifier) + !this.nonContractNames.includes(identifier) ) { this.reporter.addMessage( ctx.getSourceInterval(), @@ -53,12 +57,12 @@ class MarkCallableContractsChecker { } } - gatherStructNames(ctx) { + gatherNonContractNames(ctx) { const identifier = ctx.children[1] - const structName = identifier.getText() + const name = identifier.getText() - if (structName) { - this.structNames.push(structName) + if (name) { + this.nonContractNames.push(name) } } } diff --git a/test/rules/security/mark-callable-contracts.js b/test/rules/security/mark-callable-contracts.js index 0a5c6f93..09923128 100644 --- a/test/rules/security/mark-callable-contracts.js +++ b/test/rules/security/mark-callable-contracts.js @@ -55,4 +55,20 @@ describe('Linter - mark-callable-contracts', () => { assert.equal(report.warningCount, 0) }) + + it('should not return error for an event', () => { + const code = contractWith(` + event UpdatedToken(); + + function b() public { + emit UpdatedToken(); + } + `) + + const report = linter.processStr(code, { + rules: { 'mark-callable-contracts': 'warn' } + }) + + assert.equal(report.warningCount, 0) + }) })