Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:23:32 +08:00
commit bdbf04e5aa
11 changed files with 596 additions and 0 deletions

View File

@@ -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.

View File

@@ -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.

View File

@@ -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"]

View File

@@ -0,0 +1,138 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Code Coverage Report</title>
<style>
/* Inline CSS for styling */
body {
font-family: sans-serif;
margin: 20px;
background-color: #f4f4f4;
color: #333;
}
h1 {
text-align: center;
color: #007bff;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
overflow: hidden; /* Ensures rounded corners work correctly */
}
th, td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #007bff;
color: white;
font-weight: bold;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ddd;
}
.coverage-bar {
width: 100%;
height: 10px;
background-color: #ddd;
border-radius: 5px;
overflow: hidden; /* Hide overflowing gradient */
}
.coverage-bar-inner {
height: 100%;
background: linear-gradient(to right, #4CAF50, #8BC34A); /* Green gradient */
width: {{coverage_percentage}}%; /* Placeholder for coverage percentage */
}
.summary {
margin-top: 20px;
padding: 15px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
.summary p {
margin: 5px 0;
}
@media (max-width: 600px) {
table {
overflow-x: auto; /* Enable horizontal scrolling on small screens */
display: block; /* Required for overflow-x to work */
}
th, td {
white-space: nowrap; /* Prevent text wrapping */
}
}
</style>
</head>
<body>
<!-- Main heading -->
<h1>Code Coverage Report</h1>
<!-- Coverage Summary -->
<div class="summary">
<p><strong>Total Coverage:</strong> {{total_coverage}}%</p>
<p><strong>Covered Lines:</strong> {{covered_lines}}</p>
<p><strong>Uncovered Lines:</strong> {{uncovered_lines}}</p>
<p><strong>Timestamp:</strong> {{timestamp}}</p>
</div>
<!-- Coverage Table -->
<table>
<thead>
<tr>
<th>File</th>
<th>Coverage</th>
<th>Lines Covered</th>
<th>Lines Uncovered</th>
</tr>
</thead>
<tbody>
{{table_rows}} <!-- Placeholder for table rows -->
</tbody>
</table>
<!-- Example Table Row (to be replaced by actual data) -->
<!-- Example:
<tr>
<td>example.py</td>
<td>
<div class="coverage-bar">
<div class="coverage-bar-inner" style="width: 85%;"></div>
</div>
85%
</td>
<td>170</td>
<td>30</td>
</tr>
-->
<!-- Footer -->
<footer>
<p>&copy; {{year}} Test Coverage Analyzer Plugin</p>
</footer>
</body>
</html>

View File

@@ -0,0 +1,136 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Coverage Report</title>
<style>
/* Inline CSS for styling */
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
color: #333;
}
.container {
width: 90%;
max-width: 1200px;
margin: 20px auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
color: #007bff;
}
h2 {
color: #333;
border-bottom: 1px solid #ddd;
padding-bottom: 5px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
}
th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
}
.coverage-summary {
margin-top: 20px;
}
.coverage-metric {
display: inline-block;
margin-right: 20px;
}
.coverage-metric strong {
color: #007bff;
}
.untested-code {
margin-top: 20px;
}
pre {
background-color: #f9f9f9;
padding: 10px;
border: 1px solid #eee;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
}
@media (max-width: 768px) {
.container {
width: 95%;
}
table {
font-size: 0.8em;
}
}
</style>
</head>
<body>
<div class="container">
<h1>Test Coverage Report</h1>
<div class="coverage-summary">
<h2>Overall Coverage</h2>
<div class="coverage-metric">
Lines Covered: <strong>{{lines_covered}}%</strong>
</div>
<div class="coverage-metric">
Branches Covered: <strong>{{branches_covered}}%</strong>
</div>
<div class="coverage-metric">
Functions Covered: <strong>{{functions_covered}}%</strong>
</div>
<div class="coverage-metric">
Statements Covered: <strong>{{statements_covered}}%</strong>
</div>
</div>
<h2>File Coverage Details</h2>
<table>
<thead>
<tr>
<th>File</th>
<th>Lines</th>
<th>Branches</th>
<th>Functions</th>
<th>Statements</th>
</tr>
</thead>
<tbody>
{{file_coverage_rows}}
</tbody>
</table>
<div class="untested-code">
<h2>Untested Code Snippets</h2>
{{untested_code_snippets}}
</div>
<h2>Coverage Trends</h2>
<img src="{{coverage_trend_chart_url}}" alt="Coverage Trend Chart">
</div>
</body>
</html>

View File

@@ -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.

View File

@@ -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.