Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

Commit

Permalink
Added rule for "_" suffix for internal variables
Browse files Browse the repository at this point in the history
  • Loading branch information
viquezclaudio committed Aug 31, 2018
1 parent aec043c commit 64b94ae
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ In the .soliumrc.json file, add:
],
"zeppelin/no-unused-imports": [
"warning"
],
"zeppelin/internal-state-underscore-suffix": [
"warning"
]
}

Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
"no-arithmetic-operations": require("./rules/no-arithmetic-operations"),
"no-state-variable-shadowing": require("./rules/no-state-variable-shadowing"),
"no-unchecked-send": require("./rules/no-unchecked-send"),
"no-unused-imports": require("./rules/no-unused-imports")
"no-unused-imports": require("./rules/no-unused-imports"),
"internal-state-underscore-suffix": require("./rules/internal-state-underscore-suffix")
}
};
38 changes: 38 additions & 0 deletions rules/internal-state-underscore-suffix.js
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
};
}
};
65 changes: 65 additions & 0 deletions test/internal-state-underscore-suffix.js
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();
});

});

0 comments on commit 64b94ae

Please sign in to comment.