-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(linter): add initial oxlint plugin, docs, and e2e coverage #34838
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
Draft
juristr
wants to merge
9
commits into
master
Choose a base branch
from
alabaster-stetson
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.
Draft
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
03c4293
feat(linter): add initial oxlint plugin, docs, and e2e coverage
juristr 7843952
fix(linter): export package.json for @nx/oxlint
juristr e334939
fix(linter): run inferred oxlint targets from workspace root
juristr c9172d5
fix(linter): fix oxlint docs, broken links, and executor schema
juristr 854bea0
fix(linter): ensure eslint-plugin is built before linting oxlint package
juristr abdd131
docs(core): update module boundary rules with oxlint options
juristr 374ff46
docs(core): update module boundary rules with oxlint options
juristr b05843a
chore(linter): move oxlint plugin implementation to nx-labs
juristr 6cf9a90
chore(linter): move oxlint plugin implementation to nx-labs
nx-cloud[bot] 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 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
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
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,9 @@ | ||
| --- | ||
| title: OXLint | ||
| description: OXLint guides and best practices for Nx workspaces | ||
| sidebar: | ||
| hidden: true | ||
| pagefind: false | ||
| --- | ||
|
|
||
| {% sidebar_group_cards group="Knowledge Base/OXLint" /%} |
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,9 @@ | ||
| --- | ||
| title: OXLint | ||
| sidebar: | ||
| hidden: true | ||
| description: Guides and API references for OXLint in Nx | ||
| pagefind: false | ||
| --- | ||
|
|
||
| {% index_page_cards path="technologies/oxlint" /%} |
111 changes: 111 additions & 0 deletions
111
astro-docs/src/content/docs/technologies/oxlint/introduction.mdoc
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,111 @@ | ||
| --- | ||
| title: OXLint Plugin for Nx | ||
| description: Learn how to set up and use the @nx/oxlint plugin with inferred tasks, hybrid migration, and experimental module-boundary enforcement. | ||
| sidebar: | ||
| label: Introduction | ||
| filter: 'type:References' | ||
| --- | ||
|
|
||
| The `@nx/oxlint` plugin integrates [OXLint](https://oxc.rs/docs/guide/usage/linter/) with Nx for fast lint execution in monorepos. | ||
|
|
||
| ## Experimental status | ||
|
|
||
| {% aside type="note" title="Experimental" %} | ||
| `@nx/oxlint` and the OXLint JS-plugin boundary bridge are experimental. | ||
| The feature set may evolve quickly while OXLint JS plugins are still stabilizing. | ||
| {% /aside %} | ||
|
|
||
| ## Setup | ||
|
|
||
| Install the plugin: | ||
|
|
||
| ```shell | ||
| nx add @nx/oxlint | ||
| ``` | ||
|
|
||
| This registers `@nx/oxlint/plugin` (when inference plugins are enabled), installs `oxlint`, and creates a root `.oxlintrc.json` if needed. | ||
|
|
||
| ## Inferred tasks | ||
|
|
||
| `@nx/oxlint/plugin` infers tasks from OXLint config files: | ||
|
|
||
| - `.oxlintrc.json` | ||
| - `.oxlintrc.jsonc` | ||
| - `oxlint.config.ts` | ||
|
|
||
| The plugin infers command-based targets and configures caching using Nx inputs. | ||
|
|
||
| You can view inferred tasks with: | ||
|
|
||
| ```shell | ||
| nx show project my-project --web | ||
| ``` | ||
|
|
||
| ## Target naming in hybrid workspaces | ||
|
|
||
| For mixed ESLint + OXLint workspaces, Nx attempts to avoid target collisions. | ||
| When adding the plugin, it tries target names in this order: | ||
|
|
||
| 1. `lint` | ||
| 2. `oxlint` | ||
| 3. `oxlint:lint` | ||
| 4. `oxlint-lint` | ||
|
|
||
| This enables incremental migration without removing ESLint. | ||
|
|
||
| ## Explicit target fallback | ||
|
|
||
| If `useInferencePlugins` is disabled, use explicit targets with `@nx/oxlint:lint`: | ||
|
|
||
| ```json | ||
| { | ||
| "targets": { | ||
| "oxlint": { | ||
| "executor": "@nx/oxlint:lint", | ||
| "options": { | ||
| "lintFilePatterns": ["{projectRoot}"] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Hybrid migration from ESLint | ||
|
|
||
| Use the migration helper to register OXLint while keeping ESLint targets intact: | ||
|
|
||
| ```shell | ||
| nx g @nx/oxlint:convert-from-eslint | ||
| ``` | ||
|
|
||
| By default this adds an `oxlint` target per converted project and leaves existing ESLint configuration untouched. | ||
|
|
||
| For hybrid setups that still run ESLint for some checks, you can optionally use `eslint-plugin-oxlint` to reduce overlap while migrating. | ||
|
|
||
| ## Experimental module boundaries bridge | ||
|
|
||
| `@nx/oxlint` exposes an experimental JS-plugin bridge at `@nx/oxlint/boundaries-plugin`. | ||
| It reuses Nx project-graph-aware `enforce-module-boundaries` logic from `@nx/eslint-plugin`. | ||
|
|
||
| Example config snippet: | ||
|
|
||
| ```json | ||
| { | ||
| "jsPlugins": [ | ||
| { | ||
| "name": "@nx", | ||
| "specifier": "@nx/oxlint/boundaries-plugin" | ||
| } | ||
| ], | ||
| "rules": { | ||
| "@nx/enforce-module-boundaries": [ | ||
| "error", | ||
| { | ||
| "depConstraints": [] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| This path is intended for early adopters and may change. |
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
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,13 @@ | ||
| /* eslint-disable */ | ||
| module.exports = { | ||
| transform: { | ||
| '^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }], | ||
| }, | ||
| moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], | ||
| maxWorkers: 1, | ||
| globals: {}, | ||
| globalSetup: '../utils/global-setup.ts', | ||
| globalTeardown: '../utils/global-teardown.ts', | ||
| displayName: 'e2e-oxlint', | ||
| preset: '../jest.preset.e2e.js', | ||
| }; |
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,8 @@ | ||
| { | ||
| "name": "@nx/e2e-oxlint", | ||
| "version": "0.0.1", | ||
| "private": true, | ||
| "dependencies": { | ||
| "@nx/e2e-utils": "workspace:*" | ||
| } | ||
| } |
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,9 @@ | ||
| { | ||
| "name": "e2e-oxlint", | ||
| "$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
| "sourceRoot": "e2e/oxlint", | ||
| "projectType": "application", | ||
| "implicitDependencies": ["oxlint"], | ||
| "// targets": "to see all targets run: nx show project e2e-oxlint --web", | ||
| "targets": {} | ||
| } |
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,162 @@ | ||
| import { | ||
| cleanupProject, | ||
| newProject, | ||
| readJson, | ||
| runCLI, | ||
| uniq, | ||
| updateFile, | ||
| updateJson, | ||
| } from '@nx/e2e-utils'; | ||
|
|
||
| describe('OXLint', () => { | ||
| const explicitLib = uniq('mylib-explicit'); | ||
| const inferredLib = uniq('mylib-inferred'); | ||
| const inferredViteLib = uniq('mylib-inferred-vite'); | ||
| const hybridLib = uniq('mylib-hybrid'); | ||
|
|
||
| beforeAll(() => { | ||
| newProject({ | ||
| packages: ['@nx/js', '@nx/oxlint'], | ||
| }); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| cleanupProject(); | ||
| }); | ||
|
|
||
| it('should add explicit fallback target when inference is disabled', () => { | ||
| updateJson('nx.json', (json) => { | ||
| json.useInferencePlugins = false; | ||
| return json; | ||
| }); | ||
|
|
||
| runCLI(`generate @nx/js:lib libs/${explicitLib} --linter none`); | ||
| runCLI(`generate @nx/oxlint:lint-project --project ${explicitLib}`); | ||
|
|
||
| const project = readJson(`libs/${explicitLib}/project.json`); | ||
| expect(project.targets.oxlint.executor).toBe('@nx/oxlint:lint'); | ||
| }); | ||
|
|
||
| it('should report lint failures with @nx/oxlint:lint', () => { | ||
| updateFile( | ||
| `.oxlintrc.json`, | ||
| JSON.stringify( | ||
| { | ||
| rules: { | ||
| eqeqeq: 'error', | ||
| }, | ||
| }, | ||
| null, | ||
| 2 | ||
| ) | ||
| ); | ||
|
|
||
| updateFile( | ||
| `libs/${explicitLib}/src/lib/${explicitLib}.ts`, | ||
| 'export const bad = (a: number) => a == 1;\n' | ||
| ); | ||
|
|
||
| const out = runCLI(`run ${explicitLib}:oxlint`, { | ||
| silenceError: true, | ||
| env: { CI: 'false' }, | ||
| }); | ||
|
|
||
| expect(out).toContain('eqeqeq'); | ||
| }, 300000); | ||
|
|
||
| it('should infer an OXLint target when inference plugins are enabled', () => { | ||
| updateJson('nx.json', (json) => { | ||
| json.useInferencePlugins = true; | ||
| return json; | ||
| }); | ||
|
|
||
| runCLI(`generate @nx/js:lib libs/${inferredLib} --linter none`); | ||
| runCLI(`generate @nx/oxlint:init --addPlugin`); | ||
|
|
||
| const nxJson = readJson('nx.json'); | ||
| const plugin = nxJson.plugins.find((p) => | ||
| typeof p === 'string' | ||
| ? p === '@nx/oxlint/plugin' | ||
| : p.plugin === '@nx/oxlint/plugin' | ||
| ); | ||
| const targetName = | ||
| typeof plugin === 'string' | ||
| ? 'oxlint' | ||
| : (plugin.options?.targetName ?? 'oxlint'); | ||
|
|
||
| const project = JSON.parse(runCLI(`show project ${inferredLib} --json`)); | ||
| expect(project.targets[targetName]).toBeDefined(); | ||
| }, 300000); | ||
|
|
||
| it('should run inferred target from workspace root and avoid loading project vite config', () => { | ||
| updateJson('nx.json', (json) => { | ||
| json.useInferencePlugins = true; | ||
| return json; | ||
| }); | ||
|
|
||
| runCLI(`generate @nx/js:lib libs/${inferredViteLib} --linter none`); | ||
| runCLI(`generate @nx/oxlint:init --addPlugin`); | ||
|
|
||
| updateFile( | ||
| `libs/${inferredViteLib}/vite.config.ts`, | ||
| 'export default { lint: { paths: [__dirname] } };' | ||
| ); | ||
|
|
||
| const nxJson = readJson('nx.json'); | ||
| const plugin = nxJson.plugins.find((p) => | ||
| typeof p === 'string' | ||
| ? p === '@nx/oxlint/plugin' | ||
| : p.plugin === '@nx/oxlint/plugin' | ||
| ); | ||
| const targetName = | ||
| typeof plugin === 'string' | ||
| ? 'oxlint' | ||
| : (plugin.options?.targetName ?? 'oxlint'); | ||
|
|
||
| const project = JSON.parse( | ||
| runCLI(`show project ${inferredViteLib} --json`) | ||
| ); | ||
| expect(project.targets[targetName].options.command).toBe( | ||
| `oxlint libs/${inferredViteLib}` | ||
| ); | ||
| expect(() => | ||
| runCLI(`run ${inferredViteLib}:${targetName}`, { | ||
| env: { CI: 'false' }, | ||
| }) | ||
| ).not.toThrow(); | ||
| }, 300000); | ||
|
|
||
| it('should cache repeated OXLint runs', () => { | ||
| updateFile( | ||
| `libs/${explicitLib}/src/lib/${explicitLib}.ts`, | ||
| 'export const good = (a: number) => a === 1;\n' | ||
| ); | ||
|
|
||
| runCLI(`run ${explicitLib}:oxlint --verbose`, { | ||
| env: { CI: 'false' }, | ||
| }); | ||
|
|
||
| const out = runCLI(`run ${explicitLib}:oxlint --verbose`, { | ||
| env: { CI: 'false' }, | ||
| }); | ||
|
|
||
| expect(out).toMatch( | ||
| /local cache|remote cache|existing outputs match the cache/ | ||
| ); | ||
| }, 300000); | ||
|
|
||
| it('should keep eslint lint target and add oxlint target in hybrid migration', () => { | ||
| updateJson('nx.json', (json) => { | ||
| json.useInferencePlugins = false; | ||
| return json; | ||
| }); | ||
|
|
||
| runCLI(`generate @nx/js:lib libs/${hybridLib} --linter eslint`); | ||
| runCLI(`generate @nx/oxlint:convert-from-eslint --project ${hybridLib}`); | ||
|
|
||
| const project = readJson(`libs/${hybridLib}/project.json`); | ||
| expect(project.targets.lint).toBeDefined(); | ||
| expect(project.targets.oxlint).toBeDefined(); | ||
| expect(project.targets.oxlint.executor).toBe('@nx/oxlint:lint'); | ||
| }, 300000); | ||
| }); |
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,16 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "types": ["node", "jest"] | ||
| }, | ||
| "include": [], | ||
| "files": [], | ||
| "references": [ | ||
| { | ||
| "path": "../utils" | ||
| }, | ||
| { | ||
| "path": "./tsconfig.spec.json" | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.