Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 194 additions & 0 deletions .github/workflows/lint-automation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
name: πŸ”§ Automated Lint Issue Detection

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
workflow_dispatch:
inputs:
create_issues:
description: 'Create GitHub issues for lint problems'
required: false
default: 'true'
type: boolean

permissions:
contents: read
issues: write
pull-requests: write

jobs:
lint-analysis:
runs-on: ubuntu-latest
name: πŸ” Lint Analysis & Issue Creation

outputs:
has-lint-issues: ${{ steps.analyze.outputs.has-issues }}
issues-count: ${{ steps.analyze.outputs.issues-count }}
report-url: ${{ steps.upload-artifacts.outputs.artifact-url }}

steps:
- name: πŸ“¦ Checkout repository
uses: actions/checkout@v4

- name: 🟒 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: πŸ“₯ Install dependencies
run: npm ci

- name: πŸ” Run lint analysis
id: analyze
run: |
echo "πŸ” Running comprehensive lint analysis..."

# Run the lint analyzer
npx tsx scripts/lint-automation/lint-analyzer.ts || true

# Check if we generated a report
if [ -f "lint-analysis-report.json" ]; then
ISSUES_COUNT=$(jq '.summary.totalIssues' lint-analysis-report.json)
echo "has-issues=true" >> $GITHUB_OUTPUT
echo "issues-count=${ISSUES_COUNT}" >> $GITHUB_OUTPUT
echo "πŸ“Š Found ${ISSUES_COUNT} lint issues"
else
echo "has-issues=false" >> $GITHUB_OUTPUT
echo "issues-count=0" >> $GITHUB_OUTPUT
echo "βœ… No lint issues found!"
fi

- name: πŸ“„ Upload lint analysis artifacts
id: upload-artifacts
if: steps.analyze.outputs.has-issues == 'true'
uses: actions/upload-artifact@v4
with:
name: lint-analysis-report-${{ github.run_number }}
path: |
lint-analysis-report.json
lint-analysis-report.md
retention-days: 30

- name: 🎯 Create GitHub issues for lint problems
if: |
steps.analyze.outputs.has-issues == 'true' && (
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.create_issues == true)
)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
GITHUB_REPOSITORY_NAME: ${{ github.event.repository.name }}
run: |
echo "πŸ“ Creating GitHub issues for lint problems..."
npx tsx scripts/lint-automation/github-issue-creator.ts

- name: πŸ“‹ Comment on PR with lint analysis
if: |
github.event_name == 'pull_request' &&
steps.analyze.outputs.has-issues == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');

try {
const report = JSON.parse(fs.readFileSync('lint-analysis-report.json', 'utf8'));
const markdown = fs.readFileSync('lint-analysis-report.md', 'utf8');

// Create a summary for the PR comment
const summary = `## πŸ”§ Lint Analysis Results

**Found ${report.summary.totalIssues} lint issues in ${report.summary.affectedFiles} files:**
- ❌ ${report.summary.errorCount} errors
- ⚠️ ${report.summary.warningCount} warnings

### Most Common Issues:
${report.summary.commonPatterns.map(p => `- ${p}`).join('\n')}

### Immediate Actions Required:
${report.recommendations.immediate.map(r => `- [ ] ${r}`).join('\n')}

<details>
<summary>πŸ“„ Full Analysis Report</summary>

${markdown}

</details>

---
πŸ€– *This analysis was automatically generated. Issues will be created on merge to main.*`;

await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: summary
});
} catch (error) {
console.log('Could not post PR comment:', error.message);
}

- name: ❌ Fail build on lint errors
if: steps.analyze.outputs.has-issues == 'true'
run: |
echo "πŸ’₯ Build failed due to lint issues!"
echo "πŸ“Š Found ${{ steps.analyze.outputs.issues-count }} lint issues"
echo "πŸ” Check the analysis report for detailed information"

if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "ℹ️ GitHub issues will be created when this PR is merged to main"
else
echo "πŸ“ GitHub issues should have been created for tracking"
fi

exit 1

# Optional: Job to run only when lint issues are found and resolved
validation:
runs-on: ubuntu-latest
needs: lint-analysis
if: needs.lint-analysis.outputs.has-lint-issues == 'false'

steps:
- name: βœ… Lint validation passed
run: |
echo "πŸŽ‰ All lint checks passed!"
echo "✨ Code quality standards are maintained"

# Summary job for workflow status
summary:
runs-on: ubuntu-latest
needs: lint-analysis
if: always()

steps:
- name: πŸ“Š Workflow Summary
run: |
echo "## πŸ”§ Lint Automation Workflow Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

if [ "${{ needs.lint-analysis.outputs.has-lint-issues }}" = "true" ]; then
echo "❌ **Status:** Lint issues detected" >> $GITHUB_STEP_SUMMARY
echo "πŸ“Š **Issues Found:** ${{ needs.lint-analysis.outputs.issues-count }}" >> $GITHUB_STEP_SUMMARY
echo "πŸ” **Analysis:** Complete - check artifacts for details" >> $GITHUB_STEP_SUMMARY

if [ "${{ github.event_name }}" = "push" ] && [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "πŸ“ **GitHub Issues:** Created for tracking and resolution" >> $GITHUB_STEP_SUMMARY
else
echo "πŸ“ **GitHub Issues:** Will be created on merge to main" >> $GITHUB_STEP_SUMMARY
fi
else
echo "βœ… **Status:** All lint checks passed" >> $GITHUB_STEP_SUMMARY
echo "πŸŽ‰ **Code Quality:** Maintained" >> $GITHUB_STEP_SUMMARY
fi

echo "" >> $GITHUB_STEP_SUMMARY
echo "### πŸ”„ Workflow Details" >> $GITHUB_STEP_SUMMARY
echo "- **Trigger:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
echo "- **Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "- **Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "- **Run:** #${{ github.run_number }}" >> $GITHUB_STEP_SUMMARY
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts
.env*.local

# lint automation reports
lint-analysis-report.json
lint-analysis-report.md
lint-output.json
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,56 @@ ClearView's proprietary engine seamlessly integrates diverse data sources across
- Rich UI component rendering
- Mobile-optimized presentation

## πŸš€ Development & Integration Guide
## πŸ”§ Automated Code Quality & Lint Management

### πŸ€– Intelligent Lint Issue Detection

ClearView features an advanced automated lint analysis system that provides:

#### πŸ” AI-Powered Analysis
- **Root Cause Identification**: Determines why lint issues occur
- **Smart Solutions**: Provides specific, actionable fix suggestions
- **Prevention Strategies**: Offers recommendations to avoid future issues
- **Pattern Recognition**: Identifies similar issues across comparable files

#### πŸ“Š Comprehensive Reporting
- **Detailed JSON Reports**: Machine-readable analysis data
- **Markdown Documentation**: Human-friendly issue summaries
- **GitHub Integration**: Automatic issue creation with structured templates
- **Pattern Analysis**: Identifies code similarity patterns and consistency issues

#### 🎯 Workflow Integration
```bash
# Manual analysis and reporting
npm run lint:analyze # Generate comprehensive lint analysis
npm run lint:create-issues # Create GitHub issues for tracking
npm run lint:auto # Complete automated workflow

# Test the automation system
./scripts/lint-automation/test-workflow.sh
```

#### πŸš€ CI/CD Automation
The system automatically runs on:
- **Push to main branch**: Creates GitHub issues for new lint problems
- **Pull requests**: Adds detailed analysis comments
- **Manual triggers**: On-demand analysis via workflow dispatch

**Key Features:**
- Detects patterns across similar files (e.g., route.ts, logic.ts files)
- Provides context-aware solutions based on project structure
- Groups related issues for efficient resolution
- Maintains issue history and tracks resolution progress

### πŸ› οΈ Lint Rule Categories

| Category | Examples | Auto-Fix Available |
|----------|----------|-------------------|
| **Type Safety** | `@typescript-eslint/no-explicit-any` | βœ… Partial |
| **Code Quality** | `@typescript-eslint/no-unused-vars` | βœ… Yes |
| **Best Practices** | `prefer-const`, `no-console` | βœ… Yes |
| **Consistency** | Import organization, formatting | βœ… Yes |


### πŸ› οΈ Quick Start Development

Expand Down Expand Up @@ -367,6 +416,11 @@ npm start

# Lint codebase
npm run lint

# πŸ”§ NEW: Automated lint analysis and issue creation
npm run lint:analyze # Analyze lint issues with AI insights
npm run lint:create-issues # Create GitHub issues for lint problems
npm run lint:auto # Run full automated workflow
```

### πŸ”Œ API Integration
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"script": "tsx",
"alberta:convertPDF": "tsx app/api/verify/alberta/convertPDF.ts",
"alberta:convertCSV": "tsx app/api/verify/alberta/convertCSV.ts",
"alberta:test": "tsx app/api/verify/alberta/test.ts"
"alberta:test": "tsx app/api/verify/alberta/test.ts",
"lint:analyze": "tsx scripts/lint-automation/lint-analyzer.ts",
"lint:create-issues": "tsx scripts/lint-automation/github-issue-creator.ts",
"lint:auto": "npm run lint:analyze && npm run lint:create-issues"
},
"dependencies": {
"@chakra-ui/react": "^3.19.1",
Expand Down
56 changes: 56 additions & 0 deletions scripts/lint-automation/example-issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Example: Automated GitHub Issue

## πŸ”§ ESLint Rule Violation: `@typescript-eslint/no-unused-vars`

**6 instance(s) of this rule violation found across the codebase.**

### πŸ” Analysis

**Likely Cause:** Variable is declared but never used in the code. This often happens during development when code is partially implemented or when refactoring removes usage.

**Suggested Solution:** Remove the unused variable or prefix it with underscore (_) if it's intentionally unused. For function parameters that must exist for interface compliance, use underscore prefix.

**Prevention:** Use IDE features to highlight unused code. Consider enabling "Remove unused imports" on save. Review code before committing to catch unused declarations.

### πŸ“ Affected Files

- `./app/api/verify/alabama/route.ts:10:11` - 'searchParams' is assigned a value but never used.
- `./app/api/verify/arkansas/logic.ts:3:11` - 'VetRecord' is defined but never used.
- `./app/api/verify/colorado/logic.ts:3:11` - 'VetRecord' is defined but never used.
- `./app/api/verify/connecticut/logic.ts:3:11` - 'VetRecord' is defined but never used.
- `./app/api/verify/florida/route.ts:17:9` - 'key' is assigned a value but never used.
- `./app/api/verify/missouri/logic.ts:3:11` - 'VetRecord' is defined but never used.

### 🧩 Pattern Analysis

**Directory `./app/api/verify`** has 6 instances of this issue. Consider applying a consistent fix pattern across this module.

**Similar File Pattern Detected:** This issue appears in files with similar naming patterns. Consider reviewing the template or base implementation that these files might share.

### πŸ› οΈ How to Fix

1. **Review each affected file** listed above
2. **Apply the suggested solution** for each instance
3. **Test the changes** to ensure functionality is preserved
4. **Run `npm run lint`** to verify the fixes

**Tip:** Since this affects multiple files, consider using find-and-replace tools or IDE refactoring features for consistent fixes.

### πŸ“š Additional Resources

- [ESLint Rule Documentation](https://typescript-eslint.io/rules/no-unused-vars/)
- **Quick Fix:** Remove unused variables or prefix with underscore if intentionally unused
- **IDE Setup:** Configure your editor to highlight unused variables automatically

### πŸ€– Issue Details

- **Rule:** `@typescript-eslint/no-unused-vars`
- **Category:** Code Quality
- **Severity:** error
- **Auto-generated:** 2024-12-21T21:30:00.000Z

---

**Labels:** `lint`, `code-quality`, `bug`, `automated`

This issue was automatically created by the ClearView Lint Automation system to help maintain code quality standards.
Loading
Loading