-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`assert.fail()` is often mistakenly used with a single argument even in Node.js core. (See fixes to previous instances in b7f4b1b, 28e9a02. and 676e618.) This commit adds a linting rule to identify instances of this issue. PR-URL: #6261 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @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); | ||
} | ||
} | ||
}; | ||
}; |