Skip to content

fix: support JSX in .js files for usage and lint - #241

Merged
afc163 merged 1 commit into
ant-design:mainfrom
dvd233:fix/jsx-in-js-240
Oct 28, 2026
Merged

afc163 merged 1 commit into
ant-design:mainfrom
dvd233:fix/jsx-in-js-240

Conversation

@dvd233

@dvd233 dvd233 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • retry .js files with Oxc's JSX dialect only when standard JavaScript parsing fails
  • share the fallback across antd usage and antd lint
  • preserve parse errors for files that remain invalid and document the behavior
  • add regression coverage for usage counting, lint analysis, and genuine syntax errors

Verification

  • focused regressions — 3 passed
  • remaining suite excluding three Windows-incompatible fixture files — 48 files, 638 passed, 1 skipped
  • lint suite excluding the existing unreadable-file simulation — 88 passed, 2 skipped
  • npm run typecheck
  • npm run build
  • built CLI smoke: .js JSX produced 2 usage imports and 1 a11y finding with no skipped files

Full npm test on Windows: 736 passed, 2 skipped, 5 environment-specific failures in unchanged tests (chmod(000), /tmp snapshots, and sync-token-meta tarball fixtures).

Fixes #240

AI assistance disclosure: Codex was used to trace the parser behavior, implement the fallback, and run the verification. The final diff and outputs were reviewed before submission.

Summary by CodeRabbit

  • 新功能
    • 支持在 .js 文件中识别和分析 JSX。
    • antd lint 可对包含 JSX 的 .js 文件执行规则检查。
    • 无法解析的 .js 文件会以解析错误标记并列入跳过文件列表。

@coderabbitai

coderabbitai Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 45982663-67c4-4a44-8fd7-8332d6d587fa

📥 Commits

Reviewing files that changed from the base of the PR and between bf8c683 and e523111.

📒 Files selected for processing (5)
  • spec.md
  • src/__tests__/commands/lint.test.ts
  • src/__tests__/commands/usage.test.ts
  • src/commands/lint.ts
  • src/utils/scan.ts

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

新增统一解析助手。.js 文件在标准 JavaScript 解析失败时改用 JSX 模式重试。usage 和 lint 均采用该行为,并新增成功与失败场景测试及文档说明。

Changes

.js JSX 分析

Layer / File(s) Summary
统一解析回退
src/utils/scan.ts
新增 parseSourceFile。.js 文件标准解析失败时,使用 JSX 模式重新解析。scanFile 改用该助手。
lint 解析接入
src/commands/lint.ts
lintFile 改用 parseSourceFile,并移除直接使用的 parseSync。
行为验证与文档契约
src/__tests__/commands/lint.test.ts, src/__tests__/commands/usage.test.ts, spec.md
测试覆盖 .js 中的 JSX 和真实语法错误。文档说明 usage 与 lint 的回退及 skippedFiles 行为。

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant lintFile
  participant parseSourceFile
  participant parseSync
  lintFile->>parseSourceFile: 传入 .js 文件内容
  parseSourceFile->>parseSync: 首次按 JavaScript 解析
  parseSync-->>parseSourceFile: 返回解析错误
  parseSourceFile->>parseSync: 按 JSX 模式重新解析
  parseSourceFile-->>lintFile: 返回解析结果
Loading

Suggested reviewers: afc163

Merge Risk: ⚪ Minimal · up to e5231

The JSX fallback is consistently routed through usage scanning and lint parsing, with coverage for successful JSX handling and remaining syntax errors. No merge-blocking issue is identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次变更:为 usage 和 lint 命令支持在 .js 文件中使用 JSX。标题简洁、明确,并与 PR 的主要目标一致。
Linked Issues check ✅ Passed 针对 #240,src/utils/scan.ts 新增 parseSourceFile。该函数先使用标准 JavaScript 解析,.js 文件在解析失败后使用 { lang: 'jsx' } 重试。scanFile 和 src/commands/lint.ts 共用该函数。因此,antd usage 可统计 JSX .js 文件中的组件,antd lint…
Out of Scope Changes check ✅ Passed 变更范围与 #240 直接相关。共享解析辅助函数支持 usage 和 lint,相关回归测试验证目标行为,spec.md 更新解析行为说明。未见与 JSX .js 解析、usage 统计或 lint 跳过错误无关的功能变更。
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

小兔挥耳朵,JSX 进了 .js
首次解析失败,回退来相识
usage 数组件,lint 查问题
真语法错误,仍记 parse-error
代码跑得稳,胡萝卜也欢喜

Comment @coderabbitai help to get the list of available commands.

@coderabbitai
coderabbitai Bot requested a review from afc163 September 14, 2026 21:28
@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.70%. Comparing base (973fec3) to head (e523111).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #241   +/-   ##
=======================================
  Coverage   99.70%   99.70%           
=======================================
  Files          40       40           
  Lines        2752     2757    +5     
  Branches      836      838    +2     
=======================================
+ Hits         2744     2749    +5     
  Misses          8        8           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@afc163
afc163 merged commit 4f31391 into ant-design:main Oct 28, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

usage/lint skip JSX in .js files (parse-error: Unexpected JSX expression)

2 participants