Commit Graph

883 Commits

Author SHA1 Message Date
Colin Delahunty ad8693e3de
[`pyupgrade`] Implement import-replacement rule (`UP035`) (#2049) 2023-01-30 19:58:28 -05:00
Charlie Marsh 69e20c4554
Minor improvements to the docs (#2371) 2023-01-30 19:06:05 -05:00
Charlie Marsh b5816634b3
Add a link to MkDocs (#2370) 2023-01-30 19:00:57 -05:00
Charlie Marsh 1cbd929a0a Bump version to 0.0.238 2023-01-30 16:44:19 -05:00
Charlie Marsh 5f07e70762
Recommend disabling `explicit-string-concatenation` (#2366)
If `allow-multiline = false` is set, then if the user enables `explicit-string-concatenation` (`ISC003`), there's no way for them to create valid multiline strings. This PR notes that they should turn off `ISC003`.

Closes #2362.
2023-01-30 16:42:30 -05:00
Charlie Marsh 4589daa0bd
Ignore magic comparisons to bytes by default (#2365) 2023-01-30 16:31:48 -05:00
Charlie Marsh ea0274d22c Use bold for deprecated 2023-01-30 16:28:21 -05:00
Charlie Marsh ca1129ad27 Document new rule config resolution 2023-01-30 16:26:59 -05:00
Martin Fischer ba457c21b5 Improve rule config resolution
Ruff allows rules to be enabled with `select` and disabled with
`ignore`, where the more specific rule selector takes precedence,
for example:

    `--select ALL --ignore E501` selects all rules except E501
    `--ignore ALL --select E501` selects only E501

(If both selectors have the same specificity ignore selectors
take precedence.)

Ruff always had two quirks:

* If `pyproject.toml` specified `ignore = ["E501"]` then you could
  previously not override that with `--select E501` on the command-line
  (since the resolution didn't take into account that the select was
  specified after the ignore).

* If `pyproject.toml` specified `select = ["E501"]` then you could
  previously not override that with `--ignore E` on the command-line
  (since the resolution didn't take into account that the ignore was
  specified after the select).

Since d067efe265 (#1245)
`extend-select` and `extend-ignore` always override
`select` and `ignore` and are applied iteratively in pairs,
which introduced another quirk:

* If some `pyproject.toml` file specified `extend-select`
  or `extend-ignore`, `select` and `ignore` became pretty much
  unreliable after that with no way of resetting that.

This commit fixes all of these quirks by making later configuration
sources take precedence over earlier configuration sources.

While this is a breaking change, we expect most ruff configuration
files to not rely on the previous unintutive behavior.
2023-01-30 16:26:59 -05:00
Charlie Marsh 01fedec1e7
Add SciPy and meson-python (#2363) 2023-01-30 15:34:19 -05:00
Martin Fischer ef20692149
fix: clap usage for CLI help generation in the README (#2358) 2023-01-30 13:14:40 -05:00
Simon Brugman 50046fbed3
Extend conventional imports defaults to include TensorFlow et al (#2353)
extend conventional imports

Based on configuration from Visual Studio for Python
(https://code.visualstudio.com/docs/python/editing#_quick-fixes)
2023-01-30 11:04:19 -05:00
Akhil 8e5a944ce1
Implement Pylint's `too-many-arguments` rule (`PLR0913`) (#2308) 2023-01-30 07:34:37 -05:00
Simon Brugman 2ef28f217c pandas vet autofix for PD002 and general refactor 2023-01-29 22:30:37 -05:00
Martin Fischer d76a47d366 Implement `ruff linter` subcommand
The subcommand lists all supported upstream linters and their prefixes:

    $ ruff linter
       F Pyflakes
     E/W pycodestyle
     C90 mccabe
       I isort
       N pep8-naming
       D pydocstyle
      UP pyupgrade
     YTT flake8-2020
    # etc...

Just like with the `rule` subcommand `--format json` is supported:

    $ ruff linter --format json
    [
      {
        "prefix": "F",
        "name": "Pyflakes"
      },
      {
        "prefix": "",
        "name": "pycodestyle",
        "categories": [
          {
            "prefix": "E",
            "name": "Error"
          },
          {
            "prefix": "W",
            "name": "Warning"
          }
        ]
      },
      # etc...
2023-01-29 21:32:37 -05:00
Charlie Marsh 3ee6a90905
Remove remove-six-compat (UP016) (#2332) 2023-01-29 21:19:59 -05:00
Simon Brugman 5165b703d9
Add VS Code to gitignore; fix typos (#2333) 2023-01-29 21:14:38 -05:00
Charlie Marsh 64fb0bd2cc
Include both `ruff help` and `ruff help check` in README (#2325) 2023-01-29 17:01:15 -05:00
Charlie Marsh 546413defb Fix remaining RelativeImportsOrder typo 2023-01-29 11:33:12 -05:00
Charlie Marsh c9585fe304 Run generate-all 2023-01-28 22:13:07 -05:00
Charlie Marsh 535868f939
Update fixable list (#2316) 2023-01-28 20:18:55 -05:00
Chirag cec993aaa9
Add `ruff .` to documentation (#2307) 2023-01-28 14:53:11 -05:00
Charlie Marsh add7fefeb5 Bump version to 0.0.237 2023-01-28 10:52:14 -05:00
Charlie Marsh 071e3fd196
Split MkDocs site into multiple pages (#2296) 2023-01-28 08:31:16 -05:00
Martin Fischer dd79ec293a Rename new `explain` subcommand to `rule`
We probably want to introduce multiple explain subcommands and
overloading `explain` to explain it all seems like a bad idea.
We may want to introduce a subcommand to explain config options and
config options may end up having the same name as their rules, e.g. the
current `banned-api` is both a rule name (although not yet exposed to
the user) and a config option.

The idea is:

* `ruff rule` lists all rules supported by ruff
* `ruff rule <code>` explains a specific rule
* `ruff linter` lists all linters supported by ruff
* `ruff linter <name>` lists all rules/options supported by a specific linter

(After this commit only the 2nd case is implemented.)
2023-01-28 07:26:20 -05:00
Matt Morris caada2f8bb
add missing backticks to flake8 plugin urls in `README` (#2291) 2023-01-28 07:16:23 -05:00
Charlie Marsh fd56414b2f Re-add ALL disclaimer 2023-01-27 22:18:20 -05:00
Charlie Marsh 1a0191f1ac Add release to breaking changes 2023-01-27 20:34:24 -05:00
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
Samuel Cormier-Iijima dd15c69181
[`flake8-bandit`] Add Rule S110 (try/except/pass) (#2197) 2023-01-27 18:52:55 -05:00
Charlie Marsh df44c5124e Add missing autofix levels to sometimes-fixable rules 2023-01-27 18:25:23 -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ä 221b87332c
feat: add more DTZ fix suggestions in messages (#2274) 2023-01-27 18:14:17 -05:00
Simon Brugman 94551a203e
feat: pylint `PLE0604` and `PLE0605` (#2241) 2023-01-27 11:26:33 -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 615e62ae24
Clarify E-category rule support (#2239) 2023-01-26 18:12:28 -05:00
Simon Brugman 8766e6a666
docs(readme): add featuretools (#2236) 2023-01-26 17:24:45 -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 5f8810e987
Add strictness setting for `flake8-typing-imports` (#2221) 2023-01-26 16:04:21 -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
Charlie Marsh f7be192f8b
Alphabetize Flake8 plugins in the README (#2209) 2023-01-26 13:05:30 -05:00
Edgar R. M e88275280b
Implement some rules from `flake8-logging-format` (#2150) 2023-01-26 12:58:10 -05:00
jvstme 0ad6b8224d
Fix typo in src option docs (#2201) 2023-01-26 12:23:09 -05:00
Henry Schreiner f3aa409d9a
docs(readme): add pypa's build (#2200) 2023-01-26 12:18:04 -05:00
Charlie Marsh adb5c5b150
Fix `respect_gitignore` reference (#2196) 2023-01-26 09:53:17 -05:00
Charlie Marsh b346f74915
Run cargo update (#2185) 2023-01-25 21:32:44 -05:00
Florian Stasse 353857e2a5
Implement TRY400 (#2115) 2023-01-25 19:42:19 -05:00
Denis Gavrilyuk 55b43c8ea7
feat: implement TRY002 and TRY003 (#2135) 2023-01-25 19:22:43 -05:00
Charlie Marsh edd0e16a02 Bump version to 0.0.235 2023-01-25 18:28:27 -05:00
Charlie Marsh 9b07d0bd92 Bump version to 0.0.234 2023-01-25 16:55:57 -05:00
Charlie Marsh 23525a8ea0
Actually, rename TYP rules to TCH (#2176) 2023-01-25 16:52:49 -05:00
Charlie Marsh 35cf9e242e
Rename TYP rules to TYC (#2175) 2023-01-25 16:26:22 -05:00
Charlie Marsh 8e1fac620e
Add flake8-builtins options to README (#2173) 2023-01-25 15:43:26 -05:00
Aarni Koskela 0da691c0d5
Add Babel to readme (#2170) 2023-01-25 15:21:26 -05:00
Hugo van Kemenade 6d87adbcc0 Fix singular and plural for error(s) 2023-01-25 15:21:10 -05:00
Florian Best 43a8ce6c89
fix: avoid flagging unused loop variable (B007) with globals(), vars() or eval() (#2166) 2023-01-25 15:18:58 -05:00
Charlie Marsh 6978dcf035
Add an FAQ on autofix (#2163) 2023-01-25 13:09:16 -05:00
Charlie Marsh 63b4f60ba4
Implement typing-only import detection (TYP001, TYP002, TYP003) (#2147) 2023-01-24 23:48:11 -05:00
Charlie Marsh 9eb13bc9da Downgrade recommended pre-commit version to v0.0.231 2023-01-24 23:47:13 -05:00
Charlie Marsh 0758049e49
Implement runtime-import-in-type-checking-block (TYP004) (#2146) 2023-01-24 23:33:26 -05:00
Charlie Marsh 605416922d Bump version to 0.0.233 2023-01-24 10:46:49 -05:00
Charlie Marsh d645a19e0a Bump version to 0.0.232 2023-01-24 09:49:07 -05:00
Charlie Marsh 30ae0d3723
Add Dagger and Great Expectations (#2130) 2023-01-24 09:48:00 -05:00
Ville Skyttä 7e92485f43
feat: autofix `multi-line-summary-*-line` (#2093) 2023-01-24 08:17:13 -05:00
Edgar R. M f5f0ed280a
Implement `EXE001` and `EXE002` from `flake8-executable` (#2118) 2023-01-24 08:02:47 -05:00
Hugo b29b4084ff
Add apk instructions to README (#2121) 2023-01-24 07:29:03 -05:00
Aarni Koskela c61ca4a953
Add Home Assistant to Readme (#2120) 2023-01-24 07:27:45 -05:00
Denis Gavrilyuk 58d5ac08a8
feat: implement TRY301 (#2113) 2023-01-24 07:25:26 -05:00
Charlie Marsh cc63a4be6a
Allow flagging of multiline implicit string concatenations (#2117)
At present, `ISC001` and `ISC002` flag concatenations like the following:

```py
"a" "b"  # ISC001
"a" \
  "b"  # ISC002
```

However, multiline concatenations are allowed.

This PR adds a setting:

```toml
[tool.ruff.flake8-implicit-str-concat]
allow-multiline = false
```

Which extends `ISC002` to _also_ flag multiline concatenations, like:

```py
(
  "a"  # ISC002
  "b"
)
```

Note that this is backwards compatible, as `allow-multiline` defaults to `true`.
2023-01-24 00:01:01 -05:00
Denis Gavrilyuk d65ce6308b
feat: implement TRY200 (#2087)
#2056
2023-01-23 14:12:42 -05:00
Charlie Marsh 1c3265ef98 Bump version to 0.0.231 2023-01-23 12:51:09 -05:00
Maksudul Haque 8001a1639c
[`flake8-bandit`] Added Rule `S612` (Use of insecure `logging.config.listen`) (#2108)
ref: https://github.com/charliermarsh/ruff/issues/1646
2023-01-23 12:37:33 -05:00
Charlie Marsh 7d9c1d7a5a Add a note on some isort incompatibilities 2023-01-23 12:32:35 -05:00
Thomas MK c5cebb106e
Fix outdated description of ruff's support of isort settings (#2106)
Ruff supports more than `known-first-party`, `known-third-party`, `extra-standard-library`, and `src` nowadays.

Not sure if this is the best wording. Suggestions welcome!
2023-01-23 12:29:44 -05:00
Simon Brugman f472fbc6d4
docs(readme): add pypa cibuildwheel (#2107) 2023-01-23 11:39:23 -05:00
Steve Dignam 0c624af036
Add flake8-pie PIE800: no-unnecessary-spread (#1881)
Checks for unnecessary spreads, like `{**foo, **{"bar": True}}`
rel: https://github.com/charliermarsh/ruff/issues/1879
rel: https://github.com/charliermarsh/ruff/issues/1543
2023-01-22 21:43:34 -05:00
Steve Dignam 4ca328f964
Add flake8-pie PIE804: no-unnecessary-dict-kwargs (#1884)
Warn about things like `foo(**{"bar": True})` which is equivalent to `foo(bar=True)`

rel: https://github.com/charliermarsh/ruff/issues/1879
rel: https://github.com/charliermarsh/ruff/issues/1543
2023-01-22 21:32:45 -05:00
Charlie Marsh f40ae943a7 Fix bad documentation message for init option 2023-01-22 19:25:23 -05:00
alm 4fb0c6e3ad
feat: Implement TRY201 (#2073) 2023-01-22 17:08:57 -05:00
Simon Brugman 11f06055a0
feat: flake8-use-pathlib PTH100-124 (#2090) 2023-01-22 15:17:25 -05:00
Charlie Marsh 23b622943e Bump version to 0.0.230 2023-01-22 13:58:41 -05:00
alm e11cf1bf65
Update linters PyPI links to latest version (#2062) 2023-01-22 13:10:22 -05:00
Martin Fischer 4758ee6ac4 refactor: Generate Linter -> RuleSelector mapping via macro
To enable ruff_dev to automatically generate the rule Markdown tables in
the README the ruff library contained the following function:

    Linter::codes() -> Vec<RuleSelector>

which was slightly changed to `fn prefixes(&self) -> Prefixes` in
9dc66b5a65 to enable ruff_dev to split
up the Markdown tables for linters that have multiple prefixes
(pycodestyle has E & W, Pylint has PLC, PLE, PLR & PLW).

The definition of this method was however largely redundant with the
#[prefix] macro attributes in the Linter enum, which are used to
derive the Linter::parse_code function, used by the --explain command.

This commit removes the redundant Linter::prefixes by introducing a
same-named method with a different signature to the RuleNamespace trait:

     fn prefixes(&self) -> &'static [&'static str];

As well as implementing IntoIterator<Rule> for &Linter. We extend the
extisting RuleNamespace proc macro to automatically derive both
implementations from the Linter enum definition.

To support the previously mentioned Markdown table splitting we
introduce a very simple hand-written method to the Linter impl:

    fn categories(&self) -> Option<&'static [LinterCategory]>;
2023-01-22 11:51:29 -05:00
Simon Brugman 6fc6bf0648
feat: enable autofix for TRY004 (#2084)
functionality was already implemented, just the trait needed to be added
2023-01-22 07:18:56 -05:00
Cosmo 39aed6f11d
Update link to Pylint parity tracking issue (#2074) 2023-01-21 17:46:55 -05:00
Simon Brugman 67de8ac85e
feat: implementation for TRY004 (#2066)
See: #2056.
2023-01-21 14:58:59 -05:00
Charlie Marsh 84300e00ff Bump version to 0.0.229 2023-01-21 13:18:06 -05:00
Simon Brugman afcf5c0ee0
feat: plugin scaffold for tryceratops with TRY300 (#2055)
Renamed to TRY to avoid conflicts, as proposed in https://github.com/guilatrova/tryceratops/pull/55

https://github.com/guilatrova/tryceratops/blob/main/docs/violations/TC300.md

See: #2056
2023-01-21 11:25:10 -05:00
Colin Delahunty 80295f335b
Pyupgrade: Printf string formatting (#1803) 2023-01-21 09:37:22 -05:00
Charlie Marsh 8e558a3458
Add scaffolding for `flake8-type-checking` extension (#2048)
This PR adds the scaffolding files for `flake8-type-checking`, along with the simplest rule (`empty-type-checking-block`), just as an example to get us started.

See: #1785.
2023-01-20 22:41:36 -05:00
Martin Fischer b19258a243 refactor: Rename RuleCodePrefix to RuleSelector
More accurate since the enum also encompasses:

* ALL (which isn't a prefix at all)

* fully-qualified rule codes (which aren't prefixes unless you say
  they're a prefix to the empty string but that's not intuitive)
2023-01-20 20:25:57 -05:00
Simon Brugman 608b2191aa
[`flake8-executable`] EXE003-005 (#2023)
Tracking issue: https://github.com/charliermarsh/ruff/issues/2024

Implementation for EXE003, EXE004 and EXE005 of `flake8-executable` 
(shebang should contain "python", not have whitespace before, and should be on the first line)

Please take in mind that this is my first rust contribution.

The remaining EXE-rules are a combination of shebang (`lines.rs`), file permissions (`fs.rs`) and if-conditions (`ast.rs`). I was not able to find other rules that have interactions/dependencies in them. Any advice on how this can be best implemented would be very welcome.

For autofixing `EXE005`, I had in mind to _move_  the shebang line to the top op the file. This could be achieved by a combination of `Fix::insert` and `Fix::delete` (multiple fixes per diagnostic), or by implementing a dedicated `Fix::move`, or perhaps in other ways. For now I've left it out, but keen on hearing what you think would be most consistent with the package, and pointer where to start (if at all).

---
If you care about another testimonial:
`ruff` not only helps staying on top of the many excellent flake8 plugins and other Python code quality tools that are available, it also applies them at baffling speed.
(Planning to implement it soon for github.com/pandas-profiling/pandas-profiling (as largest contributor) and github.com/ing-bank/popmon.)
2023-01-20 18:19:07 -05:00
Eric Roberts 3939c2dbf7
Add support for pycodestyle E101 (#2038)
Rule described here: https://www.flake8rules.com/rules/E101.html

I tried to follow contributing guidelines closely, I've never worked with Rust before. Stumbled across Ruff a few days ago and would like to use it in our project, but we use a bunch of flake8 rules that are not yet implemented in ruff, so I decided to give it a go.
2023-01-20 17:24:58 -05:00
Hugo van Kemenade a0e3347e43
README: `--force-exclude` is already set (#2042)
Re: https://github.com/charliermarsh/ruff-pre-commit/issues/19 / https://github.com/charliermarsh/ruff-pre-commit/pull/20

This is now always set, no need to include it in the README example.
2023-01-20 17:20:22 -05:00
Charlie Marsh 5377d24507 Bump version to 0.0.228 2023-01-20 09:58:56 -05:00