Skip to content

refactor: Use inline eslint called#15

Merged
zombieJ merged 3 commits into
mainfrom
strict
Mar 27, 2025
Merged

refactor: Use inline eslint called#15
zombieJ merged 3 commits into
mainfrom
strict

Conversation

@zombieJ

@zombieJ zombieJ commented Mar 27, 2025

Copy link
Copy Markdown
Member

antd 用的 eslint 9 会导致配置冲突启动不起来,改成 plugin 自带 eslint module 进行检查。

Summary by CodeRabbit

  • Chores

    • 更新了构建配置和依赖管理,实现了更精准的 TypeScript 检查和环境变量控制。
    • 调整了项目配置策略,从目标版本转为插件机制,提高了集成灵活性。
  • Refactor

    • 改进了代码中 lint 检查的流程,提供了更清晰、彩色化的错误提示,便于快速识别问题。

@coderabbitai

coderabbitai Bot commented Mar 27, 2025

Copy link
Copy Markdown

Walkthrough

本次 PR 主要更新了项目配置和构建脚本,同时重构了 ESLint 检测逻辑。在 .fatherrc.ts 中移除了基于 targets 的配置,改为使用基于插件的方式来处理路径解析。在 package.json 中,更新了构建脚本以运用 cross-env 设置环境变量,并添加了 ESLint 及其相关依赖项。在 src/index.ts 中,引入了 ESLint API 及 chalk 库,替换了之前通过命令行执行 ESLint 的方式,使错误处理与日志输出更为清晰,并引入环境变量判断。

Changes

文件 变更摘要
.fatherrc.ts 移除 targets 对象;新增 plugins 数组,使用 path.resolve(__dirname, 'src') 进行路径解析。
package.json 更新 build 脚本:由 "father build" 改为 "cross-env CHECK_TS_ONLY=1 father build";添加依赖项:@typescript-eslint/eslint-plugin@typescript-eslint/parserchalkeslint;在开发依赖中添加 @types/eslint@types/fs-extra,并将原 eslint 替换为 cross-env
src/index.ts 引入 ESLint API (import { ESLint } from 'eslint') 及 chalk 库;重构 linting 逻辑,移除 execSync 调用,使用 ESLint 检查错误,若检测到错误则格式化输出并调用 process.exit(1);增加环境变量 CHECK_TS_ONLY 的判断。

Sequence Diagram(s)

sequenceDiagram
    participant B as 构建脚本
    participant I as src/index.ts
    participant ESL as ESLint

    B->>I: 调用构建流程
    I->>ESL: 实例化 ESLint 进行检测
    ESL-->>I: 返回检测结果
    alt 检测到错误
        I->>B: 使用 chalk 输出错误日志
        I->>B: 调用 process.exit(1) 终止构建
    else 无错误
        I->>B: 正常继续构建流程
    end
Loading

Possibly related PRs

Poem

我是一只小兔子 🐰,快乐跳跃在代码林间。
旧 targets 已随风而去,
插件点亮崭新路径。
ESLint 查错如晨曦,
彩色日志绘就美丽篇。
伴我前行,代码飞扬!

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@socket-security

Copy link
Copy Markdown

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@types/eslint@8.56.12 None +1 219 kB types
npm/@types/fs-extra@11.0.4 None +3 126 kB types
npm/@typescript-eslint/eslint-plugin@8.28.0 Transitive: environment, filesystem +18 25.4 MB
npm/@typescript-eslint/parser@8.28.0 Transitive: environment, filesystem +14 24.4 MB jameshenry
npm/cross-env@7.0.3 environment Transitive: filesystem, shell +1 45.2 kB kentcdodds

View full report↗︎

Comment thread .fatherrc.ts
targets: {
chrome: 85,
},
plugins: [path.resolve(__dirname, 'src')],

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是当前 plugin 自己用的 father 配置,和消费侧没关系

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/index.ts (1)

57-105: 收集并格式化 ESLint 错误信息的逻辑清晰,但可考虑完善提示。
建议在输出时附带具体规则名称(如 message.ruleId),方便定位问题。若希望改善可读性,亦可考虑按文件合并错误输出,减少冗余信息。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc2cb3a and 1ebae06.

📒 Files selected for processing (3)
  • .fatherrc.ts (1 hunks)
  • package.json (2 hunks)
  • src/index.ts (3 hunks)
🔇 Additional comments (10)
.fatherrc.ts (2)

2-2: 在配置文件中引入 path 模块是必要的操作。
此处引入 path 用于后续解析路径,逻辑正确,无需额外修改。


6-6: 插件配置看起来简洁有效。
通过 path.resolve(__dirname, 'src')src 目录作为插件来源,能够与 father 进行集成,无明显问题。

src/index.ts (4)

1-2: 导入 chalkESLint 符合新上线的 ESLint API 用法。
对输出进行着色和使用 ESLint 的方式都不错,保持现状即可。


24-25: 在构建开始时打印提示信息,有助于开发者注意到 TS 导出检查流程。
此处仅输出文案,无任何副作用,保持即可。


109-129: 仅在未设置 CHECK_TS_ONLY 时才修改默认配置,思路合理。
这样可以在不同环境下灵活控制构建行为,避免影响纯类型检查流程。


40-55:

Details

✅ Verification successful

初始化 ESLint 实例时需确认 tsconfig 是否配合正常使用。
如果项目内缺少 tsconfig.json 或配置不正确,可能导致解析错误。请确认此文件存在并有效。


🏁 Script executed:

#!/bin/bash
# 检查仓库中是否存在名为 tsconfig.json 的文件
fd tsconfig.json

Length of output: 32


确保 tsconfig 存在且正确配置
已通过验证脚本确认仓库根目录下存在 tsconfig.json 文件。在初始化 ESLint 实例时,请确保该文件的配置与项目要求相符,以避免可能的解析错误。如果有必要,请再检查文件内容是否符合预期。

package.json (4)

13-13: 通过 cross-env 设置 CHECK_TS_ONLY 环境变量简化了脚本写法。
该方式在跨平台场景下更兼容,满足了一键执行的需求。


38-41: 新增 ESLint、TypeScript ESLint 插件及 chalk 有助于改进代码质量和可读性。
引用版本相对新,功能较稳定,可继续保持。


47-48: 类型声明的引入可进一步提升 TypeScript 对 fs-extra 和 ESLint 的支持。
能减少潜在的类型错误与兼容问题,值得保留。


50-50: cross-env 作为开发依赖可以确保本地和 CI 环境一致。
有助于自动化脚本运行,无需额外调整。

@zombieJ zombieJ merged commit 21865a5 into main Mar 27, 2025
@zombieJ zombieJ deleted the strict branch March 27, 2025 08:14
zombieJ added a commit that referenced this pull request Apr 7, 2025
* revert: antd support

* chore: update config

* chore: update version
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.

1 participant