Repository: protofire/solhint (js)

Issue:
mark-callable-contracts rule is firing a false positive on constants
The mark-callable-contracts rule is being triggered against emitting events, as events are camel-cased very similarly to contracts. We should update this rule so that it does not get triggered by emitting an event. Take for instance this example:
```
contract A {
  uint8 private constant TOKEN_DECIMALS = 15;

  function b() public view returns(uint8) {
    return TOKEN_DECIMALS;
  }

}
```

Pull request description:
Fixes #118 mark-callable-contracts firing false positive on constant names
Fixes #118 

Patch:
diff --git a/lib/rules/security/mark-callable-contracts.js b/lib/rules/security/mark-callable-contracts.js
index 8673fee..148fd8b 100644
--- a/lib/rules/security/mark-callable-contracts.js
+++ b/lib/rules/security/mark-callable-contracts.js
@@ -36,6 +36,18 @@ class MarkCallableContractsChecker {
     this.gatherNonContractNames(ctx)
   }
 
+  exitStateVariableDeclaration(ctx) {
+    const hasConstModifier = ctx.children.some(i => i.getText() === 'constant')
+
+    if (hasConstModifier) {
+      this._forEachIdentifier(ctx, (curId, name) => {
+        if (name) {
+          this.nonContractNames.push(name)
+        }
+      })
+    }
+  }
+
   exitIdentifier(ctx) {
     const identifier = ctx.getText()
     const isFirstCharUpper = /[A-Z]/.test(identifier[0])
@@ -65,6 +77,16 @@ class MarkCallableContractsChecker {
       this.nonContractNames.push(name)
     }
   }
+
+  _forEachIdentifier(ctx, callback) {
+    for (const curId of traversing.findIdentifier(ctx)) {
+      const text = curId.getText()
+
+      if (callback) {
+        callback(curId, text)
+      }
+    }
+  }
 }
 
 module.exports = MarkCallableContractsChecker


Test patch:
diff --git a/test/rules/security/mark-callable-contracts.js b/test/rules/security/mark-callable-contracts.js
index 0992312..fbcc6e4 100644
--- a/test/rules/security/mark-callable-contracts.js
+++ b/test/rules/security/mark-callable-contracts.js
@@ -71,4 +71,20 @@ describe('Linter - mark-callable-contracts', () => {
 
     assert.equal(report.warningCount, 0)
   })
+
+  it('should not return error for constant', () => {
+    const code = contractWith(`
+  uint8 private constant TOKEN_DECIMALS = 15;
+
+  function b() public view returns(uint8) {
+    return TOKEN_DECIMALS;
+  }
+    `)
+
+    const report = linter.processStr(code, {
+      rules: { 'mark-callable-contracts': 'warn' }
+    })
+
+    assert.equal(report.warningCount, 0)
+  })
 })