From bdbf04e5aaa9c04fee77e566832c4a2080a8c98d Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sun, 30 Nov 2025 08:23:32 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 15 ++ README.md | 3 + commands/analyze-coverage.md | 66 +++++++++ plugin.lock.json | 73 +++++++++ skills/test-coverage-analyzer/SKILL.md | 53 +++++++ .../test-coverage-analyzer/assets/README.md | 7 + .../assets/configuration_template.yaml | 91 ++++++++++++ .../assets/example_coverage_report.html | 138 ++++++++++++++++++ .../assets/report_template.html | 136 +++++++++++++++++ .../references/README.md | 7 + .../test-coverage-analyzer/scripts/README.md | 7 + 11 files changed, 596 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 commands/analyze-coverage.md create mode 100644 plugin.lock.json create mode 100644 skills/test-coverage-analyzer/SKILL.md create mode 100644 skills/test-coverage-analyzer/assets/README.md create mode 100644 skills/test-coverage-analyzer/assets/configuration_template.yaml create mode 100644 skills/test-coverage-analyzer/assets/example_coverage_report.html create mode 100644 skills/test-coverage-analyzer/assets/report_template.html create mode 100644 skills/test-coverage-analyzer/references/README.md create mode 100644 skills/test-coverage-analyzer/scripts/README.md diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..9235232 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,15 @@ +{ + "name": "test-coverage-analyzer", + "description": "Analyze code coverage metrics, identify untested code, and generate comprehensive coverage reports", + "version": "1.0.0", + "author": { + "name": "Claude Code Plugins", + "email": "[email protected]" + }, + "skills": [ + "./skills" + ], + "commands": [ + "./commands" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ee5f4b4 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# test-coverage-analyzer + +Analyze code coverage metrics, identify untested code, and generate comprehensive coverage reports diff --git a/commands/analyze-coverage.md b/commands/analyze-coverage.md new file mode 100644 index 0000000..b4df339 --- /dev/null +++ b/commands/analyze-coverage.md @@ -0,0 +1,66 @@ +--- +description: Analyze code coverage metrics and identify untested code +shortcut: cov +--- + +# Test Coverage Analyzer + +Analyze test coverage metrics, identify untested code paths, and generate comprehensive coverage reports. + +## Capabilities + +- **Line coverage** - Which lines are executed +- **Branch coverage** - Which branches taken +- **Function coverage** - Which functions called +- **Statement coverage** - Which statements executed +- **Uncovered code identification** - Find gaps +- **Coverage trends** - Track over time +- **Threshold enforcement** - Minimum coverage requirements + +## Usage + +```bash +/analyze-coverage # Analyze current coverage +/analyze-coverage --threshold 80 # Enforce 80% minimum +/analyze-coverage --detailed # Detailed report +/cov # Shortcut +``` + +## Report Format + +``` +Code Coverage Report +==================== +Overall Coverage: 78.5% + +By File: + src/utils/validator.js 95.2% + src/api/users.js 82.1% + src/api/products.js 68.4% ️ + src/services/payment.js 45.7% + +By Type: + Lines: 78.5% (1,571 / 2,000) + Branches: 72.3% (289 / 400) + Functions: 85.1% (85 / 100) + Statements: 78.2% (1,563 / 2,000) + +Uncovered Lines: + src/api/products.js:45-52 (error handling) + src/api/products.js:78-82 (edge case) + src/services/payment.js:23-67 (refund logic) + +Recommendations: + 1. Add tests for payment service refund logic + 2. Test error handling in products API + 3. Cover edge cases in product filtering +``` + +## Best Practices + +- Aim for 80%+ coverage +- 100% coverage != bug-free +- Focus on critical paths +- Cover edge cases +- Test error handling +- Track coverage trends diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..cfd7b91 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,73 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:jeremylongshore/claude-code-plugins-plus:plugins/testing/test-coverage-analyzer", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "51108ef3348fe7c6b2282ab81ca8e79d6d49eb99", + "treeHash": "a2a491560675753f17907594c2d440eb11dfabde5fb48928a1e40630559b8fdf", + "generatedAt": "2025-11-28T10:18:48.797477Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "test-coverage-analyzer", + "description": "Analyze code coverage metrics, identify untested code, and generate comprehensive coverage reports", + "version": "1.0.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "fe831e8798dc5ae62aa6c7d7bb5da97fbe1516e74840af1d96da6b3ca579cd1e" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "d319ff5c110949199fb0314e0716321a39e0839e5dd385129bdfbf8d19f3d658" + }, + { + "path": "commands/analyze-coverage.md", + "sha256": "651fddc37107392f88c84354fbbc300a0eedbeec342b310c428890af637606d2" + }, + { + "path": "skills/test-coverage-analyzer/SKILL.md", + "sha256": "4c900fb89535d4852b31ebc5e8a5bf043e017a3c6d6c2bd4c5333a990a06f6ef" + }, + { + "path": "skills/test-coverage-analyzer/references/README.md", + "sha256": "d16bac6a5457c4cc70486e44296661ec7cc892ff83fbab237fc27ff8cffac18e" + }, + { + "path": "skills/test-coverage-analyzer/scripts/README.md", + "sha256": "d7d01228ae07181312ecddd7290004dae5d527452100e1d5cade511fd5ca4963" + }, + { + "path": "skills/test-coverage-analyzer/assets/configuration_template.yaml", + "sha256": "68bed9e02737bfaf6f8b03dd7d21d54b6c19869a9e4844a01c455dfeec769e21" + }, + { + "path": "skills/test-coverage-analyzer/assets/README.md", + "sha256": "b79ac1f996354569a5394d0422814d35785bb7efaa07af3f6febbf3dd534a167" + }, + { + "path": "skills/test-coverage-analyzer/assets/example_coverage_report.html", + "sha256": "ffd004ae434d17755ada2e1bdc52f737a93dc3f79e85d2580f00739ce9c4723d" + }, + { + "path": "skills/test-coverage-analyzer/assets/report_template.html", + "sha256": "9a4e0ad8dc4d42428b144f6b273e1473ed9a0e01b815d100ac3afaa60404e237" + } + ], + "dirSha256": "a2a491560675753f17907594c2d440eb11dfabde5fb48928a1e40630559b8fdf" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file diff --git a/skills/test-coverage-analyzer/SKILL.md b/skills/test-coverage-analyzer/SKILL.md new file mode 100644 index 0000000..e10fea1 --- /dev/null +++ b/skills/test-coverage-analyzer/SKILL.md @@ -0,0 +1,53 @@ +--- +name: analyzing-test-coverage +description: | + This skill analyzes code coverage metrics to identify untested code and generate comprehensive coverage reports. It is triggered when the user requests analysis of code coverage, identification of coverage gaps, or generation of coverage reports. The skill is best used to improve code quality by ensuring adequate test coverage and identifying areas for improvement. Use trigger terms like "analyze coverage", "code coverage report", "untested code", or the shortcut "cov". +allowed-tools: Read, Write, Edit, Grep, Glob, Bash +version: 1.0.0 +--- + +## Overview + +This skill enables Claude to analyze code coverage metrics, pinpoint areas of untested code, and generate detailed reports. It helps you identify gaps in your test suite and ensure comprehensive code coverage. + +## How It Works + +1. **Coverage Data Collection**: Claude executes the project's test suite with coverage tracking enabled (e.g., using `nyc`, `coverage.py`, or JaCoCo). +2. **Report Generation**: The plugin parses the coverage data and generates a detailed report, including metrics for line, branch, function, and statement coverage. +3. **Uncovered Code Identification**: Claude highlights specific lines or blocks of code that are not covered by any tests. + +## When to Use This Skill + +This skill activates when you need to: +- Analyze the overall code coverage of your project. +- Identify specific areas of code that lack test coverage. +- Generate a detailed report of code coverage metrics. +- Enforce minimum code coverage thresholds. + +## Examples + +### Example 1: Analyzing Project Coverage + +User request: "Analyze code coverage for the entire project" + +The skill will: +1. Execute the project's test suite with coverage tracking. +2. Generate a comprehensive coverage report, showing line, branch, and function coverage. + +### Example 2: Identifying Untested Code + +User request: "Show me the untested code in the `src/utils.js` file" + +The skill will: +1. Analyze the coverage data for `src/utils.js`. +2. Highlight the lines of code in `src/utils.js` that are not covered by any tests. + +## Best Practices + +- **Configuration**: Ensure your project has a properly configured coverage tool (e.g., `nyc` in package.json). +- **Thresholds**: Define minimum coverage thresholds to enforce code quality standards. +- **Report Review**: Regularly review coverage reports to identify and address coverage gaps. + +## Integration + +This skill can be integrated with other testing and CI/CD tools to automate coverage analysis and reporting. For example, it can be used in conjunction with a linting plugin to identify both code style issues and coverage gaps. \ No newline at end of file diff --git a/skills/test-coverage-analyzer/assets/README.md b/skills/test-coverage-analyzer/assets/README.md new file mode 100644 index 0000000..74126a1 --- /dev/null +++ b/skills/test-coverage-analyzer/assets/README.md @@ -0,0 +1,7 @@ +# Assets + +Bundled resources for test-coverage-analyzer skill + +- [ ] report_template.html: HTML template for generating visually appealing coverage reports. +- [ ] example_coverage_report.html: Example HTML coverage report. +- [ ] configuration_template.yaml: Template for configuring the coverage analysis. diff --git a/skills/test-coverage-analyzer/assets/configuration_template.yaml b/skills/test-coverage-analyzer/assets/configuration_template.yaml new file mode 100644 index 0000000..55b34c0 --- /dev/null +++ b/skills/test-coverage-analyzer/assets/configuration_template.yaml @@ -0,0 +1,91 @@ +# Configuration for the Test Coverage Analyzer Plugin + +# General settings for the analysis +general: + # Project name (used in reports) + project_name: "REPLACE_ME - Project Name" + + # Root directory of the project (where the source code resides) + project_root: "/path/to/your/project/root" # REPLACE_ME + + # Output directory for generated reports + report_output_dir: "coverage_reports" + + # Enable/disable verbose logging + verbose: false + +# Coverage data settings +coverage_data: + # Type of coverage data format. Supported values: lcov, cobertura, gcov + format: "lcov" + + # Path to the coverage data file (e.g., lcov.info, coverage.xml, *.gcov) + # Can be a single file or a glob pattern. + data_file: "coverage.info" # REPLACE_ME + + # Exclude files or directories from coverage analysis (glob patterns) + exclude: + - "**/test/**" + - "**/vendor/**" + - "**/node_modules/**" + - "**/migrations/**" + +# Threshold settings for enforcing minimum coverage +thresholds: + # Enable or disable threshold checks + enabled: true + + # Minimum overall coverage percentage required for the project to pass + overall: 80 + + # Minimum coverage percentage required for each file + file: 70 + + # Minimum coverage percentage required for each function + function: 60 + + # Allow thresholds to be bypassed on specific files or paths + exemptions: + # - path: "path/to/file.py" + # overall: 70 # Reduced overall threshold for this specific file + # file: 60 # Reduced file threshold for this specific file + # function: 50 # Reduced function threshold for this specific file + +# Report generation settings +report: + # Type of report to generate. Supported values: html, json, console + type: "html" + + # Include uncovered code snippets in the report (can make reports larger) + include_uncovered_code: true + + # Custom CSS file to apply to the HTML report (optional) + custom_css: "" # "path/to/custom.css" + +# Advanced settings (for specific coverage tools) +advanced: + # GCOV specific settings + gcov: + # Path to the gcov executable + executable: "gcov" # /usr/bin/gcov + + # Cobertura specific settings + cobertura: + # Path to the source root (if not correctly specified in the cobertura report) + source_root: "" # REPLACE_ME + +# Integration with CI/CD systems (optional) +ci: + # Fail the build if coverage thresholds are not met + fail_on_threshold: true + + # Output format for CI integration (e.g., junit) + output_format: "" # junit + +# Example configuration for a specific language (Python) +python: + # Path to the python executable + executable: "python3" # REPLACE_ME + + # Additional arguments to pass to the python executable + arguments: [] # ["-m", "pytest"] \ No newline at end of file diff --git a/skills/test-coverage-analyzer/assets/example_coverage_report.html b/skills/test-coverage-analyzer/assets/example_coverage_report.html new file mode 100644 index 0000000..f6e6864 --- /dev/null +++ b/skills/test-coverage-analyzer/assets/example_coverage_report.html @@ -0,0 +1,138 @@ + + + + + + Code Coverage Report + + + + +

Code Coverage Report

+ + +
+

Total Coverage: {{total_coverage}}%

+

Covered Lines: {{covered_lines}}

+

Uncovered Lines: {{uncovered_lines}}

+

Timestamp: {{timestamp}}

+
+ + + + + + + + + + + + + {{table_rows}} + +
FileCoverageLines CoveredLines Uncovered
+ + + + + + + + + \ No newline at end of file diff --git a/skills/test-coverage-analyzer/assets/report_template.html b/skills/test-coverage-analyzer/assets/report_template.html new file mode 100644 index 0000000..fd209bc --- /dev/null +++ b/skills/test-coverage-analyzer/assets/report_template.html @@ -0,0 +1,136 @@ + + + + + + Test Coverage Report + + + +
+

Test Coverage Report

+ +
+

Overall Coverage

+
+ Lines Covered: {{lines_covered}}% +
+
+ Branches Covered: {{branches_covered}}% +
+
+ Functions Covered: {{functions_covered}}% +
+
+ Statements Covered: {{statements_covered}}% +
+
+ +

File Coverage Details

+ + + + + + + + + + + + {{file_coverage_rows}} + +
FileLinesBranchesFunctionsStatements
+ +
+

Untested Code Snippets

+ {{untested_code_snippets}} +
+ +

Coverage Trends

+ Coverage Trend Chart +
+ + \ No newline at end of file diff --git a/skills/test-coverage-analyzer/references/README.md b/skills/test-coverage-analyzer/references/README.md new file mode 100644 index 0000000..549a4db --- /dev/null +++ b/skills/test-coverage-analyzer/references/README.md @@ -0,0 +1,7 @@ +# References + +Bundled resources for test-coverage-analyzer skill + +- [ ] coverage_tool_integration.md: Documentation on integrating with various coverage tools (nyc, coverage.py, JaCoCo). +- [ ] coverage_metrics_explained.md: Explanation of different coverage metrics (lines, branches, functions, statements). +- [ ] setting_coverage_thresholds.md: Guidance on setting appropriate coverage thresholds for different projects. diff --git a/skills/test-coverage-analyzer/scripts/README.md b/skills/test-coverage-analyzer/scripts/README.md new file mode 100644 index 0000000..8a7e622 --- /dev/null +++ b/skills/test-coverage-analyzer/scripts/README.md @@ -0,0 +1,7 @@ +# Scripts + +Bundled resources for test-coverage-analyzer skill + +- [ ] analyze_coverage.py: Script to execute coverage analysis using a specified coverage tool (e.g., coverage.py, nyc) and threshold. +- [ ] generate_report.py: Script to generate a detailed coverage report in various formats (e.g., HTML, XML, text). +- [ ] find_untested_code.py: Script to identify specific lines or functions of code that lack test coverage.