← 中文资源

简体中文版本

本地 Lint 设置工作流

配置并在本地运行 linter,在推送到远程仓库前捕获代码质量问题。

阅读英文原文

概述

本地 Lint 设置工作流是一个初级难度的工作流。配置并在本地运行 linter,在推送到远程仓库前捕获代码质量问题。该工作流的目标是:Catch lint errors locally before they reach CI to save build time and reduce review cycles.

环境准备

执行本工作流需要以下环境:A project with a linter configured;Package manager to install dependencies;Source files to lint。请确保在开始前准备好所有必需的工具和资源,以避免中途因环境问题中断。

执行步骤

本工作流包含4个步骤。步骤1:Install linter——Install the linter and its plugins as development dependencies. 步骤2:Run lint——Execute the linter on the source directory and review the output. 步骤3:Fix issues——Address each lint error; suppress or configure rules for acceptable warnings. 步骤4:Verify clean run——Run the linter again to confirm zero errors.

验证与清理

预期结果:The linter passes with zero errors, and the configuration is saved for the team.。验证方法:Run the linter and confirm exit code 0 with no error-level issues.。清理操作:No cleanup needed; lint configuration should be committed.。estimatedMinutes 为 20 分钟。

代码示例

npx eslint src/
npx ruff check src/