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

[Rule] Extra level of indentation #6893

Closed
serjflint opened this issue Aug 26, 2023 · 4 comments
Closed

[Rule] Extra level of indentation #6893

serjflint opened this issue Aug 26, 2023 · 4 comments
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule

Comments

@serjflint
Copy link

serjflint commented Aug 26, 2023

Hello!

Black is great and uncompromising but has changed over the years.
I am migrating a large codebase and the diff's size is insane. I hope to make the process more gradual.

I use ruff with autofixes to decrease the diff. Having a monorepo-compatible configuration helps a lot.
After the migration I will change configs in each sub-project separately.

The only problem left for me is an indentation. Our very old version of black puts extra level of space (8 in total) before the args, according to PEP 8. The modern black only uses one level of space (just 4).

Is it possible to add the number of spaces as a custom rule in ruff with autofix?

# In:
def func(
    arg1, arg2, arg3, ..., argN
):

# Out:
def func(
        arg1, arg2, arg3, ..., argN
):

P.S.: I can't migrate in smaller chunks because the whole codebase uses common tooling and CI.

@serjflint serjflint changed the title [Rule] Extra level of indentation for function definitions [Rule] Extra level of indentation Aug 26, 2023
@charliermarsh
Copy link
Member

Why is the indentation a problem here? Is the thinking here that would want to upgrade Black to latest, and use Ruff to modify the code to add the 8-space indentation? Or is Ruff flagging the 8-space indentation, and you want to avoid Ruff raising errors there?

I think I understand the use-case but I don't know that we can justify adding a rule for this -- it's a fairly specific need, but something we'll need to implement and maintain in perpetuity.

@charliermarsh charliermarsh added the needs-info More information is needed from the issue author label Aug 30, 2023
@serjflint
Copy link
Author

@charliermarsh Hi! Thank you for a detailed answer.

Why is the indentation a problem here?

The indentation is not a problem by itself. The problem is that Black switched the indentation without giving a way to configure it. Both 4 and 8 spaces are ok by PEP 8 if I understand it correctly.

Is the thinking here that would want to upgrade Black to latest, and use Ruff to modify the code to add the 8-space indentation?

Yes, exactly. I want to use Ruff to temporarily force it back to 8 spaces. After that I will use Ruff's .toml to configure sub-projects finely.

Or is Ruff flagging the 8-space indentation, and you want to avoid Ruff raising errors there?

Actually it isn't flagging neither 4 nor 8 spaces. And I haven't met a rule in Ruff which isn't configurable via .toml.

I think I understand the use-case but I don't know that we can justify adding a rule for this -- it's a fairly specific need, but something we'll need to implement and maintain in perpetuity.

I understand that it is a bit niche use-case. Not many people are skipping so many updates to catch up =) But for me this rule is a bit like a setting of single and double quotes (a problem with no way to use single quotes in Black). And I actually use Q000 and COM812 to decrease the diff, too.

@zanieb zanieb added rule Implementing or modifying a lint rule needs-decision Awaiting a decision from a maintainer and removed needs-info More information is needed from the issue author labels Sep 7, 2023
@charliermarsh
Copy link
Member

I'm going to close this in favor of the discussion happening in our own formatter here: #7310 (comment). Feel free to chime in there. I think we're unlikely to support this as a standalone lint rule, but perhaps it will end up being supported in our formatter.

@serjflint
Copy link
Author

Similar to #8360

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

3 participants