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

Use --output-format instead of --format #266

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
zanieb marked this conversation as resolved.
Show resolved Hide resolved
"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",
zanieb marked this conversation as resolved.
Show resolved Hide resolved
]

# 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 sufficiently recent, use the deprecated `--format`
# argument instead of `--output-format`.
zanieb marked this conversation as resolved.
Show resolved Hide resolved
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