Skip to content

Implement policy validation engine with ESLint/Prettier integration#1

Merged
ikjeong merged 15 commits intomainfrom
feat/test-coverage
Oct 28, 2025
Merged

Implement policy validation engine with ESLint/Prettier integration#1
ikjeong merged 15 commits intomainfrom
feat/test-coverage

Conversation

@ikjeong
Copy link
Copy Markdown
Contributor

@ikjeong ikjeong commented Oct 28, 2025

Summary

Symphony CLI의 핵심 검증 시스템을 구현했습니다.
Engine 추상화 계층, 4개의 엔진(Pattern, Length, Style, AST)과 2개의 어댑터(ESLint, Prettier)를 포함하며, 언어 중립적 인터페이스와 테스트를 제공합니다.
자연어 기반 규칙, LLM 통합, 외부 도구 재활용을 목표로 설계되었습니다.

Changes

  • Engine Layer
    • Engine 인터페이스 정의 및 구현 (Pattern, Length, Style, AST)
    • Context 기반 취소, 선언적 Rule 구조 지원
    • Thread-safe Registry 시스템 추가
  • Adapter Layer
    • ESLint Adapter: Pattern/Length/Style/AST 엔진 통합
    • Prettier Adapter: 코드 포맷팅 및 자동 수정(--check, --write) 지원
  • 테스트 및 커버리지
    • 유닛 + 통합 테스트 40개 이상
    • 평균 커버리지 약 50%
    • ESLint/Prettier 기반 통합 테스트 및 샘플 코드 추가
  • 확장성
    • 새 엔진 및 언어(Python, Java 등) 추가를 위한 공통 인터페이스 및 레지스트리 등록 구조 확립
  • 향후 계획
    • Metric/Dependency/Commit 엔진 추가
    • Orchestrator 및 CLI 통합 (sym validate, sym fix, sym report)
    • MCP 서버 연동 및 CI/CD 통합 예정

- Define Engine interface with Init/Validate/GetCapabilities/Close
- Add ValidationResult, Violation, Rule types
- Add EngineCapabilities for describing engine features
- Add helper methods for safe config access (GetString, GetInt, etc.)
- Define Adapter interface for wrapping external tools
- Add CheckAvailability, Install, GenerateConfig, Execute, ParseOutput
- Add SubprocessExecutor for running tools as child processes
- Add ToolOutput and Violation types
- Adapters will wrap tools like ESLint, Prettier, etc.
- Add Registry for managing available engines
- Support lazy initialization (create on first Get)
- Thread-safe with RWMutex
- Global registry accessible via Global()
- MustRegister helper for init() registration
- Add tests for Rule helper methods (GetString, GetInt, etc.)
- Add tests for Violation.String() formatting
- Add tests for Registry (register, get, lazy init, duplicates)
- All tests passing
- Add Adapter with CheckAvailability, Install, GenerateConfig
- Support local (tools dir) and global ESLint installation
- Auto-install via npm if not found
- Add config generator for pattern/length/style rules
- Map Symphony rules to ESLint rules:
  - Pattern: id-match, no-restricted-syntax, no-restricted-imports
  - Length: max-len, max-lines, max-params, max-lines-per-function
  - Style: indent, quotes, semi
- Implement execute() to run ESLint with generated config
- Write config to temp file, execute ESLint with --format json
- Support both local (tools dir) and global ESLint
- Implement parseOutput() to convert ESLint JSON to violations
- Map ESLint severity (0/1/2) to string (info/warning/error)
Pattern Engine:
- Validates naming conventions (id-match)
- Detects forbidden patterns (no-restricted-syntax)
- Controls imports (no-restricted-imports)
- Delegates to ESLint adapter

Length Engine:
- Validates line length (max-len)
- Validates file length (max-lines)
- Validates function length (max-lines-per-function)
- Validates parameter count (max-params)
- Delegates to ESLint adapter

Both engines:
- Auto-install ESLint if not found
- Support JavaScript/TypeScript/JSX/TSX
- Filter files by language selector
- Convert adapter violations to core violations
- Add builtin.go to register engines in init()
- Add unit tests for ESLint config generation
- Add unit tests for ESLint output parsing
- All tests passing
- Add bad-naming.js with intentional violations
- Add good-code.js with correct code
- Add pattern engine integration test
- Test validates naming conventions via ESLint
- Test skips if ESLint not available
- Add Adapter with CheckAvailability, Install
- Support --check mode (validation) and --write mode (autofix)
- Generate .prettierrc.json from style rules
- Map style options: tabWidth, semi, singleQuote, trailingComma
- Parse Prettier output (file list when formatting needed)
- Auto-install via npm if not found
Style Engine:
- Validates with ESLint (indent, quotes, semi rules)
- Auto-fixes with Prettier (--write mode)
- Supports diff preview before applying fixes

Features:
- Validation: ESLint respects user config
- Autofix: Prettier for fast formatting
- Diff generation: Preview changes before applying
- Two-tier strategy: validate strictly, fix quickly

Autofix methods:
- Autofix(): Apply Prettier formatting
- GenerateDiff(): Preview changes without writing
- Register style engine in builtin.go
- Add Prettier config generation tests
- Add bad-style.js (unprettified code)
- Add good-style.js (prettified code)
- All tests passing
@ikjeong ikjeong self-assigned this Oct 28, 2025
@ikjeong ikjeong merged commit d7890fd into main Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant