本站在允许 JavaScript 运行的环境下浏览效果更佳

自动追踪 Oxlint 对 ESLint 规则的新增支持

两个月前我写了一篇 ESLint 到 Oxlint 渐进式迁移快速上手指南,里面提到了 Oxlint 官方提供的迁移工具,用于将 ESLint Flat Config 配置转换为 Oxlint 配置。

几个月来 Oxlint 逐渐实现了许多原先不支持的规则,执行迁移工具时提示的 unsupported rule 逐渐减少。

为了方便自己在 Oxlint 支持新规则后能第一时间享受到,我写了一个简单的 GitHub Actions 工作流:每天自动执行迁移工具,并且在 .oxlint.json 有更新时自动 PR。

将下面内容直接复制到项目 .github/workflows/oxlint-migrate.yml 即可使用,相关说明已写在注释。

name: Oxlint Migration

on:
  schedule:
    # 每天定时运行,可根据实际修改
    - cron: '0 16 * * *'
  workflow_dispatch:  # 可手动触发

jobs:
  migrate:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - uses: pnpm/action-setup@v4
        name: Install pnpm
        with:
          run_install: false

      - name: Install Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'pnpm'

      - name: Install dependencies
        run: pnpm install

      - name: Run oxlint migration
        # 可以改成你需要的,比如 pnpm dlx @oxlint/migrate --type-aware
        # 详情参考:https://howiehz.top/archives/eslint-to-oxlint-gradual-migration-guide#%E8%87%AA%E5%8A%A8%E8%BF%81%E7%A7%BB-ESLint-%E9%85%8D%E7%BD%AE
        run: pnpm dlx @oxlint/migrate --type-aware --with-nursery
        # 我在实际使用在上一行末尾加上了自己在 package.json 里定义的格式化任务,避免格式不一致导致的意外更改,即加上“&& pnpm run format”

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v7
        with:
          token: ${{ secrets.PR_WORKFLOW_TOKEN }}
          # 创建 Fine-grained PAT:https://github.com/settings/personal-access-tokens
          # 创建项目 secrets:https://github.com/用户或组织名/仓库名/settings/secrets/actions
          # 创建一个 Fine-grained PAT 得到 token,再创建一个项目 secrets 命名为 PR_WORKFLOW_TOKEN 填入 token,就配置完毕了。
          # 使用 Fine-grained PAT 而非默认的 GITHUB_TOKEN,以便创建的 PR 能触发其他工作流,以进行其他自动检查。
          # 如不需要触发其他工作流,可以删除上一行
          # 所需权限(Fine-grained PAT):
          # - Contents: Read and Write(创建分支和提交)
          # - Pull requests: Read and Write(创建 PR)
          # - Workflows: Read and Write(允许 PR 触发工作流)
          commit-message: 'chore: update oxlint configuration'
          title: 'chore: update oxlint configuration'
          body: |
            This PR updates the oxlint configuration by running the migration tool.
            
            Generated automatically by the oxlint-migrate workflow.
          branch: chore/oxlint-migrate-${{ github.run_number }}
          delete-branch: true
          labels: dependencies
          add-paths: |
            .oxlintrc.json

欢迎评论区留言讨论🚀️。


0
上一篇 中文博客圈列表
下一篇 Halo 贡献者证书与实体周边盲盒开箱