mirror of https://github.com/nodejs/node.git
tools: replace custom assert.fail lint rule
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>pull/12293/head
parent
0ec0272e10
commit
b3f2e3b7e2
|
@ -110,6 +110,9 @@ rules:
|
|||
}, {
|
||||
selector: "ThrowStatement > CallExpression[callee.name=/Error$/]",
|
||||
message: "Use new keyword when throwing an Error."
|
||||
}, {
|
||||
selector: "CallExpression[callee.object.name='assert'][callee.property.name='fail'][arguments.length=1]",
|
||||
message: "assert.fail() message should be third argument"
|
||||
}]
|
||||
no-tabs: 2
|
||||
no-trailing-spaces: 2
|
||||
|
@ -142,7 +145,6 @@ rules:
|
|||
|
||||
# Custom rules in tools/eslint-rules
|
||||
align-multiline-assignment: 2
|
||||
assert-fail-single-argument: 2
|
||||
assert-throws-arguments: [2, { requireTwo: false }]
|
||||
no-unescaped-regexp-dot: 2
|
||||
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
/**
|
||||
* @fileoverview Prohibit use of a single argument only in `assert.fail()`. It
|
||||
* is almost always an error.
|
||||
* @author Rich Trott
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const msg = 'assert.fail() message should be third argument';
|
||||
|
||||
function isAssert(node) {
|
||||
return node.callee.object && node.callee.object.name === 'assert';
|
||||
}
|
||||
|
||||
function isFail(node) {
|
||||
return node.callee.property && node.callee.property.name === 'fail';
|
||||
}
|
||||
|
||||
module.exports = function(context) {
|
||||
return {
|
||||
'CallExpression': function(node) {
|
||||
if (isAssert(node) && isFail(node) && node.arguments.length === 1) {
|
||||
context.report(node, msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue