Comparing version 0.1.2 to 0.1.3
@@ -25,2 +25,3 @@ { | ||
"no-ex-assign": 2, | ||
"no-extra-semi": 2, | ||
"no-func-assign": 2, | ||
@@ -27,0 +28,0 @@ "no-floating-decimal": 0, |
@@ -54,5 +54,7 @@ /** | ||
output += "\n" + total + " problem" + (total !== 1 ? "s" : ""); | ||
if (total > 0) { | ||
output += "\n" + total + " problem" + (total !== 1 ? "s" : ""); | ||
} | ||
return output; | ||
}; |
@@ -15,11 +15,17 @@ /** | ||
function findOpenParen(tokens) { | ||
var openParenIndices = []; | ||
var i, token, hasArgumentList = false, numOpen = 0; | ||
tokens.forEach(function(token, i) { | ||
// start at the end of the token stream; skip over argument list contents | ||
for(i = tokens.length - 1; i >= 0; --i) { | ||
token = tokens[i]; | ||
if (token.value === "(") { | ||
openParenIndices.push(i); | ||
--numOpen; | ||
} else if (token.value === ")") { | ||
hasArgumentList = true; | ||
++numOpen; | ||
} | ||
}); | ||
return openParenIndices; | ||
if (hasArgumentList && numOpen <= 0) { | ||
return i; | ||
} | ||
} | ||
} | ||
@@ -29,24 +35,13 @@ | ||
var tokens = context.getTokens(node), | ||
openParenIndices = findOpenParen(tokens), | ||
prevToken, | ||
curToken, | ||
isSpaceBetweenRange, | ||
isPrevTokenValid; | ||
openParenIndex = findOpenParen(tokens), | ||
openParen = tokens[openParenIndex], | ||
callee = tokens[openParenIndex - 1]; | ||
openParenIndices.forEach(function(i) { | ||
prevToken = tokens[i-1]; | ||
curToken = tokens[i]; | ||
// openParenIndex will be undefined for a NewExpression with no argument list | ||
if (!openParenIndex) { return; } | ||
if (!prevToken) { | ||
return; | ||
} | ||
isSpaceBetweenRange = prevToken.range[1] !== curToken.range[0]; | ||
isPrevTokenValid = prevToken.value !== "("; | ||
// If theres a gap between the end of the identifier and open paren | ||
if (isSpaceBetweenRange && isPrevTokenValid) { | ||
context.report(node, "Spaced function application is not allowed."); | ||
} | ||
}); | ||
// look for a space between the callee and the open paren | ||
if (callee.range[1] !== openParen.range[0]) { | ||
context.report(node, "Spaced function application is not allowed."); | ||
} | ||
} | ||
@@ -53,0 +48,0 @@ |
@@ -12,3 +12,3 @@ /** | ||
* "{code}", | ||
* { code: "{code}", args: {args} } | ||
* { code: "{code}", args: {args}, global: {globals}, globals: {globals} } | ||
* ], | ||
@@ -25,2 +25,4 @@ * invalid: [ | ||
* supplied "1" is passed to the rule | ||
* {globals} - An object representing a list of variables that are | ||
* registered as globals | ||
* {numErrors} - If failing case doesn't need to check error message, | ||
@@ -56,8 +58,13 @@ * this integer will specify how many errors should be | ||
//all valid cases go through this. | ||
function testValidTemplate(ruleName, code, args) { | ||
function testValidTemplate(ruleName, item) { | ||
var config = { rules: {} }; | ||
config.rules[ruleName] = args ? args : 1; | ||
var messages = eslint.verify(code, config); | ||
if (item.globals || item.global) { | ||
config.global = item.globals ? item.globals : item.global; | ||
} | ||
config.rules[ruleName] = item.args ? item.args : 1; | ||
var messages = eslint.verify(item.code ? item.code : item, config); | ||
assert.equal(messages.length, 0, "Should have no errors"); | ||
@@ -67,21 +74,26 @@ } | ||
//all invalid cases go through this. | ||
function testInvalidTemplate(ruleName, code, errors, args) { | ||
function testInvalidTemplate(ruleName, item) { | ||
var config = { rules: {} }; | ||
config.rules[ruleName] = args ? args : 1; | ||
var messages = eslint.verify(code, config); | ||
if (item.globals || item.global) { | ||
config.global = item.globals ? item.globals : item.global; | ||
} | ||
if (typeof errors === "number") { | ||
assert.equal(messages.length, errors); | ||
config.rules[ruleName] = item.args ? item.args : 1; | ||
var messages = eslint.verify(item.code, config); | ||
if (typeof item.errors === "number") { | ||
assert.equal(messages.length, item.errors); | ||
} else { | ||
assert.equal(messages.length, errors.length); | ||
assert.equal(messages.length, item.errors.length); | ||
if (messages.length === errors.length) { | ||
for (var i=0, l=errors.length; i<l; i++) { | ||
if (messages.length === item.errors.length) { | ||
for (var i=0, l=item.errors.length; i<l; i++) { | ||
assert.equal(messages[i].ruleId, ruleName, "Error rule name should be the same as the name of the rule being tested"); | ||
if (errors[i].message) { | ||
assert.equal(messages[i].message, errors[i].message, "Error message should be " + errors[i].message); | ||
if (item.errors[i].message) { | ||
assert.equal(messages[i].message, item.errors[i].message, "Error message should be " + item.errors[i].message); | ||
} | ||
if (errors[i].type) { | ||
assert.equal(messages[i].node.type, errors[i].type, "Error type should be " + errors[i].type); | ||
if (item.errors[i].type) { | ||
assert.equal(messages[i].node.type, item.errors[i].type, "Error type should be " + item.errors[i].type); | ||
} | ||
@@ -102,7 +114,3 @@ } | ||
test.valid.forEach(function(valid) { | ||
if (typeof valid === "string") { | ||
it(valid, function() { testValidTemplate(ruleName, valid); }); | ||
} else { | ||
it(valid.code, function() { testValidTemplate(ruleName, valid.code, valid.args); }); | ||
} | ||
it(valid, function() { testValidTemplate(ruleName, valid); }); | ||
}); | ||
@@ -116,3 +124,3 @@ } | ||
test.invalid.forEach(function(invalid) { | ||
it(invalid.code, function() { testInvalidTemplate(ruleName, invalid.code, invalid.errors, invalid.args); }); | ||
it(invalid.code, function() { testInvalidTemplate(ruleName, invalid); }); | ||
}); | ||
@@ -119,0 +127,0 @@ } |
{ | ||
"name": "eslint", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>", | ||
@@ -34,3 +34,2 @@ "description": "An Esprima-based pattern checker for JavaScript.", | ||
"devDependencies": { | ||
"vows": "~0.7.0", | ||
"sinon": "*", | ||
@@ -42,3 +41,2 @@ "commonjs-everywhere": "~0.9.0", | ||
"grunt-contrib-jshint": "~0.6.4", | ||
"grunt-vows-runner": "~0.6.0", | ||
"grunt-istanbul-coverage": "0.0.2", | ||
@@ -45,0 +43,0 @@ "grunt-istanbul": "~0.2.3", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
173075
12
4381
0