mirror of
https://github.com/Minidoracat/mcp-feedback-enhanced.git
synced 2025-07-27 10:42:25 +08:00
✅ 增加程式碼自動檢查和 make 命令
This commit is contained in:
parent
a2d4180cf6
commit
50dbcc6e31
102
.pre-commit-config.yaml
Normal file
102
.pre-commit-config.yaml
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
# Pre-commit hooks configuration for mcp-feedback-enhanced
|
||||||
|
# See https://pre-commit.com for more information
|
||||||
|
# See https://pre-commit.com/hooks.html for more hooks
|
||||||
|
|
||||||
|
repos:
|
||||||
|
# 通用檔案檢查
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v5.0.0
|
||||||
|
hooks:
|
||||||
|
# 移除行尾空白
|
||||||
|
- id: trailing-whitespace
|
||||||
|
args: [--markdown-linebreak-ext=md]
|
||||||
|
# 確保檔案以換行符結尾
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
# 檢查合併衝突標記
|
||||||
|
- id: check-merge-conflict
|
||||||
|
# 檢查 YAML 語法
|
||||||
|
- id: check-yaml
|
||||||
|
args: [--unsafe] # 允許自定義 YAML 標籤
|
||||||
|
# 檢查 TOML 語法
|
||||||
|
- id: check-toml
|
||||||
|
# 檢查 JSON 語法
|
||||||
|
- id: check-json
|
||||||
|
# 檢查是否有大檔案
|
||||||
|
- id: check-added-large-files
|
||||||
|
args: [--maxkb=1000]
|
||||||
|
# 檢查檔案名稱
|
||||||
|
- id: check-case-conflict
|
||||||
|
# 檢查可執行檔案有 shebang
|
||||||
|
- id: check-executables-have-shebangs
|
||||||
|
# 修復混合行結尾
|
||||||
|
- id: mixed-line-ending
|
||||||
|
args: [--fix=lf]
|
||||||
|
|
||||||
|
# Ruff - Python linting 和 formatting
|
||||||
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
|
rev: v0.11.12
|
||||||
|
hooks:
|
||||||
|
# Ruff linter with auto-fix
|
||||||
|
- id: ruff
|
||||||
|
args: [--fix, --exit-non-zero-on-fix]
|
||||||
|
types_or: [python, pyi]
|
||||||
|
# Ruff formatter
|
||||||
|
- id: ruff-format
|
||||||
|
types_or: [python, pyi]
|
||||||
|
|
||||||
|
# mypy - 靜態類型檢查(暫時禁用,需要修復類型問題)
|
||||||
|
# - repo: https://github.com/pre-commit/mirrors-mypy
|
||||||
|
# rev: v1.16.0
|
||||||
|
# hooks:
|
||||||
|
# - id: mypy
|
||||||
|
# additional_dependencies:
|
||||||
|
# - types-psutil
|
||||||
|
# - types-aiofiles
|
||||||
|
# args: [--config-file=pyproject.toml]
|
||||||
|
# files: ^src/
|
||||||
|
# exclude: ^tests/
|
||||||
|
|
||||||
|
# 檢查 Python 安全性問題(可選,較嚴格)
|
||||||
|
# - repo: https://github.com/PyCQA/bandit
|
||||||
|
# rev: 1.7.10
|
||||||
|
# hooks:
|
||||||
|
# - id: bandit
|
||||||
|
# args: ["-c", "pyproject.toml"]
|
||||||
|
# additional_dependencies: ["bandit[toml]"]
|
||||||
|
|
||||||
|
# 全域配置
|
||||||
|
default_language_version:
|
||||||
|
python: python3.11
|
||||||
|
|
||||||
|
# 排除的檔案和目錄
|
||||||
|
exclude: |
|
||||||
|
(?x)^(
|
||||||
|
\.git/|
|
||||||
|
\.venv/|
|
||||||
|
venv/|
|
||||||
|
build/|
|
||||||
|
dist/|
|
||||||
|
node_modules/|
|
||||||
|
\.trunk/|
|
||||||
|
\.mypy_cache/|
|
||||||
|
\.ruff_cache/|
|
||||||
|
\.pytest_cache/|
|
||||||
|
__pycache__/|
|
||||||
|
.*\.egg-info/|
|
||||||
|
tests/fixtures/.*|
|
||||||
|
scripts/.*\.js|
|
||||||
|
src/mcp_feedback_enhanced/web/static/.*
|
||||||
|
)$
|
||||||
|
|
||||||
|
# CI 配置
|
||||||
|
ci:
|
||||||
|
autofix_commit_msg: |
|
||||||
|
[pre-commit.ci] auto fixes from pre-commit.com hooks
|
||||||
|
|
||||||
|
for more information, see https://pre-commit.ci
|
||||||
|
autofix_prs: true
|
||||||
|
autoupdate_branch: ''
|
||||||
|
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
|
||||||
|
autoupdate_schedule: weekly
|
||||||
|
skip: []
|
||||||
|
submodules: false
|
144
Makefile
Normal file
144
Makefile
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
# Makefile for mcp-feedback-enhanced development
|
||||||
|
# 適用於 mcp-feedback-enhanced 專案開發
|
||||||
|
# Compatible with Windows PowerShell and Unix systems
|
||||||
|
# 兼容 Windows PowerShell 和 Unix 系統
|
||||||
|
|
||||||
|
.PHONY: help install install-dev install-hooks lint format type-check test clean pre-commit-run pre-commit-all update-deps
|
||||||
|
|
||||||
|
# 預設目標 - 顯示幫助訊息
|
||||||
|
help: ## Show this help message
|
||||||
|
@echo "Available commands:"
|
||||||
|
@echo ""
|
||||||
|
@echo " dev-setup Complete development setup"
|
||||||
|
@echo " install Install the package"
|
||||||
|
@echo " install-dev Install development dependencies"
|
||||||
|
@echo " install-hooks Install pre-commit hooks"
|
||||||
|
@echo " lint Run linting with Ruff"
|
||||||
|
@echo " lint-fix Run linting with auto-fix"
|
||||||
|
@echo " format Format code with Ruff"
|
||||||
|
@echo " format-check Check code formatting"
|
||||||
|
@echo " type-check Run type checking with mypy"
|
||||||
|
@echo " check Run all code quality checks"
|
||||||
|
@echo " check-fix Run all checks with auto-fix"
|
||||||
|
@echo " pre-commit-run Run pre-commit on staged files"
|
||||||
|
@echo " pre-commit-all Run pre-commit on all files"
|
||||||
|
@echo " pre-commit-update Update pre-commit hooks"
|
||||||
|
@echo " test Run tests"
|
||||||
|
@echo " test-cov Run tests with coverage"
|
||||||
|
@echo " test-fast Run tests without slow tests"
|
||||||
|
@echo " clean Clean up cache and temporary files"
|
||||||
|
@echo " ps-clean PowerShell version of clean (Windows)"
|
||||||
|
@echo " update-deps Update dependencies"
|
||||||
|
@echo " build Build the package"
|
||||||
|
@echo " build-check Check the built package"
|
||||||
|
@echo " bump-patch Bump patch version"
|
||||||
|
@echo " bump-minor Bump minor version"
|
||||||
|
@echo " bump-major Bump major version"
|
||||||
|
@echo " ci Simulate CI pipeline locally"
|
||||||
|
@echo " quick-check Quick check with auto-fix"
|
||||||
|
|
||||||
|
# 安裝相關命令
|
||||||
|
install: ## Install the package
|
||||||
|
uv sync
|
||||||
|
|
||||||
|
install-dev: ## Install development dependencies
|
||||||
|
uv sync --dev
|
||||||
|
|
||||||
|
install-hooks: ## Install pre-commit hooks
|
||||||
|
uv run pre-commit install
|
||||||
|
@echo "✅ Pre-commit hooks installed successfully!"
|
||||||
|
|
||||||
|
# 程式碼品質檢查命令
|
||||||
|
lint: ## Run linting with Ruff
|
||||||
|
uv run ruff check .
|
||||||
|
|
||||||
|
lint-fix: ## Run linting with auto-fix
|
||||||
|
uv run ruff check . --fix
|
||||||
|
|
||||||
|
format: ## Format code with Ruff
|
||||||
|
uv run ruff format .
|
||||||
|
|
||||||
|
format-check: ## Check code formatting
|
||||||
|
uv run ruff format . --check
|
||||||
|
|
||||||
|
type-check: ## Run type checking with mypy
|
||||||
|
uv run mypy
|
||||||
|
|
||||||
|
# 組合品質檢查命令
|
||||||
|
check: lint format-check type-check ## Run all code quality checks
|
||||||
|
|
||||||
|
check-fix: lint-fix format type-check ## Run all checks with auto-fix
|
||||||
|
|
||||||
|
# Pre-commit 相關命令
|
||||||
|
pre-commit-run: ## Run pre-commit on staged files
|
||||||
|
uv run pre-commit run
|
||||||
|
|
||||||
|
pre-commit-all: ## Run pre-commit on all files
|
||||||
|
uv run pre-commit run --all-files
|
||||||
|
|
||||||
|
pre-commit-update: ## Update pre-commit hooks
|
||||||
|
uv run pre-commit autoupdate
|
||||||
|
|
||||||
|
# 測試相關命令
|
||||||
|
test: ## Run tests
|
||||||
|
uv run pytest
|
||||||
|
|
||||||
|
test-cov: ## Run tests with coverage
|
||||||
|
uv run pytest --cov=src/mcp_feedback_enhanced --cov-report=html --cov-report=term
|
||||||
|
|
||||||
|
test-fast: ## Run tests without slow tests
|
||||||
|
uv run pytest -m "not slow"
|
||||||
|
|
||||||
|
# 維護相關命令
|
||||||
|
clean: ## Clean up cache and temporary files
|
||||||
|
@echo "Cleaning up..."
|
||||||
|
@if exist ".mypy_cache" rmdir /s /q ".mypy_cache" 2>nul || true
|
||||||
|
@if exist ".ruff_cache" rmdir /s /q ".ruff_cache" 2>nul || true
|
||||||
|
@if exist ".pytest_cache" rmdir /s /q ".pytest_cache" 2>nul || true
|
||||||
|
@if exist "htmlcov" rmdir /s /q "htmlcov" 2>nul || true
|
||||||
|
@if exist "dist" rmdir /s /q "dist" 2>nul || true
|
||||||
|
@if exist "build" rmdir /s /q "build" 2>nul || true
|
||||||
|
@find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
|
||||||
|
@find . -name "*.pyc" -delete 2>/dev/null || true
|
||||||
|
@find . -name "*.pyo" -delete 2>/dev/null || true
|
||||||
|
@find . -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
|
||||||
|
@echo "✅ Cleanup completed!"
|
||||||
|
|
||||||
|
update-deps: ## Update dependencies
|
||||||
|
uv sync --upgrade
|
||||||
|
|
||||||
|
# 建置相關命令
|
||||||
|
build: ## Build the package
|
||||||
|
uv build
|
||||||
|
|
||||||
|
build-check: ## Check the built package
|
||||||
|
uv run twine check dist/*
|
||||||
|
|
||||||
|
# 版本發布命令
|
||||||
|
bump-patch: ## Bump patch version
|
||||||
|
uv run bump2version patch
|
||||||
|
|
||||||
|
bump-minor: ## Bump minor version
|
||||||
|
uv run bump2version minor
|
||||||
|
|
||||||
|
bump-major: ## Bump major version
|
||||||
|
uv run bump2version major
|
||||||
|
|
||||||
|
# 開發工作流程
|
||||||
|
dev-setup: install-dev install-hooks ## Complete development setup
|
||||||
|
@echo "🎉 Development environment setup complete!"
|
||||||
|
@echo ""
|
||||||
|
@echo "Next steps:"
|
||||||
|
@echo " 1. Run 'make check' to verify everything works"
|
||||||
|
@echo " 2. Start coding! Pre-commit hooks will run automatically"
|
||||||
|
@echo " 3. Use 'make help' to see all available commands"
|
||||||
|
|
||||||
|
# CI 流程模擬
|
||||||
|
ci: clean install-dev pre-commit-all test ## Simulate CI pipeline locally
|
||||||
|
|
||||||
|
# 快速開發命令
|
||||||
|
quick-check: lint-fix format type-check ## Quick check with auto-fix (recommended for development)
|
||||||
|
|
||||||
|
# Windows PowerShell 專用命令
|
||||||
|
ps-clean: ## PowerShell version of clean (Windows)
|
||||||
|
powershell -Command "Get-ChildItem -Path . -Recurse -Name '__pycache__' | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue; Get-ChildItem -Path . -Recurse -Name '*.pyc' | Remove-Item -Force -ErrorAction SilentlyContinue; @('.mypy_cache', '.ruff_cache', '.pytest_cache', 'htmlcov', 'dist', 'build') | ForEach-Object { if (Test-Path $$_) { Remove-Item $$_ -Recurse -Force } }"
|
199
pyproject.toml
199
pyproject.toml
@ -35,7 +35,8 @@ dev = [
|
|||||||
"pytest-asyncio>=0.21.0",
|
"pytest-asyncio>=0.21.0",
|
||||||
]
|
]
|
||||||
desktop = [
|
desktop = [
|
||||||
"nodejs>=16.0.0", # Node.js 環境(需要系統安裝)
|
# Node.js 環境需要系統安裝,不是 Python 套件
|
||||||
|
# 請確保系統已安裝 Node.js >= 16.0.0
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
@ -61,4 +62,200 @@ dev-dependencies = [
|
|||||||
"pytest-asyncio>=0.21.0",
|
"pytest-asyncio>=0.21.0",
|
||||||
"pytest-timeout>=2.1.0",
|
"pytest-timeout>=2.1.0",
|
||||||
"twine>=6.1.0",
|
"twine>=6.1.0",
|
||||||
|
"ruff>=0.11.0",
|
||||||
|
"mypy>=1.16.0",
|
||||||
|
"pre-commit>=4.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# ===== Ruff 配置 =====
|
||||||
|
[tool.ruff]
|
||||||
|
# 目標 Python 版本
|
||||||
|
target-version = "py311"
|
||||||
|
|
||||||
|
# 程式碼行長度
|
||||||
|
line-length = 88
|
||||||
|
|
||||||
|
# 包含的檔案模式
|
||||||
|
include = ["*.py", "*.pyi", "**/pyproject.toml"]
|
||||||
|
|
||||||
|
# 排除的檔案和目錄
|
||||||
|
exclude = [
|
||||||
|
".bzr",
|
||||||
|
".direnv",
|
||||||
|
".eggs",
|
||||||
|
".git",
|
||||||
|
".git-rewrite",
|
||||||
|
".hg",
|
||||||
|
".mypy_cache",
|
||||||
|
".nox",
|
||||||
|
".pants.d",
|
||||||
|
".pytype",
|
||||||
|
".ruff_cache",
|
||||||
|
".svn",
|
||||||
|
".tox",
|
||||||
|
".venv",
|
||||||
|
"__pypackages__",
|
||||||
|
"_build",
|
||||||
|
"buck-out",
|
||||||
|
"build",
|
||||||
|
"dist",
|
||||||
|
"node_modules",
|
||||||
|
"venv",
|
||||||
|
"*.egg-info",
|
||||||
|
".trunk",
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.ruff.lint]
|
||||||
|
# 啟用的規則集
|
||||||
|
select = [
|
||||||
|
"E", # pycodestyle errors
|
||||||
|
"W", # pycodestyle warnings
|
||||||
|
"F", # Pyflakes
|
||||||
|
"I", # isort
|
||||||
|
"B", # flake8-bugbear
|
||||||
|
"C4", # flake8-comprehensions
|
||||||
|
"UP", # pyupgrade
|
||||||
|
"ARG", # flake8-unused-arguments
|
||||||
|
"C90", # mccabe
|
||||||
|
"T20", # flake8-print
|
||||||
|
"TID", # flake8-tidy-imports
|
||||||
|
"ICN", # flake8-import-conventions
|
||||||
|
"RET", # flake8-return
|
||||||
|
"SIM", # flake8-simplify
|
||||||
|
"S", # bandit (安全檢查)
|
||||||
|
"A", # flake8-builtins
|
||||||
|
"COM", # flake8-commas
|
||||||
|
"PL", # Pylint
|
||||||
|
"RUF", # Ruff-specific rules
|
||||||
|
]
|
||||||
|
|
||||||
|
# 忽略的規則
|
||||||
|
ignore = [
|
||||||
|
"E501", # 行長度由 formatter 處理
|
||||||
|
"S101", # 允許使用 assert
|
||||||
|
"S603", # 允許 subprocess 調用
|
||||||
|
"S607", # 允許部分路徑執行
|
||||||
|
"PLR0913", # 允許多參數函數
|
||||||
|
"PLR0912", # 允許多分支
|
||||||
|
"PLR0911", # 允許多返回語句
|
||||||
|
"PLR2004", # 允許魔術數字
|
||||||
|
"COM812", # 避免與 formatter 衝突
|
||||||
|
"COM819", # 避免與 formatter 衝突
|
||||||
|
"T201", # 允許 print 語句(調試用)
|
||||||
|
"RUF001", # 允許全角字符(中文項目)
|
||||||
|
"RUF002", # 允許全角字符(中文項目)
|
||||||
|
"RUF003", # 允許全角字符(中文項目)
|
||||||
|
"C901", # 允許複雜函數(暫時)
|
||||||
|
"TID252", # 允許相對導入(暫時)
|
||||||
|
"E402", # 允許模組級導入不在頂部(暫時)
|
||||||
|
"F841", # 允許未使用變數(暫時)
|
||||||
|
"B007", # 允許未使用循環變數(暫時)
|
||||||
|
"SIM105", # 允許 try-except-pass(暫時)
|
||||||
|
"SIM102", # 允許嵌套 if(暫時)
|
||||||
|
"SIM103", # 允許複雜條件(暫時)
|
||||||
|
"SIM117", # 允許嵌套 with(暫時)
|
||||||
|
"RET504", # 允許不必要賦值(暫時)
|
||||||
|
"RUF005", # 允許列表連接(暫時)
|
||||||
|
"S108", # 允許臨時文件路徑(暫時)
|
||||||
|
"S110", # 允許 try-except-pass(暫時)
|
||||||
|
"E712", # 允許布林比較(暫時)
|
||||||
|
"E722", # 允許裸露 except(暫時)
|
||||||
|
]
|
||||||
|
|
||||||
|
# 每個檔案的最大複雜度
|
||||||
|
mccabe.max-complexity = 10
|
||||||
|
|
||||||
|
[tool.ruff.lint.per-file-ignores]
|
||||||
|
# 測試檔案的特殊規則
|
||||||
|
"tests/**/*.py" = [
|
||||||
|
"S101", # 測試中允許 assert
|
||||||
|
"ARG", # 測試中允許未使用參數
|
||||||
|
"FBT", # 測試中允許布林參數
|
||||||
|
"PLR2004", # 測試中允許魔術數字
|
||||||
|
"S311", # 測試中允許偽隨機生成器
|
||||||
|
]
|
||||||
|
|
||||||
|
# __init__.py 檔案的特殊規則
|
||||||
|
"__init__.py" = [
|
||||||
|
"F401", # 允許未使用的導入
|
||||||
|
]
|
||||||
|
|
||||||
|
# 腳本檔案的特殊規則
|
||||||
|
"scripts/**/*.py" = [
|
||||||
|
"T201", # 腳本中允許 print
|
||||||
|
"S602", # 腳本中允許 shell 調用
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.ruff.format]
|
||||||
|
# 使用雙引號
|
||||||
|
quote-style = "double"
|
||||||
|
|
||||||
|
# 縮排樣式
|
||||||
|
indent-style = "space"
|
||||||
|
|
||||||
|
# 跳過魔術逗號
|
||||||
|
skip-magic-trailing-comma = false
|
||||||
|
|
||||||
|
# 行結尾
|
||||||
|
line-ending = "auto"
|
||||||
|
|
||||||
|
[tool.ruff.lint.isort]
|
||||||
|
# import 排序配置
|
||||||
|
known-first-party = ["mcp_feedback_enhanced"]
|
||||||
|
force-single-line = false
|
||||||
|
lines-after-imports = 2
|
||||||
|
|
||||||
|
# ===== mypy 配置 =====
|
||||||
|
[tool.mypy]
|
||||||
|
# Python 版本
|
||||||
|
python_version = "3.11"
|
||||||
|
|
||||||
|
# 基本設定
|
||||||
|
warn_return_any = true
|
||||||
|
warn_unused_configs = true
|
||||||
|
disallow_untyped_defs = false # 漸進式啟用
|
||||||
|
disallow_incomplete_defs = false # 漸進式啟用
|
||||||
|
check_untyped_defs = true
|
||||||
|
disallow_untyped_decorators = false # 漸進式啟用
|
||||||
|
|
||||||
|
# 嚴格模式(漸進式啟用)
|
||||||
|
strict_optional = true
|
||||||
|
warn_redundant_casts = true
|
||||||
|
warn_unused_ignores = true
|
||||||
|
warn_no_return = true
|
||||||
|
warn_unreachable = true
|
||||||
|
|
||||||
|
# 錯誤格式
|
||||||
|
show_error_codes = true
|
||||||
|
show_column_numbers = true
|
||||||
|
pretty = true
|
||||||
|
|
||||||
|
# 包含和排除
|
||||||
|
files = ["src", "tests"]
|
||||||
|
exclude = [
|
||||||
|
"build/",
|
||||||
|
"dist/",
|
||||||
|
".venv/",
|
||||||
|
"venv/",
|
||||||
|
".trunk/",
|
||||||
|
"node_modules/",
|
||||||
|
]
|
||||||
|
|
||||||
|
# 第三方庫配置
|
||||||
|
[[tool.mypy.overrides]]
|
||||||
|
module = [
|
||||||
|
"fastmcp.*",
|
||||||
|
"mcp.*",
|
||||||
|
"psutil.*",
|
||||||
|
"uvicorn.*",
|
||||||
|
"websockets.*",
|
||||||
|
"aiohttp.*",
|
||||||
|
]
|
||||||
|
ignore_missing_imports = true
|
||||||
|
|
||||||
|
# 測試檔案的寬鬆配置
|
||||||
|
[[tool.mypy.overrides]]
|
||||||
|
module = "tests.*"
|
||||||
|
disallow_untyped_defs = false
|
||||||
|
disallow_incomplete_defs = false
|
||||||
|
disallow_untyped_decorators = false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user