UNPKG

eslint-plugin-green

Version:

ESLint plugin for evaluating and promoting green coding practices

30 lines (29 loc) 927 B
"use strict"; const rule = { meta: { type: 'suggestion', docs: { description: 'Enforce efficient DOM operations', category: 'DOM', recommended: true, }, schema: [], // no options }, create(context) { return { CallExpression(node) { if (node.callee.type === 'MemberExpression' && node.callee.object.type === 'Identifier' && node.callee.object.name === 'document' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'getElementById') { context.report({ node, message: 'Consider caching DOM elements in variables to avoid repeated lookups' }); } } }; } }; module.exports = rule;