Commit graph

450 commits

Author SHA1 Message Date
Auguste Lalande
3ed707f245
Spellcheck & grammar (#10375)
## Summary

I used `codespell` and `gramma` to identify mispellings and grammar
errors throughout the codebase and fixed them. I tried not to make any
controversial changes, but feel free to revert as you see fit.
2024-03-13 02:34:23 +00:00
Jane Lewis
0c84fbb6db
ruff server - A new built-in LSP for Ruff, written in Rust (#10158)
<!--
Thank you for contributing to Ruff! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

This PR introduces the `ruff_server` crate and a new `ruff server`
command. `ruff_server` is a re-implementation of
[`ruff-lsp`](https://github.com/astral-sh/ruff-lsp), written entirely in
Rust. It brings significant performance improvements, much tighter
integration with Ruff, a foundation for supporting entirely new language
server features, and more!

This PR is an early version of `ruff_lsp` that we're calling the
**pre-release** version. Anyone is more than welcome to use it and
submit bug reports for any issues they encounter - we'll have some
documentation on how to set it up with a few common editors, and we'll
also provide a pre-release VSCode extension for those interested.

This pre-release version supports:
- **Diagnostics for `.py` files**
- **Quick fixes**
- **Full-file formatting**
- **Range formatting**
- **Multiple workspace folders**
- **Automatic linter/formatter configuration** - taken from any
`pyproject.toml` files in the workspace.

Many thanks to @MichaReiser for his [proof-of-concept
work](https://github.com/astral-sh/ruff/pull/7262), which was important
groundwork for making this PR possible.

## Architectural Decisions

I've made an executive choice to go with `lsp-server` as a base
framework for the LSP, in favor of `tower-lsp`. There were several
reasons for this:

1. I would like to avoid `async` in our implementation. LSPs are mostly
computationally bound rather than I/O bound, and `async` adds a lot of
complexity to the API, while also making harder to reason about
execution order. This leads into the second reason, which is...
2. Any handlers that mutate state should be blocking and run in the
event loop, and the state should be lock-free. This is the approach that
`rust-analyzer` uses (also with the `lsp-server`/`lsp-types` crates as a
framework), and it gives us assurances about data mutation and execution
order. `tower-lsp` doesn't support this, which has caused some
[issues](https://github.com/ebkalderon/tower-lsp/issues/284) around data
races and out-of-order handler execution.
3. In general, I think it makes sense to have tight control over
scheduling and the specifics of our implementation, in exchange for a
slightly higher up-front cost of writing it ourselves. We'll be able to
fine-tune it to our needs and support future LSP features without
depending on an upstream maintainer.

## Test Plan

The pre-release of `ruff_server` will have snapshot tests for common
document editing scenarios. An expanded test suite is on the roadmap for
future version of `ruff_server`.
2024-03-08 20:57:23 -08:00
Charlie Marsh
a892fc755d
Bump version to v0.3.2 (#10304) 2024-03-09 00:24:22 +00:00
Charlie Marsh
ea79f616bc
Bump version to v0.3.1 (#10252) 2024-03-06 19:59:04 +00:00
Micha Reiser
fe6afbe406
Fix ruff-action documentation to consistently use args instead of options (#10249) 2024-03-06 18:09:45 +01:00
Hoël Bagard
d441338358
Improve documentation of the preview mode (#10168)
## Summary

This PR was prompted by the discussion in #10153.
It adds CLI tab examples next to the `pyproject.toml` and `ruff.toml`
examples. It should be helpful for users wanting to try out the preview
mode without modifying or creating a `.toml` file.
It also adds a paragraph to try to make the effect of the preview mode
less confusing.
2024-03-05 03:08:30 +00:00
Alex Waygood
8b749e1d4d
Make --config and --isolated global flags (#10150) 2024-03-04 11:19:40 +00:00
Hoël Bagard
c27e048ff2
docs: update docker release version (#10218)
## Summary

This PR updates the docker release version from `0.1.3` to `0.3.0`
(latest), since `0.1.3` does not seem to exist anymore.
2024-03-03 21:17:54 -05:00
Greenstar
8b5daaec7d
Fix broken documentation links affected by namespace changes in lint rules (#10182) 2024-03-01 12:35:29 +01:00
Micha Reiser
b53118ed00
Bump version to v0.3.0 (#10151)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-02-29 16:05:20 +01:00
Micha Reiser
8044c24c7e
Remove "Beta" Label from formatter documentation (#10144) 2024-02-28 12:47:37 +00:00
Charlie Marsh
f5904a20d5
Add package name to requirements-insiders.txt (#10090) 2024-02-26 10:52:58 -05:00
Raphael Boidol
51ce88bb23
docs: update actions in documentation to recent versions without deprecation warnings (#10109) 2024-02-24 13:16:10 +00:00
Charlie Marsh
235cfb7976
Bump version to v0.2.2 (#10018) 2024-02-17 22:15:04 +00:00
Micha Reiser
46db3f96ac
Add example demonstrating that fmt: skip on expression level is not supported (#9973) 2024-02-13 15:35:27 +00:00
wzy
25868d0371
docs: add mdformat-ruff to integrations.md (#9924)
Can [mdformat-ruff](https://github.com/Freed-Wu/mdformat-ruff) be hosted
in <https://github.com/astral-sh> like other integrations of ruff? TIA!
2024-02-11 03:39:15 +00:00
Alex Waygood
8ec56277e9
Allow arbitrary configuration options to be overridden via the CLI (#9599)
Fixes #8368
Fixes https://github.com/astral-sh/ruff/issues/9186

## Summary

Arbitrary TOML strings can be provided via the command-line to override
configuration options in `pyproject.toml` or `ruff.toml`. As an example:
to run over typeshed and respect typeshed's `pyproject.toml`, but
override a specific isort setting and enable an additional pep8-naming
setting:

```
cargo run -- check ../typeshed --no-cache --config ../typeshed/pyproject.toml --config "lint.isort.combine-as-imports=false" --config "lint.extend-select=['N801']"
```

---------

Co-authored-by: Micha Reiser <micha@reiser.io>
Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-02-09 21:56:37 +00:00
Charlie Marsh
0ccca4083a
Bump version to v0.2.1 (#9843) 2024-02-05 15:31:05 -05:00
Micha Reiser
b3dc565473
Add --range option to ruff format (#9733)
Co-authored-by: T-256 <132141463+T-256@users.noreply.github.com>
2024-02-05 19:21:45 +00:00
Zanie Blue
1fadefa67b
Bump version to 0.2.0 (#9762)
Follows https://github.com/astral-sh/ruff/pull/9680
2024-02-01 17:10:33 -06:00
Zanie Blue
a0ef087e73 Add rule deprecation infrastructure (#9689)
Adds a new `Deprecated` rule group in addition to `Stable` and
`Preview`.

Deprecated rules:
- Warn on explicit selection without preview
- Error on explicit selection with preview
- Are excluded when selected by prefix with preview

Deprecates `TRY200`, `ANN101`, and `ANN102` as a proof of concept. We
can consider deprecating them separately.
2024-02-01 13:35:02 -06:00
Zanie
a0f32dfa55 Error if nursery rules are selected without preview (#9683)
Extends #9682 to error if the nursery selector is used or nursery rules
are selected without preview.

Part of #7992 — we will remove this in 0.3.0 instead so we can provide
nice errors in 0.2.0.
# Conflicts:
#	crates/ruff/tests/integration_test.rs
#	crates/ruff_workspace/src/configuration.rs
2024-02-01 13:35:02 -06:00
Zanie
6aa643346f Replace --show-source and --no-show-source with --output_format=<full|concise> (#9687)
Fixes #7350

## Summary

* `--show-source` and `--no-show-source` are now deprecated.
* `output-format` supports two new variants, `full` and `concise`.
`text` is now a deprecated variant, and any use of it is treated as the
default serialization format.
* `--output-format` now default to `concise`
* In preview mode, `--output-format` defaults to `full`
* `--show-source` will still set `--output-format` to `full` if the
output format is not otherwise specified.
* likewise, `--no-show-source` can override an output format that was
set in a file-based configuration, though it will also be overridden by
`--output-format`

## Test Plan

A lot of tests were updated to use `--output-format=full`. Additional
tests were added to ensure the correct deprecation warnings appeared,
and that deprecated options behaved as intended.
# Conflicts:
#	crates/ruff/tests/integration_test.rs
2024-02-01 13:35:02 -06:00
Micha Reiser
c3b33e9c4d Promote lint. settings over top-level settings (#9476) 2024-02-01 13:35:02 -06:00
Charlie Marsh
a7755d7a8d
Bump version to v0.1.15 (#9690) 2024-01-29 17:44:05 -05:00
Andrew Gallant
fc3e2664f9
help: enable auto-wrapping of help output (#9633)
Previously, without the 'wrap_help' feature enabled, Clap would not do
any auto-wrapping of help text. For help text with long lines, this
tends to lead to non-ideal formatting. It can be especially difficult to
read when the width of the terminal is smaller.

This commit enables 'wrap_help', which will automatically cause Clap to
query the terminal size and wrap according to that. Or, if the terminal
size cannot be determined, it will default to a maximum line width of
100.

Ref https://github.com/astral-sh/ruff/pull/9599#discussion_r1464992692
2024-01-24 10:51:07 -05:00
Robert Craigie
9dc59cbb81
Docs: fix isort rule code (#9598)
## Summary

Fixes a typo in the docs, the isort rule code in an example was not
correct.
2024-01-21 15:30:14 +00:00
Charlie Marsh
866bea60a5
Bump version to v0.1.14 (#9581) 2024-01-19 12:54:39 -05:00
Charlie Marsh
8788d57030
Add instructions on using noqa with isort rules (#9555)
Closes https://github.com/astral-sh/ruff/issues/9554.
2024-01-16 20:19:33 +00:00
port19
b6ce4f5f3a
update emacs integration section to include emacs-ruff-format (#9403)
## Summary

For emacs users just seeking a ruff formatter, apheleia is overkill.
Instead, a melpa package
[emacs-ruff-format](https://github.com/scop/emacs-ruff-format) exists
now.
This change prepends a mention of this package, without removing
apheleia as an alternative.

## Test Plan

This is how I integrated ruff into my emacs.
2024-01-14 02:55:51 +00:00
pabepadu
ef2798f758
fix(docs): admonition in dark mode (#9502)
## Summary

The admonition in dark mode are in actually same as in light mode here:
https://docs.astral.sh/ruff/formatter/#ruff-format

I propose to move admonition in real dark mode as shown below:
- Before the PR https://github.com/astral-sh/ruff/pull/9385

![image](abb7e0db-bf12-49cd-9f9b-e353accd571f)
- Current version

![image](da8ab46d-dc87-412e-be2b-ac937cd87666)
- Proposal

![image](7279cb02-e6af-4320-9dee-486fbfddcbc8)

Close #9501

## Test Plan

Documentation was regenerated via mkdocs and the supplied requirements.
2024-01-13 07:43:13 -05:00
Charlie Marsh
3261d16e61
Add --extension support to the formatter (#9483)
## Summary

We added `--extension` to `ruff check`, but it's equally applicable to
`ruff format`.

Closes https://github.com/astral-sh/ruff/issues/9482.

Resolves https://github.com/astral-sh/ruff/discussions/9481.

## Test Plan

`cargo test`
2024-01-12 18:53:25 +00:00
Charlie Marsh
d16c4a2d25
Bump version to v0.1.13 (#9493) 2024-01-12 09:27:39 -05:00
Charlie Marsh
55f8f3b2cc
Bump version to v0.1.12 (#9475) 2024-01-11 22:13:00 +00:00
Randy Syring
7fc51d29c5
docs: fix typo in formatter.md (#9473)
I believe there was a typo in the formatter docs and I've attempted to
fix it according to what I think was originally intended.
2024-01-11 12:59:01 -05:00
Noah Jenner
1293383cdc
[docs] - Fix admonition hyperlink colouring (#9385)
<!--
Thank you for contributing to Ruff! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->
Fix the colouration of hyperlinks within admonitions on dark theme to be
more readable. Closes #9046

## Test Plan

<!-- How was it tested? -->
Documentation was regenerated via mkdocs and the supplied requirements.

Signed-off-by: 64815328+Eutropios@users.noreply.github.com
2024-01-03 19:41:27 -05:00
Charlie Marsh
fefc7e8199
Bump version to 0.1.11 (#9370) 2024-01-02 17:46:06 -05:00
Charlie Marsh
2743387910
Bump version to 0.1.10 (#9360) 2024-01-02 13:03:45 -05:00
Andrew Gallant
0263f2715e
Bump version to v0.1.9 (#9231) 2023-12-21 13:19:50 -05:00
Charlie Marsh
c97d3ddafb
Add site-packages to default exclusions (#9188)
Suggested in
https://github.com/astral-sh/ruff-vscode/issues/232#issuecomment-1860788600.
This is technically a non-backwards-compatible change, but I would be
very surprised if it affected anyone in practice given that
`site-packages` is always ignored already in virtual environments.
2023-12-18 11:37:25 -05:00
Joffrey Bluthé
db38078ca3
Document link between import sorting and formatter (#9117) 2023-12-15 10:47:19 +00:00
Charlie Marsh
c014622003
Bump version to v0.1.8 (#9116) 2023-12-13 13:19:51 -05:00
Andrew Gallant
b6fb972e6f
config: add new docstring-code-format knob (#8854)
This PR does the plumbing to make a new formatting option,
`docstring-code-format`, available in the configuration for end users.
It is disabled by default (opt-in). It is opt-in at least initially to
reflect a conservative posture. The intent is to make it opt-out at some
point in the future.

This was split out from #8811 in order to make #8811 easier to merge.
Namely, once this is merged, docstring code snippet formatting will
become available to end users. (See comments below for how we arrived at
the name.)

Closes #7146

## Test Plan

Other than the standard test suite, I ran the formatter over the CPython
and polars projects to ensure both that the result looked sensible and
that tests still passed. At time of writing, one issue that currently
appears is that reformatting code snippets trips the long line lint:
1905886802
2023-12-13 11:02:11 -05:00
Chris Hipple
cb99815c3e
Feature: Add SARIF output support (#9078)
## Summary

Adds support for sarif v2.1.0 output to cli, usable via the
output-format paramter.

`ruff . --output-format=sarif` 

Includes a few changes I wasn't sure of, namely:
* Adds a few derives for Clone & Copy, which I think could be removed
with a little extra work as well.

## Test Plan

I built and ran this against several large open source projects and
verified that the output sarif was valid, using [Microsoft's SARIF
validator tool](https://sarifweb.azurewebsites.net/Validation)

I've also attached an output of the sarif generated by this version of
ruff on the main branch of django at commit: b287af5dc9

[django_main_b287af5dc9_sarif.json](13626222/django_main_b287af5dc9_sarif.json)

Note: this needs to be regenerated with the latest changes and
confirmed.


## Open Points
[ ] Convert to just using all Rules all the time
[ ] Fix the issue with getting the file URI when compiling for web
assembly
2023-12-13 00:33:19 -05:00
Zanie Blue
8e9bf84047
Hide unsafe fix suggestions when explicitly disabled (#9095)
Hides hints about unsafe fixes when they are disabled e.g. with
`--no-unsafe-fixes` or `unsafe-fixes = false`. By default, unsafe fix
hints are still displayed. This seems like a nice way to remove the nag
for users who have chosen not to apply unsafe fixes.

Inspired by comment at
https://github.com/astral-sh/ruff/issues/9063#issuecomment-1850289675
2023-12-11 15:42:53 -06:00
Charlie Marsh
2993c342d2
Add beta note to the formatter docs (#9097)
Closes https://github.com/astral-sh/ruff/issues/9092.
2023-12-11 15:50:01 -05:00
Eli Schwartz
fcc08894cf
Fix documentation snafu that recommended invalid settings (#9018) 2023-12-07 05:01:55 +00:00
Ondřej Súkup
af88ffc57e
Add openSUSE Tumbleweed into install doc (#8996) 2023-12-06 17:07:59 +00:00
Eero Vaher
b4a050c21d
Fix formatting of a warning box in docs (#9017)
## Summary

The last few words of a sentence that should be inside a warning box (in
https://docs.astral.sh/ruff/configuration/#default-inclusions) are
currently placed just after it because of a mistake in indentation.
2023-12-06 01:12:10 +00:00
Charlie Marsh
8d9912a83a
Bump version to v0.1.7 (#8999) 2023-12-04 16:28:23 -05:00