# 代码检视规范 Gate 规则
# 来源: 代码检视指导书.md

rules:
  # === 3.1 整体要求 ===

  - id: review-overall-quality-requirements
    type: regex-check
    blocking: false
    severity: warning
    scope: full-only
    source: "代码检视指导书#3.1"
    message: "经检视代码须满足: 功能正确/安全可靠/可读易维护/架构一致/易扩展可移植/充分测试/高效性能好"
    pattern: "(?!)"
    match_mode: absent
    includes:
      - "**/*.ts"
      - "**/*.js"
    excludes: []

  # === 3.2 功能正确 ===

  - id: review-function-correctness
    type: regex-check
    blocking: false
    severity: warning
    scope: full-only
    source: "代码检视指导书#3.2"
    message: "功能正确性需人工走读确认, 包括代码逻辑分析和单元测试完备性分析 (不可自动化: 需理解业务逻辑)"
    pattern: "(?!)"
    match_mode: absent
    includes:
      - "**/*.ts"
      - "**/*.js"
    excludes: []

  # === 3.3 安全可靠 ===

  - id: review-security-reliability
    type: regex-check
    blocking: false
    severity: warning
    scope: full-only
    source: "代码检视指导书#3.3"
    message: "安全可靠性需人工确认 (内部无空指针/内存泄漏, 外部防注入攻击), 已有 security-design 规则覆盖部分"
    pattern: "(?!)"
    match_mode: absent
    includes:
      - "**/*.ts"
      - "**/*.js"
    excludes: []

  - id: review-test-must-exist-with-code
    type: regex-check
    blocking: false
    severity: warning
    scope: incremental
    source: "代码检视指导书#3.8"
    message: "代码变更须同步提交测试用例 (开发者测试代码与功能代码一同提交)"
    pattern: "(?:describe|it|test)\\s*\\("
    match_mode: present
    includes:
      - "**/*.test.ts"
      - "**/*.spec.ts"
      - "**/*.test.js"
    excludes: []

  # === 3.4 可读易维护 ===

  - id: review-no-select-star
    type: regex-check
    blocking: false
    severity: warning
    scope: incremental
    source: "代码检视指导书#3.6"
    message: "禁止使用 SELECT * FROM, 须显式指定字段以保障后向兼容性"
    pattern: "SELECT\\s+\\*\\s+FROM"
    match_mode: absent
    includes:
      - "**/*.ts"
      - "**/*.js"
      - "**/*.sql"
    excludes:
      - "**/*.d.ts"
      - "**/*.test.*"

  - id: review-commit-msg-has-task-id
    type: regex-check
    blocking: false
    severity: warning
    scope: full-only
    source: "代码检视指导书#3.4"
    message: "提交信息须包含需求号/问题单号"
    pattern: "(?:feat|fix|refactor|docs|chore|test)\\s*[:：]"
    match_mode: present
    includes:
      - "**/*.ts"
    excludes: []

  # === 3.7 谨慎引入第三方件 ===

  - id: review-no-select-all-from-table
    type: regex-check
    blocking: false
    severity: warning
    scope: incremental
    source: "代码检视指导书#3.6"
    message: "数据库查询禁止 SELECT * FROM TABLE, 须显式指定字段"
    pattern: "(?:SELECT\\s+)?\\*\\s+FROM\\s+\\w+"
    match_mode: absent
    includes:
      - "**/*.ts"
      - "**/*.js"
      - "**/*.sql"
    excludes:
      - "**/*.d.ts"
      - "**/*.test.*"

  - id: review-prefer-native-over-third-party
    type: regex-check
    blocking: false
    severity: warning
    scope: incremental
    source: "代码检视指导书#3.7"
    message: "优先使用系统原生能力而非引入新第三方件, 禁止私自修改第三方件源码"
    pattern: "(?:lodash|moment|underscore|axios)\\b"
    match_mode: absent
    includes:
      - "**/*.ts"
      - "**/*.js"
    excludes:
      - "**/*.d.ts"
      - "**/*.test.*"
      - "**/package.json"
      - "**/package-lock.json"

  # === 3.8 充分测试 ===

  - id: review-no-skip-tests
    type: regex-check
    blocking: false
    severity: warning
    scope: incremental
    source: "代码检视指导书#3.8"
    message: "禁止跳过测试用例 (skip/only/xit/xdescribe)"
    pattern: "(?:\\.skip|\\.only|xit|xdescribe|xit\\()"
    match_mode: absent
    includes:
      - "**/*.test.ts"
      - "**/*.spec.ts"
      - "**/*.test.js"
    excludes: []

  # === 3.9 高效性能好 ===

  - id: review-no-sync-in-async
    type: regex-check
    blocking: false
    severity: warning
    scope: incremental
    source: "代码检视指导书#3.9"
    message: "避免使用同步IO操作 (readFileSync/writeFileSync/execSync), 影响性能"
    pattern: "(?:readFileSync|writeFileSync|execSync|execFileSync)\\s*\\("
    match_mode: absent
    includes:
      - "**/*.ts"
      - "**/*.js"
    excludes:
      - "**/*.d.ts"
      - "**/*.test.*"

  # === 3.10 合理重构 - 清理调试语句 ===

  - id: review-no-console-debug-leftovers
    type: regex-check
    blocking: false
    severity: warning
    scope: incremental
    source: "代码检视指导书#3.10"
    message: "提交代码前应清理调试语句 (console.debug)"
    pattern: "console\\.debug\\s*\\("
    match_mode: absent
    includes:
      - "**/*.ts"
      - "**/*.js"
    excludes:
      - "**/*.d.ts"
      - "**/*.test.*"

  # === 3.5 与实现架构保持一致 ===

  - id: review-architecture-consistency
    type: regex-check
    blocking: false
    severity: warning
    scope: full-only
    source: "代码检视指导书#3.5"
    message: "代码实现须与当前整体架构保持一致, 不破坏现有架构 (不可自动化: 需理解架构上下文)"
    pattern: "(?!)"
    match_mode: absent
    includes:
      - "**/*.ts"
      - "**/*.js"
    excludes: []
