sublimelsp / LSP-ruff

LSP helper for ruff - an extremely fast Python linter, written in Rust.

Home Page:https://packagecontrol.io/packages/LSP-ruff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Diagnostics stop when ignoring PLR0904

jgbishop opened this issue · comments

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?

Anything relevant in LSP: Log Panel?

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

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.

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

Use

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

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"]

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.

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

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.

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': []}

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.

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': []}

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.

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...

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.

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

Makes sense. Thanks for your help!