// @ts-check const message = 'Only absolute URLs are valid.'; /** @type {import("eslint").Rule.RuleModule} */ const rule = { create(context) { return { // e.g. `history.push('./test')` CallExpression(node) { if ( node.type === 'CallExpression' && node.callee.type === 'MemberExpression' && node.callee.object.type === 'Identifier' && node.callee.object.name === 'history' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'push' ) { const argument = node.arguments[0]; if ( argument && argument.type === 'Literal' && !argument.value.toString().startsWith('/') ) { context.report({ node, message }); } } } }; } }; module.exports = rule;