Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #116 mark-callable-contracts firing false positive on event names #117

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/rules/security/mark-callable-contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -42,7 +46,7 @@ class MarkCallableContractsChecker {
isFirstCharUpper &&
!containsTrustInfo &&
isStatement &&
!this.structNames.includes(identifier)
!this.nonContractNames.includes(identifier)
) {
this.reporter.addMessage(
ctx.getSourceInterval(),
Expand All @@ -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)
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/rules/security/mark-callable-contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})