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

is --line-length argument working? #357

Closed
BartolomeSintes opened this issue Dec 12, 2023 · 12 comments
Closed

is --line-length argument working? #357

BartolomeSintes opened this issue Dec 12, 2023 · 12 comments

Comments

@BartolomeSintes
Copy link

I am using VSCode 1.85 with Ruff extension updated (0.1.5).
I am trying to set the limit-length argument, but the E501 is not showing.
I think some screenshots will be useful in order to explain the issue:
My program is just two lines: one with an f-string without placeholders (line 2) and another one with a long line (line 3, 135 characters long). The F541 warning is shown as expected:
2023-12-12-1
If I ignore the F541 warning in settings.json, the warning is not shown anymore:
2023-12-12-2
So ruff seems to be working as expected, but the E501 is not shown.
I understand that line length must be set in ruff.lint.args, as explained in astral-sh/ruff#8363
Am I doing something wrong or is it a ruff extension bug?
Thanking you in advance,
Bartolomé Sintes

@charliermarsh
Copy link
Member

Sorry for the confusion -- we no longer include E501 in the default rule set, so you need to add --select=E501 or --select=E to your ruff.lint.args.

@charliermarsh
Copy link
Member

You can see the default configuration at the top here: https://docs.astral.sh/ruff/configuration/

@BartolomeSintes
Copy link
Author

Thank you for your fast answer. You are completely right.
When I read the pull 8363, "Add --line-length option to format command" I did not realize it was a pull in the ruff repository, not in the ruff-vscode one. I supposed that line-length should be added to the ruff.format.args section, not to the ruff.lint.args as it should. My mistake, sorry.
Keep your very good work!

@jmakov
Copy link

jmakov commented Jan 3, 2024

What's even more confusing to me is running ruff check --line-length 10 my.py doesn't return any errors.

@charliermarsh
Copy link
Member

@jmakov -- Per the above, you need to enable the line-length rule -- it's not included by default, since it often conflicts with using a formatter. Can you try adding --extend-select=E to your command and configuration?

@jmakov
Copy link

jmakov commented Jan 3, 2024

@jmakov -- Per the above, you need to enable the line-length rule -- it's not included by default, since it often conflicts with using a formatter. Can you try adding --extend-select=E to your command and configuration?

Thank you for the quick response. Yes, that works. Would expect a flag to overwrite everything when the user uses it. Anyhow, my probl is solved, thanks.

@romanholidaypancakes
Copy link

romanholidaypancakes commented Jan 15, 2025

hi, so what is the correct approach here? I added "--extend-select=E" and it will cause an error when running

Image

I want it to stay formatted after it exceeds 130 characters.

@dhruvmanila
Copy link
Member

@romanholidaypancakes I'm assuming that you're using ruff-lsp as you're using ruff.format.args setting. I'd suggest to migrate to using the native server.

Regardless, the --extend-select flag is part of the linter but you're providing it for the formatter which is why it must be causing an error.

@romanholidaypancakes
Copy link

romanholidaypancakes commented Jan 16, 2025

I am using vscode, I reconfigured the following in settings.json,

    "ruff.enable": true,
    "ruff.lint.args": [
        "--select=E --line-length 130"
    ],

but still got an error

Then I set this

    "ruff.lineLength": 130,
    "ruff.lint.select": [
        "E"
    ],

No error is reported, but the string is not formatted when the length is exceeded

@dhruvmanila
Copy link
Member

No error is reported, but the string is not formatted when the length is exceeded

Can you share a minimal source code on which you're running Ruff? I'm guessing that it's a long string and your expectation is that the string should break once it goes beyond the line length. Is that correct? If so, then that's not currently supported, it can be tracked here: astral-sh/ruff#6936.

@romanholidaypancakes
Copy link

Yes, for example, if I set the maximum length to 130, then the excess will be automatically formatted. I remember using ruff before and it worked fine.

@dhruvmanila
Copy link
Member

Yes, for example, if I set the maximum length to 130, then the excess will be automatically formatted. I remember using ruff before and it worked fine.

Yeah, that is not yet supported, refer to the linked issue.

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

5 participants