summaryrefslogtreecommitdiff
path: root/tools/eslint-rules
AgeCommit message (Collapse)Author
2017-08-30tools: add eslint rule for inspector checkingDaniel Bevenius
The motivation for this commit is to pick up early on missing checks for inspector support (when Node is built --without-inspector). PR-URL: https://github.com/nodejs/node/pull/13813 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
2017-08-30tools: add eslint rule for hasCrypto checkingDaniel Bevenius
The motivation for this commit is to pick up early on missing checks for crypto support (when Node is built --without-ssl). There are currently usages of common.hasCrypto which are not just for detecting if crypto support is available and then skip the test in question. For these case we still want to have a lint error generated which can then be disabled using an ESLint comment. PR-URL: https://github.com/nodejs/node/pull/13813 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
2017-08-03tools: simplify no-unescaped-regexp-dot ruleRich Trott
no-unescaped-regexp-dot ESLint custom rule contains feature detection that is not needed on master or the v6.x-staging branch. The rule does not exist in the v4.x-staging branch. Remove the unnecessary complexity. PR-URL: https://github.com/nodejs/node/pull/14561 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-08-02tools: replace assert-throw-arguments custom lintRich Trott
The functionality of ESLint custom rule assert-throws-arguments can be replaced with no-restricted-syntax entries. PR-URL: https://github.com/nodejs/node/pull/14547 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-21lib,src: fix consistent spacing inside bracesSebastiaan Deckers
PR-URL: https://github.com/nodejs/node/pull/14162 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-06tools: remove align-multiline-assignment lint ruleRich Trott
In preparation for stricter indentation linting, remove the align-multiline-assignment custom rule, as it may conflict with the ESLint stricter indentation linting. PR-URL: https://github.com/nodejs/node/pull/14079 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-07-02tools: change var to const in ./eslint-rulesRuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/13732 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-06-28tools: remove comment in eslint ruleDaniel Bevenius
I noticed this comment while working on a different task and could not find any reason for it being there. Just bringing this up in case it was overlooked. PR-URL: https://github.com/nodejs/node/pull/13945 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-06-22tools: fix error in custom ESLint ruleRich Trott
Fix previously-unnoticed typo in `required-modules.js`. Refs: https://github.com/nodejs/node/pull/13758#discussion_r122582786 PR-URL: https://github.com/nodejs/node/pull/13758 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-06-22tools: fix indentation in required-modules.jsRich Trott
In preparation for applying the more strict indentation linting available in ESLint 4.0.0, correct minor indentation issues in tools/eslint-rules/required-modules.js. This is the only file with indentation that does not conform to the stricter checks. PR-URL: https://github.com/nodejs/node/pull/13758 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-04-12tools: replace custom assert.fail lint ruleRich Trott
Replace custom lint rule for `assert.fail()` function signature errors with a restricted-syntax rule. PR-URL: https://github.com/nodejs/node/pull/12287 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-04-08tools: replace custom new-with-error ruleRich Trott
Use no-restricted-syntax to implement the requirement that `Error` objects must be thrown with the `new` keyword. PR-URL: https://github.com/nodejs/node/pull/12249 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
2017-04-04tools: replace custom ESLint timers ruleRich Trott
ESLint 3.19.0 allows the specification of selectors that represent disallowed syntax. Replace our custom rule for timer arguments with a pair of `no-restricted-syntax` option objects. PR-URL: https://github.com/nodejs/node/pull/12162 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-03-29tools: add unescaped regexp dot rule to linterBrian White
PR-URL: https://github.com/nodejs/node/pull/11834 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2017-03-26tools: add rule prefering common.mustNotCall()James M Snell
Prefer using `common.mustNotCall()` over `common.mustCall(fn, 0)` PR-URL: https://github.com/nodejs/node/pull/12027 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2017-01-09tools,test: enforce assert.ifError with lint ruleTeddy Katz
This adds an ESLint rule to enforce the use of `assert.ifError(err)` instead of `if (err) throw err;` in tests. PR-URL: https://github.com/nodejs/node/pull/10671 Ref: https://github.com/nodejs/node/pull/10543 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com>
2017-01-06tools: add lint rule to enforce timer argumentsRich Trott
Add a custom ESLint rule to require that setTimeout() and setInterval() get called with at least two arguments. This prevents omitting the duration or interval. PR-URL: https://github.com/nodejs/node/pull/9472 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-01-06tools: remove no-useless-regex-char-class-escapeRich Trott
The `no-useless-regex-char-class-escape` custom lint rule was introduced as a less aggressive alternative to some enhancements that were introduced into ESLint. Those enhancements were blocking us from updating ESLint. However, they have since been relaxed and the custom rule is no longer needed. Remove it. PR-URL: https://github.com/nodejs/node/pull/10561 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
2017-01-06tools: remove custom align-function-arguments ruleRich Trott
ESLint `indent` rule now has options that duplicate functionality in our custom `align-function-arguments` rule. Remove `align-function-arguments` custom rule. PR-URL: https://github.com/nodejs/node/pull/10561 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
2016-12-22tools: enforce linebreak after ternary operatorsMichaël Zasso
This is to be consistent with the other operators and helps understanding the context when the code is grepped. PR-URL: https://github.com/nodejs/node/pull/10213 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-12-19tools: forbid template literals in assert.throwsMichaël Zasso
Extend the assert-throws-arguments custom ESLint rule to also check for the use of template literals as a second argument to assert.throws. PR-URL: https://github.com/nodejs/node/pull/10301 Ref: https://github.com/nodejs/node/pull/10282#discussion_r92607290 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Italo A. Casas <me@italoacasas.com>
2016-12-05tools: add ESLint rule for assert.throws argumentsMichaël Zasso
The second argument to "assert.throws" is usually a validation RegExp or function for the thrown error. However, the function also accepts a string and in this case it is interpreted as a message for the AssertionError and not used for validation. It is common for people to forget this and pass a validation string by mistake. This new rule checks that we never pass a string literal as a second argument to "assert.throws". Additionally, there is an option to enforce the function to be called with at least two arguments. It is currently off because we have many tests that do not comply with this rule. PR-URL: https://github.com/nodejs/node/pull/10089 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
2016-11-23tools: Add no useless regex char class rulePrince J Wesley
Eslint Rule: Disallow useless escape in regex character class with optional override characters option and auto fixable with eslint --fix option. Usage: no-useless-regex-char-class-escape: [2, { override: ['[', ']'] }] PR-URL: https://github.com/nodejs/node/pull/9591 Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
2016-10-21tools: replace custom lint rule for getter/setterRich Trott
Replace custom `no-definegetter-definesetter` lint rule with ESLint's built-in `no-restricted-properties`. Refs: https://github.com/nodejs/node/pull/9112#pullrequestreview-4378536 PR-URL: https://github.com/nodejs/node/pull/9194 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-10-14tools: avoid let in for loopsjessicaquynh
This adds a new ESLint tool to check for let declarations within the for, forIn, forOf expressions. Fixes: https://github.com/nodejs/node/issues/9045 Ref: https://github.com/nodejs/node/pull/8873 PR-URL: https://github.com/nodejs/node/pull/9049 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-09-20tools: add eslint rule prefer-assert-methodsDany Shaanan
PR-URL: https://github.com/nodejs/node/pull/8622 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com> Reviewed-By: Jackson Tian <shvyo1987@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
2016-09-20tools: make argument alignment linting more strictRich Trott
A few nits in recent PR comments suggest that we can have slightly more strict linting for argument alignment in multiline function calls. This enables the existing linting requirements to apply when one or more of the arguments themselves are function calls. Previously, that situation had been excluded from linting. Refs: https://github.com/nodejs/node/pull/8628#issuecomment-247797311 PR-URL: https://github.com/nodejs/node/pull/8642 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2016-09-12tools: replace custom ESLint rule with built-inRich Trott
ESLint 3.5.0 introduces a `no-restricted-properties` rule. Replace our custom `no-deepEqual` rule with this rule. PR-URL: https://github.com/nodejs/node/pull/8478 Reviewed-By: James M Snell <jasnell@gmail.com>
2016-05-19tools: disallow deprecated define getter/setterRich Trott
PR-URL: https://github.com/nodejs/node/pull/6774 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Refs: https://github.com/nodejs/node/pull/6768
2016-05-15tools,test: make argument linting more stringentRich Trott
The custom linting rule for argument alignment in multi-line function calls previously ignored template strings in an effort to avoid false positives. This isn't really necessary. Enforce for template strings and adjust whitespace in three tests to abide. (Insert "The test abides" joke of your choosing here.) PR-URL: https://github.com/nodejs/node/pull/6720 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-04-28tools: remove default parameters from lint ruleRich Trott
The CI server uses system Node.js for linting, which is currently v5.x. So default parameters are not supported there. This change removes the default parameters. PR-URL: https://github.com/nodejs/node/pull/6411 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-04-28tools: lint for function argument alignmentRich Trott
In function calls that span multiple lines, apply a custom lint rule to enforce argument alignment. With this rule, the following code will be flagged as an error by the linter because the arguments on the second line start in a different column than on the first line: myFunction(a, b, c, d); The following code will not be flagged as an error by the linter: myFunction(a, b, c, d); PR-URL: https://github.com/nodejs/node/pull/6390 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Imran Iqbal <imran@imraniqbal.org> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Ryan Graham <r.m.graham@gmail.com>
2016-04-22tools: enforce deepStrictEqual over deepEqualRich Trott
Introduce a lint rule that enforces use of `assert.deepStrictEqual()` over `assert.deepEqual()`. PR-URL: https://github.com/nodejs/node/pull/6213 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-04-20tools: lint rule for assert.fail()Rich Trott
`assert.fail()` is often mistakenly used with a single argument even in Node.js core. (See fixes to previous instances in b7f4b1ba4cca320cf576aa73fae15902fd801190, 28e9a022df3ef89a0ea21e4ad86655eb408a8d96. and 676e61872f54dd546e324599c7871c20b798386a.) This commit adds a linting rule to identify instances of this issue. PR-URL: https://github.com/nodejs/node/pull/6261 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-04-18tools: lint for alignment of variable assignmentsRich Trott
Enforce alignment/indentation on variable assignments that span multiple lines. PR-URL: https://github.com/nodejs/node/pull/6242 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-18tools: add buffer-constructor eslint ruleJames M Snell
Now that the Buffer.alloc, allocUnsafe, and from methods have landed, add a linting rule that requires their use within lib. Tests and benchmarks are explicitly excluded by the rule. PR-URL: https://github.com/nodejs/node/pull/5740 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-02-18tools: remove obsolete lint rulesRich Trott
We are about to upgrade from ESlint 1 to ESLint 2. Remove lint rules that will not exist in ESLint 2. PR-URL: https://github.com/nodejs/node/pull/5214 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: jbergstroem - Johan Bergström <bugs@bergstroem.nu> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Myles Borins <myles.borins@gmail.com>
2016-01-13tools: fix style issue after eslint updateMichaël Zasso
PR-URL: https://github.com/nodejs/io.js/pull/2286 Reviewed-By: Roman Reiss <me@silverwind.io>
2015-11-10tools: enforce `throw new Error()` with lint ruleRich Trott
Add linting rule requiring `throw new Error()` over `throw Error()`. PR-URL: https://github.com/nodejs/node/pull/3714 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2015-10-06test: make common.js mandatory via linting ruleRich Trott
test/common.js contains code that detects global variable leaks. This eslint rule checks that a module named `common` is loaded. It is only applicable to files in the test directory. Tests that intentionally leak variables can opt out with an eslint-disable comment. PR-URL: https://github.com/nodejs/node/pull/3157 Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-10-06tools: apply linting to custom rules codeRich Trott
Apply our eslint rules to the code for our custom eslint rules. Eslint Inception! Maybe. I never saw that movie... PR-URL: https://github.com/nodejs/node/pull/3195 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Roman Reiss <me@silverwind.io>
2015-06-11tools: enable/add additional eslint rulesRoman Reiss
Enables the following rules: - no-undef: Valuable rule to error on usage of undefined variables - require-buffer: Custom rule that forbids usage of the global Buffer inside lib/ because of REPL issues. PR-URL: https://github.com/nodejs/io.js/pull/1794 Reviewed-By: Trevor Norris <trev.norris@gmail.com>