linter-autofix
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLinter Autofix Patterns
代码检查器自动修复模式
Quick reference for running linter autofixes across languages.
跨语言运行代码检查器自动修复的速查指南。
Autofix Commands
自动修复命令
| Language | Linter | Autofix Command |
|---|---|---|
| TypeScript/JS | biome | |
| TypeScript/JS | biome format | |
| Python | ruff | |
| Python | ruff format | |
| Rust | clippy | |
| Rust | rustfmt | |
| Go | gofmt | |
| Go | go mod | |
| Shell | shellcheck | No autofix (manual only) |
| 语言 | Linter | 自动修复命令 |
|---|---|---|
| TypeScript/JS | biome | |
| TypeScript/JS | biome format | |
| Python | ruff | |
| Python | ruff format | |
| Rust | clippy | |
| Rust | rustfmt | |
| Go | gofmt | |
| Go | go mod | |
| Shell | shellcheck | 无自动修复(仅支持手动修复) |
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
undefinedBefore
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)**
```pythonimport os
import sys
from typing import List
**未使用的导入(F401)**
```pythonBefore
Before
import os
import sys # unused
import os
import sys # unused
After
After
import os
**Line too long (E501)**
```pythonimport os
**行过长(E501)**
```pythonBefore
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,
)
undefinedresult = some_function(
very_long_argument_one,
very_long_argument_two,
very_long_argument_three,
)
undefinedRust (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
undefinedBefore
Before
echo $variable
echo $variable
After
After
echo "$variable"
**Use $(...) instead of backticks (SC2006)**
```bashecho "$variable"
**使用$(...)替代反引号(SC2006)**
```bashBefore
Before
result=
commandresult=
commandAfter
After
result=$(command)
undefinedresult=$(command)
undefinedQuick Autofix (Recommended)
快速自动修复(推荐)
Auto-detect project linters and run all appropriate fixers in one command:
bash
undefined自动检测项目中的代码检查器,一键运行所有适用的修复工具:
bash
undefinedFix 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
手动工作流
- Run autofix first:
ruff check --fix . && ruff format . - Check remaining issues:
ruff check . - Manual fixes for complex cases
- Verify: re-run linter to confirm clean
- 先运行自动修复:
ruff check --fix . && ruff format . - 检查剩余问题:
ruff check . - 对复杂情况进行手动修复
- 验证:重新运行检查器确认无问题
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