Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--range support #94

Open
skairunner opened this issue Aug 13, 2024 · 4 comments
Open

--range support #94

skairunner opened this issue Aug 13, 2024 · 4 comments

Comments

@skairunner
Copy link

skairunner commented Aug 13, 2024

Ruff introduced a new parameter --range that allows the formatter to only check the specified range. This would be useful to allow migrating from black to ruff formatting without causing whole-file diffs whenever a file is touched for the first time.

Quote from docs:

Editor options:
      --range <RANGE>  When specified, Ruff will try to only format the code in
                       the given range.
                       It might be necessary to extend the start backwards or
                       the end forwards, to fully enclose a logical line.
                       The `<RANGE>` uses the format
                       `<start_line>:<start_column>-<end_line>:<end_column>`.

Is there a way to have range support within the pre-commit framework?

@AlexWaygood
Copy link
Member

AlexWaygood commented Aug 13, 2024

Hi! Would you be able to do this using the args key in your .pre-commit-config.yaml file? E.g. something like

  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.5.7
    hooks:
      - id: ruff
        name: Run ruff
        args: ["--range=1:2-3:4"]

@skairunner
Copy link
Author

Unfortunately not -- that would hardcode all pre-commits to use that specific range. I was thinking that it would be ideal if ruff could somehow receive the line numbers edited in the git commit and pass those along to ruff formatter, per-file. So it would basically only format the lines that were touched by the commit rather than all files touched.

But I don't know if that's supported within the pre-commit framework.

@AlexWaygood
Copy link
Member

Ahh I see, thanks for explaining

@MichaReiser
Copy link
Member

Yeah, this requires pre-commit support and possibly support for passing multiple ranges astral-sh/ruff#12800

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

No branches or pull requests

3 participants