Commit Graph

2031 Commits

Author SHA1 Message Date
Martin Fischer eda2be6350 Use subcommands for CLI instead of incompatible boolean flags
This commit greatly simplifies the implementation of the CLI,
as well as the user expierence (since --help no longer lists all
options even though many of them are in fact incompatible).

To preserve backwards-compatability as much as possible aliases have
been added for the new subcommands, so for example the following two
commands are equivalent:

    ruff explain E402 --format json
    ruff --explain E402 --format json

However for this to work the legacy-format double-dash command has to
come first, i.e. the following no longer works:

    ruff --format json --explain E402

Since ruff previously had an implicitly default subcommand,
this is preserved for backwards compatibility, i.e. the following two
commands are equivalent:

    ruff .
    ruff check .

Previously ruff didn't complain about several argument combinations that
should have never been allowed, e.g:

    ruff --explain RUF001 --line-length 33

previously worked but now rightfully fails since the explain command
doesn't support a `--line-length` option.
2023-01-27 19:38:17 -05:00
Charlie Marsh 57a68f7c7d
Document the location of the personal config file (#2283) 2023-01-27 19:25:55 -05:00
Charlie Marsh a19dd9237b
Add comparison to type checkers (#2282) 2023-01-27 19:18:40 -05:00
Simon Brugman 4f067d806e
add clippy and rust_dev to pre-commit (#2256)
I presume the reasoning for not including clippy in `pre-commit` was that it passes all files. This can be turned off with `pass_filenames`, in which case it only runs once.

`cargo +nightly dev generate-all` is also added (when excluding `target` is does not give false positives).

(The overhead of these commands is not much when the build is there. People can always choose to run only certain hooks with `pre-commit run [hook] --all-files`)
2023-01-27 18:53:44 -05:00
Samuel Cormier-Iijima dd15c69181
[`flake8-bandit`] Add Rule S110 (try/except/pass) (#2197) 2023-01-27 18:52:55 -05:00
Charlie Marsh b692921160
Use rustup show in lieu of actions-rs/toolchain (#2280) 2023-01-27 18:51:41 -05:00
Charlie Marsh b3e8b1b787
Expand heuristic for detecting logging calls (#2279) 2023-01-27 18:41:16 -05:00
Charlie Marsh 0b34ca7107
Move off nightly Rust for dev workflows (#2278) 2023-01-27 18:35:19 -05:00
Charlie Marsh df44c5124e Add missing autofix levels to sometimes-fixable rules 2023-01-27 18:25:23 -05:00
Simon Brugman 0e27f78b3f
feat: include os.getcwdb (bytes) into flake8-use-pathlib (#2276) 2023-01-27 18:25:02 -05:00
Florian Best cd8ad1df08
mark some fixers as sometimes-fixable (#2271) 2023-01-27 18:23:32 -05:00
Charlie Marsh d1aaf16e40
Omit typing module from flake8-type-checking by default (#2277) 2023-01-27 18:19:45 -05:00
Ville Skyttä 7320058ce2
Incompatiblity warning updates (#2272) 2023-01-27 18:17:23 -05:00
Aarni Koskela 3a8b367b1c
flake8-annotations: Move has_any_typed_arg into correct nested `if` (#2269) 2023-01-27 18:15:46 -05:00
Ville Skyttä 221b87332c
feat: add more DTZ fix suggestions in messages (#2274) 2023-01-27 18:14:17 -05:00
Franck Nijhof 8149c8cbc4
Treat attribute constants as constant for yoda-conditions (#2266)
Accessed attributes that are Python constants should be considered for yoda-conditions


```py
## Error
JediOrder.YODA == age  # SIM300

## OK
age == JediOrder.YODA
```

~~PS: This PR will fail CI, as the `main` branch currently failing.~~
2023-01-27 12:55:12 -05:00
Charlie Marsh 2c415016a6 Update F401 snapshots 2023-01-27 12:43:42 -05:00
Sladyn bb85119ba8
Convert UnusedImport violation to struct fields (#2141) 2023-01-27 11:31:39 -05:00
Simon Brugman 94551a203e
feat: pylint `PLE0604` and `PLE0605` (#2241) 2023-01-27 11:26:33 -05:00
Charlie Marsh 64c4e4c6c7
Treat constant tuples as constants for yoda-conditions (#2265) 2023-01-27 11:25:57 -05:00
Charlie Marsh 84e4b7c96f
Treat builtins as synthetically used (#2251) 2023-01-27 11:25:45 -05:00
Franck Nijhof ca26f664ec
Fix SIM300 to take Python constants into account (#2255)
SIM300 currently doesn't take Python constants into account when looking for Yoda conditions, this PR fixes that behavior.

```python
# Errors
YODA == age  # SIM300
YODA > age  # SIM300
YODA >= age  # SIM300

# OK
age == YODA
age < YODA
age <= YODA
```

Ref: <https://github.com/home-assistant/core/pull/86793>
2023-01-27 11:20:21 -05:00
Aarni Koskela 779b232db9
Fix typo: RelatveImportsOrder (#2264) 2023-01-27 11:15:43 -05:00
Charlie Marsh a316b26b49
Rewrite some string-format violation messages (#2242) 2023-01-26 19:42:16 -05:00
Charlie Marsh 685d9ab848 Bump version to 0.0.236 2023-01-26 18:47:00 -05:00
Charlie Marsh 093f9156e1
Wrap return-bool-condition-directly fixes in bool() (#2240) 2023-01-26 18:22:34 -05:00
Charlie Marsh 615e62ae24
Clarify E-category rule support (#2239) 2023-01-26 18:12:28 -05:00
Charlie Marsh 76a0c45773
Track type-checking blocks during tree traversal (#2238) 2023-01-26 18:09:28 -05:00
Charlie Marsh 3ec46f0936
Allow `pytest` in shebang (#2237) 2023-01-26 17:32:23 -05:00
Charlie Marsh a6ec2eb044
Avoid removing trailing comments on `pass` statements (#2235)
This isn't super consistent with some other rules, but... if you have a lone body, with a `pass`, followed by a comment, it's probably surprising if it gets removed. Let's retain the comment.

Closes #2231.
2023-01-26 17:29:13 -05:00
Simon Brugman 9d3a5530af
refactor: move violations to linters (#2234) 2023-01-26 17:28:14 -05:00
Simon Brugman 8766e6a666
docs(readme): add featuretools (#2236) 2023-01-26 17:24:45 -05:00
Charlie Marsh b08367b5a8
Avoid flagging blind exceptions with valid logging (#2232) 2023-01-26 17:05:01 -05:00
Charlie Marsh 98a8330124
Add stylist settings to all LibCST invocations (#2225) 2023-01-26 16:59:33 -05:00
Charlie Marsh 4d52ea87ef
Implement `exempt-modules` setting from flake8-type-checking (#2230) 2023-01-26 16:55:32 -05:00
Charlie Marsh 291239b9f1
Fix range for `try-consider-else` (#2228) 2023-01-26 16:36:18 -05:00
Charlie Marsh 224334b6d1
Avoid erroneous class autofixes in indented blocks (#2226) 2023-01-26 16:24:21 -05:00
Charlie Marsh 0cab3f8437
Preserve indentation when fixing via LibCST (#2223) 2023-01-26 16:09:35 -05:00
Charlie Marsh 5f8810e987
Add strictness setting for `flake8-typing-imports` (#2221) 2023-01-26 16:04:21 -05:00
Charlie Marsh f15c562a1c
Remove unused overridden property (#2217) 2023-01-26 14:46:46 -05:00
Martin Fischer 4f3b63edd4 fix: --explain reporting the wrong linter
Fixes a regression introduced in 4e4643aa5d.

We want the longest prefixes to be checked first so we of course
have to reverse the sorting when sorting by prefix length.

Fixes #2210.
2023-01-26 13:53:35 -05:00
Simon Brugman bab8691132
chore: fix script indent (#2213) 2023-01-26 13:53:22 -05:00
Charlie Marsh 50c85fd192
Add a fixable and unfixable example to the docs (#2211) 2023-01-26 13:23:21 -05:00
Martin Fischer 23819ae338 Group options in --help output and sort them by importance
`ruff --help` previously listed 37 options in no particular order
(with niche options like --isolated being listed before before essential
options such as --select).  This commit remedies that and additionally
groups the options by making use of the Clap help_heading feature.

Note that while the source code has previously also referred to
--add-noqa, --show-settings, and --show-files as "subcommands"
this commit intentionally does not list them under the new
Subcommands section since contrary to --explain and --clean
combining them with most of the other options makes sense.
2023-01-26 13:06:29 -05:00
Martin Fischer 4bf2879067 refactor: Move add_noqa if branch up 2023-01-26 13:06:29 -05:00
Martin Fischer b359f3a9ff refactor: Get rid of ruff::resolver::FileDiscovery 2023-01-26 13:06:29 -05:00
Martin Fischer 73d0461d55 refactor: Check required_version in Settings::from_configuration
The idiomatic way in Rust is to make invalid types unrepresentable
instead of paranoidly calling a validate method everywhere.
2023-01-26 13:06:29 -05:00
Martin Fischer 55bb36fb8b refactor: Introduce LogLevelArgs 2023-01-26 13:06:29 -05:00
Martin Fischer cebea16fe4 refactor: Move Args::partition call after panic::set_hook 2023-01-26 13:06:29 -05:00
Charlie Marsh f7be192f8b
Alphabetize Flake8 plugins in the README (#2209) 2023-01-26 13:05:30 -05:00