Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

manavgup
Copy link
Collaborator

@manavgup manavgup commented Aug 3, 2025

Closes #410

  • Add support for linting specific files and directories via arguments
  • Implement smart file type detection (Python, YAML, JSON, Markdown, TOML)
  • Add convenience targets: lint-quick, lint-fix, lint-smart
  • Add git integration: lint-changed, lint-staged, pre-commit hooks
  • Fix TARGET variable parsing for multiple directories
  • Add dummy targets to prevent 'No rule to make target' errors

✅ Changes Made

Core Implementation

  • Fixed TARGET variable handling: Changed from TARGET ?= mcpgateway tests to DEFAULT_TARGETS := mcpgateway tests; TARGET ?= $(DEFAULT_TARGETS) to properly handle multiple directories
  • Added dummy target support: Implemented ifneq block to create dummy targets for file arguments, preventing "No rule to make target" errors
  • Enhanced argument parsing: Updated lint target to properly handle multiple file arguments passed as additional goals

Linting Enhancements

  • Smart file type detection: Added lint-smart target that auto-detects file types (.py, .yaml, .json, .md, .toml, .sh) and runs appropriate linters
  • File-specific linting targets: Implemented lint-py, lint-yaml, lint-json, lint-md for targeting specific file types
  • Convenience targets: Added lint-quick (fast linters only), lint-fix (auto-fix formatting), lint-changed (git integration)

Git Integration

  • Changed files linting: make lint-changed lints only files modified in git
  • Staged files linting: make lint-staged lints only git-staged files
  • Pre-commit hook support: Added targets for git hook integration

🚀 Usage Examples

# Single file linting
make lint mcpgateway/config.py

# Directory linting  
make lint mcpgateway/

# Multiple files
make lint mcpgateway/config.py mcpgateway/validators.py

# Quick lint (fast checks only)
make lint-quick mcpgateway/config.py

# Auto-fix formatting issues
make lint-fix mcpgateway/config.py

# Smart file type detection
make lint-smart config.yaml

# Git integration
make lint-changed    # Lint only changed files
make lint-staged     # Lint only staged files

# Traditional full project (still works)
make lint

✅ Acceptance Criteria Met

  • ✅ make lint filename works for single files
  • ✅ make lint dirname works for directories
  • ✅ make lint without args still lints entire project
  • ✅ All Python linters support file/directory targeting
  • ✅ Config file linters detect file type and run appropriately
  • ✅ Clear error messages for non-existent files
  • ✅ make lint-fix repairs formatting issues
  • ✅ make lint-quick provides fast feedback
  • ✅ Performance: Single file linting is notably faster than full project
  • ✅ Git integration for changed/staged files
  • ✅ Pre-commit hook support

🧪 Testing

All functionality has been tested and verified:

# Core functionality tests
make lint mcpgateway/config.py          # ✅ Single file
make lint mcpgateway/                   # ✅ Directory  
make lint                               # ✅ Full project
make lint-quick mcpgateway/config.py    # ✅ Quick lint
make lint-fix mcpgateway/config.py      # ✅ Auto-fix
make lint-changed                       # ✅ Git integration

# File type detection tests  
make lint-smart test.yaml               # ✅ YAML detection
make lint-smart test.json               # ✅ JSON detection
make lint-smart test.md                 # ✅ Markdown detection

# Error handling tests
make lint nonexistent.py               # ✅ Graceful error for missing files

- Add support for linting specific files and directories via arguments
- Implement smart file type detection (Python, YAML, JSON, Markdown, TOML)
- Add convenience targets: lint-quick, lint-fix, lint-smart
- Add git integration: lint-changed, lint-staged, pre-commit hooks
- Fix TARGET variable parsing for multiple directories
- Remove duplicate lint-changed target definitions
- Add dummy targets to prevent 'No rule to make target' errors

Usage:
- make lint filename.py (single file)
- make lint dirname/ (directory)
- make lint-quick filename.py (fast linters only)
- make lint-changed (git changed files)

Resolves: 'mcpgateway tests is not a Python file or directory' error
Fixes: Duplicate target override warnings
Implements: All requirements from file-specific linting chore
@manavgup manavgup requested a review from crivetimihai as a code owner August 3, 2025 02:31
Signed-off-by: Mihai Criveti <[email protected]>
Signed-off-by: Mihai Criveti <[email protected]>
Copy link
Member

@crivetimihai crivetimihai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very very cool. Should follow up with some documentation.

Added markdownlint-cli2 and config.

@crivetimihai crivetimihai merged commit 43bae43 into IBM:main Aug 3, 2025
31 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CHORE]: Add make lint filename|dirname target to Makefile
2 participants