sublimelsp / LSP-ruff

LSP helper for ruff - an extremely fast Python linter, written in Rust.
https://packagecontrol.io/packages/LSP-ruff
MIT License
26 stars 4 forks source link

Diagnostics stop when ignoring PLR0904 #35

Closed jgbishop closed 9 months ago

jgbishop commented 9 months ago

I have the following .ruff.toml file in my repo folder:

select = ["ALL"]
ignore = [
    "PLR0904"
]

With PLR0904 in the ignore list, no diagnostics appear. Ruff itself runs just fine from the command line (at least a separate copy of it does; not sure how to call the bundled one just yet). As soon as I remove this entry from the ignore list, things resume working. I see no oddities in the Sublime console when log_debug is set to true. Any ideas what could be happening here?

rchl commented 9 months ago

Anything relevant in LSP: Log Panel?

jgbishop commented 9 months ago

I'm out of town until the 30th. Once I'm back, I'll check and let you know.

jgbishop commented 9 months ago

I see the following output in the LSP log panel:

LSP-ruff: ruff failed
  Cause: Failed to parse `c:\Repos\{redacted}\.ruff.toml`: TOML parse error at line 29, column 2
   |
29 |    "PLR0904",  # too-many-public-methods
   |  ^^^^^^^^^
Unknown rule selector: `PLR0904`

I have preview=True set in the file, which should enable this rule.

rchl commented 9 months ago

It looks more like a syntax error to me. How does the full configuration file look like?

rchl commented 9 months ago

Use

preview = true
select = ["ALL"]
ignore = [
    "PLR0904"
]
jgbishop commented 9 months ago

Here's my entire file:

extend-exclude = ["migrations"]
line-length = 100
preview = true
target-version = "py310"

select = ["ALL"]
ignore = [
    "ANN",  # Annotations
    "ARG",  # flake8-unused-arguments
    "C90",  # McCabe complexity
    "CPY",  # flake8-copyright  (** experimental **)
    "D",    # pydocstyle
    "I",    # import sorting
    "INP",  # flake8-no-pep420 (implicit namespace package)
    "PYI",  # flake8-pyi (type hinting)
    "Q",    # Quotes
    "SLF",  # flake8-self
    "TD",   # flake8-todos
    "TRY",  # tryceratops

    # Specific rules
    "A003",     # builtin-attribute-shadowing
    "B904",     # raise-without-from-inside-except
    "DJ012",    # django-unordered-body-content-in-model
    "EM101",    # raw-string-in-exception
    "FBT002",   # boolean-default-value-positional-argument
    "PERF203",  # try-except-in-loop
    "PLR6301",  # no-self-use
    # "PLR0904",  # too-many-public-methods
    "PLR0911",  # too-many-return-statements
    "PLR0912",  # too-many-branches
    "PLR0913",  # too-many-arguments
    "PLR0915",  # too-many-statements
    "RUF012",   # mutable-class-default
    "S603",     # subprocess-without-shell-equals-true
]

[flake8-builtins]
builtins-ignorelist = ["id"]
jgbishop commented 9 months ago

Even your minimal example yields the same results for me when I try it (same error as this comment above). I have my rules in a .ruff.toml file, if that makes a difference.

jgbishop commented 9 months ago

Could the bundled ruff version be to blame somehow? How do I even figure out what version is being used?

rchl commented 9 months ago

The version of ruff used is dictated by the version of LSP-ruff used (unless you've overriden command setting for some reason). You can check the version by running "Package Control: List packages" from the Command Palette.

Also please use my minimal config and provide the exact error it shows.

jgbishop commented 9 months ago

I'm using LSP-ruff 1.0.10 in Sublime Text 4. Here's the log output using your minimal example:

LSP-ruff: Using interpreter executable: C:\Users\jbishop\AppData\Local\Sublime Text\Package Storage\LSP-ruff\Scripts\ruff.exe
LSP-ruff: Running Ruff with: C:\Users\jbishop\AppData\Local\Sublime Text\Package Storage\LSP-ruff\Scripts\ruff.exe ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--format', 'json', '-', '--stdin-filename', 'c:\\Repos\\{redacted}\\examine_rest_log.py']
:: [15:47:34.721] <-  LSP-ruff window/logMessage: {'message': 'Using interpreter executable: C:\\Users\\jbishop\\AppData\\Local\\Sublime Text\\Package Storage\\LSP-ruff\\Scripts\\ruff.exe', 'type': 4}
:: [15:47:34.721] <-  LSP-ruff window/logMessage: {'message': "Running Ruff with: C:\\Users\\jbishop\\AppData\\Local\\Sublime Text\\Package Storage\\LSP-ruff\\Scripts\\ruff.exe ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--format', 'json', '-', '--stdin-filename', 'c:\\\\Repos\\\\{redacted}\\\\examine_rest_log.py']", 'type': 4}
LSP-ruff: ruff failed
  Cause: Failed to parse `c:\Repos\{redacted}\.ruff.toml`: TOML parse error at line 3, column 11
  |
3 | ignore = ["PLR0904"]
  |           ^^^^^^^^^
Unknown rule selector: `PLR0904`

:: [15:47:34.768] <-  LSP-ruff window/logMessage: {'message': 'ruff failed\n  Cause: Failed to parse `c:\\Repos\\{redacted}\\.ruff.toml`: TOML parse error at line 3, column 11\n  |\n3 | ignore = ["PLR0904"]\r\n  |           ^^^^^^^^^\nUnknown rule selector: `PLR0904`\n\n', 'type': 4}
:: [15:47:34.768] <-  LSP-ruff textDocument/publishDiagnostics: {'uri': 'file:///C:/Repos/{redacted}/examine_rest_log.py', 'diagnostics': []}
rchl commented 9 months ago

That's not the exact config I've provided. Please follow my instructions so that we can resolve this quicker. Maybe you are modifying wrong file and that causes this whole confusion.

jgbishop commented 9 months ago

The only change I made was to remove the whitespace in what you provided:

preview = true
select = ["ALL"]
ignore = ["PLR0904"]

I find it hard to imagine that whitespace is an issue, but I've tried it with exactly what you provided:

preview = true
select = ["ALL"]
ignore = [
    "PLR0904"
]

Here's the resulting output:

:: [15:58:32.914] <-  LSP-ruff window/logMessage: {'message': 'Using interpreter executable: C:\\Users\\jbishop\\AppData\\Local\\Sublime Text\\Package Storage\\LSP-ruff\\Scripts\\ruff.exe', 'type': 4}
:: [15:58:32.914] <-  LSP-ruff window/logMessage: {'message': "Running Ruff with: C:\\Users\\jbishop\\AppData\\Local\\Sublime Text\\Package Storage\\LSP-ruff\\Scripts\\ruff.exe ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--format', 'json', '-', '--stdin-filename', 'c:\\\\Repos\\\\{redacted}\\\\examine_rest_log.py']", 'type': 4}
LSP-ruff: ruff failed
  Cause: Failed to parse `c:\Repos\{redacted}\.ruff.toml`: TOML parse error at line 4, column 5
  |
4 |     "PLR0904"
  |     ^^^^^^^^^
Unknown rule selector: `PLR0904`

:: [15:58:33.052] <-  LSP-ruff window/logMessage: {'message': 'ruff failed\n  Cause: Failed to parse `c:\\Repos\\{redacted}\\.ruff.toml`: TOML parse error at line 4, column 5\n  |\n4 |     "PLR0904"\r\n  |     ^^^^^^^^^\nUnknown rule selector: `PLR0904`\n\n', 'type': 4}
:: [15:58:33.052] <-  LSP-ruff textDocument/publishDiagnostics: {'uri': 'file:///C:/Repos/{redacted}/examine_rest_log.py', 'diagnostics': []}
rchl commented 9 months ago

I wanted to make sure you are using the exact configuration to rule out issues like editing the wrong file.

How are you specifying this configuration file in LSP-ruff settings?

BTW. You can check which version of ruff it's using by running C:\Users\jbishop\AppData\Local\Sublime Text\Package Storage\LSP-ruff\Scripts\ruff.exe --version. Though I would expect that if it's too old version then it would complain about preview setting and if it's a recent version that it shouldn't complain about PLR0904 rule (even without preview enabled). So not sure what's happening.

jgbishop commented 9 months ago

Looks like my installed ruff version is 0.0.289. I'm actually not specifying the configuration file in the settings specifically, but I rather have a file named .ruff.toml in the top-level of my repo directory. According to the Ruff docs, this is an acceptable filename for the config.

It occurred to me just now that I also have a .ruff.toml file in my User folder (%APPDATA%\Roaming\ruff if I remember correctly), but I removed that file, restarted Sublime, and I still have the same issue.

This is a very puzzling problem...

rchl commented 9 months ago

You can delete C:\Users\jbishop\AppData\Local\Sublime Text\Package Storage\LSP-ruff\ and restart ST. It should reinstall the latest version. I think it will install 0.0.292 then.

rchl commented 9 months ago

And this rule was added in 0.0.290 so it makes sense that it doesn't work for you.

jgbishop commented 9 months ago

Makes sense. Thanks for your help!