Comparing version 0.5.2 to 0.5.3
@@ -22,2 +22,41 @@ /** | ||
/** | ||
* If the left & right side of expression span over multiple lines, | ||
* make sure that the operator resides on the same line as the left expression (ie, first line) | ||
*/ | ||
// 1. take line no. of both left & right expr. Line no (right) = line (left) + 1 | ||
// Take string btw them, should be NO \n before operator. that's it | ||
var rightNodeStartingLine = sourceCode.getLine (node.right), | ||
leftNodeEndingLine = sourceCode.getEndingLine (node.left), | ||
opRegExp = node.operator.replace (/([\+\*\/\|\^])/g, '\\$1'); | ||
if (rightNodeStartingLine > leftNodeEndingLine) { | ||
var validationRegexOpOnSameLineAsLeftNodeEnd = new RegExp ('^[^\\n]*' + opRegExp), | ||
strBetweenLeftAndRightNode = sourceCode.getStringBetweenNodes (node.left, node.right); | ||
if (rightNodeStartingLine !== leftNodeEndingLine + 1) { | ||
context.report ({ | ||
node: node, | ||
location: { | ||
column: sourceCode.getColumn (node.right), | ||
line: sourceCode.getLine (node.right) | ||
}, | ||
message: 'In Binary Expressions that span over multiple lines, expression on the right side of the operator (' + node.operator + ') must be exactly 1 line below the line on which the left expression ends.' | ||
}); | ||
} | ||
if (!validationRegexOpOnSameLineAsLeftNodeEnd.test (strBetweenLeftAndRightNode)) { | ||
context.report ({ | ||
node: node, | ||
location: { | ||
column: sourceCode.getEndingColumn (node.left) | ||
}, | ||
message: 'Operator "' + node.operator + '" should be on the line where left side of the Binary expression ends.' | ||
}); | ||
} | ||
return; | ||
} | ||
// Handle case where left node is a binary expression and right node may be a literal | ||
@@ -24,0 +63,0 @@ if (sourceCode.isASTNode(node.left) && node.left.type === 'BinaryExpression'){ |
{ | ||
"name": "solium", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "A flexible, stand-alone linter for Ethereum Solidity", | ||
@@ -5,0 +5,0 @@ "main": "./lib/solium.js", |
@@ -50,98 +50,28 @@ /** | ||
code = code.map(function(item){return toFunction(item)}); | ||
code.forEach (function (snippet) { | ||
var errors = Solium.lint (snippet, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
}); | ||
errors = Solium.lint (code [0], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
Solium.reset (); | ||
done (); | ||
}); | ||
errors = Solium.lint (code [1], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
it ('should accept multi-line Binary Expression whose operator resides on the line where left side expression ends AND whose right side expression begins 1 line below the line where left expression ends.', function (done) { | ||
var code = [ | ||
'if (foobarMotherfuckers (price, 100) &&\n\t++crazyCounter) {\n}', | ||
'if (foobarMotherfuckers (price, 100)\t &&\n\t++crazyCounter) {\n}' | ||
]; | ||
errors = Solium.lint (code [2], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
code = code.map (function (str) { return toFunction (str); }); | ||
code.forEach (function (snippet) { | ||
var errors = Solium.lint (snippet, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
}); | ||
errors = Solium.lint (code [3], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [4], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [5], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [6], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [7], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [8], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [9], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [10], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [11], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [12], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [13], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [14], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [15], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [16], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [17], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [18], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [19], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [20], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [21], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
errors = Solium.lint (code [22], userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
Solium.reset (); | ||
done (); | ||
}) | ||
}); | ||
@@ -153,3 +83,3 @@ }); | ||
it ('should reject reject BinaryExpressions with extraneous whitespace or comments next to operators', function (done) { | ||
it ('should reject BinaryExpressions with extraneous whitespace or comments next to operators', function (done) { | ||
var code = [ | ||
@@ -160,4 +90,4 @@ 'x [10] +y.foo;', | ||
'x.foo**\tbar ();', | ||
'x.foo\n^ bar ();', | ||
'x.foo\n>>\nbar ();', | ||
'x.foo ^ bar ();', | ||
'x.foo\t>>\t\tbar ();', | ||
'x.foo/**/&& bar ();', | ||
@@ -170,6 +100,6 @@ 'x.foo||/**/bar ();', | ||
'(90.89 * 1) /**/-/**/ (100 - 76 % (3**2));', | ||
'x.foo\n**\nbar ();', | ||
'8 *\n9 /\t3 % 2;', | ||
'x.foo **\t \tbar ();', | ||
'8 *\t9 /\t3 % 2;', | ||
'1+ 8- 67;', | ||
'1909\n+\n189 * 1 ** 29 / 190;', | ||
'1909\t+\t\t189 * 1 ** 29 / 190;', | ||
'1909\t+ 189*1\t** 29/190;', | ||
@@ -237,3 +167,3 @@ '1909+ 189 *1**29/190;', | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (2); | ||
errors.length.should.equal (1); | ||
@@ -268,2 +198,42 @@ errors = Solium.lint (code [14], userConfig); | ||
it ('should reject multi-line Binary Expression whose operator is not on the line where left side of the exp. ends.', function (done) { | ||
var code = [ | ||
'if (foobarMotherfuckers (price, 100)\n&&\t++crazyCounter) {\n}', | ||
'if (foobarMotherfuckers (price, 100)\t\n&&++crazyCounter) {\n}' | ||
]; | ||
code = code.map (function (str) { return toFunction (str); }); | ||
code.forEach (function (snippet) { | ||
var errors = Solium.lint (snippet, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (1); | ||
}); | ||
var opErrorAndRightExprErrorCode = 'if (foobarMotherfuckers (price, 100)\n&&\n\t++crazyCounter) {\n}', | ||
errors = Solium.lint (toFunction (opErrorAndRightExprErrorCode), userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (2); | ||
Solium.reset (); | ||
done (); | ||
}); | ||
it ('should reject multi-line Binary Expression whose right side doesn\'t fall exactly 1 line below the ending line of left side of the expr.', function (done) { | ||
var code = [ | ||
'if (foobarMotherfuckers (price, 100)&&\n\n\t++crazyCounter) {\n}', | ||
'if (foobarMotherfuckers (price, 100) &&\t\n\n\n\n++crazyCounter) {\n}' | ||
]; | ||
code = code.map (function (str) { return toFunction (str); }); | ||
code.forEach (function (snippet) { | ||
var errors = Solium.lint (snippet, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (1); | ||
}); | ||
Solium.reset (); | ||
done (); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
259880
6370