Repository navigation
feat(oxlint-config): report any flowing into typed code #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@stll/oxlint-config": major | ||
| "@stll/test-kit": patch | ||
| --- | ||
|
|
||
| `library()` enables `typescript/no-unsafe-argument`, `no-unsafe-assignment`, `no-unsafe-call`, `no-unsafe-member-access` and `no-unsafe-return`, so an `any` from `JSON.parse`, untyped libraries or an unresolved import can no longer flow into typed code unchecked. Test files keep reporting calls, member access and returns but allow passing and storing `any` values such as asymmetric matchers. JavaScript files are exempt. The rules are exported as `unsafeAnyRules` so a consumer can turn them off per directory while adopting them, and the two exemptions as `unsafeAnyOverrides`; `libraryOverrides` does not include them, so a config that spreads it over another preset keeps that preset's scope for these rules. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,13 @@ import { tmpdir } from "node:os"; | |
| import { join } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| import { library } from "./index"; | ||
| import { | ||
| library, | ||
| libraryOverrides, | ||
| libraryRules, | ||
| unsafeAnyOverrides, | ||
| unsafeAnyRules, | ||
| } from "./index"; | ||
|
|
||
| const oxlintBin = fileURLToPath( | ||
| new URL("./bin/oxlint", import.meta.resolve("oxlint/package.json")), | ||
|
|
@@ -69,3 +75,27 @@ test("test overrides reach nested test folders and every module extension", asyn | |
| await rm(directory, { recursive: true, force: true }); | ||
| } | ||
| }, 15_000); | ||
|
|
||
| test("unsafe any rules are on, relaxed for test matchers and off in JavaScript, only through their own overrides", () => { | ||
| expect(libraryRules).toEqual(expect.objectContaining(unsafeAnyRules)); | ||
| const [tests, javascript] = unsafeAnyOverrides; | ||
| expect(tests?.files).toEqual(libraryOverrides[0]?.files); | ||
| expect(tests?.rules).toEqual( | ||
| expect.objectContaining({ | ||
| "typescript/no-unsafe-argument": "off", | ||
| "typescript/no-unsafe-assignment": "off", | ||
| }), | ||
| ); | ||
| expect(tests?.rules).not.toHaveProperty(["typescript/no-unsafe-call"]); | ||
| // Configs that spread `libraryOverrides` over a preset with its own | ||
| // any-flow scope must not have those rules relaxed. | ||
| expect( | ||
| libraryOverrides.flatMap((override) => Object.keys(override.rules)), | ||
| ).not.toEqual(expect.arrayContaining(Object.keys(unsafeAnyRules))); | ||
|
Comment on lines
+93
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| expect(javascript?.files).toEqual(["**/*.{js,jsx,mjs,cjs}"]); | ||
| expect(javascript?.rules).toEqual( | ||
| Object.fromEntries( | ||
| Object.keys(unsafeAnyRules).map((rule) => [rule, "off"]), | ||
| ), | ||
| ); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.