Comparing version 0.0.6 to 0.0.7
@@ -0,1 +1,81 @@ | ||
v0.0.7 - July 22, 2013 | ||
* 0.0.7 (Nicholas C. Zakas) | ||
* Add code coverage checks to npm test and update rule tests to have better coverage (Nicholas C. Zakas) | ||
* Merge pull request #39 from jamesallardice/rule-missing-radix (Nicholas C. Zakas) | ||
* Merge pull request #88 from mduvall/optional-args-for-rule (Nicholas C. Zakas) | ||
* Merge pull request #106 from iancmyers/fix-cli-results (Nicholas C. Zakas) | ||
* Merge pull request #105 from goatslacker/rm-maxlen (Nicholas C. Zakas) | ||
* Fixed CLI output on serial programatic executions (Ian Christian Myers) | ||
* Removes line length from code style convention docs (Josh Perez) | ||
* Merge pull request #98 from goatslacker/templates (Nicholas C. Zakas) | ||
* Merge pull request #97 from goatslacker/dot-notation (Nicholas C. Zakas) | ||
* Adds escapeRegExp and fixes documentation (Josh Perez) | ||
* Add quotes rule and test coverage for configuration options (Matt DuVall) | ||
* Adds templating for lint messages and refactors rules to use it (Josh Perez) | ||
* Fixes lint rules for unchecked test file (Josh Perez) | ||
* Changes dotnotation rule to match JSHint style (Josh Perez) | ||
* Change configInfo to options and add test coverage (Matt DuVall) | ||
* Merge branch 'master' of https://github.com/nzakas/eslint into optional-args-for-rule (Matt DuVall) | ||
* Adds dot notation lint rule (Josh Perez) | ||
* Merge pull request #83 from mamacdon/new-parens-func-fix (Nicholas C. Zakas) | ||
* Merge pull request #96 from qmx/ml (Nicholas C. Zakas) | ||
* Merge pull request #95 from captainbrosset/camelcase (Nicholas C. Zakas) | ||
* Strip trailing underscores in camelcase rule - Fixes #94 (Patrick Brosset) | ||
* add mailing list link (Douglas Campos) | ||
* Strip leading underscores in camelcase rule - Fixes #94 (Patrick Brosset) | ||
* Merge pull request #87 from iancmyers/rule-no-dangle (Nicholas C. Zakas) | ||
* Merge pull request #85 from ilyavolodin/no-new-func (Nicholas C. Zakas) | ||
* Merge pull request #92 from jamesallardice/rule-no-implied-eval (Nicholas C. Zakas) | ||
* Created no-dangle rule. (Ian Christian Myers) | ||
* Merge pull request #89 from iancmyers/fix-config-option (Nicholas C. Zakas) | ||
* Merge pull request #24 from mduvall/rule-fall-through (Nicholas C. Zakas) | ||
* Merge pull request #91 from spmurrayzzz/master (Nicholas C. Zakas) | ||
* Fixed rule name (James Allardice) | ||
* Make sure the callee type is Identifier (James Allardice) | ||
* Add rule for implied eval via setTimeout/Interval (James Allardice) | ||
* Fix rule name in config (James Allardice) | ||
* Fixes #90 -- updates docstrings (Stephen Murray) | ||
* Fixes issue with fs.existsSync on NodeJS 0.6 (Ian Christian Myers) | ||
* Fixing -c config option. (Ian Christian Myers) | ||
* Allow arrays to be passed as multiple args to rule (Matt DuVall) | ||
* Test to make sure empty case with one line break is safe (Matt DuVall) | ||
* Rule: The Function constructor is eval (Ilya Volodin) | ||
* Merge pull request #80 from iancmyers/fix-require (Nicholas C. Zakas) | ||
* Enabled require("eslint") and exposed out CLI. (Ian Christian Myers) | ||
* Merge pull request #73 from iancmyers/rule-one-true-brace (Nicholas C. Zakas) | ||
* Merge pull request #71 from Constellation/estraverse-controller (Nicholas C. Zakas) | ||
* Adds test and fix for issue #82 (Mark Macdonald) | ||
* Merge branch 'master' of https://github.com/nzakas/eslint into ok (Yusuke Suzuki) | ||
* Created brace-style rule. (Ian Christian Myers) | ||
* Merge pull request #81 from xjamundx/multi-formatters (Nicholas C. Zakas) | ||
* Formatters can now process multiple files at once (Jamund Ferguson) | ||
* Merge pull request #79 from ilyavolodin/no-new (Nicholas C. Zakas) | ||
* Merge pull request #75 from goatslacker/smarter-eqeqeq-rule (Nicholas C. Zakas) | ||
* Merge pull request #67 from jedhunsaker/editorconfig (Nicholas C. Zakas) | ||
* Rule: Do not use 'new' for side effects (Ilya Volodin) | ||
* Adds smarter-eqeqeq rule (Josh Perez) | ||
* Merge pull request #72 from mamacdon/no-octal-0 (Nicholas C. Zakas) | ||
* Add EditorConfig file for consistent editor/IDE behavior (Jed Hunsaker) | ||
* Merge pull request #74 from jrfeenst/master (Nicholas C. Zakas) | ||
* Fix the positive case for no-unreachable where there is no return statement at all, or if the return is at the end. Those cases should not return any errors. The error condition was not be checked before throwing the rule error. (Joel Feenstra) | ||
* Adds test and fix for no-octal on 0 literal (Mark Macdonald) | ||
* Don't report no-empty warnings when a parent is FunctionExpression / FunctionDeclaration (Yusuke Suzuki) | ||
* Add api.getAncestors (Yusuke Suzuki) | ||
* Ensure estraverse version 1.2.0 or later (Yusuke Suzuki) | ||
* Merge pull request #62 from goatslacker/fix-no-alert (Nicholas C. Zakas) | ||
* Merge pull request #61 from goatslacker/dont-die-on-undefined (Nicholas C. Zakas) | ||
* Merge pull request #60 from goatslacker/fix-octal-check (Nicholas C. Zakas) | ||
* Fixes no-alert lint rule for non identifier calls (Josh Perez) | ||
* Fixes exception when init is null (Josh Perez) | ||
* Fixes no-octal check to only check for numbers (Josh Perez) | ||
* 0.0.7-dev (Nicholas C. Zakas) | ||
* 0.0.6 (Nicholas C. Zakas) | ||
* Follow the rule naming conventions (James Allardice) | ||
* Add rule for missing radix argument to parseInt (James Allardice) | ||
* Allow return, falls-through comment, and throw for falls-through (Matt DuVall) | ||
* Merge branch 'master' of https://github.com/nzakas/eslint into rule-fall-through (Matt DuVall) | ||
* Globals are not good, declare len (Matt DuVall) | ||
* Rule to add no-fall-through (Matt DuVall) | ||
v0.0.6 - July 16, 2013 | ||
@@ -2,0 +82,0 @@ |
@@ -8,2 +8,3 @@ { | ||
"no-console": 1, | ||
"no-dangle": 1, | ||
"no-debugger": 1, | ||
@@ -13,3 +14,5 @@ "no-empty": 1, | ||
"no-floating-decimal": 0, | ||
"no-implied-eval": 1, | ||
"no-with": 1, | ||
"no-fallthrough": 1, | ||
"no-unreachable": 1, | ||
@@ -19,14 +22,21 @@ "no-undef-init": 1, | ||
"no-new-wrappers": 1, | ||
"no-new": 1, | ||
"no-new-func": 1, | ||
"smarter-eqeqeq": 0, | ||
"brace-style": 0, | ||
"camelcase": 1, | ||
"curly": 1, | ||
"dot-notation": 1, | ||
"eqeqeq": 1, | ||
"new-parens": 1, | ||
"guard-for-in": 0, | ||
"radix": 0, | ||
"new-cap": 1, | ||
"quote-props": 0, | ||
"semi": 1, | ||
"use-isnan": 1 | ||
"use-isnan": 1, | ||
"quotes": [1, "double"] | ||
} | ||
} |
@@ -0,0 +0,0 @@ # Submitting Bugs |
@@ -14,18 +14,2 @@ # Code Conventions | ||
## Line Length | ||
Each line should be no longer than 80 characters. If a line goes longer than 80 characters, it should be wrapped after an operator (comma, plus, etc.). The following line should be indented two levels (eight characters). | ||
// Good | ||
doSomething(argument1, argument2, argument3, argument4, | ||
argument5); | ||
// Bad: Following line only indented four spaces | ||
doSomething(argument1, argument2, argument3, argument4, | ||
argument5); | ||
// Bad: Breaking before operator | ||
doSomething(argument1, argument2, argument3, argument4 | ||
, argument5); | ||
## Primitive Literals | ||
@@ -40,3 +24,3 @@ | ||
var name = 'Nicholas'; | ||
// Bad: Wrapping to second line | ||
@@ -116,3 +100,3 @@ var longString = "Here's the story, of a man \ | ||
} | ||
// Bad: Using undefined literal | ||
@@ -129,3 +113,3 @@ if (variable == undefined) { | ||
var found = (values[i] === item); | ||
// Good | ||
@@ -135,19 +119,19 @@ if (found && (count > 10)) { | ||
} | ||
// Good | ||
for (i = 0; i < count; i++) { | ||
process(i); | ||
process(i); | ||
} | ||
// Bad: Missing spaces | ||
var found = (values[i]===item); | ||
// Bad: Missing spaces | ||
if (found&&(count>10)) { | ||
doSomething(); | ||
doSomething(); | ||
} | ||
// Bad: Missing spaces | ||
for (i=0; i<count; i++) { | ||
process(i); | ||
process(i); | ||
} | ||
@@ -157,28 +141,28 @@ | ||
When parentheses are used, there should be no white space immediately after the opening paren or immediately before the closing paren. | ||
When parentheses are used, there should be no white space immediately after the opening paren or immediately before the closing paren. | ||
// Good | ||
var found = (values[i] === item); | ||
// Good | ||
if (found && (count > 10)) { | ||
doSomething(); | ||
doSomething(); | ||
} | ||
// Good | ||
for (i = 0; i < count; i++) { | ||
process(i); | ||
process(i); | ||
} | ||
// Bad: Extra space after opening paren | ||
var found = ( values[i] === item); | ||
// Bad: Extra space before closing paren | ||
if (found && (count > 10) ) { | ||
doSomething(); | ||
doSomething(); | ||
} | ||
// Bad: Extra space around argument | ||
for (i = 0; i < count; i++) { | ||
process( i ); | ||
process( i ); | ||
} | ||
@@ -201,13 +185,13 @@ | ||
var object = { | ||
key1: value1, | ||
key2: value2, | ||
func: function() { | ||
// do something | ||
}, | ||
key3: value3 | ||
}; | ||
// Bad: Improper indentation | ||
@@ -218,11 +202,11 @@ var object = { | ||
}; | ||
// Bad: Missing blank lines around function | ||
var object = { | ||
key1: value1, | ||
key2: value2, | ||
key2: value2, | ||
func: function() { | ||
// do something | ||
}, | ||
}, | ||
key3: value3 | ||
@@ -232,3 +216,3 @@ }; | ||
When an object literal is passed to a function, the opening brace should be on the same line as if the value is a variable. All other formatting rules from above still apply. | ||
// Good | ||
@@ -239,3 +223,3 @@ doSomething({ | ||
}); | ||
// Bad: All on one line | ||
@@ -252,3 +236,3 @@ doSomething({ key1: value1, key2: value2 }); | ||
* Documentation generation is necessary for an object, method, or property (use appropriate documentation comments). | ||
### Single-Line Comments | ||
@@ -283,3 +267,3 @@ | ||
} | ||
// Bad: This should be a multi-line comment | ||
@@ -310,3 +294,3 @@ // This next piece of code is quite difficult, so let me explain. | ||
// thenDoSomethingElse(); | ||
// } | ||
// } | ||
@@ -327,3 +311,3 @@ ### Multi-Line Comments | ||
/* | ||
* if you made it here, | ||
* if you made it here, | ||
* then all security checks passed | ||
@@ -337,3 +321,3 @@ */ | ||
/* | ||
* if you made it here, | ||
* if you made it here, | ||
* then all security checks passed | ||
@@ -348,3 +332,3 @@ */ | ||
/* | ||
*if you made it here, | ||
*if you made it here, | ||
*then all security checks passed | ||
@@ -359,3 +343,3 @@ */ | ||
/* | ||
* if you made it here, | ||
* if you made it here, | ||
* then all security checks passed | ||
@@ -384,3 +368,3 @@ */ | ||
doSomething(); | ||
// Good | ||
@@ -395,3 +379,3 @@ /* | ||
} | ||
// Good | ||
@@ -402,7 +386,7 @@ // REVIEW: Is there a better way to do this? | ||
} | ||
// Bad: Annotation spacing is incorrect | ||
// TODO : I'd like to find a way to make this faster | ||
doSomething(); | ||
// Bad: Comment should be at the same indentation as code | ||
@@ -412,5 +396,5 @@ // REVIEW: Is there a better way to do this? | ||
doSomething(); | ||
} | ||
} | ||
## Variable Declarations | ||
@@ -425,3 +409,3 @@ | ||
empty; | ||
// Bad: Improper initialization alignment | ||
@@ -432,3 +416,3 @@ var count = 10, | ||
empty; | ||
// Bad: Incorrect indentation | ||
@@ -439,3 +423,3 @@ var count = 10, | ||
empty; | ||
// Bad: Multiple declarations on one line | ||
@@ -450,10 +434,10 @@ var count = 10, name = "Nicholas", | ||
found = false; | ||
// Bad: Multiple var statements | ||
var count = 10, | ||
name = "Nicholas"; | ||
var found = false, | ||
empty; | ||
Always declare variables. Implied globals should not be used. | ||
@@ -474,3 +458,3 @@ | ||
} | ||
// Bad: Function expression | ||
@@ -480,3 +464,3 @@ var doSomething = function(arg1, arg2) { | ||
}; | ||
// Bad: Left brace on wrong line | ||
@@ -487,11 +471,11 @@ function doSomething(arg1, arg2) | ||
} | ||
// Bad: Using Function constructor | ||
var doSomething = new Function("arg1", "arg2", "return arg1 + arg2"); | ||
Functions declared inside of other functions should be declared immediately after the `var` statement. | ||
Functions declared inside of other functions should be declared immediately after the `var` statement. | ||
// Good | ||
function outer() { | ||
var count = 10, | ||
@@ -501,17 +485,17 @@ name = "Nicholas", | ||
empty; | ||
function inner() { | ||
// code | ||
} | ||
// code that uses inner() | ||
} | ||
// Bad: Inner function declared before variables | ||
function outer() { | ||
function inner() { | ||
// code | ||
} | ||
} | ||
var count = 10, | ||
@@ -521,3 +505,3 @@ name = "Nicholas", | ||
empty; | ||
// code that uses inner() | ||
@@ -542,5 +526,5 @@ } | ||
var value = (function() { | ||
// function body | ||
return { | ||
@@ -550,8 +534,8 @@ message: "Hi" | ||
}()); | ||
// Bad: No parentheses around function call | ||
var value = function() { | ||
// function body | ||
return { | ||
@@ -561,8 +545,8 @@ message: "Hi" | ||
}(); | ||
// Bad: Improper parentheses placement | ||
var value = (function() { | ||
// function body | ||
return { | ||
@@ -581,9 +565,9 @@ message: "Hi" | ||
var accountNumber = "8401-1"; | ||
// Bad: Begins with uppercase letter | ||
var AccountNumber = "8401-1"; | ||
// Bad: Begins with verb | ||
var getAccountNumber = "8401-1"; | ||
// Bad: Uses underscore | ||
@@ -596,5 +580,5 @@ var account_number = "8401-1"; | ||
function doSomething() { | ||
// code | ||
// code | ||
} | ||
// Bad: Begins with uppercase letter | ||
@@ -604,3 +588,3 @@ function DoSomething() { | ||
} | ||
// Bad: Begins with noun | ||
@@ -610,3 +594,3 @@ function car() { | ||
} | ||
// Bad: Uses underscores | ||
@@ -623,3 +607,3 @@ function do_something() { | ||
} | ||
// Bad: Begins with lowercase letter | ||
@@ -629,3 +613,3 @@ function myObject() { | ||
} | ||
// Bad: Uses underscores | ||
@@ -635,3 +619,3 @@ function My_Object() { | ||
} | ||
// Bad: Begins with verb | ||
@@ -646,6 +630,6 @@ function getMyObject() { | ||
var TOTAL_COUNT = 10; | ||
// Bad: Camel case | ||
var totalCount = 10; | ||
// Bad: Mixed case | ||
@@ -657,5 +641,5 @@ var total_COUNT = 10; | ||
// Good | ||
var object = { | ||
var object = { | ||
_count: 10, | ||
_getCount: function () { | ||
@@ -668,32 +652,32 @@ return this._count; | ||
Strict mode should be used only inside of functions and never globally. | ||
Strict mode should be used only inside of functions and never globally. | ||
// Bad: Global strict mode | ||
"use strict"; | ||
function doSomething() { | ||
// code | ||
} | ||
// Good | ||
function doSomething() { | ||
"use strict"; | ||
// code | ||
} | ||
If you want strict mode to apply to multiple functions without needing to write `"use strict"` multiple times, use immediate function invocation: | ||
// Good | ||
(function() { | ||
"use strict"; | ||
function doSomething() { | ||
// code | ||
} | ||
function doSomethingElse() { | ||
// code | ||
} | ||
} | ||
}()); | ||
@@ -707,3 +691,3 @@ | ||
var flag = (i < count); | ||
// Bad: Missing parentheses | ||
@@ -718,3 +702,3 @@ var flag = i < count; | ||
var same = (a === b); | ||
// Bad: Using == | ||
@@ -729,3 +713,3 @@ var same = (a == b); | ||
var value = condition ? value1 : value2; | ||
// Bad: no assignment, should be an if statement | ||
@@ -738,3 +722,3 @@ condition ? doSomething() : doSomethingElse(); | ||
Each line should contain at most one statement. All simple statements should end with a semicolon (`;`). | ||
Each line should contain at most one statement. All simple statements should end with a semicolon (`;`). | ||
@@ -744,6 +728,6 @@ // Good | ||
a = b; | ||
// Bad: Multiple statements on one line | ||
count++; a = b; | ||
count++; a = b; | ||
### return Statement | ||
@@ -758,6 +742,6 @@ | ||
return (size > 0 ? size : defaultSize); | ||
### Compound Statements | ||
Compound statements are lists of statements enclosed inside of braces. | ||
Compound statements are lists of statements enclosed inside of braces. | ||
@@ -776,3 +760,3 @@ * The enclosed statements should be indented one more level than the compound statement. | ||
} | ||
if (condition) { | ||
@@ -783,3 +767,3 @@ statements | ||
} | ||
if (condition) { | ||
@@ -799,3 +783,3 @@ statements | ||
} | ||
// Bad: Improper spacing | ||
@@ -805,10 +789,10 @@ if(condition){ | ||
} | ||
// Bad: Missing braces | ||
if (condition) | ||
doSomething(); | ||
// Bad: All on one line | ||
if (condition) { doSomething(); } | ||
// Bad: All on one line without braces | ||
@@ -834,7 +818,7 @@ if (condition) doSomething(); | ||
len; | ||
for (i=0, len=10; i < len; i++) { | ||
// code | ||
} | ||
// Bad: Variables declared during initialization | ||
@@ -844,3 +828,3 @@ for (var i=0, len=10; i < len; i++) { | ||
} | ||
// Bad: Variables declared during initialization | ||
@@ -878,3 +862,3 @@ for (var prop in object) { | ||
statements | ||
default: | ||
@@ -886,3 +870,3 @@ statements | ||
Each group of statements (except the default) should end with `break`, `return`, `throw`, or a comment indicating fall through. | ||
Each group of statements (except the default) should end with `break`, `return`, `throw`, or a comment indicating fall through. | ||
@@ -893,12 +877,12 @@ // Good | ||
/* falls through */ | ||
case 2: | ||
doSomething(); | ||
break; | ||
case 3: | ||
return true; | ||
default: | ||
throw new Error("This shouldn't happen.); | ||
throw new Error("This shouldn't happen.); | ||
} | ||
@@ -912,11 +896,11 @@ | ||
/*falls through*/ | ||
case 2: | ||
doSomething(); | ||
break; | ||
case 3: | ||
return true; | ||
// no default | ||
// no default | ||
} | ||
@@ -962,4 +946,4 @@ | ||
* A blank space should appear after commas in argument lists. | ||
* All binary operators except dot (`.`) should be separated from their operands by spaces. Blank spaces should never separate unary operators such as unary minus, increment (`++`), and decrement (`--`) from their operands. | ||
* The expressions in a `for` statement should be separated by blank spaces. | ||
* All binary operators except dot (`.`) should be separated from their operands by spaces. Blank spaces should never separate unary operators such as unary minus, increment (`++`), and decrement (`--`) from their operands. | ||
* The expressions in a `for` statement should be separated by blank spaces. | ||
@@ -966,0 +950,0 @@ ## Things to Avoid |
@@ -8,11 +8,11 @@ # Command line Interface | ||
npm install -g eslint | ||
This installs the ESLint CLI from the npm repository. To run ESLint, use the following format: | ||
eslint [options] [file|dir]* | ||
Such as: | ||
eslint file1.js file2.js | ||
## Options | ||
@@ -43,3 +43,3 @@ | ||
eslint -c ~/my-eslint.json file.js | ||
This example uses the configuration file at `~/my-eslint.json` instead of the default. | ||
@@ -54,7 +54,7 @@ | ||
eslint -f compact file.js | ||
When specified, the given format is output to the console. If you'd like to save that output into a file, you can do so on the command line like so: | ||
eslint -f compact file.js > results.txt | ||
This saves the output into the `results.txt` file. | ||
@@ -61,0 +61,0 @@ |
@@ -14,4 +14,4 @@ # Contributing | ||
* Make sure there is an issue for any pull request you send. | ||
* If an issue doesn't exist, create one *before* you submit the pull request. | ||
* Issues should have full descriptions explaining the bug, enhancement, or request. | ||
* If an issue doesn't exist, create one *before* you submit the pull request. | ||
* Issues should have full descriptions explaining the bug, enhancement, or request. | ||
* The commit message should say "(fixes #1234)" at the of the description if it closes out an existing issue (replace 1234 with the issue number). | ||
@@ -22,8 +22,8 @@ * The change should introduce no functional regression. Be sure to run `npm test` to verify your changes before submitting a pull request. | ||
* All changes must work on the following Node.JS versions: | ||
* 0.6.x | ||
* 0.8.x | ||
* 0.10.x | ||
* 0.6.x | ||
* 0.8.x | ||
* 0.10.x | ||
* Follow the [Code Conventions](Code-Conventions.md). | ||
## New Rules | ||
## New Rules | ||
@@ -34,11 +34,11 @@ Once you've written a rule, you can decide whether the rule is generic enough to be included in ESLint or if it's specific to your own use case. If you decide to submit your rule via a pull request, there are some things to keep in mind: | ||
1. In your pull request include: | ||
1. The use case for the rule - what is it trying to prevent or flag? | ||
1. Why you believe this rule is generic enough to be included in the main distribution | ||
1. Whether the rule should be on or off by default. | ||
1. Documentation for the rule (see [no-console](no-console.md) as an example). Put this documentation directly into the pull request. | ||
Keep in mind that not all rules will be accepted for the main distribution. You may also request that your rule by on by default but we may accept it as off by default. | ||
1. The use case for the rule - what is it trying to prevent or flag? | ||
1. Why you believe this rule is generic enough to be included in the main distribution | ||
1. Whether the rule should be on or off by default. | ||
1. Documentation for the rule (see [no-console](no-console.md) as an example). Put this documentation directly into the pull request. | ||
Keep in mind that not all rules will be accepted for the main distribution. You may also request that your rule by on by default but we may accept it as off by default. | ||
## Following Up | ||
All pull requests are sent through Travis CI to verify that no tests are broken. If the Travis build fails, it will show up on the pull request. We cannot accept any code that fails in Travis, so if this happens, make fixes and update the pull request to trigger another build. |
@@ -7,3 +7,3 @@ # Development Environment | ||
Go to http://nodejs.org to download and install the latest stable version for your operating system. | ||
Go to http://nodejs.org to download and install the latest stable version for your operating system. | ||
@@ -10,0 +10,0 @@ Most of the installers come with [npm](http://npmjs.org) already installed, but if for some reason it doesn't work on your system, you can install it manually using the instructions on the website. |
# No empty | ||
Empty statements usually occur due to refactoring that wasn't completed. You may end up with empty statements inside of blocks or `switch`, or by having too many semicolons in a row. | ||
Empty statements usually occur due to refactoring that wasn't completed. You may end up with empty statements inside of blocks or `switch`, or by having too many semicolons in a row. | ||
## Rule Details | ||
This rule is aimed at eliminating empty statements. While not technically an error, empty statements can be a source of confusion when reading code. | ||
This rule is aimed at eliminating empty statements. While not technically an error, empty statements can be a source of confusion when reading code. | ||
@@ -9,0 +9,0 @@ The following patterns are considered warnings: |
@@ -10,2 +10,3 @@ # Rules | ||
* [no-console](no-console.md) - disallow use of `console` | ||
* [no-dangle](no-dangle.md) - disallow trailing commas in object literals | ||
* [no-debugger](No-debugger.md) - disallow use of `debugger` | ||
@@ -23,2 +24,3 @@ * [no-empty](No-empty.md) - disallow empty statements | ||
* [eqeqeq] - require the use of `===` and `!==` | ||
* [dot-notation] - encourages use of dot notation whenever possible | ||
* [no-eval] - disallow use of `eval()` | ||
@@ -29,6 +31,8 @@ * [no-with] - disallow use of the `with` statement | ||
* [no-octal] - disallow use of octal literals | ||
* [no-new] - disallow use of new operator when not part of the assignment or comparison | ||
* [no-new-func] - disallow use of new operator for `Function` object | ||
## Stylistic Issues | ||
These rules are purely matters of style and are quite subjective. | ||
These rules are purely matters of style and are quite subjective. | ||
@@ -40,2 +44,6 @@ * [camelcase] - require camel case names | ||
## Alternate Rules | ||
* [smarter-eqeqeq](smarter-eqeqeq.md) - require the use of `===` and `!==` when it makes sense to use them | ||
## Legacy | ||
@@ -42,0 +50,0 @@ |
@@ -8,3 +8,3 @@ # Source Code | ||
git clone git://github.com/nzakas/eslint.git | ||
If you're planning on contributing to ESLint, then it's a good idea to fork the repository. You can find instructions for forking a repository at http://help.github.com/fork-a-repo/. After forking the ESLintrepository, you'll want to create a local copy of your fork. | ||
@@ -35,7 +35,7 @@ | ||
* `lib` - contains the source code | ||
* `formatters` - all source files defining formatters | ||
* `rules` - all source files defining rules | ||
* `formatters` - all source files defining formatters | ||
* `rules` - all source files defining rules | ||
* `tests` - the main unit test folder | ||
* `lib` - tests for the source code | ||
* `reporters` - tests for the reporters | ||
* `rules` - tests for the rules | ||
* `lib` - tests for the source code | ||
* `reporters` - tests for the reporters | ||
* `rules` - tests for the rules |
@@ -32,3 +32,3 @@ # Working with Rules | ||
return { | ||
"Identifier": function(node) { | ||
@@ -42,8 +42,12 @@ // do something with node | ||
Each method that matches a node in the AST will be passed the corresponding node. You can then evaluate the node and it's surrounding tree to determine whether or not an issue needs reporting. | ||
Each method that matches a node in the AST will be passed the corresponding node. You can then evaluate the node and it's surrounding tree to determine whether or not an issue needs reporting. | ||
The main method you'll use is `context.report()`, which publishes a warning or error (depending on the configuration being used). This method accepts two arguments: the AST node that caused the report and a message to display. For example: | ||
The main method you'll use is `context.report()`, which publishes a warning or error (depending on the configuration being used). This method accepts three arguments: the AST node that caused the report, a message to display, and an optional object literal which is used to interpolate. For example: | ||
context.report(node, "This is unexpected!"); | ||
or | ||
context.report(node, "`{{identifier}}` is unexpected!", { identifier: node.name }); | ||
The node contains all of the information necessary to figure out the line and column number of the offending text as well the source text representing the node. | ||
@@ -74,3 +78,3 @@ | ||
Each rule must have a set of unit tests submitted with it to be accepted. The test file is named the same as the source file but lives in `tests/lib/`. For example, if your rule source file is `lib/rules/foo.js` then your test file should be `tests/lib/rules/foo.js`. | ||
Each rule must have a set of unit tests submitted with it to be accepted. The test file is named the same as the source file but lives in `tests/lib/`. For example, if your rule source file is `lib/rules/foo.js` then your test file should be `tests/lib/rules/foo.js`. | ||
@@ -77,0 +81,0 @@ For your rule, be sure to test: |
@@ -26,6 +26,13 @@ /** | ||
var results = []; | ||
function readConfig(options) { | ||
var configLocation = path.resolve(__dirname, options.c || options.config || | ||
DEFAULT_CONFIG); | ||
return require(configLocation); | ||
var configLocation = null; | ||
if (options.c || options.config) { | ||
configLocation = path.resolve(process.cwd(), options.c || | ||
options.config); | ||
} | ||
return require(configLocation || DEFAULT_CONFIG); | ||
} | ||
@@ -72,2 +79,17 @@ | ||
function storeResults(filename, messages) { | ||
results.push({filePath: filename, messages: messages}); | ||
} | ||
function printResults(config) { | ||
var formatter; | ||
try { | ||
formatter = require("./formatters/" + config.format); | ||
} catch (ex) { | ||
console.log("Could not find formatter '%s'.", config.format); | ||
process.exit(1); | ||
} | ||
console.log(formatter(results, config)); | ||
} | ||
/** | ||
@@ -77,6 +99,5 @@ * Processes an individual file using ESLint. | ||
* @param {Object} config The configuration object for ESLint. | ||
* @param {Function} formatter The formatter to use to output results. | ||
* @returns {int} The total number of errors. | ||
*/ | ||
function processFile(filename, config, formatter) { | ||
function processFile(filename, config) { | ||
@@ -87,6 +108,7 @@ // clear all existing settings for a new file | ||
var filePath = path.resolve(filename), | ||
existsSync = fs.existsSync || path.existsSync, | ||
text, | ||
messages; | ||
if (fs.existsSync(filePath)) { | ||
if (existsSync(filePath)) { | ||
text = fs.readFileSync(path.resolve(filename), "utf8"); | ||
@@ -99,3 +121,4 @@ messages = eslint.verify(text, config); | ||
console.log(formatter(messages, filename, config)); | ||
// save the results for printing later | ||
storeResults(filename, messages); | ||
@@ -121,12 +144,4 @@ // count all errors and return the total | ||
var fullFileList = [], | ||
formatter; | ||
errors = 0; | ||
// just in case an incorrect formatter was passed in | ||
try { | ||
formatter = require("./formatters/" + config.format); | ||
} catch (ex) { | ||
console.log("Could not find formatter '%s'.", config.format); | ||
process.exit(1); | ||
} | ||
files.forEach(function(file) { | ||
@@ -141,5 +156,10 @@ | ||
return fullFileList.reduce(function(previous, file) { | ||
return previous + processFile(file, config, formatter); | ||
errors = fullFileList.reduce(function(previous, file) { | ||
return previous + processFile(file, config); | ||
}, 0); | ||
printResults(config); | ||
return errors; | ||
} | ||
@@ -169,2 +189,5 @@ | ||
// Ensure results from previous execution are not printed. | ||
results = []; | ||
if (currentOptions.v) { // version from package.json | ||
@@ -171,0 +194,0 @@ |
@@ -17,2 +17,10 @@ /** | ||
//------------------------------------------------------------------------------ | ||
// Helpers | ||
//------------------------------------------------------------------------------ | ||
function escapeRegExp(rx) { | ||
return rx.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); | ||
} | ||
//------------------------------------------------------------------------------ | ||
// Public Interface | ||
@@ -27,3 +35,4 @@ //------------------------------------------------------------------------------ | ||
currentConfig = null, | ||
currentTokens = null; | ||
currentTokens = null, | ||
controller = null; | ||
@@ -40,2 +49,3 @@ /** | ||
currentTokens = null; | ||
controller = null; | ||
}; | ||
@@ -57,10 +67,20 @@ | ||
Object.keys(config.rules).filter(function(key) { | ||
return config.rules[key] > 0; // ignore rules that are turned off | ||
if (typeof config.rules[key] === "number") { | ||
return config.rules[key] > 0; | ||
} else if (Array.isArray(config.rules[key])) { | ||
// Here the rule looks like [1, ...] - the first value is the key we want | ||
return config.rules[key][0] > 0; | ||
} | ||
}).forEach(function(key) { | ||
var ruleCreator = rules.get(key), | ||
options = [], | ||
rule; | ||
if (Array.isArray(config.rules[key])) { | ||
// The additional config data is after the bool value | ||
options = config.rules[key].slice(1); | ||
} | ||
if (ruleCreator) { | ||
rule = ruleCreator(new RuleContext(key, api)); | ||
rule = ruleCreator(new RuleContext(key, api, options)); | ||
@@ -79,2 +99,3 @@ // add all the node types as listeners | ||
currentText = text; | ||
controller = new estraverse.Controller(); | ||
@@ -89,3 +110,3 @@ /* | ||
currentTokens = ast.tokens; | ||
estraverse.traverse(ast, { | ||
controller.traverse(ast, { | ||
enter: function(node) { | ||
@@ -119,6 +140,13 @@ api.emit(node.type, node); | ||
* @param {string} message The actual message. | ||
* @param {Object} opts Optional template data which produces a formatted message | ||
* with symbols being replaced by this object's values. | ||
* @returns {void} | ||
*/ | ||
api.report = function(ruleId, node, message) { | ||
api.report = function(ruleId, node, message, opts) { | ||
Object.keys(opts || {}).forEach(function (key) { | ||
var rx = new RegExp("{{" + escapeRegExp(key) + "}}", "g"); | ||
message = message.replace(rx, opts[key]); | ||
}); | ||
messages.push({ | ||
@@ -182,4 +210,12 @@ ruleId: ruleId, | ||
/** | ||
* Gets nodes that are ancestors of current node. | ||
* @returns {ASTNode[]} Array of objects representing ancestors. | ||
*/ | ||
api.getAncestors = function() { | ||
return controller.parents(); | ||
}; | ||
return api; | ||
}()); |
@@ -25,18 +25,26 @@ /** | ||
module.exports = function(messages, filename, config) { | ||
module.exports = function(results, config) { | ||
var output = "", | ||
total = 0, | ||
rules = config.rules || {}; | ||
messages.forEach(function(message) { | ||
results.forEach(function(result) { | ||
output += filename + ": "; | ||
output += "line " + message.line + ", col " + | ||
message.column + ", " + getMessageType(message, rules); | ||
output += " - " + message.message + "\n"; | ||
var messages = result.messages; | ||
total += messages.length; | ||
messages.forEach(function(message) { | ||
output += result.filePath + ": "; | ||
output += "line " + message.line + ", col " + | ||
message.column + ", " + getMessageType(message, rules); | ||
output += " - " + message.message + "\n"; | ||
}); | ||
}); | ||
output += "\n" + messages.length + " problems"; | ||
output += "\n" + total + " problems"; | ||
return output; | ||
}; |
@@ -13,3 +13,4 @@ /** | ||
"getTokens", | ||
"isNodeJS" | ||
"isNodeJS", | ||
"getAncestors" | ||
]; | ||
@@ -26,4 +27,5 @@ | ||
* @param {eslint} eslint The eslint object. | ||
* @param {array} options the configuration information to be added to the rule | ||
*/ | ||
function RuleContext(ruleId, eslint) { | ||
function RuleContext(ruleId, eslint, options) { | ||
@@ -37,2 +39,9 @@ /** | ||
/** | ||
* The read-only options of the rule | ||
*/ | ||
Object.defineProperty(this, "options", { | ||
value: options | ||
}); | ||
// copy over passthrough methods | ||
@@ -49,6 +58,8 @@ PASSTHROUGHS.forEach(function(name) { | ||
* @param {string} message The message to display to the user. | ||
* @param {Object} opts Optional template data which produces a formatted message | ||
* with symbols being replaced by this object's values. | ||
* @returns {void} | ||
*/ | ||
this.report = function(node, message) { | ||
eslint.report(ruleId, node, message); | ||
this.report = function(node, message, opts) { | ||
eslint.report(ruleId, node, message, opts); | ||
}; | ||
@@ -55,0 +66,0 @@ |
@@ -15,12 +15,8 @@ /** | ||
"Identifier": function(node) { | ||
var name = node.name; | ||
// Leading and trailing underscores are commonly used to flag private/protected identifiers, strip them | ||
var name = node.name.replace(/^_+|_+$/g, ""); | ||
// if there's an underscore, it might be A_CONSTANT, which is okay | ||
if (name.indexOf("_") > -1 && name !== name.toUpperCase()) { | ||
// Node.js exception: __dirname and __filename | ||
if (!(context.isNodeJS() && name.match(/^__(dirname|filename)$/))) { | ||
context.report(node, "Non-camelcased identifier '" + name + "' found."); | ||
} | ||
context.report(node, "Non-camelcased identifier '{{name}}' found.", { name: node.name }); | ||
} | ||
@@ -27,0 +23,0 @@ } |
@@ -19,3 +19,3 @@ /** | ||
}); | ||
if (prenticesTokens.length !== 2) { | ||
if (prenticesTokens.length < 2) { | ||
context.report(node, "Missing '()' invoking a constructor"); | ||
@@ -22,0 +22,0 @@ } |
@@ -14,3 +14,7 @@ /** | ||
function report(context, node, result) { | ||
context.report(node, "Unexpected {{name}}.", { name: result[1] }); | ||
} | ||
//------------------------------------------------------------------------------ | ||
@@ -34,6 +38,6 @@ // Rule Definition | ||
if (result) { | ||
context.report(node, "Unexpected " + result[1] + "."); | ||
report(context, node, result); | ||
} | ||
} else if (node.callee.type === "MemberExpression") { | ||
} else if (node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier") { | ||
@@ -43,3 +47,3 @@ result = matchProhibited(node.callee.property.name); | ||
if (result && node.callee.object.name === "window") { | ||
context.report(node, "Unexpected " + result[1] + "."); | ||
report(context, node, result); | ||
} | ||
@@ -46,0 +50,0 @@ |
@@ -17,3 +17,3 @@ /** | ||
if (node.operator.match(/^[\^&\|]$/)) { | ||
context.report(node, "Unexpected use of " + node.operator + " found."); | ||
context.report(node, "Unexpected use of {{operator}} found.", { operator: node.operator }); | ||
} | ||
@@ -20,0 +20,0 @@ |
@@ -19,3 +19,3 @@ /** | ||
if (objectName === "arguments" && propertyName.match(/^calle[er]$/)) { | ||
context.report(node, "Avoid arguments." + propertyName + "."); | ||
context.report(node, "Avoid arguments.{{property}}.", { property: propertyName }); | ||
} | ||
@@ -22,0 +22,0 @@ |
/** | ||
* @fileoverview Rule to flag use of an empty block statement | ||
* @fileoverview Rule to flag use of console object | ||
* @author Nicholas C. Zakas | ||
@@ -4,0 +4,0 @@ */ |
/** | ||
* @fileoverview Rule to flag use of an empty block statement | ||
* @fileoverview Rule to flag use of a debugger statement | ||
* @author Nicholas C. Zakas | ||
@@ -4,0 +4,0 @@ */ |
@@ -14,3 +14,9 @@ /** | ||
"BlockStatement": function(node) { | ||
var ancestors = context.getAncestors(), | ||
parentType = ancestors[ancestors.length - 1].type; | ||
if (parentType === "FunctionExpression" || parentType === "FunctionDeclaration") { | ||
return; | ||
} | ||
if (node.body.length === 0) { | ||
@@ -17,0 +23,0 @@ context.report(node, "Empty block statement."); |
@@ -17,3 +17,3 @@ /** | ||
if (wrapperObjects.indexOf(node.callee.name) > -1) { | ||
context.report(node, "Do not use " + node.callee.name + " as a constructor"); | ||
context.report(node, "Do not use {{fn}} as a constructor", { fn: node.callee.name }); | ||
} | ||
@@ -20,0 +20,0 @@ } |
@@ -15,3 +15,3 @@ /** | ||
"Literal": function(node) { | ||
if (node.raw !== node.value.toString() && node.raw.indexOf("x") < 0) { | ||
if (typeof node.value === "number" && node.raw[0] === "0" && node.raw.length > 1 && node.raw.indexOf("x") < 0) { | ||
context.report(node, "Octal literals should not be used."); | ||
@@ -18,0 +18,0 @@ } |
@@ -16,6 +16,6 @@ /** | ||
var name = node.id.name; | ||
var init = node.init.name; | ||
var init = node.init && node.init.name; | ||
if (init === "undefined") { | ||
context.report(node, "Variable '" + name + "' initialized to undefined."); | ||
context.report(node, "Variable '{{name}}' initialized to undefined.", { name: name }); | ||
} | ||
@@ -22,0 +22,0 @@ } |
@@ -11,3 +11,7 @@ /** | ||
function report(context, node, unreachableType) { | ||
context.report(node, "Found unexpected statement after a {{type}}.", { type: unreachableType }); | ||
} | ||
//------------------------------------------------------------------------------ | ||
@@ -18,2 +22,3 @@ // Rule Definition | ||
module.exports = function(context) { | ||
function checkForUnreachable(node) { | ||
@@ -39,3 +44,5 @@ switch (node.type) { | ||
unreachableType = unreachableType || checkForUnreachable(node.body[i - 1]); | ||
context.report(node.body[i], "Found unexpected statement after a " + unreachableType + "."); | ||
if (unreachableType) { | ||
report(context, node.body[i], unreachableType); | ||
} | ||
} | ||
@@ -48,3 +55,5 @@ }, | ||
unreachableType = unreachableType || checkForUnreachable(node.consequent[i - 1]); | ||
context.report(node.consequent[i], "Found unexpected statement after a " + unreachableType + "."); | ||
if (unreachableType) { | ||
report(context, node.consequent[i], unreachableType); | ||
} | ||
} | ||
@@ -51,0 +60,0 @@ } |
@@ -19,3 +19,3 @@ /** | ||
if (key.type !== "Literal") { | ||
context.report(node, "Non-quoted property `" + key.name + "` found."); | ||
context.report(node, "Non-quoted property `{{key}}` found.", { key: key.name }); | ||
} | ||
@@ -22,0 +22,0 @@ |
{ | ||
"name": "eslint", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>", | ||
@@ -9,5 +9,6 @@ "description": "An Esprima-based pattern checker for JavaScript.", | ||
}, | ||
"main": "./lib/api.js", | ||
"scripts": { | ||
"changelog": "bash ./scripts/changelog-update.sh", | ||
"test": "npm run-script lint && node ./node_modules/istanbul/lib/cli.js cover --print both ./node_modules/vows/bin/vows -- --spec ./tests/*/*.js ./tests/*/*/*.js", | ||
"test": "bash ./scripts/test.sh", | ||
"lint": "node node_modules/jshint/bin/jshint ./conf/eslint.json ./lib" | ||
@@ -21,3 +22,3 @@ }, | ||
"optimist": "*", | ||
"estraverse": "*", | ||
"estraverse": "~1.2.0", | ||
"esprima": "*", | ||
@@ -24,0 +25,0 @@ "jshint": "*" |
@@ -35,1 +35,5 @@ [![Build Status](https://secure.travis-ci.org/nzakas/eslint.png?branch=master)](http://travis-ci.org/nzakas/eslint) | ||
That's not really a question, but I got it. I'm not trying to convince you that ESLint is better than JSHint. The only thing I know is that ESLint is better than JSHint for what I'm doing. In the off chance you're doing something similar, it might be better for you. Otherwise, keep using JSHint, I'm certainly not going to tell you to stop using it. | ||
### Where to ask for help? | ||
Join our [Mailing List](https://groups.google.com/group/eslint) |
@@ -193,2 +193,35 @@ /** | ||
"when calling getAncestors": { | ||
topic: TEST_CODE, | ||
"should retrieve all ancestors when used": function(topic) { | ||
var config = { rules: {} }; | ||
eslint.reset(); | ||
eslint.on("BinaryExpression", function(node) { | ||
var ancestors = eslint.getAncestors(); | ||
assert.equal(ancestors.length, 3); | ||
}); | ||
eslint.verify(topic, config, true); | ||
}, | ||
"should retrieve empty ancestors for root node": function(topic) { | ||
var config = { rules: {} }; | ||
eslint.reset(); | ||
eslint.on("Program", function(node) { | ||
var ancestors = eslint.getAncestors(); | ||
assert.equal(ancestors.length, 0); | ||
}); | ||
eslint.verify(topic, config, true); | ||
} | ||
}, | ||
"when evaluating code": { | ||
@@ -227,2 +260,33 @@ | ||
"when passing in configuration values for rules": { | ||
topic: "var answer = 6 * 7", | ||
"should be configurable by only setting the boolean value": function(topic) { | ||
var rule = "semi", | ||
config = { rules: {} }; | ||
config.rules[rule] = 1; | ||
eslint.reset(); | ||
var messages = eslint.verify(topic, config, true); | ||
assert.equal(messages.length, 1); | ||
assert.equal(messages[0].ruleId, rule); | ||
}, | ||
"should be configurable by passing in values as an array": function(topic) { | ||
var rule = "semi", | ||
config = { rules: {} }; | ||
config.rules[rule] = [1]; | ||
eslint.reset(); | ||
var messages = eslint.verify(topic, config, true); | ||
assert.equal(messages.length, 1); | ||
assert.equal(messages[0].ruleId, rule); | ||
} | ||
}, | ||
"after calling reset()": { | ||
@@ -229,0 +293,0 @@ |
@@ -20,9 +20,12 @@ /** | ||
"when passed a message": { | ||
"when passed a single message": { | ||
topic: [{ | ||
message: "Unexpected foo.", | ||
line: 5, | ||
column: 10, | ||
ruleId: "foo" | ||
filePath: "foo.js", | ||
messages: [{ | ||
message: "Unexpected foo.", | ||
line: 5, | ||
column: 10, | ||
ruleId: "foo" | ||
}] | ||
}], | ||
@@ -35,3 +38,3 @@ | ||
var result = formatter(topic, "foo.js", config); | ||
var result = formatter(topic, config); | ||
assert.equal("foo.js: line 5, col 10, Error - Unexpected foo.\n\n1 problems", result); | ||
@@ -45,3 +48,3 @@ }, | ||
var result = formatter(topic, "foo.js", config); | ||
var result = formatter(topic, config); | ||
assert.equal("foo.js: line 5, col 10, Warning - Unexpected foo.\n\n1 problems", result); | ||
@@ -55,7 +58,10 @@ } | ||
topic: [{ | ||
fatal: true, | ||
message: "Unexpected foo.", | ||
line: 5, | ||
column: 10, | ||
ruleId: "foo" | ||
filePath: "foo.js", | ||
messages: [{ | ||
fatal: true, | ||
message: "Unexpected foo.", | ||
line: 5, | ||
column: 10, | ||
ruleId: "foo" | ||
}] | ||
}], | ||
@@ -66,3 +72,3 @@ | ||
var result = formatter(topic, "foo.js", config); | ||
var result = formatter(topic, config); | ||
assert.equal("foo.js: line 5, col 10, Error - Unexpected foo.\n\n1 problems", result); | ||
@@ -74,12 +80,14 @@ } | ||
topic: [{ | ||
message: "Unexpected foo.", | ||
line: 5, | ||
column: 10, | ||
ruleId: "foo" | ||
}, { | ||
message: "Unexpected bar.", | ||
line: 6, | ||
column: 11, | ||
ruleId: "bar" | ||
filePath: "foo.js", | ||
messages: [{ | ||
message: "Unexpected foo.", | ||
line: 5, | ||
column: 10, | ||
ruleId: "foo" | ||
}, { | ||
message: "Unexpected bar.", | ||
line: 6, | ||
column: 11, | ||
ruleId: "bar" | ||
}] | ||
}], | ||
@@ -92,8 +100,37 @@ | ||
var result = formatter(topic, "foo.js", config); | ||
var result = formatter(topic, config); | ||
assert.equal("foo.js: line 5, col 10, Error - Unexpected foo.\nfoo.js: line 6, col 11, Warning - Unexpected bar.\n\n2 problems", result); | ||
} | ||
}, | ||
"when passed multiple files with 1 message each": { | ||
topic: [{ | ||
filePath: "foo.js", | ||
messages: [{ | ||
message: "Unexpected foo.", | ||
line: 5, | ||
column: 10, | ||
ruleId: "foo" | ||
}] | ||
}, { | ||
filePath: "bar.js", | ||
messages: [{ | ||
message: "Unexpected bar.", | ||
line: 6, | ||
column: 11, | ||
ruleId: "bar" | ||
}] | ||
}], | ||
"should return a string with multiple entries": function(topic) { | ||
var config = { | ||
rules: { foo: 2, bar: 1 } | ||
}; | ||
var result = formatter(topic, config); | ||
assert.equal("foo.js: line 5, col 10, Error - Unexpected foo.\nbar.js: line 6, col 11, Warning - Unexpected bar.\n\n2 problems", result); | ||
} | ||
} | ||
}).export(module); | ||
}).export(module); |
@@ -75,8 +75,8 @@ /** | ||
"when evaluating '__myPrivateVariable = \"Patrick\"'": { | ||
"when evaluating 'dir = __dirname'": { | ||
topic: "__myPrivateVariable = \"Patrick\"", | ||
topic: "dir = __dirname", | ||
"should not report a violation": function(topic) { | ||
"should report a violation when not in Node.JS mode": function(topic) { | ||
var config = { rules: {} }; | ||
@@ -87,13 +87,14 @@ config.rules[RULE_ID] = 1; | ||
assert.equal(messages.length, 1); | ||
assert.equal(messages[0].ruleId, RULE_ID); | ||
assert.equal(messages[0].message, "Non-camelcased identifier '__dirname' found."); | ||
assert.include(messages[0].node.type, "Identifier"); | ||
assert.include(messages[0].node.name, "__dirname"); | ||
}, | ||
assert.equal(messages.length, 0); | ||
} | ||
}, | ||
"should not report a violation when in Node.JS mode": function(topic) { | ||
var config = { rules: {}, env: {} }; | ||
"when evaluating 'myPrivateVariable_ = \"Patrick\"'": { | ||
topic: "myPrivateVariable_ = \"Patrick\"", | ||
"should not report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
config.rules[RULE_ID] = 1; | ||
config.env.nodejs = true; | ||
@@ -106,7 +107,8 @@ var messages = eslint.verify(topic, config); | ||
"when evaluating 'dir = __filename'": { | ||
"when evaluating '__private_first_name = \"Patrick\"'": { | ||
topic: "dir = __filename", | ||
topic: "__private_first_name = \"Patrick\"", | ||
"should report a violation when not in Node.JS mode": function(topic) { | ||
"should report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
@@ -119,15 +121,5 @@ config.rules[RULE_ID] = 1; | ||
assert.equal(messages[0].ruleId, RULE_ID); | ||
assert.equal(messages[0].message, "Non-camelcased identifier '__filename' found."); | ||
assert.equal(messages[0].message, "Non-camelcased identifier '__private_first_name' found."); | ||
assert.include(messages[0].node.type, "Identifier"); | ||
assert.include(messages[0].node.name, "__filename"); | ||
}, | ||
"should not report a violation when in Node.JS mode": function(topic) { | ||
var config = { rules: {}, env: {} }; | ||
config.rules[RULE_ID] = 1; | ||
config.env.nodejs = true; | ||
var messages = eslint.verify(topic, config); | ||
assert.equal(messages.length, 0); | ||
assert.include(messages[0].node.name, "__private_first_name"); | ||
} | ||
@@ -134,0 +126,0 @@ } |
@@ -58,3 +58,18 @@ /** | ||
} | ||
}, | ||
"when evaluating 'var a = new Date(function() {})'": { | ||
topic: "var a = new Date(function() {});", | ||
"should not report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
config.rules[RULE_ID] = 1; | ||
var messages = eslint.verify(topic, config); | ||
assert.equal(messages.length, 0); | ||
} | ||
} | ||
}).export(module); |
@@ -26,2 +26,14 @@ /** | ||
"when attempting to lint a bracket notation MemberExpression": { | ||
topic: "a[o.k](1)", | ||
"should not report violation or crash": function(topic) { | ||
var config = { rules: {} }; | ||
config.rules[RULE_ID] = 1; | ||
var messages = eslint.verify(topic, config); | ||
assert.equal(messages.length, 0); | ||
} | ||
}, | ||
"when evaluating 'alert(foo)'": { | ||
@@ -28,0 +40,0 @@ |
@@ -216,10 +216,32 @@ /** | ||
} | ||
} | ||
}, | ||
"when evaluating '(function() { }())'": { | ||
topic: "(function() { }())", | ||
"should not report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
config.rules[RULE_ID] = 1; | ||
var messages = eslint.verify(topic, config); | ||
assert.equal(messages.length, 0); | ||
} | ||
}, | ||
"when evaluating 'function foo() { }'": { | ||
topic: "function foo() { }", | ||
"should not report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
config.rules[RULE_ID] = 1; | ||
var messages = eslint.verify(topic, config); | ||
assert.equal(messages.length, 0); | ||
} | ||
} | ||
}).export(module); |
@@ -89,4 +89,19 @@ /** | ||
} | ||
}, | ||
"when evaluating 'var x = \"2.5\";'": { | ||
topic: "var x = \"2.5\";", | ||
"should not report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
config.rules[RULE_ID] = 1; | ||
var messages = eslint.verify(topic, config); | ||
assert.equal(messages.length, 0); | ||
} | ||
} | ||
}).export(module); |
@@ -133,3 +133,3 @@ /** | ||
"when evaluating 'var a = String(\"test\"), b = String.fromCharCode(32);": { | ||
topic: "var a = String('test'), b = String.fromCharCode(32);", | ||
@@ -136,0 +136,0 @@ |
@@ -25,3 +25,13 @@ /** | ||
vows.describe(RULE_ID).addBatch({ | ||
"when evaluating a string": { | ||
topic: "var a = 'hello world';", | ||
"should not report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
config.rules[RULE_ID] = 1; | ||
var messages = eslint.verify(topic, config); | ||
assert.equal(messages.length, 0); | ||
} | ||
}, | ||
"when evaluating 'var a = 01234'": { | ||
@@ -77,2 +87,17 @@ | ||
}, | ||
"when evaluating the literal 0": { | ||
topic: "a = 0;", | ||
"should not report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
config.rules[RULE_ID] = 1; | ||
var messages = eslint.verify(topic, config); | ||
assert.equal(messages.length, 0); | ||
} | ||
}, | ||
}).export(module); |
@@ -26,2 +26,14 @@ /** | ||
"when evaluating an empty var": { | ||
topic: "var a;", | ||
"should not die": function(topic) { | ||
var config = { rules: {} }; | ||
config.rules[RULE_ID] = 1; | ||
var messages = eslint.verify(topic, config); | ||
assert.equal(messages.length, 0); | ||
} | ||
}, | ||
"when evaluating 'var a = undefined'": { | ||
@@ -28,0 +40,0 @@ |
@@ -26,6 +26,45 @@ /** | ||
"when evaluation 'function foo() { return; x = 1; }'": { | ||
"when evaluating a function which contains a function": { | ||
topic: "function foo() { function bar() { return 1; } return bar(); }", | ||
"should not report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
config.rules[RULE_ID] = 1; | ||
var messages = eslint.verify(topic, config); | ||
assert.equal(messages.length, 0); | ||
} | ||
}, | ||
"when evaluating a function with no return": { | ||
topic: "function foo() { var x = 1; var y = 2; }", | ||
"should not report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
config.rules[RULE_ID] = 1; | ||
var messages = eslint.verify(topic, config); | ||
assert.equal(messages.length, 0); | ||
} | ||
}, | ||
"when evaluating a function with return at end": { | ||
topic: "function foo() { var x = 1; var y = 2; return; }", | ||
"should not report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
config.rules[RULE_ID] = 1; | ||
var messages = eslint.verify(topic, config); | ||
assert.equal(messages.length, 0); | ||
} | ||
}, | ||
"when evaluating 'function foo() { return; x = 1; }'": { | ||
topic: "function foo() { return; x = 1; }", | ||
"should return a violation": function(topic) { | ||
"should report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
@@ -43,6 +82,6 @@ config.rules[RULE_ID] = 1; | ||
"when evaluation 'function foo() { throw error; x = 1; }'": { | ||
"when evaluating 'function foo() { throw error; x = 1; }'": { | ||
topic: "function foo() { throw error; x = 1; }", | ||
"should return a violation": function(topic) { | ||
"should report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
@@ -60,6 +99,6 @@ config.rules[RULE_ID] = 1; | ||
"when evaluation 'while (true) { break; x = 1; }'": { | ||
"when evaluating 'while (true) { break; x = 1; }'": { | ||
topic: "while (true) { break; x = 1; }", | ||
"should return a violation": function(topic) { | ||
"should report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
@@ -77,6 +116,6 @@ config.rules[RULE_ID] = 1; | ||
"when evaluation 'while (true) { continue; x = 1; }'": { | ||
"when evaluating 'while (true) { continue; x = 1; }'": { | ||
topic: "while (true) { continue; x = 1; }", | ||
"should return a violation": function(topic) { | ||
"should report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
@@ -94,6 +133,6 @@ config.rules[RULE_ID] = 1; | ||
"when evaluation 'function foo() { switch (foo) { case 1: return; x = 1; } }'": { | ||
"when evaluating 'function foo() { switch (foo) { case 1: return; x = 1; } }'": { | ||
topic: "function foo() { switch (foo) { case 1: return; x = 1; } }", | ||
"should return a violation": function(topic) { | ||
"should report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
@@ -111,6 +150,6 @@ config.rules[RULE_ID] = 1; | ||
"when evaluation 'function foo() { switch (foo) { case 1: throw e; x = 1; } }'": { | ||
"when evaluating 'function foo() { switch (foo) { case 1: throw e; x = 1; } }'": { | ||
topic: "function foo() { switch (foo) { case 1: throw e; x = 1; } }", | ||
"should return a violation": function(topic) { | ||
"should report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
@@ -128,6 +167,6 @@ config.rules[RULE_ID] = 1; | ||
"when evaluation 'while (true) { switch (foo) { case 1: break; x = 1; } }'": { | ||
"when evaluating 'while (true) { switch (foo) { case 1: break; x = 1; } }'": { | ||
topic: "while (true) { switch (foo) { case 1: break; x = 1; } }", | ||
"should return a violation": function(topic) { | ||
"should report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
@@ -145,6 +184,6 @@ config.rules[RULE_ID] = 1; | ||
"when evaluation 'while (true) { switch (foo) { case 1: continue; x = 1; } }'": { | ||
"when evaluating 'while (true) { switch (foo) { case 1: continue; x = 1; } }'": { | ||
topic: "while (true) { switch (foo) { case 1: continue; x = 1; } }", | ||
"should return a violation": function(topic) { | ||
"should report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
@@ -160,5 +199,19 @@ config.rules[RULE_ID] = 1; | ||
} | ||
}, | ||
"when evaluating 'while (true) { switch (foo) { case 1: x = 1; } }'": { | ||
topic: "while (true) { switch (foo) { case 1: x = 1; x = 2;} }", | ||
"should not report a violation": function(topic) { | ||
var config = { rules: {} }; | ||
config.rules[RULE_ID] = 1; | ||
var messages = eslint.verify(topic, config); | ||
assert.equal(messages.length, 0); | ||
} | ||
} | ||
}).export(module); | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
255486
116
4297
3
38
+ Addedestraverse@1.2.0(transitive)
- Removedestraverse@5.3.0(transitive)
Updatedestraverse@~1.2.0