This repository has been archived by the owner on Jan 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added rule for "_" suffix for internal variables
- Loading branch information
1 parent
aec043c
commit 64b94ae
Showing
4 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @fileoverview Report internal state variables without underscore suffix. | ||
*/ | ||
|
||
"use strict"; | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
recommended: true, | ||
type: "error", | ||
description: "Report internal state variables without underscore suffix" | ||
}, | ||
schema: [] | ||
}, | ||
|
||
create: function(context) { | ||
|
||
function inspectStateVariableDeclaration(emitted) { | ||
if (emitted.exit) { | ||
return; | ||
} | ||
|
||
if ( (param.id.charAt(param.id.length - 1) !== "_") && | ||
(param.visibility != "public")) { | ||
context.report({ | ||
node: emitted.node, | ||
message: `'${param.id}' does not have an underscore as suffix.` | ||
}); | ||
} | ||
|
||
} | ||
|
||
return { | ||
StateVariableDeclaration: inspectStateVariableDeclaration | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* @fileoverview Tests for internal-state-underscore-suffix rule | ||
*/ | ||
|
||
"use strict"; | ||
|
||
const dedent = require("dedent"); | ||
const Solium = require("solium"); | ||
const wrappers = require("./utils/wrappers"); | ||
const addPragma = wrappers.addPragma; | ||
|
||
const userConfig = { | ||
rules: { | ||
"zeppelin/internal-state-underscore-suffix": 1 | ||
} | ||
}; | ||
|
||
describe("[RULE] internal-state-underscore-suffix: Rejections", function() { | ||
|
||
afterEach(function(done) { | ||
Solium.reset(); | ||
done(); | ||
}); | ||
|
||
it("should reject internal state variables without underscore suffix", function(done) { | ||
const code = dedent` | ||
contract TestContract { | ||
bool internal_no_underscore_suffix = false; | ||
function testFunction(uint parameter) {} | ||
}`, | ||
errors = Solium.lint(addPragma(code), userConfig); | ||
|
||
errors.should.be.instanceof(Array); | ||
errors.length.should.equal(1); | ||
errors[0].message.should.equal( | ||
"'internal_no_underscore_suffix' does not have an underscore suffix."); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe("[RULE] internal-state-underscore-suffix: Acceptances", function() { | ||
|
||
afterEach(function(done) { | ||
Solium.reset(); | ||
done(); | ||
}); | ||
|
||
it("should accept internal state variables with underscore suffix", function(done) { | ||
const code = dedent` | ||
contract TestContract { | ||
bool public internal_underscore_suffix_ = false; | ||
function testFunction(uint parameter) {} | ||
}`, | ||
errors = Solium.lint(addPragma(code), userConfig); | ||
|
||
errors.should.deepEqual([]); | ||
|
||
done(); | ||
}); | ||
|
||
}); |