fix(cli): merge root and sub-package lint configs for vp lint#1115
fix(cli): merge root and sub-package lint configs for vp lint#1115kazupon wants to merge 4 commits intovoidzero-dev:mainfrom
Conversation
✅ Deploy Preview for viteplus-preview canceled.
|
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e926afee0d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (mergedLint) { | ||
| const mergedConfigPath = writeMergedLintConfig(cwd, mergedLint); | ||
| return JSON.stringify({ | ||
| configFile: mergedConfigPath, |
There was a problem hiding this comment.
Keep fmt pointed at a config that contains fmt settings
When cwd has its own vite.config and mergedLint is produced, this branch returns configFile: mergedConfigPath, but mergedConfigPath is a JSON file written from mergedLint only. The Rust resolver reuses configFile for both vp lint and vp fmt, so vp fmt/vp check in that sub-package will be run with a config file that lacks fmt fields, causing formatter options from root/cwd vite.config to be ignored (or rejected, depending on parser behavior).
Useful? React with 👍 / 👎.
|
I think the configuration handling logic for lint and fmt should be considered clearly on the oxlint and oxfmt side first. |
Yes, and I understand that in order to do that, we need to decide how to handle the config files in Vite+ first. 🐣 In any case, I don't think we can make any code changes at this moment. Also, this approach won't be aligned with the LSP. |
|
Oxlint oxfmt handles it like so https://oxc.rs/docs/guide/usage/linter/nested-config.html |
Summary
Fixes
vp lintignoring sub-packageignorePatterns(and other lint config overrides) when running in a monorepo sub-package.resolves #997
Root Cause
vp lintalways resolved the vite config from the workspace root, regardless of the current working directory.When a sub-package defined its own
vite.config.tswithlint.ignorePatterns, it was never read, oxlint only received the root's config via-c.Fix
When
cwddiffers from the workspace root and the sub-package has its ownvite.config.ts, both configs are resolved and merged.The root config serves as the base and the sub-package config overrides specific fields (
pluginsare unioned,rules/optionsare shallow-merged with sub-package priority,ignorePatternsare fully overridden by sub-package,overridesare concatenated).The merged result is written to a fixed cache path (
node_modules/.cache/vite-plus/merged-lint-config.json) and passed to oxlint via-c.Bug flow — sub-package config ignored
sequenceDiagram participant User as User (in packages/some-package/) participant Rust as vp lint (Rust CLI) participant JS as resolveUniversalViteConfig participant Vite as Vite resolveConfig participant Oxlint as oxlint User->>Rust: vp lint Rust->>Rust: workspace_path = /root (always) Rust->>JS: resolveUniversalViteConfig("/root") JS->>Vite: resolveViteConfig("/root") Vite-->>JS: configFile: /root/vite.config.ts Note over JS: lint: { plugins: ["import"],<br/>rules: { "import/no-commonjs": "error" } }<br/>Warn: No ignorePatterns JS-->>Rust: { configFile: "/root/vite.config.ts", lint } Rust->>Oxlint: oxlint -c /root/vite.config.ts Note over Oxlint: Reads root config only<br/>Sub-package ignorePatterns never seen Oxlint-->>User: NG: import/no-commonjs error on fixture filesFix flow — configs merged
sequenceDiagram participant User as User (in packages/some-package/) participant Rust as vp lint (Rust CLI) participant JS as resolveUniversalViteConfig participant Vite as Vite resolveConfig participant Oxlint as oxlint User->>Rust: vp lint Rust->>Rust: workspace_path = /root, cwd = /root/packages/some-package Rust->>JS: resolveUniversalViteConfig(JSON) Note over Rust: {"workspacePath": "/root",<br/>"cwd": "/root/packages/some-package"} JS->>Vite: resolveViteConfig("/root") Vite-->>JS: rootLint: { plugins, rules } JS->>Vite: resolveViteConfig("/root/packages/some-package") Vite-->>JS: cwdLint: { ignorePatterns, options } JS->>JS: mergeLintConfig(rootLint, cwdLint) Note over JS: merged: { plugins, rules,<br/>ignorePatterns, options } JS->>JS: Write merged config to<br/>node_modules/.cache/vite-plus/<br/>merged-lint-config.json JS-->>Rust: { configFile: "merged-lint-config.json", lint } Rust->>Oxlint: oxlint -c merged-lint-config.json Note over Oxlint: Reads merged config<br/>ignorePatterns excludes fixtures<br/>Root rules still apply Oxlint-->>User: OK: 0 errors (fixtures excluded)Fix
When
cwddiffers from the workspace root and the sub-package has its ownvite.config.ts, both configs are resolved and merged.The root config serves as the base and the sub-package config overrides specific fields (
pluginsare unioned,rules/optionsare shallow-merged with sub-package priority,ignorePatternsare fully overridden by sub-package,overridesare concatenated).The merged result is written to a fixed cache path (
node_modules/.cache/vite-plus/merged-lint-config.json) and passed to oxlint via-c.