mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-02 02:29:51 +00:00
e44c9a2070
* ci: move custom oxlint rules to typescript and alternative API * ci: add to test sharding
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import { RuleTester } from 'oxlint/plugins-dev';
|
|
import rule from './prefer-is-object.ts';
|
|
|
|
RuleTester.describe = describe;
|
|
RuleTester.it = it;
|
|
|
|
const ruleTester = new RuleTester({
|
|
languageOptions: { parserOptions: { lang: 'ts' } },
|
|
});
|
|
|
|
ruleTester.run('prefer-is-object', rule, {
|
|
valid: [
|
|
// already using the helper
|
|
`is.plainObject(x);`,
|
|
// other typeof comparisons
|
|
`typeof x === 'string';`,
|
|
`typeof x !== 'function';`,
|
|
// non-equality operators
|
|
`typeof x + 'object';`,
|
|
`typeof x > 'object';`,
|
|
// literal without typeof
|
|
`x === 'object';`,
|
|
// typeof compared to a non-literal
|
|
`typeof x === y;`,
|
|
// unary operator other than typeof
|
|
`-x === 'object';`,
|
|
// neither side is a string literal
|
|
`typeof x === typeof y;`,
|
|
],
|
|
invalid: [
|
|
{
|
|
code: `typeof x === 'object';`,
|
|
errors: [{ messageId: 'preferIsObject' }],
|
|
},
|
|
{
|
|
code: `typeof x !== 'object';`,
|
|
errors: [{ messageId: 'preferIsObject' }],
|
|
},
|
|
{
|
|
code: `typeof x == 'object';`,
|
|
errors: [{ messageId: 'preferIsObject' }],
|
|
},
|
|
{
|
|
code: `typeof x != 'object';`,
|
|
errors: [{ messageId: 'preferIsObject' }],
|
|
},
|
|
// reversed operand order
|
|
{
|
|
code: `'object' === typeof x;`,
|
|
errors: [{ messageId: 'preferIsObject' }],
|
|
},
|
|
// member expression operand
|
|
{
|
|
code: `typeof foo.bar === 'object';`,
|
|
errors: [{ messageId: 'preferIsObject' }],
|
|
},
|
|
],
|
|
});
|