Files
renovate/tools/lint/rules/no-host-rules-mock.ts
Sebastian Poxhofer e44c9a2070 ci(oxlint): move custom oxlint rules to typescript and alternative API (#45337)
* ci: move custom oxlint rules to typescript and alternative API

* ci: add  to test sharding
2026-08-19 05:37:56 +00:00

38 lines
1.2 KiB
TypeScript

import { defineRule } from '@oxlint/plugins';
export default defineRule({
meta: {
type: 'problem',
messages: {
noHostRulesMock:
"Do not mock host-rules; configure real rules via the test util instead: import { hostRules } from '~test/host-rules.ts' and call hostRules.add() in the test.",
},
},
createOnce(context) {
return {
CallExpression(node) {
const { callee } = node;
if (
callee.type !== 'MemberExpression' ||
callee.computed ||
callee.object.type !== 'Identifier' ||
callee.object.name !== 'vi' ||
callee.property.type !== 'Identifier' ||
(callee.property.name !== 'mock' && callee.property.name !== 'doMock')
) {
return;
}
const [specifier] = node.arguments;
if (
specifier?.type === 'Literal' &&
typeof specifier.value === 'string' &&
// only the host-rules module itself, not e.g. `host-rules-from-env`
/(?:^|\/)host-rules(?:\.[cm]?[jt]s)?$/.test(specifier.value)
) {
context.report({ node, messageId: 'noHostRulesMock' });
}
},
};
},
});