Files
renovate/tools/lint/rules/prefer-partial-in-specs.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

40 lines
1.0 KiB
TypeScript

import type { ESTree } from '@oxlint/plugins';
import { defineRule } from '@oxlint/plugins';
/**
* `as const` assertions are represented as a type reference named `const`.
* They narrow instead of bypassing type checking, so they stay allowed.
*/
function isConstAssertion(typeAnnotation: ESTree.TSType): boolean {
return (
typeAnnotation.type === 'TSTypeReference' &&
typeAnnotation.typeName.type === 'Identifier' &&
typeAnnotation.typeName.name === 'const'
);
}
export default defineRule({
meta: {
type: 'problem',
messages: {
preferPartial:
'Casting an object literal with `as` bypasses type checking; use `partial<T>()` from `test/util` (or a properly typed value) instead.',
},
},
createOnce(context) {
return {
TSAsExpression(node) {
if (
node.expression.type === 'ObjectExpression' &&
!isConstAssertion(node.typeAnnotation)
) {
context.report({
node,
messageId: 'preferPartial',
});
}
},
};
},
});