From 98905ae8e0d8db3b04d8caf774c7d90918ba7202 Mon Sep 17 00:00:00 2001 From: Hassan Abdel-Rahman Date: Tue, 14 May 2019 17:14:30 -0400 Subject: [PATCH 1/2] Fixes #116 mark-callable-contracts firing false positive on event names --- lib/rules/security/mark-callable-contracts.js | 18 +++++++++++------- test/rules/security/mark-callable-contracts.js | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) 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..3b15ac71 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 a 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) + }) }) From f4975748543f597111917d35717fe95b37d22a36 Mon Sep 17 00:00:00 2001 From: Hassan Abdel-Rahman Date: Tue, 14 May 2019 17:15:30 -0400 Subject: [PATCH 2/2] typo --- test/rules/security/mark-callable-contracts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/rules/security/mark-callable-contracts.js b/test/rules/security/mark-callable-contracts.js index 3b15ac71..09923128 100644 --- a/test/rules/security/mark-callable-contracts.js +++ b/test/rules/security/mark-callable-contracts.js @@ -56,7 +56,7 @@ describe('Linter - mark-callable-contracts', () => { assert.equal(report.warningCount, 0) }) - it('should not return error for a event', () => { + it('should not return error for an event', () => { const code = contractWith(` event UpdatedToken();