lint-python

star 27

Check Python code quality with Ruff

y1feng200156 By y1feng200156 schedule Updated 2/10/2026

name: lint-python description: Check Python code quality with Ruff

Python Lint Skill

๐Ÿ“‹ Overview

Use Ruff to check Python code quality, an extremely fast Python linter written in Rust:

  • ๐Ÿš€ 10-100x faster than traditional linters (Flake8, Pylint)
  • ๐Ÿ”„ Replaces multiple tools: Flake8, isort, pyupgrade, autoflake
  • ๐Ÿ“ 800+ rules: Covering code style, error detection, performance optimization
  • ๐Ÿ”ง Auto-fix: One-click fix for most issues

๐Ÿ”ง Prerequisites

Tool Min Version Check Command Installation
Python 3.8+ python --version python.org
Ruff 0.1.0+ ruff --version pip install ruff or pipx install ruff

Note: The script will auto-detect if Ruff is installed and provide a friendly prompt if missing.

๐Ÿš€ Usage

Method 1: Use AI Assistant

"Use lint-python skill to check my code"
"Check Python code quality with Ruff"

Method 2: Run Script Directly

Windows (PowerShell):

.\.agent\skills\lint-python\scripts\lint.ps1

Linux/Mac (Bash):

./.agent/skills/lint-python/scripts/lint.sh

Method 3: With Parameters

Check specific directory:

# Windows
.\.agent\skills\lint-python\scripts\lint.ps1 -Path ".\src"

# Linux/Mac  
./.agent/skills/lint-python/scripts/lint.sh src

Auto-fix issues:

# Windows
.\.agent\skills\lint-python\scripts\lint.ps1 -Fix

# Linux/Mac
./.agent/skills/lint-python/scripts/lint.sh --fix

Show errors only (ignore warnings):

# Windows
.\.agent\skills\lint-python\scripts\lint.ps1 -ErrorsOnly

# Linux/Mac
./.agent/skills/lint-python/scripts/lint.sh --errors-only

๐ŸŽฏ What It Checks

Code Style (Pycodestyle)

  • โœ… PEP 8 compliance
  • โœ… Indentation and whitespace
  • โœ… Line length limits
  • โœ… Naming conventions

Error Detection (Pyflakes)

  • โœ… Unused imports and variables
  • โœ… Undefined names
  • โœ… Duplicate keys
  • โœ… Invalid print statements

Import Sorting (isort)

  • โœ… Import statement grouping
  • โœ… Alphabetical ordering
  • โœ… Stdlib/third-party/local separation

Code Upgrade (pyupgrade)

  • โœ… Old syntax detection (e.g., % formatting)
  • โœ… Type annotation simplification
  • โœ… Recommend modern Python patterns

Performance and Best Practices

  • โœ… List comprehension optimization
  • โœ… f-string recommendation
  • โœ… Set operation efficiency
  • โœ… Exception handling standards

๐Ÿ“Š Output Example

๐Ÿ Python Lint - Checking code...

โœ… Python: Python 3.11.7
โœ… Ruff: ruff 0.2.1

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
๐Ÿ“ Scanning directory: C:\Users\WJ\Project\src
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

src/main.py:15:1: F401 [*] `os` imported but unused
    |
 15 | import os
    | ^^^^^^^^^ F401
    |
    = help: Remove unused import: `os`

src/utils.py:42:5: E501 Line too long (95 > 88 characters)
    |
 42 |     return f"Processing data from {source} with parameters {params_dict}"
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501

src/config.py:23:5: S105 Possible hardcoded password: "secret123"
    |
 23 |     password = "secret123"
    |     ^^^^^^^^^^^^^^^^^^^^^^ S105

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
๐Ÿ“Š Check Results:
   โœ… Passed: 12 files
   โš ๏ธ  Warnings: 1 issue (E501)
   โŒ Errors: 2 issues (F401, S105)

๐Ÿ’ก Tips:
   - Run lint.ps1 -Fix to auto-fix F401
   - Security issue S105 requires manual handling
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โš™๏ธ Configuration

Create pyproject.toml or ruff.toml in the project root:

pyproject.toml

[tool.ruff]
# Set line length
line-length = 88

# Target Python version
target-version = "py38"

# Excluded directories
exclude = [
    ".git",
    ".venv",
    "__pycache__",
    "build",
    "dist",
]

[tool.ruff.lint]
# Enabled rule sets
select = [
    "E",     # pycodestyle errors
    "W",     # pycodestyle warnings
    "F",     # pyflakes
    "I",     # isort
    "N",     # pep8-naming
    "S",     # flake8-bandit (security)
    "B",     # flake8-bugbear
    "C90",   # mccabe complexity
    "UP",    # pyupgrade
]

# Ignored rules
ignore = [
    "E501",  # Line length (handled by formatter)
]

# Per-file ignores
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]  # Allow unused imports
"tests/*" = ["S101"]      # Allow assert statements

[tool.ruff.lint.mccabe]
# Maximum complexity
max-complexity = 10

ruff.toml (Simplified)

line-length = 88
target-version = "py38"

[lint]
select = ["E", "F", "I", "N", "S", "B"]
ignore = ["E501"]

[lint.per-file-ignores]
"__init__.py" = ["F401"]

๐Ÿ”„ CI/CD Integration

GitHub Actions

name: Python Lint
on: [push, pull_request]

jobs:
  ruff:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      
      - name: Install Ruff
        run: pip install ruff
      
      - name: Run Ruff
        run: ruff check .

GitLab CI

ruff:
  image: python:3.11
  script:
    - pip install ruff
    - ruff check .
  only:
    - merge_requests
    - main

Pre-commit Hook

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.2.1
    hooks:
      - id: ruff
        args: [--fix, --exit-non-zero-on-fix]

๐Ÿ†˜ FAQ

Q: What's the difference between Ruff and Flake8/Pylint?
A: Ruff is 10-100x faster and consolidates multiple tools, reducing configuration complexity

Q: What if Ruff is not installed?
A: The script will auto-detect and prompt installation:

pip install ruff        # Local install
pipx install ruff       # Global install (recommended)

Q: How to ignore warnings on specific lines?
A: Use inline comments:

import os  # noqa: F401
password = "temp"  # noqa: S105

Q: How to see all available rules?
A: Run ruff linter or visit Ruff Rules

Q: Can all issues be auto-fixed?
A: Some issues can be auto-fixed with --fix. Security issues require manual review

Q: Is it compatible with Black formatter?
A: Fully compatible! Ruff's formatting is 100% compatible with Black

๐Ÿ”— Related Resources

Install via CLI
npx skills add https://github.com/y1feng200156/ham-study --skill lint-python
Repository Details
star Stars 27
call_split Forks 5
navigation Branch main
article Path SKILL.md
More from Creator
y1feng200156
y1feng200156 Explore all skills →