mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-01 02:00:10 +00:00
e44c9a2070
* ci: move custom oxlint rules to typescript and alternative API * ci: add to test sharding
35 lines
1016 B
TypeScript
35 lines
1016 B
TypeScript
import { defineRule } from '@oxlint/plugins';
|
|
|
|
export default defineRule({
|
|
meta: {
|
|
type: 'suggestion',
|
|
messages: {
|
|
preferIsObject:
|
|
"Consider `isObject()` or `isPlainObject()` from `@sindresorhus/is` instead of comparing `typeof` against 'object'. Semantics differ (`typeof null === 'object'`, arrays are objects, `isObject()` includes functions) — verify equivalence before changing.",
|
|
},
|
|
},
|
|
createOnce(context) {
|
|
return {
|
|
BinaryExpression(node) {
|
|
if (!['===', '!==', '==', '!='].includes(node.operator)) {
|
|
return;
|
|
}
|
|
for (const [a, b] of [
|
|
[node.left, node.right],
|
|
[node.right, node.left],
|
|
]) {
|
|
if (
|
|
a.type === 'UnaryExpression' &&
|
|
a.operator === 'typeof' &&
|
|
b.type === 'Literal' &&
|
|
b.value === 'object'
|
|
) {
|
|
context.report({ node, messageId: 'preferIsObject' });
|
|
return;
|
|
}
|
|
}
|
|
},
|
|
};
|
|
},
|
|
});
|