Skip to content

Conversation

@dguido
Copy link
Member

@dguido dguido commented Nov 28, 2025

Summary

Replace multiple Python linting tools with Ruff - a single, fast, unified linter.

Changes

Deleted (6 files)

File What it was
black.yml Black formatter workflow
black_auto.yml Auto-fix black formatting
pylint.yml Pylint linter workflow
linter.yml Super-linter (GitHub's multi-linter)
matchers/*.json VS Code problem matchers

Added (4 files)

File Purpose
ruff.yml Ruff linting + yamllint workflow
.pre-commit-config.yaml Git hooks for local checks
.yamllint YAML linting config
pyproject.toml Ruff configuration

Why Ruff?

  • 10-100x faster than black + pylint + flake8
  • Single tool replaces multiple linters
  • Native pyproject.toml - no extra config files
  • Drop-in replacement - same rules, better performance

Pre-commit Hooks

Developers can now catch issues locally before pushing:

# Install hooks (one time)
pip install pre-commit
pre-commit install

# Hooks run automatically on git commit
# Or run manually:
pre-commit run --all-files

Part of

This is PR 2 of 4 splitting up #2768 (modernize-linting-and-config) into reviewable chunks.

PR Status
PR 1: Build system migration #2818
PR 2: Replace linters with ruff This PR
PR 3: CI modernization Pending
PR 4: Documentation Pending

🤖 Generated with Claude Code

Ruff is 10-100x faster than traditional Python linters and can replace
multiple tools with a single, unified configuration.

## Deleted (replaced by ruff)
- .github/workflows/black.yml
- .github/workflows/black_auto.yml
- .github/workflows/pylint.yml
- .github/workflows/linter.yml (super-linter)
- .github/workflows/matchers/*.json

## Added
- .github/workflows/ruff.yml - Fast Python linting + YAML validation
- .pre-commit-config.yaml - Git hooks for automated checks
- .yamllint - YAML linting configuration
- pyproject.toml - Ruff configuration (replaces black/pylint settings)

## Benefits
- Single tool instead of black + pylint + flake8 + isort
- 10-100x faster than traditional linters
- Pre-commit hooks catch issues before CI
- Native pyproject.toml configuration

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Comment on lines +26 to +68
name: Lint Code
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Run Ruff linter
uses: astral-sh/ruff-action@v1
with:
args: "check slither/ tests/ scripts/"

# Formatting check disabled to avoid changes to existing code
# - name: Run Ruff formatter check
# run: |
# echo "::group::Checking formatting with Ruff"
# ruff format --check slither/ tests/ scripts/ || FORMAT_EXIT=$?
# echo "::endgroup::"
# if [ "${FORMAT_EXIT:-0}" -ne 0 ]; then
# echo "❌ Formatting check failed. Run 'make reformat' or 'ruff format' locally to fix formatting."
# exit $FORMAT_EXIT
# fi
# echo "✅ Formatting check passed"

- name: Set up Python for yamllint
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install and run yamllint
run: |
# Use uv for fast installation
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
uv tool install yamllint
echo "::group::Running yamllint"
uvx yamllint .github/ || YAML_EXIT=$?
echo "::endgroup::"
if [ "${YAML_EXIT:-0}" -ne 0 ]; then
echo "❌ YAML linting failed. Fix the YAML syntax errors shown above."
exit $YAML_EXIT
fi
echo "✅ YAML linting passed"

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 3 days ago

To fix the problem, we need to explicitly set the permissions block in the workflow. For this workflow, the only activities are linting the code and yaml files—no steps involve writing results back to the repository, interacting with issues, or creating PRs. Therefore, the minimal permission required is contents: read. The permissions: key can be added either at the workflow root (affecting all jobs) or within a specific job (affecting only that job). Since there is only one job (lint), either is acceptable; best practice is at the workflow root for simplicity. To implement the change, add a block directly below the workflow name: on line 2:

permissions:
  contents: read

No new imports or custom methods are needed for this change.

Suggested changeset 1
.github/workflows/ruff.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml
--- a/.github/workflows/ruff.yml
+++ b/.github/workflows/ruff.yml
@@ -1,5 +1,7 @@
 ---
 name: Lint with Ruff
+permissions:
+  contents: read
 
 defaults:
   run:
EOF
@@ -1,5 +1,7 @@
---
name: Lint with Ruff
permissions:
contents: read

defaults:
run:
Copilot is powered by AI and may make mistakes. Always verify output.
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.

2 participants