-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
line-length for formatter doesn't respect noqa: E501 comment #9393
Comments
You might be looking for |
I did not know about Also understand that linting and formatting are separate things, but I think some lint rules that are related to formatting (like E501) should be considered when formatting. |
Can you provide an example of what you’re trying to accomplish? I don’t quite understand. (The skip comment must be placed at the end of the statement, not the end of the line.) |
Sure, I tend to write function definitions in a single line, even if they surpass the line length limit. To achieve this I add a def some_function_with_a_very_long_and_descriptive_name(arg_1: str, arg_2: int) -> tuple[SomeType | SomeOtherType, str | None]: # noqa: E501
pass Based on your comment I should also add a def some_function_with_a_very_long_and_descriptive_name_1(arg_1: str, arg_2: int) -> tuple[SomeType | SomeOtherType, str | None]: # noqa: E501 # fmt: skip
pass
def some_function_with_a_very_long_and_descriptive_name_2(arg_1: str, arg_2: int) -> tuple[SomeType | SomeOtherType, str | None]: # fmt: skip # noqa: E501
pass
def some_function_with_a_very_long_and_descriptive_name_3(arg_1: str, arg_2: int) -> tuple[SomeType | SomeOtherType, str | None]: # fmt: skip
pass The first two does not work (you can see the result bellow), and the last one that works will cause a lint error (as it still requires an def some_function_with_a_very_long_and_descriptive_name_1(
arg_1: str, arg_2: int
) -> tuple[SomeType | SomeOtherType, str | None]: # noqa: E501 # fmt: skip
pass
def some_function_with_a_very_long_and_descriptive_name_2(
arg_1: str, arg_2: int
) -> tuple[SomeType | SomeOtherType, str | None]: # fmt: skip # noqa: E501
pass
def some_function_with_a_very_long_and_descriptive_name_3(arg_1: str, arg_2: int) -> tuple[SomeType | SomeOtherType, str | None]: # fmt: skip
pass Now, if I run # fmt: skip
def some_function_with_a_very_long_and_descriptive_name_3(
arg_1: str, arg_2: int
) -> tuple[SomeType | SomeOtherType, str | None]:
pass Further more, even if I disable the E501 rule and only rely on formatter for line length, def some_function_with_a_very_long_and_descriptive_name(arg_1: str, arg_2 : int ) -> tuple[ SomeType | SomeOtherType, str | None]:
pass what I want is to be able to skip the line length formatting for this line, while still applying the whitespace formatting. But if I apply the So it will become: def some_function_with_a_very_long_and_descriptive_name(arg_1: str, arg_2 : int ) -> tuple[ SomeType | SomeOtherType, str | None]: # fmt: skip
pass while the desired outcome is something like: def some_function_with_a_very_long_and_descriptive_name(arg_1: str, arg_2: int ) -> tuple[ SomeType | SomeOtherType, str | None]: # fmt: skip-line-length
pass |
Thanks, that's really helpful! That Ruff is ignoring the skip in To be honest, I think it's unlikely that we modify the formatter to respect |
If allowing individual switches for individual formatting rules is too complicated to implement, can we at least have the ability to set a separate line length limit for formatter (separate from the linter's line length limit)? This way I'll be able to set the formatter's line length limit to something large (say 1000 characters) and effectively offload the line length formatting to the linter. |
I believe that actually is supported, if you use the setting under [tool.ruff]
# Use a line length of 100 by default (e.g., in the formatter).
line-length = 100
[tool.ruff.lint.pycodestyle]
# But override the linter's enforced line length to 10.
max-line-length = 10 |
It works and it doesn't 😆 My current config is: [tool.ruff]
line-length = 320
[tool.ruff.lint.pycodestyle]
max-line-length = 120 now when running def _some_really_really_really_really_really_long_function_name) -> tuple[SomeClassOne | SomeOtherClassTwo, str | None]: # noqa: E501
... The error I get is: The same thing happens if I run I'm not sure why, but I'm not getting this error in my IDE (I'm using ruff-lsp 0.0.48), I'm assuming its an new issue in a newer version of ruff (newer than the one used by ruff-lsp 0.0.48). I think it's a separate issue in ruff linter! If you think so as well, I'll open a separate issue for it. |
Hmm, I'm not able to reproduce this. For me running with the above configuration yields no errors on: def _some_really_really_really_really_really_long_function_name() -> tuple[SomeClassOne | SomeOtherClassTwo, str | None]: # noqa: E501
... Given: [tool.ruff]
line-length = 320
[tool.ruff.lint.pycodestyle]
max-line-length = 120 Running |
Closing for now as we support the mixed |
I'm running ruff's formatter with default config (ruff v0.1.11), and it's trying to
fix my E501 violations even when the line has a
# noqa: E501
.I'm expecting it to respect the E501 ignore comment and do not re-format and add-line-break to lines that exceed the line length limit (cause E501 error).
Not respecting the E501 ignore in formatter will effectively make it useless in linter because as soon as you run the formatter it will break all the long lines and effectivly make the
# noqa: E501
useless.The text was updated successfully, but these errors were encountered: