L1-L4 語法和結構驗證 - 檢查 Python 語法、AST 結構、縮進格式、命名規範。 BlueMouse 17-Layer Validation Group 1。 Triggers: "syntax", "格式檢查", "naming", "PEP8"
BlueMouse 17-Layer Validation System - Group 1: 語法和結構驗證
Follow the checklist below to analyze code.
python3 .claude/skills/validate-syntax/validator.py myfile.py
python3 .claude/skills/validate-syntax/validator.py --json myfile.py
What: Code compiles without syntax errors
How:
compile(code, '<string>', 'exec')
Pass: No SyntaxError raised
Fail: Report error: "語法錯誤: {error_message}"
What: Code contains at least one function or class definition
How:
tree = ast.parse(code)
has_definition = any(
isinstance(node, (ast.FunctionDef, ast.ClassDef))
for node in ast.walk(tree)
)
Pass: has_definition == True
Fail: "缺少函數或類定義"
What: Proper indentation format
Rules:
\t) anywhereHow:
for i, line in enumerate(lines, 1):
if '\t' in line:
issues.append(f"Line {i}: 使用 Tab 而非空格")
leading_spaces = len(line) - len(line.lstrip())
if leading_spaces % 4 != 0:
issues.append(f"Line {i}: 縮進不是 4 的倍數")
Pass: No issues found
Fail: "發現 N 個格式問題" + list first 3 issues
Examples:
# ✅ PASS: 4-space indentation
def foo():
if True:
return 1
# ❌ FAIL: Tab character
def foo():
return 1 # Uses tab
# ❌ FAIL: 2-space indentation
def foo():
return 1 # 2 spaces, not multiple of 4
What: PEP 8 naming conventions
Rules:
| Type | Convention | Regex |
|------|------------|-------|
| Functions | snake_case | ^[a-z_][a-z0-9_]*$ |
| Classes | PascalCase | ^[A-Z][a-zA-Z0-9]*$ |
How:
for node in ast.walk(tree):
if isinstance(node, ast.FunctionDef):
if not re.match(r'^[a-z_][a-z0-9_]*$', node.name):
issues.append(f"函數名 '{node.name}' 不符合 snake_case")
if isinstance(node, ast.ClassDef):
if not re.match(r'^[A-Z][a-zA-Z0-9]*$', node.name):
issues.append(f"類名 '{node.name}' 不符合 PascalCase")
Pass: All names follow conventions → "命名符合 PEP 8"
Fail: "發現 N 個命名問題" + list issues
Examples:
# ✅ PASS
def calculate_total(): # snake_case
pass
class UserManager: # PascalCase
pass
# ❌ FAIL
def CalculateTotal(): # Should be snake_case
pass
class user_manager: # Should be PascalCase
pass
==================================================
L1-L4: 語法和結構驗證
==================================================
Status: ✅ PASSED / ❌ FAILED
Score: X/100 (N/4 layers)
✅/❌ L1: 基本語法檢查 - [message]
✅/❌ L2: AST 結構檢查 - [message]
✅/❌ L3: 縮進和格式檢查 - [message]
✅/❌ L4: 命名規範檢查 - [message]
| Skill | Layers |
|-------|--------|
| /validate-17-layers | L1-L17 (完整) |
| /validate-syntax | L1-L4 |
| /validate-signature | L5-L8 |
| /validate-dependencies | L9-L12 |
| /validate-logic | L13-L17 |
Part of BlueMouse 17-Layer Validation System
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer