Repository navigation
build: lint with oxlint and format with oxfmt #2047
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
Open
fb55
wants to merge
11
commits into
master
Choose a base branch
from
build/oxc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,370
−2,897
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f2f5de6
build: lint with oxlint and format with oxfmt
fb55 d858074
build: preserve publish and JSON lint coverage
fb55 329cb71
build: use stock lint and format checks
fb55 7e40938
build: enable more lint rules
fb55 0e2ed35
build: simplify lint suppressions
fb55 ab4c558
build: run oxlint and oxfmt directly
fb55 6f6b6e8
test: iterate expected fixture entries directly
fb55 5faa5a7
build: move per-file lint exceptions into the files
fb55 76df7f2
refactor: fix code instead of disabling lint rules
fb55 ae49899
build: scope JSDoc return checks to non-getters
fb55 ba4dd15
test: narrow fixture lint exceptions
fb55 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { defineConfig, type OxfmtConfig } from "oxfmt"; | ||
|
|
||
| const config: OxfmtConfig = defineConfig({ | ||
| printWidth: 80, | ||
| tabWidth: 4, | ||
| sortImports: true, | ||
| sortPackageJson: true, | ||
| ignorePatterns: [".*", "package-lock.json"], | ||
| }); | ||
|
|
||
| export default config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| import { builtinModules } from "node:module"; | ||
|
|
||
| import { defineConfig, type OxlintConfig } from "oxlint"; | ||
|
|
||
| import manifest from "./package.json" with { type: "json" }; | ||
|
|
||
| const runtimePackages = Object.keys(manifest.dependencies); | ||
| const toolingPackages = Object.keys(manifest.devDependencies); | ||
|
|
||
| /** | ||
| * Rules turned off (each group says why they do not fit this code). | ||
| * | ||
| * @param rules The names of the rules. | ||
| * @returns The rules, each turned off. | ||
| */ | ||
| const off = (...rules: string[]): Record<string, "off"> => | ||
| Object.fromEntries(rules.map((rule) => [rule, "off"])); | ||
|
|
||
| const config: OxlintConfig = defineConfig({ | ||
| plugins: [ | ||
| "eslint", | ||
| "typescript", | ||
| "unicorn", | ||
| "oxc", | ||
| "import", | ||
| "jsdoc", | ||
| "node", | ||
| "promise", | ||
| "vitest", | ||
| ], | ||
| // Every rule, except those turned off below. | ||
| categories: { | ||
| correctness: "error", | ||
| suspicious: "error", | ||
| pedantic: "error", | ||
| perf: "error", | ||
| style: "error", | ||
| restriction: "error", | ||
| }, | ||
| options: { typeAware: true, reportUnusedDisableDirectives: "error" }, | ||
| ignorePatterns: ["coverage/", "dist/", "docs/", "src/__fixtures__/"], | ||
| rules: { | ||
| "no-restricted-imports": [ | ||
| "error", | ||
| { | ||
| patterns: [ | ||
| { | ||
| group: [ | ||
| "**", | ||
| "!./**", | ||
| "!../**", | ||
| "!node:*{,/**}", | ||
| ...[ | ||
| ...builtinModules, | ||
| ...runtimePackages, | ||
| ...toolingPackages, | ||
| ].map((name) => `!${name}{,/**}`), | ||
| ], | ||
| message: | ||
| "Declare tooling dependencies in package.json before importing them.", | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| eqeqeq: ["error", "smart"], | ||
| "one-var": ["error", "never"], | ||
| "func-style": ["error", "declaration", { allowArrowFunctions: true }], | ||
| "prefer-arrow-callback": ["error", { allowNamedFunctions: true }], | ||
| "prefer-destructuring": ["error", { object: true, array: false }], | ||
| "capitalized-comments": [ | ||
| "error", | ||
| "always", | ||
| // (Lines continuing a comment continue its sentence.) | ||
| { ignorePattern: "oxfmt-ignore", ignoreConsecutiveComments: true }, | ||
| ], | ||
| yoda: ["error", "never"], | ||
| curly: ["error", "multi-line"], | ||
| "no-unused-vars": [ | ||
| "error", | ||
| { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }, | ||
| ], | ||
| "typescript/no-unnecessary-condition": "error", | ||
| "typescript/strict-boolean-expressions": [ | ||
| "error", | ||
| { allowNullableBoolean: true }, | ||
| ], | ||
| // DOM node types are exposed as prototype getters with constant values. | ||
| "class-methods-use-this": ["error", { exceptMethods: ["nodeType"] }], | ||
| "typescript/class-literal-property-style": ["error", "getters"], | ||
| // Getter summaries describe the value they expose. | ||
| "jsdoc/require-returns": ["error", { checkGetters: false }], | ||
| "vitest/consistent-test-filename": [ | ||
| "error", | ||
| { pattern: String.raw`\.spec\.ts$` }, | ||
| ], | ||
| "vitest/consistent-test-it": ["error", { fn: "it" }], | ||
| "unicorn/numeric-separators-style": [ | ||
| "error", | ||
| { hexadecimal: { onlyIfContainsSeparator: true } }, | ||
| ], | ||
| "typescript/explicit-member-accessibility": [ | ||
| "error", | ||
| { accessibility: "no-public" }, | ||
| ], | ||
| "typescript/explicit-function-return-type": [ | ||
| "error", | ||
| { allowExpressions: true }, | ||
| ], | ||
| "typescript/no-confusing-void-expression": [ | ||
| "error", | ||
| { ignoreArrowShorthand: true }, | ||
| ], | ||
| "typescript/switch-exhaustiveness-check": [ | ||
| "error", | ||
| { considerDefaultExhaustiveForUnions: true }, | ||
| ], | ||
| "vitest/prefer-lowercase-title": ["error", { ignore: ["describe"] }], | ||
| // DOM node type IDs are standardized numbers, and T is a conventional type parameter. | ||
| ...off("no-magic-numbers", "id-length"), | ||
| // Node APIs use null for absent links and accept undefined for optional inputs. | ||
| ...off("unicorn/no-null", "no-undefined"), | ||
| // Modern syntax and the runtime's features are fine. | ||
| ...off( | ||
| "oxc/no-async-await", | ||
| "oxc/no-optional-chaining", | ||
| "oxc/no-rest-spread-properties", | ||
| "no-plusplus", | ||
| "no-continue", | ||
| "no-ternary", | ||
| "no-nested-ternary", | ||
| "unicorn/no-nested-ternary", | ||
| "unicorn/no-array-reduce", | ||
| "promise/avoid-new", | ||
| "node/no-top-level-await", | ||
| "node/no-sync", | ||
| "import/no-nodejs-modules", | ||
| "unicorn/import-style", | ||
| ), | ||
| // Async functions without `await` return their values and errors as promises. | ||
| ...off("require-await", "typescript/require-await"), | ||
| // Sizes, and orders that do not follow the code's structure. | ||
| ...off( | ||
| "max-params", | ||
| "max-statements", | ||
| "max-lines", | ||
| "max-lines-per-function", | ||
| "max-classes-per-file", | ||
| "unicorn/max-nested-calls", | ||
| "sort-keys", | ||
| "no-use-before-define", | ||
| "no-inline-comments", | ||
| "init-declarations", | ||
| ), | ||
| // Let the formatter sort imports and keep the existing module structure. | ||
| ...off( | ||
| "sort-imports", | ||
| "import/consistent-type-specifier-style", | ||
| "import/no-named-export", | ||
| "import/no-default-export", | ||
| "import/prefer-default-export", | ||
| "import/group-exports", | ||
| "import/exports-last", | ||
| "import/no-relative-parent-imports", | ||
| ), | ||
| // TypeScript supplies the JSDoc types, and mutable inputs are supported. | ||
| ...off( | ||
| "jsdoc/require-param-type", | ||
| "jsdoc/require-returns-type", | ||
| "jsdoc/require-yields-type", | ||
| "jsdoc/require-throws-type", | ||
| "typescript/prefer-readonly-parameter-types", | ||
| ), | ||
| // Nullish equality is allowed by eqeqeq's smart mode. | ||
| ...off("no-eq-null"), | ||
| // Synchronous tests import their APIs explicitly and check exact values. | ||
| ...off( | ||
| "vitest/prefer-expect-assertions", | ||
| "vitest/require-test-timeout", | ||
| "vitest/no-importing-vitest-globals", | ||
| "vitest/max-expects", | ||
| "vitest/prefer-to-be-truthy", | ||
| "vitest/prefer-to-be-falsy", | ||
| ), | ||
| }, | ||
| overrides: [ | ||
| { | ||
| // Published modules run in browsers. | ||
| files: ["src/**/*.ts"], | ||
| excludeFiles: ["**/*.spec.ts"], | ||
| rules: { | ||
| "import/no-nodejs-modules": "error", | ||
| "no-restricted-imports": [ | ||
| "error", | ||
| { | ||
| patterns: [ | ||
| // Check test paths before allowing relative imports. | ||
| { | ||
| regex: String.raw`(?:^|/)(?:__fixtures__|__snapshots__|__tests__|tests?)(?:/|$)|\.(?:spec|test)(?:\.[cm]?[jt]sx?)?$`, | ||
| message: | ||
| "Published modules must not import tests or fixtures.", | ||
| }, | ||
| { | ||
| group: [ | ||
| "**", | ||
| "!./**", | ||
| "!../**", | ||
| ...runtimePackages.map( | ||
| (name) => `!${name}{,/**}`, | ||
| ), | ||
| ], | ||
| message: | ||
| "Published modules may import only runtime dependencies and relative modules.", | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| // Keep indexed sibling lookup in parser and traversal hot paths. | ||
| ...off("unicorn/prefer-at"), | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| export default config; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the advertised Node >=20.19 environment,
npm run lintinvokes Oxlint, which auto-discovers this TypeScript configuration before linting; however, Oxlint documents that TypeScript configs require Node v22.18+ or v24+. The same issue affectsoxfmt.config.tsduring the formatting check, so contributors using a supported Node 20 release cannot run the lint workflow. Use JSON/JSONC configurations or raise the package's minimum Node version.Useful? React with 👍 / 👎.