Skip to content

Commit

Permalink
Use --output-format instead of --format (#266)
Browse files Browse the repository at this point in the history
`--format` is deprecated; includes backwards compatibility so we do not
need to bump the linter version

---------

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
  • Loading branch information
zanieb and dhruvmanila authored Oct 12, 2023
1 parent 36c64f4 commit 55568c4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ruff_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,18 @@ 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 = [
"--force-exclude",
"--no-cache",
"--no-fix",
"--quiet",
"--format",
"--output-format",
"json",
"-",
]
Expand Down Expand Up @@ -155,7 +158,7 @@ class VersionModified(NamedTuple):
"--watch",
# Arguments that are not supported at all, and will error when provided.
# "--stdin-filename",
# "--format",
# "--output-format",
]

# Arguments that are not allowed to be passed to `ruff format`.
Expand Down Expand Up @@ -1169,6 +1172,15 @@ async def _run_check_on_document(
else:
argv.append(arg)

# If the Ruff version is not 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 55568c4

Please sign in to comment.