linter-autofix

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Linter Autofix Patterns

代码检查器自动修复模式

Quick reference for running linter autofixes across languages.
跨语言运行代码检查器自动修复的速查指南。

Autofix Commands

自动修复命令

LanguageLinterAutofix Command
TypeScript/JSbiome
npx @biomejs/biome check --write .
TypeScript/JSbiome format
npx @biomejs/biome format --write .
Pythonruff
ruff check --fix .
Pythonruff format
ruff format .
Rustclippy
cargo clippy --fix --allow-dirty
Rustrustfmt
cargo fmt
Gogofmt
gofmt -w .
Gogo mod
go mod tidy
ShellshellcheckNo autofix (manual only)
语言Linter自动修复命令
TypeScript/JSbiome
npx @biomejs/biome check --write .
TypeScript/JSbiome format
npx @biomejs/biome format --write .
Pythonruff
ruff check --fix .
Pythonruff format
ruff format .
Rustclippy
cargo clippy --fix --allow-dirty
Rustrustfmt
cargo fmt
Gogofmt
gofmt -w .
Gogo mod
go mod tidy
Shellshellcheck无自动修复(仅支持手动修复)

Common Fix Patterns

常见修复模式

JavaScript/TypeScript (Biome)

JavaScript/TypeScript (Biome)

Unused imports
typescript
// Before
import { useState, useEffect, useMemo } from 'react';
// Only useState used

// After
import { useState } from 'react';
Prefer const
typescript
// Before
let x = 5;  // Never reassigned

// After
const x = 5;
未使用的导入
typescript
// Before
import { useState, useEffect, useMemo } from 'react';
// Only useState used

// After
import { useState } from 'react';
优先使用const
typescript
// Before
let x = 5;  // Never reassigned

// After
const x = 5;

Python (Ruff)

Python (Ruff)

Import sorting (I001)
python
undefined
导入排序(I001)
python
undefined

Before

Before

import os from typing import List import sys
import os from typing import List import sys

After

After

import os import sys from typing import List

**Unused imports (F401)**
```python
import os import sys from typing import List

**未使用的导入(F401)**
```python

Before

Before

import os import sys # unused
import os import sys # unused

After

After

import os

**Line too long (E501)**
```python
import os

**行过长(E501)**
```python

Before

Before

result = some_function(very_long_argument_one, very_long_argument_two, very_long_argument_three)
result = some_function(very_long_argument_one, very_long_argument_two, very_long_argument_three)

After

After

result = some_function( very_long_argument_one, very_long_argument_two, very_long_argument_three, )
undefined
result = some_function( very_long_argument_one, very_long_argument_two, very_long_argument_three, )
undefined

Rust (Clippy)

Rust (Clippy)

Redundant clone
rust
// Before
let s = String::from("hello").clone();

// After
let s = String::from("hello");
Use if let
rust
// Before
match option {
    Some(x) => do_something(x),
    None => {},
}

// After
if let Some(x) = option {
    do_something(x);
}
冗余克隆
rust
// Before
let s = String::from("hello").clone();

// After
let s = String::from("hello");
使用if let语法
rust
// Before
match option {
    Some(x) => do_something(x),
    None => {},
}

// After
if let Some(x) = option {
    do_something(x);
}

Shell (ShellCheck)

Shell (ShellCheck)

Quote variables (SC2086)
bash
undefined
变量加引号(SC2086)
bash
undefined

Before

Before

echo $variable
echo $variable

After

After

echo "$variable"

**Use $(...) instead of backticks (SC2006)**
```bash
echo "$variable"

**使用$(...)替代反引号(SC2006)**
```bash

Before

Before

result=
command
result=
command

After

After

result=$(command)
undefined
result=$(command)
undefined

Quick Autofix (Recommended)

快速自动修复(推荐)

Auto-detect project linters and run all appropriate fixers in one command:
bash
undefined
自动检测项目中的代码检查器,一键运行所有适用的修复工具:
bash
undefined

Fix mode: detect linters and apply all autofixes

修复模式:检测代码检查器并应用所有自动修复

bash "${CLAUDE_PLUGIN_ROOT}/skills/linter-autofix/scripts/detect-and-fix.sh"
bash "${CLAUDE_PLUGIN_ROOT}/skills/linter-autofix/scripts/detect-and-fix.sh"

Check-only mode: report issues without fixing

仅检查模式:报告问题但不修复

bash "${CLAUDE_PLUGIN_ROOT}/skills/linter-autofix/scripts/detect-and-fix.sh" --check-only

The script detects biome, eslint, prettier, ruff, black, clippy, rustfmt, gofmt, golangci-lint, and shellcheck. It reports which linters were found, runs them, and shows modified files. See [scripts/detect-and-fix.sh](scripts/detect-and-fix.sh) for details.
bash "${CLAUDE_PLUGIN_ROOT}/skills/linter-autofix/scripts/detect-and-fix.sh" --check-only

该脚本可检测biome、eslint、prettier、ruff、black、clippy、rustfmt、gofmt、golangci-lint及shellcheck。它会报告已找到的检查器、运行修复并显示修改的文件。详情请查看[scripts/detect-and-fix.sh](scripts/detect-and-fix.sh)。

Manual Workflow

手动工作流

  1. Run autofix first:
    ruff check --fix . && ruff format .
  2. Check remaining issues:
    ruff check .
  3. Manual fixes for complex cases
  4. Verify: re-run linter to confirm clean
  1. 先运行自动修复:
    ruff check --fix . && ruff format .
  2. 检查剩余问题:
    ruff check .
  3. 对复杂情况进行手动修复
  4. 验证:重新运行检查器确认无问题

When to Escalate

何时需改用其他方法

Stop and use different approach when:
  • Fix requires understanding business logic
  • Multiple files need coordinated changes
  • Warning indicates potential bug (not just style)
  • Security-related linter rule
  • Type error requires interface/API changes
出现以下情况时,请停止当前操作并更换方法:
  • 修复需要理解业务逻辑
  • 多个文件需要协同修改
  • 警告提示潜在bug(而非仅样式问题)
  • 与安全相关的检查器规则
  • 类型错误需要修改接口/API