import { RuleTester } from "oxlint/plugins-dev"; import { noObjectParametersRule } from "./no-object-parameters.ts"; const tester = new RuleTester({ languageOptions: { parserOptions: { lang: "ts" } } }); const error = { messageId: "objectParameter" }; tester.run("anti-slop/no-object-parameters", noObjectParametersRule, { valid: [ "type Alias = object;", "function f(value: Alias) {}", "interface Owner { readonly id: string } function f(value: Owner) {}", "function f(value: Value) {}", "function f(value: Value) {}", "function f(value: Value) {}", "type Owner = { readonly id: string }; function f(value: Value) {}", "type Alias = object; function consume(value: Alias) {}", "type Alias = object; type Consumer = (value: Alias) => void;", "type Alias = object; interface Consumer { consume(value: Alias): void }", "type Key = object; type Mapped = { [Key in keyof Input]: (value: Key) => void };", "type Item = object; type Unpacked = Input extends Promise ? (value: Item) => void : never;", "type Payload = object; function outer() { type Payload = { readonly id: string }; function consume(value: Payload) {} }", "type Identity = T; function consume(value: Identity) {}", "function one() { type Payload = object; } function two() { function consume(value: Payload) {} }", ], invalid: [ { code: "function f(value: object) {}", errors: [error] }, { code: "type Alias = object; function f(value: Alias) {}", errors: [error] }, { code: "type Alias = (object); function f(value: Alias) {}", errors: [error] }, { code: "type Item = object; type Fallback = Input extends infer Item ? string : (value: Item) => void;", errors: [error], }, { code: "function consume(value: object = {}): void {}", errors: [{ ...error, data: { parameter: "value" } }], }, { code: "function consume({ value }: object = {}): void {}", errors: [{ ...error, data: { parameter: "{ value }" } }], }, { code: "type Bag = object; function consume({ value }: Bag): void {}", errors: [{ ...error, data: { parameter: "{ value }" } }], }, { code: "function outer() { type Payload = object; function consume(value: Payload) {} }", errors: [error], }, { code: "function outer() { function consume(value: Payload) {} type Payload = object; }", errors: [error], }, { code: "type Identity = T; function consume(value: Identity) {}", errors: [error], }, { code: "type Identity = T; type Wrapped = Identity; function consume(value: Wrapped) {}", errors: [error], }, ], });