0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-27 22:16:50 +01:00
nodejs/tools/eslint-rules/prefer-common-mustnotcall.js
Antoine du Hamel 75dca44c60
tools: update ESLint custom rules to not use the deprecated format
Refs: https://eslint.org/docs/latest/extend/custom-rules-deprecated
PR-URL: https://github.com/nodejs/node/pull/46460
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-02-03 09:55:29 +00:00

33 lines
982 B
JavaScript

/**
* @fileoverview Prefer common.mustNotCall(msg) over common.mustCall(fn, 0)
* @author James M Snell <jasnell@gmail.com>
*/
'use strict';
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
const msg = 'Please use common.mustNotCall(msg) instead of ' +
'common.mustCall(fn, 0) or common.mustCall(0).';
const mustCallSelector = 'CallExpression[callee.object.name="common"]' +
'[callee.property.name="mustCall"]';
const arg0Selector = `${mustCallSelector}[arguments.0.value=0]`;
const arg1Selector = `${mustCallSelector}[arguments.1.value=0]`;
module.exports = {
create(context) {
function report(node) {
context.report(node, msg);
}
return {
// Catch common.mustCall(0)
[arg0Selector]: report,
// Catch common.mustCall(fn, 0)
[arg1Selector]: report,
};
},
};