code-sample-validator
Extract, validate, and test code samples in documentation. Verify syntax, execute samples, check outputs, validate imports, and ensure code samples are up-to-date with current APIs.
What this skill does
# Code Sample Validation Skill
Extract, validate, and test code samples in documentation.
## Capabilities
- Extract code blocks from Markdown/MDX
- Syntax validation for multiple languages
- Execute and verify code sample output
- Snippet compilation testing
- Version compatibility checking
- Import/dependency verification
- Code formatting validation (prettier, black)
- Generate runnable code from documentation
## Usage
Invoke this skill when you need to:
- Validate code samples in documentation
- Test code examples execute correctly
- Check for outdated API usage
- Verify import statements
- Generate test files from documentation
## Inputs
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| inputPath | string | Yes | Path to documentation file or directory |
| action | string | Yes | extract, validate, execute, format |
| languages | array | No | Filter by language (js, python, etc.) |
| outputDir | string | No | Directory for extracted runnable code |
| timeout | number | No | Execution timeout in seconds |
| config | object | No | Language-specific configuration |
### Input Example
```json
{
"inputPath": "./docs",
"action": "validate",
"languages": ["javascript", "python"],
"timeout": 30
}
```
## Output Structure
### Validation Report
```json
{
"summary": {
"total": 45,
"passed": 42,
"failed": 2,
"skipped": 1
},
"files": [
{
"file": "docs/quickstart.md",
"samples": [
{
"language": "javascript",
"line": 15,
"status": "passed",
"syntaxValid": true,
"executionResult": {
"success": true,
"output": "Hello, World!",
"duration": 125
}
},
{
"language": "python",
"line": 45,
"status": "failed",
"syntaxValid": true,
"executionResult": {
"success": false,
"error": "ModuleNotFoundError: No module named 'requests'",
"suggestion": "Add 'requests' to test dependencies"
}
}
]
}
],
"issues": [
{
"file": "docs/api/users.md",
"line": 78,
"language": "typescript",
"issue": "Type error: Property 'user' does not exist on type 'Response'",
"code": "const name = response.user.name;",
"suggestion": "Update to use 'response.data.user.name'"
}
]
}
```
## Code Extraction
### Markdown Code Block Patterns
````markdown
```javascript
// This block will be extracted and validated
const client = new Client({ apiKey: 'test' });
const result = await client.query('Hello');
console.log(result);
```
```python
# This block will be extracted and validated
from mypackage import Client
client = Client(api_key='test')
result = client.query('Hello')
print(result)
```
```bash skip-validation
# This block will be skipped due to directive
echo "Not validated"
```
```javascript title="example.js" runnable
// This block is marked as runnable
export function greet(name) {
return `Hello, ${name}!`;
}
```
````
### Extraction Configuration
```json
{
"extract": {
"includeLanguages": ["javascript", "typescript", "python", "go"],
"excludeLanguages": ["bash", "shell", "text"],
"directives": {
"skip": ["skip-validation", "no-test"],
"runnable": ["runnable", "test"],
"expectError": ["expect-error"]
},
"metaPatterns": {
"title": "title=\"([^\"]+)\"",
"filename": "filename=\"([^\"]+)\""
}
}
}
```
## Language-Specific Validation
### JavaScript/TypeScript
```javascript
// validator-config.js
module.exports = {
javascript: {
parser: 'babel',
parserOptions: {
ecmaVersion: 2024,
sourceType: 'module'
},
execute: {
runtime: 'node',
timeout: 10000,
setup: `
global.fetch = require('node-fetch');
process.env.API_KEY = 'test-key';
`
},
format: {
tool: 'prettier',
config: {
semi: true,
singleQuote: true,
trailingComma: 'es5'
}
}
},
typescript: {
compiler: 'tsc',
compilerOptions: {
target: 'ES2022',
module: 'ESNext',
strict: true
},
execute: {
runtime: 'ts-node',
timeout: 15000
}
}
};
```
### Python
```python
# validator_config.py
PYTHON_CONFIG = {
'version': '3.11',
'execute': {
'timeout': 30,
'setup': '''
import os
os.environ['API_KEY'] = 'test-key'
''',
'virtualenv': '.venv'
},
'format': {
'tool': 'black',
'config': {
'line_length': 88,
'target_version': ['py311']
}
},
'lint': {
'tool': 'ruff',
'rules': ['E', 'F', 'W']
}
}
```
### Go
```go
// validator_config.go
package main
var GoConfig = Config{
Version: "1.21",
Execute: ExecuteConfig{
Timeout: 30,
Build: true,
Run: true,
},
Format: FormatConfig{
Tool: "gofmt",
},
Lint: LintConfig{
Tool: "golangci-lint",
Rules: []string{"govet", "errcheck", "staticcheck"},
},
}
```
## Test Generation
### Generate Test Files
```javascript
// Generated from docs/quickstart.md
const { Client } = require('@example/sdk');
describe('Documentation Code Samples', () => {
describe('quickstart.md', () => {
test('Line 15: Basic client usage', async () => {
const client = new Client({ apiKey: 'test' });
const result = await client.query('Hello');
expect(result).toBeDefined();
});
test('Line 45: Error handling', async () => {
const client = new Client({ apiKey: 'invalid' });
await expect(client.query('Hello')).rejects.toThrow('Invalid API key');
});
});
});
```
### Test Configuration
```json
{
"testGeneration": {
"framework": "jest",
"outputDir": "tests/docs",
"filePattern": "{docfile}.test.js",
"imports": [
"const { Client } = require('@example/sdk');",
"const { mockServer } = require('./mocks');"
],
"beforeAll": "await mockServer.start();",
"afterAll": "await mockServer.stop();",
"assertions": {
"outputMatch": true,
"noThrow": true,
"typeCheck": true
}
}
}
```
## CI/CD Integration
### GitHub Actions
```yaml
name: Validate Documentation
on:
push:
paths:
- 'docs/**/*.md'
pull_request:
paths:
- 'docs/**/*.md'
jobs:
validate-code-samples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
npm ci
pip install -r requirements-docs.txt
- name: Validate code samples
run: |
node scripts/validate-docs.js \
--input docs/ \
--languages javascript,python \
--report validation-report.json
- name: Upload report
if: always()
uses: actions/upload-artifact@v4
with:
name: validation-report
path: validation-report.json
- name: Check for failures
run: |
if jq '.summary.failed > 0' validation-report.json | grep -q true; then
echo "Code sample validation failed"
jq '.issues' validation-report.json
exit 1
fi
```
## Formatting Validation
### Prettier Check
```javascript
const prettier = require('prettier');
async function validateFormatting(code, language) {
const options = {
parser: getParser(language),
semi: true,
singleQuote: true,
trailingComma: 'es5',
};
try {
const formatted = await prettier.format(code, options);
const isFormatted = code === formatted;
return {
valid: isFormatted,
formatted: formatted,
diff: isFormatted ? null : generateDiRelated in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.