chore: add lint script to match linter.yaml from CI#809
Conversation
1. The script invokes Python linters from the CI, JSCPD is not invoked. 2. GitHub action is updated to run pyright using local env to match versions and make results reproduciable.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request aims to standardize the development workflow by introducing a local linting script that mirrors the CI's Python linting and formatting checks. By integrating Highlights
Changelog
Ignored Files
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a linting script to replicate CI checks locally and adds pyright as a development dependency. The changes are well-aligned with the goal of improving the local development workflow and ensuring code quality. I've suggested a small refactoring in the new lint.sh script to improve its maintainability by reducing code repetition. The dependency updates in pyproject.toml and uv.lock are correct.
| #!/bin/bash | ||
| # Local replica of .github/workflows/linter.yaml (excluding jscpd copy-paste check) | ||
|
|
||
| # ANSI color codes for premium output | ||
| RED='\033[0;31m' | ||
| GREEN='\033[0;32m' | ||
| YELLOW='\033[1;33m' | ||
| BLUE='\033[0;34m' | ||
| BOLD='\033[1m' | ||
| NC='\033[0m' # No Color | ||
|
|
||
| FAILED=0 | ||
|
|
||
| echo -e "${BLUE}${BOLD}=== A2A Python Fixed-and-Lint Suite ===${NC}" | ||
| echo -e "Fixing formatting and linting issues, then verifying types...\n" | ||
|
|
||
| # 1. Ruff Linter (with fix) | ||
| echo -e "${YELLOW}${BOLD}--- [1/4] Running Ruff Linter (fix) ---${NC}" | ||
| if uv run ruff check --fix; then | ||
| echo -e "${GREEN}✓ Ruff Linter passed (and fixed what it could)${NC}" | ||
| else | ||
| echo -e "${RED}✗ Ruff Linter failed${NC}" | ||
| FAILED=1 | ||
| fi | ||
|
|
||
| # 2. Ruff Formatter | ||
| echo -e "\n${YELLOW}${BOLD}--- [2/4] Running Ruff Formatter (apply) ---${NC}" | ||
| if uv run ruff format; then | ||
| echo -e "${GREEN}✓ Ruff Formatter applied${NC}" | ||
| else | ||
| echo -e "${RED}✗ Ruff Formatter failed${NC}" | ||
| FAILED=1 | ||
| fi | ||
|
|
||
| # 3. MyPy Type Checker | ||
| echo -e "\n${YELLOW}${BOLD}--- [3/4] Running MyPy Type Checker ---${NC}" | ||
| if uv run mypy src; then | ||
| echo -e "${GREEN}✓ MyPy passed${NC}" | ||
| else | ||
| echo -e "${RED}✗ MyPy failed${NC}" | ||
| FAILED=1 | ||
| fi | ||
|
|
||
| # 4. Pyright Type Checker | ||
| echo -e "\n${YELLOW}${BOLD}--- [4/4] Running Pyright ---${NC}" | ||
| if uv run pyright; then | ||
| echo -e "${GREEN}✓ Pyright passed${NC}" | ||
| else | ||
| echo -e "${RED}✗ Pyright failed${NC}" | ||
| FAILED=1 | ||
| fi | ||
|
|
||
| echo -e "\n${BLUE}${BOLD}=========================================${NC}" | ||
| if [ $FAILED -eq 0 ]; then | ||
| echo -e "${GREEN}${BOLD}SUCCESS: All linting and formatting tasks complete!${NC}" | ||
| exit 0 | ||
| else | ||
| echo -e "${RED}${BOLD}FAILURE: One or more steps failed.${NC}" | ||
| exit 1 | ||
| fi |
There was a problem hiding this comment.
This script is well-structured and achieves its goal. To improve maintainability and reduce code duplication, you could refactor the repeated logic for running each check into a helper function. This would make it easier to add or modify checks in the future.
#!/bin/bash
# Local replica of .github/workflows/linter.yaml (excluding jscpd copy-paste check)
# ANSI color codes for premium output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m' # No Color
FAILED=0
STEP=1
TOTAL_STEPS=4
# Helper function to run a check and report its status.
# Usage: run_check "Description" "Success Message" "Failure Message" command_to_run...
run_check() {
local description="$1"
local success_msg="$2"
local failure_msg="$3"
shift 3
# Add a newline before each step except the first one.
if [ "$STEP" -gt 1 ]; then
echo
fi
echo -e "${YELLOW}${BOLD}--- [${STEP}/${TOTAL_STEPS}] $description ---${NC}"
if "$@"; then
echo -e "${GREEN}✓ $success_msg${NC}"
else
echo -e "${RED}✗ $failure_msg${NC}"
FAILED=1
fi
((STEP++))
}
echo -e "${BLUE}${BOLD}=== A2A Python Fixed-and-Lint Suite ===${NC}"
echo -e "Fixing formatting and linting issues, then verifying types...\n"
run_check "Running Ruff Linter (fix)" "Ruff Linter passed (and fixed what it could)" "Ruff Linter failed" uv run ruff check --fix
run_check "Running Ruff Formatter (apply)" "Ruff Formatter applied" "Ruff Formatter failed" uv run ruff format
run_check "Running MyPy Type Checker" "MyPy passed" "MyPy failed" uv run mypy src
run_check "Running Pyright" "Pyright passed" "Pyright failed" uv run pyright
echo -e "\n${BLUE}${BOLD}=========================================${NC}"
if [ $FAILED -eq 0 ]; then
echo -e "${GREEN}${BOLD}SUCCESS: All linting and formatting tasks complete!${NC}"
exit 0
else
echo -e "${RED}${BOLD}FAILURE: One or more steps failed.${NC}"
exit 1
fi
Uh oh!
There was an error while loading. Please reload this page.