Skip to content

Commit

Permalink
Add backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Oct 7, 2023
1 parent 4b30d69 commit f6eee83
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ruff_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ class VersionModified(NamedTuple):
# Require at least Ruff v0.0.291 for formatting, but allow older versions for linting.
VERSION_REQUIREMENT_FORMATTER = SpecifierSet(">=0.0.291,<0.2.0")
VERSION_REQUIREMENT_LINTER = SpecifierSet(">=0.0.189,<0.2.0")
# Version requirement for use of the "ALL" rule selector
VERSION_REQUIREMENT_ALL_SELECTOR = SpecifierSet(">=0.0.198,<0.2.0")
# Version requirement for use of the `--output-format` option
VERSION_REQUIREMENT_OUTPUT_FORMAT = SpecifierSet(">=0.0.291,<0.2.0")

# Arguments provided to every Ruff invocation.
CHECK_ARGS = [
Expand Down Expand Up @@ -1167,6 +1170,15 @@ async def _run_check_on_document(
else:
argv.append(arg)

# If the Ruff version is sufficiently recent, use the deprecated `--format`
# argument instead of `--output-format`.
if not VERSION_REQUIREMENT_OUTPUT_FORMAT.contains(
executable.version, prereleases=True
):
index = argv.index("--output-format")
argv.pop(index)
argv.insert(index, "--format")

# If we're trying to run a single rule, add it to the command line, and disable
# all other rules (if the Ruff version is sufficiently recent).
if only:
Expand Down

0 comments on commit f6eee83

Please sign in to comment.