360 Secure SkillHub
360 安全技能中心

Vitest Config Validator

通过 Python 脚本以正则方式解析 vitest.config.ts/js 等配置文件文本,按 22 条规则检查结构、测试设置、性能、兼容性与最佳实践,提供 validate/check/explain/suggest 命令及 text、json、summary 输出,不执行 JS 代码,并以退出码 0/1/2 表示结果。

charlie-morrison
charlie-morrison
热度 54.81
最近更新 2026-05-11 17:44:47
分类:开发依赖:代码执行 / 读写文件应用场景:代码审查

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add vitest-config-validator
Metadata
name
vitest-config-validator
description
Validate vitest.config.ts/js and vitest workspace configurations for syntax, deprecated options, plugin conflicts, and best practices. Use when validating Vitest test runner configs, auditing test setups, or linting vitest.config files.

Vitest Config Validator

Validate vitest.config.ts and vitest.config.js files for syntax errors, deprecated options, plugin conflicts, and best practices. Parses config files as text using regex patterns — no JS execution required.

Commands

# Full validation (all rules)
python3 scripts/vitest_config_validator.py validate vitest.config.ts

# Quick syntax-only check (structure rules only)
python3 scripts/vitest_config_validator.py check vitest.config.ts

# Explain config in human-readable form
python3 scripts/vitest_config_validator.py explain vitest.config.ts

# Suggest improvements
python3 scripts/vitest_config_validator.py suggest vitest.config.ts

# JSON output
python3 scripts/vitest_config_validator.py validate vitest.config.ts --format json

# One-line PASS/WARN/FAIL summary
python3 scripts/vitest_config_validator.py validate vitest.config.ts --format summary

# Strict mode (warnings become errors)
python3 scripts/vitest_config_validator.py validate vitest.config.ts --strict

Rules (22)

# Category Severity Rule
S1 Structure E File not found or unreadable
S2 Structure E Empty config or no defineConfig call
S3 Structure W No default export found
S4 Structure W Both vitest.config and vite.config with test section detected
S5 Structure W Unknown top-level config keys
T1 Test Settings E Invalid test environment (must be jsdom/happy-dom/node/edge-runtime)
T2 Test Settings W Empty include or exclude patterns
T3 Test Settings E Invalid glob pattern in include/exclude
T4 Test Settings I Coverage provider not set (recommend c8/v8/istanbul)
T5 Test Settings W testTimeout set unreasonably high (>60000ms) or low (<100ms)
P1 Performance W singleThread: true used with forks pool (disables parallelism)
P2 Performance W isolate: false without comment (risky for test isolation)
P3 Performance I No pool configuration (defaults may not be optimal)
P4 Performance W globals: true without type declaration reference
C1 Compatibility W Deprecated option used
C2 Compatibility W css.modules without css.include (potential miss)
C3 Compatibility W deps.inline and deps.external conflict
B1 Best Practices I No reporter configured
B2 Best Practices I Missing coverage configuration
B3 Best Practices W setupFiles references potentially non-existent pattern
B4 Best Practices I snapshotFormat not explicitly configured
B5 Best Practices I passWithNoTests not set (CI may fail on empty test suite)

Output Formats

  • text (default): Human-readable with [E]/[W]/[I] severity prefix
  • json: Machine-readable structured output
  • summary: Single-line PASS / WARN / FAIL

Exit Codes

  • 0 — No errors
  • 1 — Errors found (or warnings in --strict mode)
  • 2 — File not found or parse error