Skip to content

Commit

Permalink
partially solves #198
Browse files Browse the repository at this point in the history
  • Loading branch information
duaraghav8 committed Apr 26, 2018
1 parent e41b557 commit 66b2c45
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 14 deletions.
3 changes: 2 additions & 1 deletion lib/rules/arg-overflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module.exports = {
if (params.length > MAX_IN_SINGLE_LINE) {
context.report({
node: node,
message: "Function \"" + node.name + "\": in case of more than " + MAX_IN_SINGLE_LINE + " parameters, drop each into its own line."
message: "In case of more than " + MAX_IN_SINGLE_LINE + " parameters, drop each into its own line."
});
}
return;
Expand Down Expand Up @@ -115,6 +115,7 @@ module.exports = {
return {
CallExpression: inspectCallExpression,
FunctionDeclaration: inspectFunctionDeclaration,
ConstructorDeclaration: inspectFunctionDeclaration,
StructDeclaration: inspectStructDeclaration,
ArrayExpression: inspectArrayExpression
};
Expand Down
7 changes: 4 additions & 3 deletions lib/rules/function-whitespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = {
location: {
column: sourceCode.getEndingColumn(arg) + 1
},
message: node.name + " " + arg.id + "(): All arguments (except the last one) must be immediately followed by a comma."
message: "All arguments (except the last one) must be immediately followed by a comma."
});
});
}
Expand All @@ -64,7 +64,7 @@ module.exports = {
location: {
column: sourceCode.getEndingColumn(arg) + 1
},
message: node.name + " " + arg.id + "(): All arguments (except the last one) must be immediately followed by a comma."
message: "All arguments (except the last one) must be immediately followed by a comma."
});
});
}
Expand Down Expand Up @@ -129,7 +129,8 @@ module.exports = {
return {
CallExpression: inspectCallExpression,
ModifierDeclaration: inspectModifierDeclaration,
FunctionDeclaration: inspectFunctionDeclaration
FunctionDeclaration: inspectFunctionDeclaration,
ConstructorDeclaration: inspectFunctionDeclaration
};

}
Expand Down
16 changes: 8 additions & 8 deletions lib/rules/no-empty-blocks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @fileoverview Ensure that no empty blocks {} exist
* @fileoverview Ensure that no empty blocks exist
* @author Raghav Dua <[email protected]>
*/

Expand Down Expand Up @@ -42,17 +42,17 @@ module.exports = {
}

function inspectBlockStatement(emitted) {
let node = emitted.node;
const { node } = emitted, { body } = node;

/**
* Allow Function declarations to have empty bodies.
* Fallback functions - supported in Solidity v4 and above.
*/
if (emitted.exit || context.getSourceCode().getParent(node).type === "FunctionDeclaration") {
// Allow Function & Constructor declarations to have empty bodies.
if (
emitted.exit ||
["FunctionDeclaration", "ConstructorDeclaration"].includes(context.getSourceCode().getParent(node).type)
) {
return;
}

if (node.body && node.body.constructor.name === "Array" && !node.body.length) {
if (body && body.constructor.name === "Array" && !body.length) {
report(node);
}
}
Expand Down
10 changes: 9 additions & 1 deletion test/lib/rules/arg-overflow/arg-overflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ describe("[RULE] arg-overflow: Rejections", function() {
errors.should.be.Array();
errors.length.should.equal(1);
errors[0].message.should.equal(
"Function \"ArgumentOverflow\": in case of more than 3 parameters, drop each into its own line.");
"In case of more than 3 parameters, drop each into its own line.");

code = toContract("constructor(int one, int two, int three, int four) {}"),
errors = Solium.lint(code, userConfig);

errors.should.be.Array();
errors.length.should.equal(1);
errors[0].message.should.equal(
"In case of more than 3 parameters, drop each into its own line.");

code = toFunction("myFuncCall (10, \"hello world\", 20.67, 0x0);");
errors = Solium.lint(code, userConfig);
Expand Down
17 changes: 16 additions & 1 deletion test/lib/rules/no-empty-blocks/no-empty-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,28 @@ describe("[RULE] no-empty-blocks: Acceptances", function() {
done();
});

it("should ACCEPT all EMPTY function declarations (see fallback functions)", function(done) {
it("should ACCEPT all EMPTY function & constructor declarations (see fallback functions)", function(done) {
let code = "function foo () {}",
errors = Solium.lint(toContract(code), userConfig);

errors.constructor.name.should.equal("Array");
errors.length.should.equal(0);

// new constructor syntax
code = "constructor(uint x, string y, address z) {\n/*hello world*/\n}";
errors = Solium.lint(toContract(code), userConfig);

errors.should.be.Array();
errors.should.be.empty();


// fallback func
code = "function(){}";
errors = Solium.lint(toContract(code), userConfig);

errors.should.be.Array();
errors.should.be.empty();

Solium.reset();
done();
});
Expand Down
30 changes: 30 additions & 0 deletions test/lib/rules/whitespace/whitespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ describe("[RULE] whitespace: Acceptances", function() {
errors.constructor.name.should.equal("Array");
errors.length.should.equal(0);

code = "constructor(uint x, string y) {}";
errors = Solium.lint(toContract(code), userConfig);

errors.constructor.name.should.equal("Array");
errors.length.should.equal(0);

code = "constructor() {}";
errors = Solium.lint(toContract(code), userConfig);

errors.constructor.name.should.equal("Array");
errors.length.should.equal(0);

code = "constructor(uint x, string y, address z, string foobar) {}";
errors = Solium.lint(toContract(code), userConfig);

errors.constructor.name.should.equal("Array");
errors.length.should.equal(0);

Solium.reset();
done();
});
Expand Down Expand Up @@ -404,6 +422,18 @@ describe("[RULE] whitespace: Rejections", function() {
errors.constructor.name.should.equal("Array");
errors.length.should.equal(1);

code = "constructor(uint i , Coin coin) {}",
errors = Solium.lint(toContract(code), userConfig);

errors.constructor.name.should.equal("Array");
errors.length.should.equal(1);

code = "constructor(uint i , Coin coin\t,address lulu) {}",
errors = Solium.lint(toContract(code), userConfig);

errors.constructor.name.should.equal("Array");
errors.length.should.equal(2);

code = "var foobar = 100 ;";
errors = Solium.lint(toFunction(code), userConfig);

Expand Down

0 comments on commit 66b2c45

Please sign in to comment.