Compare commits
9 Commits
jack/loop-
...
brent/new-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3d26e1a62 | ||
|
|
2caf2987c0 | ||
|
|
5dfc47ff3b | ||
|
|
20cbbf03b8 | ||
|
|
f707bf6cf8 | ||
|
|
2230ab07d0 | ||
|
|
3a779a237e | ||
|
|
cf0d026b41 | ||
|
|
1c5a9681a5 |
@@ -311,9 +311,11 @@ for more on the linting and formatting commands, respectively.
|
||||
isort, pyupgrade, and others. Regardless of the rule's origin, Ruff re-implements every rule in
|
||||
Rust as a first-party feature.
|
||||
|
||||
By default, Ruff enables Flake8's `F` rules, along with a subset of the `E` rules, omitting any
|
||||
stylistic rules that overlap with the use of a formatter, like `ruff format` or
|
||||
[Black](https://github.com/psf/black).
|
||||
By default, Ruff enables Flake8's `F` rules, along with a subset of the `E`
|
||||
rules, omitting any stylistic rules that overlap with the use of a formatter,
|
||||
like `ruff format` or [Black](https://github.com/psf/black). Ruff also enables
|
||||
`B012`, which corresponds to a `SyntaxWarning`, and `PYI057`, which flags
|
||||
usage of some long-deprecated APIs in the standard library.
|
||||
|
||||
If you're just getting started with Ruff, **the default rule set is a great place to start**: it
|
||||
catches a wide variety of common errors (like unused imports) with zero configuration.
|
||||
|
||||
@@ -21,12 +21,13 @@ fn lint_select() {
|
||||
specific prefixes. `ignore` takes precedence over `select` if the
|
||||
same prefix appears in both.
|
||||
|
||||
Default value: ["E4", "E7", "E9", "F"]
|
||||
Default value: ["E4", "E7", "E9", "F", "B012", "PYI057"]
|
||||
Type: list[RuleSelector]
|
||||
Example usage:
|
||||
```toml
|
||||
# On top of the defaults (`E4`, E7`, `E9`, and `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`).
|
||||
select = ["E4", "E7", "E9", "F", "B", "Q"]
|
||||
# On top of the defaults (`E4`, E7`, `E9`, `F`, `B012`, and `PYI057`),
|
||||
# enable flake8-bugbear (`B`) and flake8-quotes (`Q`).
|
||||
select = ["E4", "E7", "E9", "F", "PYI057", "B", "Q"]
|
||||
```
|
||||
|
||||
----- stderr -----
|
||||
@@ -43,10 +44,10 @@ fn lint_select_json() {
|
||||
----- stdout -----
|
||||
{
|
||||
"doc": "A list of rule codes or prefixes to enable. Prefixes can specify exact\nrules (like `F841`), entire categories (like `F`), or anything in\nbetween.\n\nWhen breaking ties between enabled and disabled rules (via `select` and\n`ignore`, respectively), more specific prefixes override less\nspecific prefixes. `ignore` takes precedence over `select` if the\nsame prefix appears in both.",
|
||||
"default": "[\"E4\", \"E7\", \"E9\", \"F\"]",
|
||||
"default": "[\"E4\", \"E7\", \"E9\", \"F\", \"B012\", \"PYI057\"]",
|
||||
"value_type": "list[RuleSelector]",
|
||||
"scope": null,
|
||||
"example": "# On top of the defaults (`E4`, E7`, `E9`, and `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`).\nselect = [\"E4\", \"E7\", \"E9\", \"F\", \"B\", \"Q\"]",
|
||||
"example": "# On top of the defaults (`E4`, E7`, `E9`, `F`, `B012`, and `PYI057`),\n# enable flake8-bugbear (`B`) and flake8-quotes (`Q`).\nselect = [\"E4\", \"E7\", \"E9\", \"F\", \"PYI057\", \"B\", \"Q\"]",
|
||||
"deprecated": null
|
||||
}
|
||||
|
||||
|
||||
@@ -6595,3 +6595,38 @@ fn supported_file_extensions_preview_enabled() -> Result<()> {
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_rules() {
|
||||
let stdin = "\
|
||||
def f():
|
||||
try:
|
||||
from typing import ByteString as TypingByteString # PYI057
|
||||
from collections.abc import ByteString as CollectionsByteString # PYI057
|
||||
except:
|
||||
pass
|
||||
finally:
|
||||
return # B012
|
||||
";
|
||||
|
||||
assert_cmd_snapshot!(
|
||||
Command::new(get_cargo_bin(BIN_NAME))
|
||||
.args(["check", "--output-format=concise", "--no-cache", "--stdin-filename=test.py", "-"])
|
||||
.pass_stdin(stdin),
|
||||
@r"
|
||||
success: false
|
||||
exit_code: 1
|
||||
----- stdout -----
|
||||
test.py:3:23: PYI057 Do not use `typing.ByteString`, which has unclear semantics and is deprecated
|
||||
test.py:3:37: F401 [*] `typing.ByteString` imported but unused
|
||||
test.py:4:32: PYI057 Do not use `collections.abc.ByteString`, which has unclear semantics and is deprecated
|
||||
test.py:4:46: F401 [*] `collections.abc.ByteString` imported but unused
|
||||
test.py:5:3: E722 Do not use bare `except`
|
||||
test.py:8:4: B012 `return` inside `finally` blocks cause exceptions to be silenced
|
||||
Found 6 errors.
|
||||
[*] 2 fixable with the `--fix` option.
|
||||
|
||||
----- stderr -----
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -65,6 +65,8 @@ file_resolver.project_root = "<temp_dir>/"
|
||||
linter.exclude = []
|
||||
linter.project_root = "<temp_dir>/"
|
||||
linter.rules.enabled = [
|
||||
jump-statement-in-finally (B012),
|
||||
byte-string-usage (PYI057),
|
||||
multiple-imports-on-one-line (E401),
|
||||
module-import-not-at-top-of-file (E402),
|
||||
multiple-statements-on-one-line-colon (E701),
|
||||
@@ -126,6 +128,8 @@ linter.rules.enabled = [
|
||||
raise-not-implemented (F901),
|
||||
]
|
||||
linter.rules.should_fix = [
|
||||
jump-statement-in-finally (B012),
|
||||
byte-string-usage (PYI057),
|
||||
multiple-imports-on-one-line (E401),
|
||||
module-import-not-at-top-of-file (E402),
|
||||
multiple-statements-on-one-line-colon (E701),
|
||||
|
||||
@@ -18,6 +18,9 @@ use crate::checkers::ast::Checker;
|
||||
/// `break`, `continue`, or `return` statement is reached in a `finally` block,
|
||||
/// any exception raised in the `try` or `except` blocks will be silenced.
|
||||
///
|
||||
/// [PEP 765](https://peps.python.org/pep-0765/) additionally made this a `SyntaxWarning` starting
|
||||
/// in Python 3.14. It may become a `SyntaxError` in the future.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// def speed(distance, time):
|
||||
|
||||
@@ -11,20 +11,32 @@ use crate::{FixAvailability, Violation};
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// `ByteString` has been deprecated since Python 3.9 and will be removed in
|
||||
/// Python 3.14. The Python documentation recommends using either
|
||||
/// Python 3.17. The Python documentation recommends using either
|
||||
/// `collections.abc.Buffer` (or the `typing_extensions` backport
|
||||
/// on Python <3.12) or a union like `bytes | bytearray | memoryview` instead.
|
||||
/// on Python versions before 3.12) or a union like `bytes | bytearray | memoryview` instead.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// from typing import ByteString
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// On Python versions after 3.12, use the `Buffer` type from the standard library instead:
|
||||
/// ```python
|
||||
/// from collections.abc import Buffer
|
||||
/// ```
|
||||
///
|
||||
/// For earlier Python versions, you can use `typing_extensions`:
|
||||
/// ```python
|
||||
/// from typing_extensions import Buffer
|
||||
/// ```
|
||||
///
|
||||
/// or a union:
|
||||
/// ```python
|
||||
/// from typing import Union
|
||||
///
|
||||
/// x: Union[bytes, bytearray, memoryview]
|
||||
/// ```
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: The `ByteString` type](https://docs.python.org/3/library/typing.html#typing.ByteString)
|
||||
#[derive(ViolationMetadata)]
|
||||
|
||||
@@ -369,6 +369,17 @@ pub const DEFAULT_SELECTORS: &[RuleSelector] = &[
|
||||
prefix: RuleCodePrefix::Pycodestyle(codes::Pycodestyle::E9),
|
||||
redirected_from: None,
|
||||
},
|
||||
// Additionally include rules that will correspond to CPython errors in the future:
|
||||
// - B012 is a syntax warning in 3.14 and will become an error in the future
|
||||
// - PYI057 reports deprecated members of the standard library
|
||||
RuleSelector::Rule {
|
||||
prefix: RuleCodePrefix::Flake8Bugbear(codes::Flake8Bugbear::_012),
|
||||
redirected_from: None,
|
||||
},
|
||||
RuleSelector::Rule {
|
||||
prefix: RuleCodePrefix::Flake8Pyi(codes::Flake8Pyi::_057),
|
||||
redirected_from: None,
|
||||
},
|
||||
];
|
||||
|
||||
pub const TASK_TAGS: &[&str] = &["TODO", "FIXME", "XXX"];
|
||||
|
||||
@@ -804,11 +804,12 @@ pub struct LintCommonOptions {
|
||||
/// specific prefixes. `ignore` takes precedence over `select` if the
|
||||
/// same prefix appears in both.
|
||||
#[option(
|
||||
default = r#"["E4", "E7", "E9", "F"]"#,
|
||||
default = r#"["E4", "E7", "E9", "F", "B012", "PYI057"]"#,
|
||||
value_type = "list[RuleSelector]",
|
||||
example = r#"
|
||||
# On top of the defaults (`E4`, E7`, `E9`, and `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`).
|
||||
select = ["E4", "E7", "E9", "F", "B", "Q"]
|
||||
# On top of the defaults (`E4`, E7`, `E9`, `F`, `B012`, and `PYI057`),
|
||||
# enable flake8-bugbear (`B`) and flake8-quotes (`Q`).
|
||||
select = ["E4", "E7", "E9", "F", "PYI057", "B", "Q"]
|
||||
"#
|
||||
)]
|
||||
pub select: Option<Vec<RuleSelector>>,
|
||||
|
||||
@@ -51,10 +51,12 @@ If left unspecified, Ruff's default configuration is equivalent to:
|
||||
target-version = "py39"
|
||||
|
||||
[tool.ruff.lint]
|
||||
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
||||
# Enable Pyflakes (`F`), a subset of the pycodestyle (`E`) codes,
|
||||
# and a couple of other codes corresponding to CPython deprecations
|
||||
# and syntax warnings by default.
|
||||
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
|
||||
# McCabe complexity (`C901`) by default.
|
||||
select = ["E4", "E7", "E9", "F"]
|
||||
select = ["E4", "E7", "E9", "F", "PYI057", "B012"]
|
||||
ignore = []
|
||||
|
||||
# Allow fix for all enabled rules (when `--fix`) is provided.
|
||||
|
||||
Reference in New Issue
Block a user