pythonruff

Fix a specific rule in ruff


How do I fix only specific rule violations in ruff?

For example, I need to fix only rule F401.


Solution

  • To fix only specific rule violations using ruff, use:

    ruff check --select rule_name --fix
    

    Examples:

    To fix only rule F401, for all Python files in the current directory and all its subdirectories:

    ruff check --select F401 --fix
    

    Same, in a specific file:

    ruff check --select F401 --fix path/to/file