Comparing version 0.1.11 to 0.1.12
@@ -20,3 +20,3 @@ /** | ||
Object.keys (eventsToWatch).forEach (function (event) { | ||
function inspectEventsToWatch (event) { | ||
context.on (event, function (emitted) { | ||
@@ -32,10 +32,12 @@ var node = emitted.node; | ||
node: node, | ||
message: eventsToWatch [event] + ' name \'' + node.name + '\' doesn\'t follow the CamelCase notation' | ||
message: eventsToWatch [event] + ' name \'' + node.name + '\' doesn\'t follow the CamelCase notation.' | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
Object.keys (eventsToWatch).forEach (inspectEventsToWatch); | ||
} | ||
}; |
@@ -31,3 +31,3 @@ /** | ||
context.on ('Literal', function (emitted) { | ||
function inspectLiteral (emitted) { | ||
var node = emitted.node, nodeText = sourceCode.getText (node); | ||
@@ -48,6 +48,8 @@ | ||
} | ||
}); | ||
} | ||
context.on ('Literal', inspectLiteral); | ||
} | ||
}; |
@@ -36,4 +36,3 @@ /** | ||
context.on ('ImportStatement', function (emitted) { | ||
function inspectImportStatement (emitted) { | ||
var node = emitted.node, | ||
@@ -64,4 +63,5 @@ sourceCode = context.getSourceCode (), | ||
} | ||
} | ||
}); | ||
context.on ('ImportStatement', inspectImportStatement); | ||
@@ -68,0 +68,0 @@ } |
/** | ||
* @fileoverview Ensure that all if and else clauses, for, while and with statements are followed by an opening curly brace. | ||
* @fileoverview Ensure that all function declarations, if and else clauses, for, while and with statements are followed by an opening curly brace. | ||
* This starting brace must be on the same line as the statement. | ||
@@ -209,2 +209,18 @@ * @author Raghav Dua <duaraghav8@gmail.com> | ||
}); | ||
context.on ('FunctionDeclaration', function (emitted) { | ||
var node = emitted.node; | ||
if (emitted.exit) { | ||
return; | ||
} | ||
(sourceCode.getLine (node) === sourceCode.getLine (node.body)) && | ||
!/[^\s\/] {/.test (sourceCode.getPrevChars (node.body, 3)) && | ||
context.report ({ | ||
node: node.body, | ||
message: 'Function \'' + node.name + '\': Opening brace must be preceeded by a single space.' | ||
}); | ||
}); | ||
@@ -211,0 +227,0 @@ } |
@@ -11,44 +11,71 @@ /** | ||
verify: function (context) { | ||
var sourceCode = context.getSourceCode (), | ||
whitespaceRegExp = / /; | ||
var NODES_TO_CAPTURE = [ | ||
'AssignmentExpression', | ||
'BinaryExpression' | ||
]; | ||
NODES_TO_CAPTURE.forEach (function (event) { | ||
var sourceCode = context.getSourceCode (); | ||
context.on (event, function (emitted) { | ||
context.on ('BinaryExpression', function (emitted) { | ||
var node = emitted.node; | ||
var node = emitted.node, | ||
sourceCodeText = sourceCode.getText (node), | ||
opIndex = sourceCodeText.indexOf (node.operator); | ||
if (emitted.exit) { | ||
return; | ||
} | ||
if (emitted.exit) { | ||
return; | ||
} | ||
var strBetweenLeftAndRight = sourceCode.getStringBetweenNodes (node.left, node.right).split (node.operator), | ||
onlyCharsRegExp = /^[^\s\/]$/; | ||
if ( | ||
!whitespaceRegExp.test (sourceCodeText [opIndex - 1]) || | ||
whitespaceRegExp.test (sourceCodeText [opIndex - 2]) || | ||
!whitespaceRegExp.test (sourceCodeText [opIndex + node.operator.length]) || | ||
whitespaceRegExp.test (sourceCodeText [opIndex + node.operator.length + 1]) | ||
) { | ||
if (strBetweenLeftAndRight [0].slice (-1) === ' ' || strBetweenLeftAndRight [1] [0] === ' ') { | ||
if (strBetweenLeftAndRight [0].slice (-1) !== strBetweenLeftAndRight [1] [0]) { | ||
context.report ({ | ||
node: node, | ||
message: ( | ||
'Operator \'' + | ||
node.operator + | ||
'\' needs to be surrounded by (only) a single space on either side.' | ||
) | ||
location: { | ||
column: sourceCode.getEndingColumn (node.left) + 1 | ||
}, | ||
message: 'Single space should be either on both sides of \'' + node.operator + '\' or not at all.' | ||
}); | ||
} else { | ||
var secondLastCharOnLeft = strBetweenLeftAndRight [0].slice (-2, -1), | ||
secondCharOnRight = strBetweenLeftAndRight [1] [1]; | ||
secondLastCharOnLeft && (!onlyCharsRegExp.test (secondLastCharOnLeft)) && context.report ({ | ||
node: node, | ||
location: { | ||
column: sourceCode.getEndingColumn (node.left) | ||
}, | ||
message: 'There should be a maximum of single space and no comments between left side and \'' + node.operator + '\'.' | ||
}); | ||
secondCharOnRight && (!onlyCharsRegExp.test (secondCharOnRight)) && context.report ({ | ||
node: node, | ||
location: { | ||
column: sourceCode.getColumn (node.right) | ||
}, | ||
message: 'There should be a maximum of single space and no comments between right side and \'' + node.operator + '\'.' | ||
}); | ||
} | ||
return; | ||
} | ||
var firstCharOnLeft = strBetweenLeftAndRight [0].slice (-1), | ||
firstCharOnRight = strBetweenLeftAndRight [1] [0]; | ||
firstCharOnLeft && (!onlyCharsRegExp.test (firstCharOnLeft)) && context.report ({ | ||
node: node, | ||
location: { | ||
column: sourceCode.getEndingColumn (node.left) | ||
}, | ||
message: 'There should be no comments between left side and \'' + node.operator + '\'.' | ||
}); | ||
firstCharOnRight && (!onlyCharsRegExp.test (firstCharOnRight)) && context.report ({ | ||
node: node, | ||
location: { | ||
column: sourceCode.getColumn (node.right) | ||
}, | ||
message: 'There should be no comments between right side and \'' + node.operator + '\'.' | ||
}); | ||
}); | ||
} | ||
}; |
@@ -14,3 +14,3 @@ /** | ||
context.on ('VariableDeclarator', function (emitted) { | ||
function inspectVariableDeclarator (emitted) { | ||
var node = emitted.node, | ||
@@ -31,5 +31,5 @@ variableName = node.id.name; | ||
}); | ||
}); | ||
} | ||
context.on ('DeclarativeExpression', function (emitted) { | ||
function inspectDeclarativeExpression (emitted) { | ||
var node = emitted.node, | ||
@@ -50,6 +50,9 @@ variableName = node.name; | ||
}); | ||
}); | ||
} | ||
context.on ('VariableDeclarator', inspectVariableDeclarator); | ||
context.on ('DeclarativeExpression', inspectDeclarativeExpression); | ||
} | ||
}; |
@@ -39,5 +39,12 @@ /** | ||
if (!callArgs.length) { | ||
var codeWithoutArgs = nodeCode.replace (node.callee.name, '').trim (); | ||
for (var i = nodeCode.length; i > 0; i--) { | ||
if (nodeCode [i] === ')' && nodeCode [i-1] === '(') { | ||
return; | ||
} | ||
if (/[\s\(\)]/.test (nodeCode [i])) { | ||
break; | ||
} | ||
} | ||
(!/^\(\)/.test (codeWithoutArgs)) && context.report ({ | ||
return context.report ({ | ||
node: node, | ||
@@ -47,4 +54,2 @@ message: '\"' + nodeCode + '\": ' + | ||
}); | ||
return; | ||
} | ||
@@ -303,2 +308,5 @@ | ||
/************************************************************************************************ | ||
* From here on, we're explicitly looking for semicolon whitespace errors | ||
************************************************************************************************/ | ||
context.on ('ExpressionStatement', function (emitted) { | ||
@@ -324,2 +332,42 @@ var node = emitted.node; | ||
context.on ('UsingStatement', function (emitted) { | ||
var node = emitted.node; | ||
if (emitted.exit) { | ||
return; | ||
} | ||
var code = sourceCode.getText (node); | ||
//ensure there's no whitespace or comments before semicolon | ||
(code [code.length - 1] === ';' && /(\s|\/)/.test (code [code.length - 2])) && context.report ({ | ||
node: node, | ||
location: { | ||
column: code.length - 2 | ||
}, | ||
message: 'There should be no whitespace or comments before the semicolon.' | ||
}); | ||
}); | ||
context.on ('ImportStatement', function (emitted) { | ||
var node = emitted.node; | ||
if (emitted.exit) { | ||
return; | ||
} | ||
var code = sourceCode.getText (node); | ||
//ensure there's no whitespace or comments before semicolon | ||
(code [code.length - 1] === ';' && /(\s|\/)/.test (code [code.length - 2])) && context.report ({ | ||
node: node, | ||
location: { | ||
column: code.length - 2 | ||
}, | ||
message: 'There should be no whitespace or comments before the semicolon.' | ||
}); | ||
}); | ||
/************************************************************************************************ | ||
@@ -326,0 +374,0 @@ * From here on, we're explicitly looking for comma whitespace errors |
{ | ||
"name": "solium", | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"description": "A flexible, stand-alone linter for Ethereum Solidity", | ||
@@ -29,3 +29,3 @@ "main": "./lib/solium.js", | ||
"sol-explore": "^1.6.1", | ||
"solparse": "^1.0.3" | ||
"solparse": "^1.0.6" | ||
}, | ||
@@ -32,0 +32,0 @@ "devDependencies": { |
@@ -37,5 +37,8 @@ # Solium | ||
1. use ```solium --hot``` to enable Hot loading (Hot swapping). | ||
1. Use ```solium --hot``` to enable Hot loading (Hot swapping). | ||
2. When new rules are added in subsequent versions and you update Solium, you need not re-initialize with ```--init```. Simply run ```solium --sync``` in your root directory and it automatically adds the newly added rules to your ```.soliumrc.json```. The sync option **doesn't change anything else in your configuration files**. | ||
3. Use ```solium --dir <DIRECTORY_NAME>``` to run the linter over a particular directory | ||
#Plugging in your custom rules | ||
@@ -42,0 +45,0 @@ -> Open up the ```.soliumrc.json``` configuration file and set the value of ```custom-rules-filename``` to the path of the file that defines your rules. You can either provide an absolute path or a path relative to the directory in which .soliumrc.json resides. For example: ```"custom-rules-filename": "./my-rules.js"``` |
@@ -29,2 +29,8 @@ /** | ||
code = 'foo.func ();'; | ||
errors = Solium.lint (code, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
Solium.reset (); | ||
@@ -41,3 +47,3 @@ done (); | ||
code = 'foo ["fun"]; bar.baz;'; | ||
code = 'foo.bar (10, 20, 30);'; | ||
errors = Solium.lint (code, userConfig); | ||
@@ -48,2 +54,26 @@ | ||
code = 'foo.bar (10, 20, 30);'; | ||
errors = Solium.lint (code, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
code = 'foo (10, 20).func ();'; | ||
errors = Solium.lint (code, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
code = 'foo ["func ()"] ();'; | ||
errors = Solium.lint (code, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
code = 'foo ["func (10, 20)"] ();'; | ||
errors = Solium.lint (code, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (0); | ||
Solium.reset (); | ||
@@ -182,2 +212,20 @@ done (); | ||
code = 'func (/**/);'; | ||
errors = Solium.lint (code, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (1); | ||
code = 'foo ["func ()"] ( );'; | ||
errors = Solium.lint (code, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (1); | ||
code = 'foo ().func (\t);'; | ||
errors = Solium.lint (code, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (1); | ||
Solium.reset (); | ||
@@ -280,2 +328,20 @@ done (); | ||
code = 'import * as C from "chuh"/**/;'; | ||
errors = Solium.lint (code, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (1); | ||
code = 'using Foo for *\t;'; | ||
errors = Solium.lint (code, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (1); | ||
code = 'using Foo for Bar.baz\t;'; | ||
errors = Solium.lint (code, userConfig); | ||
errors.constructor.name.should.equal ('Array'); | ||
errors.length.should.equal (1); | ||
//////////////////////////////////////////////////////////////////////////// | ||
@@ -282,0 +348,0 @@ |
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
195138
66
4905
141
Updatedsolparse@^1.0.6