mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
tools: replace assert-throw-arguments custom lint
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>
This commit is contained in:
1 parent
548cc72f66
commit
e506bcd899
4 files changed
+10
-65
No files matched your search
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
* @fileoverview Check that assert.throws is never called with a string as
|
||||
* second argument.
|
||||
* @author Michaël Zasso
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function checkThrowsArguments(context, node) {
|
||||
if (node.callee.type === 'MemberExpression' &&
|
||||
node.callee.object.name === 'assert' &&
|
||||
node.callee.property.name === 'throws') {
|
||||
const args = node.arguments;
|
||||
if (args.length > 3) {
|
||||
context.report({
|
||||
message: 'Too many arguments',
|
||||
node: node
|
||||
});
|
||||
} else if (args.length > 1) {
|
||||
const error = args[1];
|
||||
if (error.type === 'Literal' && typeof error.value === 'string' ||
|
||||
error.type === 'TemplateLiteral') {
|
||||
context.report({
|
||||
message: 'Unexpected string as second argument',
|
||||
node: error
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (context.options[0].requireTwo) {
|
||||
context.report({
|
||||
message: 'Expected at least two arguments',
|
||||
node: node
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
meta: {
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
requireTwo: {
|
||||
type: 'boolean'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
create: function(context) {
|
||||
return {
|
||||
CallExpression: (node) => checkThrowsArguments(context, node)
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user