verify-language
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLanguage-Specific Verification
语言专属验证
Purpose
用途
Verify code against language-specific best practices and idioms for Python, TypeScript/JavaScript, and Go. All analysis happens locally.
针对Python、TypeScript/JavaScript和Go,对照语言专属最佳实践与惯用写法验证代码。所有分析均在本地完成。
When to Use
适用场景
Trigger this skill when the user asks to:
- "verify agent language"
- "verify language"
- "check types"
- "check Python/TypeScript/Go code"
This skill is also auto-invoked by the main verification orchestrator based on detected language.
Note: For full verification including security, patterns, and quality checks, tell the user to say "verify agent".
当用户提出以下请求时触发此技能:
- "verify agent language"
- "verify language"
- "check types"
- "check Python/TypeScript/Go code"
基于检测到的语言,主验证编排器也会自动调用此技能。
注意: 若需包含安全、模式及质量检查的完整验证,请告知用户说 "verify agent"。
Process
流程
Step 1: Detect Language
步骤1:检测语言
Identify the primary language by checking:
| Indicator | Language |
|---|---|
| Python |
| TypeScript/JavaScript |
| Go |
| Rust |
Also check file extensions in or project root:
src/- → Python
.py - ,
.ts,.tsx,.js→ TypeScript/JavaScript.jsx - → Go
.go - → Rust
.rs
通过以下标识识别主语言:
| 标识 | 语言 |
|---|---|
| Python |
| TypeScript/JavaScript |
| Go |
| Rust |
同时检查目录或项目根目录下的文件扩展名:
src/- → Python
.py - ,
.ts,.tsx,.js→ TypeScript/JavaScript.jsx - → Go
.go - → Rust
.rs
Step 2: Run Language-Specific Checks
步骤2:执行语言专属检查
Apply checks based on detected language. Each section below is only applicable for its language.
根据检测到的语言应用对应检查。以下各部分仅适用于对应语言。
Python Checks
Python检查
[PATTERN]
Type Hints on Public Functions
[PATTERN][PATTERN]
公共函数的类型提示
[PATTERN]Flag any function in public scope (no leading ) that has parameters without type annotations.
def_Examples:
python
undefined标记所有公共作用域(无前置)中参数无类型注解的函数。
_def示例:
python
undefined⚠️ Warning - Missing type hints
⚠️ 警告 - 缺少类型提示
def get_user(user_id):
return db.find_user(user_id)
def process_items(items, filter_fn):
return [filter_fn(item) for item in items]
def get_user(user_id):
return db.find_user(user_id)
def process_items(items, filter_fn):
return [filter_fn(item) for item in items]
✅ Pass - Has type hints
✅ 通过 - 包含类型提示
def get_user(user_id: int) -> User:
return db.find_user(user_id)
def process_items(items: list[Item], filter_fn: Callable[[Item], bool]) -> list[Item]:
return [filter_fn(item) for item in items]
**Scope:**
- Public functions (no leading `_`)
- Class methods (except `__init__` can skip return type)
- Module-level functions
Severity: ⚠️ Warning
---def get_user(user_id: int) -> User:
return db.find_user(user_id)
def process_items(items: list[Item], filter_fn: Callable[[Item], bool]) -> list[Item]:
return [filter_fn(item) for item in items]
**范围:**
- 公共函数(无前置`_`)
- 类方法(`__init__`可跳过返回类型)
- 模块级函数
严重程度:⚠️ 警告
---[HEURISTIC]
Docstrings
[HEURISTIC][HEURISTIC]
文档字符串
[HEURISTIC]Check for missing docstrings:
| Location | Requirement |
|---|---|
| Module | Top-level docstring explaining purpose |
| Class | Docstring explaining class responsibility |
| Public function | Docstring explaining args, returns, raises |
Examples:
python
undefined检查缺失的文档字符串:
| 位置 | 要求 |
|---|---|
| 模块 | 说明用途的顶层文档字符串 |
| 类 | 说明类职责的文档字符串 |
| 公共函数 | 说明参数、返回值、异常的文档字符串 |
示例:
python
undefined⚠️ Warning - Missing docstrings
⚠️ 警告 - 缺少文档字符串
class UserService:
def get_user(self, user_id: int) -> User:
return self.db.find(user_id)
class UserService:
def get_user(self, user_id: int) -> User:
return self.db.find(user_id)
✅ Pass - Documented
✅ 通过 - 已添加文档
class UserService:
"""Service for user-related operations."""
def get_user(self, user_id: int) -> User:
"""
Retrieve a user by ID.
Args:
user_id: The unique identifier of the user
Returns:
User object if found
Raises:
UserNotFoundError: If user doesn't exist
"""
return self.db.find(user_id)
Severity: ⚠️ Warning
---class UserService:
"""用户相关操作服务。"""
def get_user(self, user_id: int) -> User:
"""
根据ID获取用户。
参数:
user_id: 用户的唯一标识符
返回:
找到的User对象
异常:
UserNotFoundError: 用户不存在时抛出
"""
return self.db.find(user_id)
严重程度:⚠️ 警告
---[PATTERN]
Requirements Pinning
[PATTERN][PATTERN]
依赖版本锁定
[PATTERN]Check and dependencies:
requirements.txtpyproject.toml| Pattern | Severity |
|---|---|
| ❌ Issue |
| ❌ Issue |
| ❌ Issue |
| ✅ Pass |
| ✅ Pass |
In :
pyproject.tomltoml
undefined检查和中的依赖:
requirements.txtpyproject.toml| 模式 | 严重程度 |
|---|---|
| ❌ 问题 |
| ❌ 问题 |
| ❌ 问题 |
| ✅ 通过 |
| ✅ 通过 |
pyproject.tomltoml
undefined❌ Issue
❌ 问题
[project]
dependencies = [
"langchain>=0.1.0",
"openai",
]
[project]
dependencies = [
"langchain>=0.1.0",
"openai",
]
✅ Pass
✅ 通过
[project]
dependencies = [
"langchain==0.1.0",
"openai==1.12.0",
]
Severity: ❌ Issue
---[project]
dependencies = [
"langchain==0.1.0",
"openai==1.12.0",
]
严重程度:❌ 问题
---[HEURISTIC]
Python Idioms
[HEURISTIC][HEURISTIC]
Python惯用写法
[HEURISTIC]Check for non-idiomatic patterns:
| Anti-pattern | Idiomatic |
|---|---|
| |
| |
| |
| |
| Direct dict iteration |
Severity: ⚠️ Warning
检查非惯用模式:
| 反模式 | 惯用写法 |
|---|---|
| |
| |
| |
| |
| 直接遍历字典 |
严重程度:⚠️ 警告
TypeScript/JavaScript Checks
TypeScript/JavaScript检查
[PATTERN]
Strict Mode
[PATTERN][PATTERN]
严格模式
[PATTERN]Check for strict type checking:
tsconfig.jsonjson
// ❌ Issue - Not strict
{
"compilerOptions": {
"strict": false
}
}
// ❌ Issue - Strict not set
{
"compilerOptions": {
"target": "ES2020"
}
}
// ✅ Pass
{
"compilerOptions": {
"strict": true
}
}Severity: ❌ Issue (if is or absent)
strictfalse检查中的严格类型检查配置:
tsconfig.jsonjson
// ❌ 问题 - 未启用严格模式
{
"compilerOptions": {
"strict": false
}
}
// ❌ 问题 - 未设置strict
{
"compilerOptions": {
"target": "ES2020"
}
}
// ✅ 通过
{
"compilerOptions": {
"strict": true
}
}严重程度:❌ 问题(若为或未配置)
strictfalse[PATTERN]
No any
Types
[PATTERN]any[PATTERN]
禁用any
类型
[PATTERN]anyFlag unqualified type annotations:
: anytypescript
// ⚠️ Warning
function process(data: any): any {
return data.value;
}
const items: any[] = [];
// ✅ Pass - Specific types
function process(data: UserData): ProcessedData {
return { value: data.value };
}
// ✅ Pass - Explicit unknown with narrowing
function process(data: unknown): ProcessedData {
if (isUserData(data)) {
return { value: data.value };
}
throw new Error("Invalid data");
}Severity: ⚠️ Warning
标记未限定的类型注解:
: anytypescript
// ⚠️ 警告
function process(data: any): any {
return data.value;
}
const items: any[] = [];
// ✅ 通过 - 使用特定类型
function process(data: UserData): ProcessedData {
return { value: data.value };
}
// ✅ 通过 - 显式unknown并进行类型收窄
function process(data: unknown): ProcessedData {
if (isUserData(data)) {
return { value: data.value };
}
throw new Error("Invalid data");
}严重程度:⚠️ 警告
[HEURISTIC]
Async/Await Error Handling
[HEURISTIC][HEURISTIC]
Async/Await错误处理
[HEURISTIC]Check that async functions handle errors:
typescript
// ⚠️ Warning - No error handling
async function fetchUser(id: string): Promise<User> {
const response = await fetch(`/users/${id}`);
return response.json();
}
// ✅ Pass - Has error handling
async function fetchUser(id: string): Promise<User> {
try {
const response = await fetch(`/users/${id}`);
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
return response.json();
} catch (error) {
logger.error("Failed to fetch user", { id, error });
throw new UserFetchError(id, error);
}
}Severity: ⚠️ Warning
检查异步函数是否处理错误:
typescript
// ⚠️ 警告 - 无错误处理
async function fetchUser(id: string): Promise<User> {
const response = await fetch(`/users/${id}`);
return response.json();
}
// ✅ 通过 - 包含错误处理
async function fetchUser(id: string): Promise<User> {
try {
const response = await fetch(`/users/${id}`);
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
return response.json();
} catch (error) {
logger.error("Failed to fetch user", { id, error });
throw new UserFetchError(id, error);
}
}严重程度:⚠️ 警告
[HEURISTIC]
Promise Handling
[HEURISTIC][HEURISTIC]
Promise处理
[HEURISTIC]Check for common Promise anti-patterns:
| Anti-pattern | Issue |
|---|---|
Missing | Unhandled rejection |
| Anti-pattern |
| Fire-and-forget promises | No await, no handling |
typescript
// ⚠️ Warning - No catch
fetchData().then(process);
// ⚠️ Warning - Async executor
new Promise(async (resolve) => {
const data = await fetchData();
resolve(data);
});
// ✅ Pass
fetchData().then(process).catch(handleError);
// ✅ Pass - Using async/await
const data = await fetchData();
process(data);Severity: ⚠️ Warning
检查常见的Promise反模式:
| 反模式 | 问题 |
|---|---|
缺失 | 未处理的拒绝 |
| 反模式 |
| 即发即弃的Promise | 无await,无处理 |
typescript
// ⚠️ 警告 - 无catch
fetchData().then(process);
// ⚠️ 警告 - 异步执行器
new Promise(async (resolve) => {
const data = await fetchData();
resolve(data);
});
// ✅ 通过
fetchData().then(process).catch(handleError);
// ✅ 通过 - 使用async/await
const data = await fetchData();
process(data);严重程度:⚠️ 警告
Go Checks
Go检查
[PATTERN]
No Ignored Errors
[PATTERN][PATTERN]
不忽略错误
[PATTERN]Flag any assignments where the right-hand side returns :
_ = errorgo
// ❌ Issue - Ignored error
_ = file.Close()
_ = json.Unmarshal(data, &result)
result, _ := db.Query(sql)
// ✅ Pass - Error handled
if err := file.Close(); err != nil {
log.Printf("failed to close file: %v", err)
}
result, err := db.Query(sql)
if err != nil {
return nil, fmt.Errorf("query failed: %w", err)
}Severity: ❌ Issue
标记所有右侧返回的赋值:
error_ = go
// ❌ 问题 - 忽略错误
_ = file.Close()
_ = json.Unmarshal(data, &result)
result, _ := db.Query(sql)
// ✅ 通过 - 已处理错误
if err := file.Close(); err != nil {
log.Printf("failed to close file: %v", err)
}
result, err := db.Query(sql)
if err != nil {
return nil, fmt.Errorf("query failed: %w", err)
}严重程度:❌ 问题
[HEURISTIC]
Context Propagation
[HEURISTIC][HEURISTIC]
Context传递
[HEURISTIC]Check that context.Context is passed through call chains:
go
// ⚠️ Warning - Context not passed
func ProcessData(data []byte) error {
result, err := externalAPI.Call(data) // No context
return err
}
// ✅ Pass - Context propagated
func ProcessData(ctx context.Context, data []byte) error {
result, err := externalAPI.Call(ctx, data)
return err
}Check for:
- HTTP handlers that don't use
r.Context() - Functions that call external services without context
- Long-running operations without context cancellation support
Severity: ⚠️ Warning
检查context.Context是否在调用链中传递:
go
// ⚠️ 警告 - 未传递Context
func ProcessData(data []byte) error {
result, err := externalAPI.Call(data) // 无context
return err
}
// ✅ 通过 - 已传递Context
func ProcessData(ctx context.Context, data []byte) error {
result, err := externalAPI.Call(ctx, data)
return err
}检查项:
- 未使用的HTTP处理器
r.Context() - 调用外部服务未传递context的函数
- 不支持context取消的长时间运行操作
严重程度:⚠️ 警告
[HEURISTIC]
Proper Package Structure
[HEURISTIC][HEURISTIC]
合理的包结构
[HEURISTIC]Check Go project structure:
| Issue | Description |
|---|---|
| Should split into packages |
| Circular imports | Package A imports B, B imports A |
| Internal packages exposed | Internal code in public packages |
Missing | Shared code that shouldn't be public |
Severity: ⚠️ Warning
检查Go项目结构:
| 问题 | 描述 |
|---|---|
| 应拆分为多个包 |
| 循环导入 | 包A导入B,B导入A |
| 内部包暴露 | 公共包中包含内部代码 |
缺失 | 存在不应公开的共享代码 |
严重程度:⚠️ 警告
[HEURISTIC]
Go Idioms
[HEURISTIC][HEURISTIC]
Go惯用写法
[HEURISTIC]Check for non-idiomatic patterns:
| Anti-pattern | Idiomatic |
|---|---|
| Consider helper or wrap |
| Naked returns in long functions | Explicit returns |
| Use generics or specific types |
Getters named | Just |
Severity: ⚠️ Warning
检查非惯用模式:
| 反模式 | 惯用写法 |
|---|---|
重复 | 考虑使用辅助函数或包装 |
| 长函数中使用裸返回 | 使用显式返回 |
| 使用泛型或特定类型 |
Getter命名为 | 直接命名为 |
严重程度:⚠️ 警告
Step 3: Generate Report
步骤3:生成报告
markdown
undefinedmarkdown
undefinedLanguage Verification Report
语言验证报告
Project: [name or path]
Date: [current date]
Language detected: [Python | TypeScript | JavaScript | Go]
Files analyzed: [count]
项目: [名称或路径]
日期: [当前日期]
检测到的语言: [Python | TypeScript | JavaScript | Go]
分析文件数: [数量]
Summary
摘要
✅ X checks passed | ⚠️ Y warnings | ❌ Z issues
✅ X项检查通过 | ⚠️ Y项警告 | ❌ Z项问题
Type Safety
类型安全性
- Types properly defined
- ⚠️ Missing type hints at
[file:line] - ❌ Strict mode not enabled in
tsconfig.json
- 类型定义合理
- ⚠️ 处缺失类型提示
[文件:行] - ❌ 未启用严格模式
tsconfig.json
Language Idioms
语言惯用写法
- Code follows language best practices
- ⚠️ Non-idiomatic pattern at
[file:line]
- 代码遵循语言最佳实践
- ⚠️ 处存在非惯用模式
[文件:行]
Error Handling
错误处理
- Errors properly handled
- ❌ Ignored error at
[file:line]
- 错误处理合理
- ❌ 处存在忽略错误的情况
[文件:行]
Findings
检查结果
= pattern-matched ·[P]= heuristic[H]
= 模式匹配 ·[P]= 启发式检查[H]
✅ Passing
✅ 通过项
- [Check]: [confirmation]
[P]
- [检查项]: [确认信息]
[P]
⚠️ Warnings
⚠️ 警告项
- [Check]: [description]
[P|H]- Location: [file:line]
- Language rule: [which idiom/pattern]
- Suggestion: [how to fix]
- [检查项]: [描述]
[P|H]- 位置: [文件:行]
- 语言规则: [对应惯用写法/模式]
- 建议: [修复方式]
❌ Issues
❌ 问题项
- [Check]: [description]
[P]- Location: [file:line]
- Rule: [which rule violated]
- Fix: [specific remediation]
- [检查项]: [描述]
[P]- 位置: [文件:行]
- 规则: [违反的规则]
- 修复方案: [具体整改措施]
Language-Specific Recommendations
语言专属建议
Python
Python
- Add type hints to public functions
- Include docstrings for classes and functions
- 为公共函数添加类型提示
- 为类和函数添加文档字符串
TypeScript
TypeScript
- Enable strict mode in tsconfig.json
- Replace with specific types
any
- 在tsconfig.json中启用严格模式
- 用特定类型替换
any
Go
Go
- Handle all returned errors
- Propagate context through call chains
---
*For full verification including security, patterns, and quality checks, say "verify agent".*- 处理所有返回的错误
- 在调用链中传递context
---
*若需包含安全、模式及质量检查的完整验证,请说"verify agent"。*