Skip to content

Commit

Permalink
Merge branch 'main' into docs/flake8-errmsg
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 14, 2023
2 parents 3b3c654 + 4f927fb commit 9bc9350
Show file tree
Hide file tree
Showing 85 changed files with 2,047 additions and 1,131 deletions.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,11 @@ Or, to enable autofix:

<!-- Begin section: Configuration -->

Ruff is configurable both via `pyproject.toml` and the command line. For a full list of configurable
Ruff is configurable both via `pyproject.toml`, `ruff.toml`, and the command line. For a full list of configurable
options, see the [API reference](#reference).

### Configure via `pyproject.toml`

If left unspecified, the default configuration is equivalent to:

```toml
Expand Down Expand Up @@ -362,6 +364,8 @@ If you're wondering how to configure Ruff, here are some **recommended guideline
* By default, Ruff's autofix is aggressive. If you find that it's too aggressive for your liking,
consider turning off autofix for specific rules or categories (see: [FAQ](#ruff-tried-to-fix-something-but-it-broke-my-code-what-should-i-do)).

### Configure via `ruff.toml`

As an alternative to `pyproject.toml`, Ruff will also respect a `ruff.toml` file, which implements
an equivalent schema (though the `[tool.ruff]` hierarchy can be omitted). For example, the
`pyproject.toml` described above would be represented via the following `ruff.toml`:
Expand Down Expand Up @@ -725,7 +729,7 @@ For more, see [Pyflakes](https://pypi.org/project/pyflakes/) on PyPI.
| F506 | percent-format-mixed-positional-and-named | `%`-format string has mixed positional and named placeholders | |
| F507 | percent-format-positional-count-mismatch | `%`-format string has {wanted} placeholder(s) but {got} substitution(s) | |
| F508 | percent-format-star-requires-sequence | `%`-format string `*` specifier requires sequence | |
| F509 | percent-format-unsupported-format-character | `%`-format string has unsupported format character '{char}' | |
| F509 | percent-format-unsupported-format-character | `%`-format string has unsupported format character `{char}` | |
| F521 | string-dot-format-invalid-format | `.format` call has invalid format string: {message} | |
| F522 | string-dot-format-extra-named-arguments | `.format` call has unused named argument(s): {message} | 🛠 |
| F523 | string-dot-format-extra-positional-arguments | `.format` call has unused arguments at position(s): {message} | |
Expand Down Expand Up @@ -788,7 +792,7 @@ For more, see [pycodestyle](https://pypi.org/project/pycodestyle/) on PyPI.
| ---- | ---- | ------- | --- |
| W292 | no-new-line-at-end-of-file | No newline at end of file | 🛠 |
| W505 | doc-line-too-long | Doc line too long ({length} > {limit} characters) | |
| W605 | invalid-escape-sequence | Invalid escape sequence: '\{char}' | 🛠 |
| W605 | invalid-escape-sequence | Invalid escape sequence: `\{char}` | 🛠 |

### mccabe (C90)

Expand Down Expand Up @@ -859,8 +863,8 @@ For more, see [pydocstyle](https://pypi.org/project/pydocstyle/) on PyPI.
| D213 | multi-line-summary-second-line | Multi-line docstring summary should start at the second line | 🛠 |
| D214 | section-not-over-indented | Section is over-indented ("{name}") | 🛠 |
| D215 | section-underline-not-over-indented | Section underline is over-indented ("{name}") | 🛠 |
| D300 | triple-single-quotes | Use """triple double quotes""" | |
| D301 | escape-sequence-in-docstring | Use r""" if any backslashes in a docstring | |
| D300 | triple-single-quotes | Use triple double quotes `"""` | |
| D301 | escape-sequence-in-docstring | Use `r"""` if any backslashes in a docstring | |
| D400 | ends-in-period | First line should end with a period | 🛠 |
| D401 | non-imperative-mood | First line of docstring should be in imperative mood: "{first_line}" | |
| D402 | no-signature | First line should not be the function's signature | |
Expand Down Expand Up @@ -976,7 +980,7 @@ For more, see [flake8-bandit](https://pypi.org/project/flake8-bandit/) on PyPI.
| S110 | try-except-pass | `try`-`except`-`pass` detected, consider logging the exception | |
| S112 | try-except-continue | `try`-`except`-`continue` detected, consider logging the exception | |
| S113 | request-without-timeout | Probable use of requests call with timeout set to `{value}` | |
| S324 | hashlib-insecure-hash-function | Probable use of insecure hash functions in `hashlib`: "{}" | |
| S324 | hashlib-insecure-hash-function | Probable use of insecure hash functions in `hashlib`: `{string}` | |
| S501 | request-with-no-cert-validation | Probable use of `{string}` call with `verify=False` disabling SSL certificate checks | |
| S506 | unsafe-yaml-load | Probable use of unsafe loader `{name}` with `yaml.load`. Allows instantiation of arbitrary objects. Consider `yaml.safe_load`. | |
| S508 | snmp-insecure-version | The use of SNMPv1 and SNMPv2 is insecure. Use SNMPv3 if able. | |
Expand Down Expand Up @@ -1133,7 +1137,7 @@ For more, see [flake8-executable](https://pypi.org/project/flake8-executable/) o
| ---- | ---- | ------- | --- |
| EXE001 | shebang-not-executable | Shebang is present but file is not executable | |
| EXE002 | shebang-missing-executable-file | The file is executable but no shebang is present | |
| EXE003 | shebang-python | Shebang should contain "python" | |
| EXE003 | shebang-python | Shebang should contain `python` | |
| EXE004 | shebang-whitespace | Avoid whitespace before shebang | 🛠 |
| EXE005 | shebang-newline | Shebang should be at the beginning of the file | |

Expand Down Expand Up @@ -1207,8 +1211,8 @@ For more, see [flake8-pyi](https://pypi.org/project/flake8-pyi/) on PyPI.

| Code | Name | Message | Fix |
| ---- | ---- | ------- | --- |
| PYI001 | [prefix-type-params](https://beta.ruff.rs/docs/rules/prefix-type-params/) | Name of private `{kind}` must start with _ | |
| PYI007 | [unrecognized-platform-check](https://beta.ruff.rs/docs/rules/unrecognized-platform-check/) | Unrecognized sys.platform check | |
| PYI001 | [prefix-type-params](https://beta.ruff.rs/docs/rules/prefix-type-params/) | Name of private `{kind}` must start with `_` | |
| PYI007 | [unrecognized-platform-check](https://beta.ruff.rs/docs/rules/unrecognized-platform-check/) | Unrecognized `sys.platform` check | |
| PYI008 | [unrecognized-platform-name](https://beta.ruff.rs/docs/rules/unrecognized-platform-name/) | Unrecognized platform `{platform}` | |

### flake8-pytest-style (PT)
Expand Down Expand Up @@ -1465,7 +1469,7 @@ For more, see [Pylint](https://pypi.org/project/pylint/) on PyPI.

| Code | Name | Message | Fix |
| ---- | ---- | ------- | --- |
| PLW0120 | useless-else-on-loop | Else clause on loop without a break statement, remove the else and de-indent all the code inside it | |
| PLW0120 | useless-else-on-loop | `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it | |
| PLW0602 | global-variable-not-assigned | Using global for `{name}` but no assignment is done | |

### tryceratops (TRY)
Expand All @@ -1487,9 +1491,9 @@ For more, see [tryceratops](https://pypi.org/project/tryceratops/1.1.0/) on PyPI

| Code | Name | Message | Fix |
| ---- | ---- | ------- | --- |
| RUF001 | ambiguous-unicode-character-string | String contains ambiguous unicode character '{confusable}' (did you mean '{representant}'?) | 🛠 |
| RUF002 | ambiguous-unicode-character-docstring | Docstring contains ambiguous unicode character '{confusable}' (did you mean '{representant}'?) | 🛠 |
| RUF003 | ambiguous-unicode-character-comment | Comment contains ambiguous unicode character '{confusable}' (did you mean '{representant}'?) | 🛠 |
| RUF001 | ambiguous-unicode-character-string | String contains ambiguous unicode character `{confusable}` (did you mean `{representant}`?) | 🛠 |
| RUF002 | ambiguous-unicode-character-docstring | Docstring contains ambiguous unicode character `{confusable}` (did you mean `{representant}`?) | 🛠 |
| RUF003 | ambiguous-unicode-character-comment | Comment contains ambiguous unicode character `{confusable}` (did you mean `{representant}`?) | 🛠 |
| RUF004 | keyword-argument-before-star-argument | Keyword argument `{name}` must come after starred arguments | |
| RUF005 | unpack-instead-of-concatenating-to-collection-literal | Consider `{expr}` instead of concatenation | 🛠 |
| RUF100 | unused-noqa | Unused `noqa` directive | 🛠 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
..parent\
import \
world_hello

# TID252 (without autofix; too many levels up)
from ..... import ultragrantparent
from ...... import ultragrantparent
from ....... import ultragrantparent
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from typing import TYPE_CHECKING, Any, ClassVar

import attrs

from ..protocol import commands, definitions, responses
from ..server import example
from . import logger, models
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,8 +1320,8 @@ where
stmt,
level.as_ref(),
module.as_deref(),
self.module_path.as_ref(),
&self.settings.flake8_tidy_imports.ban_relative_imports,
self.path,
)
{
self.diagnostics.push(diagnostic);
Expand Down
15 changes: 8 additions & 7 deletions crates/ruff/src/checkers/noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use nohash_hasher::IntMap;
use rustpython_parser::ast::Location;

use crate::ast::types::Range;
use crate::codes::NoqaCode;
use crate::fix::Fix;
use crate::noqa;
use crate::noqa::{is_file_exempt, Directive};
Expand All @@ -20,7 +21,7 @@ pub fn check_noqa(
settings: &Settings,
autofix: flags::Autofix,
) {
let mut noqa_directives: IntMap<usize, (Directive, Vec<&str>)> = IntMap::default();
let mut noqa_directives: IntMap<usize, (Directive, Vec<NoqaCode>)> = IntMap::default();
let mut ignored = vec![];

let enforce_noqa = settings.rules.enabled(&Rule::UnusedNOQA);
Expand Down Expand Up @@ -55,13 +56,13 @@ pub fn check_noqa(
});
match noqa {
(Directive::All(..), matches) => {
matches.push(diagnostic.kind.rule().code());
matches.push(diagnostic.kind.rule().noqa_code());
ignored.push(index);
continue;
}
(Directive::Codes(.., codes), matches) => {
if noqa::includes(diagnostic.kind.rule(), codes) {
matches.push(diagnostic.kind.rule().code());
matches.push(diagnostic.kind.rule().noqa_code());
ignored.push(index);
continue;
}
Expand All @@ -82,12 +83,12 @@ pub fn check_noqa(
.or_insert_with(|| (noqa::extract_noqa_directive(lines[noqa_lineno - 1]), vec![]));
match noqa {
(Directive::All(..), matches) => {
matches.push(diagnostic.kind.rule().code());
matches.push(diagnostic.kind.rule().noqa_code());
ignored.push(index);
}
(Directive::Codes(.., codes), matches) => {
if noqa::includes(diagnostic.kind.rule(), codes) {
matches.push(diagnostic.kind.rule().code());
matches.push(diagnostic.kind.rule().noqa_code());
ignored.push(index);
}
}
Expand Down Expand Up @@ -128,12 +129,12 @@ pub fn check_noqa(
let mut self_ignore = false;
for code in codes {
let code = get_redirect_target(code).unwrap_or(code);
if code == Rule::UnusedNOQA.code() {
if Rule::UnusedNOQA.noqa_code() == code {
self_ignore = true;
break;
}

if matches.contains(&code) || settings.external.contains(code) {
if matches.iter().any(|m| *m == code) || settings.external.contains(code) {
valid_codes.push(code);
} else {
if let Ok(rule) = Rule::from_code(code) {
Expand Down
Loading

0 comments on commit 9bc9350

Please sign in to comment.