Skip to content

🔍 Enhancement: Comprehensive Code Quality and Linting Infrastructure #130

@manavgup

Description

@manavgup

🔍 Enhancement: Comprehensive Code Quality and Linting Infrastructure

📋 Summary

Enhance our code quality infrastructure to match the comprehensive linting, formatting, style checking, and documentation standards from the mcp_auto_pr project. This includes missing targets for doctest execution, stricter type checking, and improved CI integration.

🎯 Current Status Analysis

What We Have Now ✅

Our current Makefile includes basic linting and formatting:

# Current targets (basic implementation)
lint: lint-ruff lint-mypy                    # Basic linting
lint-ruff: ruff check . --line-length 120   # Basic Ruff linting
lint-mypy: mypy rag_solution/                # Relaxed MyPy settings
lint-docstrings: interrogate --fail-under=50 # Low docstring threshold
format: format-ruff                          # Basic formatting
format-check: ruff format --check           # Format checking
pre-commit-run: pre-commit run --all-files  # Pre-commit execution

What's Missing from mcp_auto_pr Standards ❌

1. Doctest Support

Missing: Documentation testing with executable examples

# mcp_auto_pr has:
test-doctest:
    poetry run pytest --doctest-modules src/

2. Stricter Type Checking

Current: Relaxed MyPy configuration

# We have (relaxed):
mypy rag_solution/ --ignore-missing-imports --disable-error-code=misc --no-strict-optional

# mcp_auto_pr has (strict):
mypy src/mcp_local_repo_analyzer/ --strict --warn-redundant-casts --warn-unused-ignores --explicit-package-bases

3. Higher Documentation Standards

Current: 50% docstring coverage threshold

# We have:
interrogate --fail-under=50 rag_solution/

# mcp_auto_pr has:
interrogate --fail-under=80 src/ -v

4. Comprehensive Quality Check Targets

Missing: Composite targets for different quality levels

# mcp_auto_pr has:
check-fast:       # Quick essential checks
check-quality:    # Comprehensive quality with formatting
check-style:      # Style checks without fixes
strict:           # Strictest quality requirements
analyze:          # Code analysis and metrics

5. Directory Structure Alignment

Issue: Mixed directory references (some use ., some use rag_solution/)

# Inconsistent:
ruff check .                    # Root directory
mypy rag_solution/              # Specific subdirectory
interrogate rag_solution/       # Specific subdirectory

📊 Gap Analysis Table

Feature mcp_auto_pr Our Project Status
Ruff Linting ruff check src/ tests/ --line-length 120 ruff check . --line-length 120 ⚠️ Missing tests/
MyPy Strictness --strict --warn-redundant-casts --warn-unused-ignores --ignore-missing-imports --no-strict-optional ❌ Too relaxed
Docstring Coverage --fail-under=80 --fail-under=50 ❌ Low standard
Doctest Execution pytest --doctest-modules src/ Not implemented ❌ Missing
Composite Targets check-fast, check-quality, strict Only ci-local ❌ Limited
Directory Consistency Consistent src/ and tests/ Mixed . and rag_solution/ ⚠️ Inconsistent
Analysis Tools analyze target with metrics Not implemented ❌ Missing

✅ Proposed Enhancements

1. Add Missing Makefile Targets

# New comprehensive targets to add:

## Doctest support
test-doctest:
	@echo "$(CYAN)📖 Running doctest examples...$(NC)"
	cd backend && poetry run pytest --doctest-modules rag_solution/ -v
	@echo "$(GREEN)✅ Doctest examples passed$(NC)"

## Stricter type checking
lint-mypy-strict:
	@echo "$(CYAN)🔎 Running strict Mypy type checker...$(NC)"
	cd backend && poetry run mypy rag_solution/ \
		--strict \
		--warn-redundant-casts \
		--warn-unused-ignores \
		--explicit-package-bases
	@echo "$(GREEN)✅ Strict Mypy checks passed$(NC)"

## Improved docstring checking
lint-docstrings-strict:
	@echo "$(CYAN)📝 Checking docstring coverage (80% threshold)...$(NC)"
	cd backend && poetry run interrogate --fail-under=80 rag_solution/ -v
	cd backend && poetry run pydocstyle rag_solution/
	@echo "$(GREEN)✅ Strict docstring checks passed$(NC)"

## Composite quality targets
check-fast: format-check lint-ruff
	@echo "$(GREEN)✅ Fast quality checks completed$(NC)"

check-quality: format lint lint-mypy-strict
	@echo "$(GREEN)✅ Comprehensive quality checks completed$(NC)"

check-style: format-check
	@echo "$(GREEN)✅ Style checks completed$(NC)"

strict: check-quality lint-docstrings-strict test-doctest
	@echo "$(GREEN)✅ Strictest quality requirements met$(NC)"

analyze:
	@echo "$(CYAN)📊 Running code analysis...$(NC)"
	cd backend && poetry run ruff check . --statistics || true
	cd backend && poetry run mypy rag_solution/ --show-error-codes --show-error-context || true
	@echo "$(GREEN)✅ Code analysis completed$(NC)"

2. Update Existing Targets for Consistency

# Enhanced existing targets:

lint-ruff:
	@echo "$(CYAN)🔍 Running Ruff linter...$(NC)"
	cd backend && poetry run ruff check rag_solution/ tests/ --line-length 120
	@echo "$(GREEN)✅ Ruff checks passed$(NC)"

format-ruff:
	@echo "$(CYAN)🔧 Running Ruff formatter and import sorter...$(NC)"
	cd backend && poetry run ruff format rag_solution/ tests/ --line-length 120
	cd backend && poetry run ruff check --fix rag_solution/ tests/ --line-length 120
	@echo "$(GREEN)✅ Ruff formatting and import sorting completed$(NC)"

format-check:
	@echo "$(CYAN)🔍 Checking code formatting...$(NC)"
	cd backend && poetry run ruff format --check rag_solution/ tests/ --line-length 120
	cd backend && poetry run ruff check rag_solution/ tests/ --line-length 120
	@echo "$(GREEN)✅ Format check completed$(NC)"

3. Enhanced CI Workflow Integration

# Add to .github/workflows/ci.yml:

- name: Run fast quality checks
  run: make check-fast
  continue-on-error: true

- name: Run doctest examples  
  run: make test-doctest
  continue-on-error: true

- name: Run code analysis
  run: make analyze
  continue-on-error: true

4. Add Required Dependencies

# Add to pyproject.toml [tool.poetry.group.dev.dependencies]:
interrogate = "^1.5.0"  # Docstring coverage
pydocstyle = "^6.3.0"   # Docstring style checking

📊 Success Criteria

Functional Requirements

  • ✅ Doctest examples execute successfully in CI
  • ✅ MyPy strict mode passes with explicit configuration
  • ✅ Docstring coverage meets 80% threshold (or fails clearly)
  • ✅ All linting targets use consistent directory structure
  • ✅ Composite targets (check-fast, strict) work correctly

Quality Standards

  • 📈 Docstring coverage: Increase from 50% → 80% threshold
  • 🔒 Type safety: Enable strict MyPy with proper warnings
  • 📖 Documentation: Executable doctest examples work
  • 🎯 Consistency: All targets reference same directories
  • 📊 Metrics: Code analysis provides actionable insights

Developer Experience

  • 😊 Clear feedback on what quality level was achieved
  • 🚀 Fast feedback with make check-fast (~30 seconds)
  • 🔧 Comprehensive checks with make strict (~2-3 minutes)
  • 📚 Documentation examples that actually run and pass
  • 🎛️ Granular control over different quality aspects

CI Integration

  • 🔄 CI runs fast checks on every commit
  • 📊 CI provides code analysis metrics
  • 📖 CI validates documentation examples
  • 🏆 Clear quality gates and standards

🚀 Implementation Plan

Phase 1: Foundation (Week 1)

  1. Add missing dependencies to pyproject.toml
  2. Update existing targets for directory consistency
  3. Add doctest support with basic examples
  4. Test locally to ensure no regressions

Phase 2: Strictness (Week 2)

  1. Implement strict MyPy configuration
  2. Raise docstring threshold to 80%
  3. Add composite quality targets
  4. Update CI workflow integration

Phase 3: Enhancement (Week 3)

  1. Add code analysis target
  2. Create quality documentation
  3. Train team on new targets
  4. Gather feedback and iterate

📈 Expected Impact

Quality Improvements

  • 80% docstring coverage (vs current 50%)
  • Strict type checking with proper error reporting
  • Executable documentation examples
  • Comprehensive code analysis metrics

Developer Productivity

  • Granular quality controls - choose appropriate level for task
  • Faster feedback loops - check-fast for quick iteration
  • Clear quality gates - understand what needs improvement
  • Better documentation - examples that actually work

Team Benefits

  • Consistent code quality across all contributors
  • Reduced PR review time - automated quality checks
  • Better onboarding - clear quality standards
  • Confidence in refactoring - strict type checking catches issues

🔗 References

🏷️ Labels

  • enhancement
  • code-quality
  • developer-experience
  • documentation

🎯 Acceptance Criteria

  • All new Makefile targets work without errors
  • CI passes with new quality checks (may be non-blocking initially)
  • Documentation includes examples of using new targets
  • Team can choose appropriate quality level for different scenarios
  • Code analysis provides actionable metrics and insights

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions