@masknet/eslint-plugin
Version:
eslint plugin for masknet
51 lines • 1.33 kB
JavaScript
import { isIdentifierName, isLiteralValue, isMemberExpression } from "../node.js";
import { createRule } from "../rule.js";
const methodNames = [
'setTimeout',
'clearTimeout',
'setInterval',
'clearInterval',
'setImmediate',
'clearImmediate',
'requestAnimationFrame',
'cancelAnimationFrame',
'requestIdleCallback',
'cancelIdleCallback',
'nextTick',
];
export default createRule({
name: 'no-timer',
meta: {
type: 'problem',
docs: {
description: 'Disallow use timer function',
},
schema: [],
messages: {
invalid: 'Disallow use timer function',
},
},
defaultOptions: [],
create(context) {
return {
CallExpression(node) {
if (!detect(node.callee))
return;
context.report({ node, messageId: 'invalid' });
},
};
},
});
function detect(node) {
if (isIdentifierName(node, methodNames))
return true;
while (isMemberExpression(node)) {
if (isIdentifierName(node.property, methodNames))
return true;
if (isLiteralValue(node.property, methodNames))
return true;
node = node.object;
}
return false;
}
//# sourceMappingURL=no-timer.js.map