mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-02 18:02:58 +00:00
Update to Rust 1.74 and use new clippy lints table (#8722)
Update to [Rust 1.74](https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html) and use the new clippy lints table. The update itself introduced a new clippy lint about superfluous hashes in raw strings, which got removed. I moved our lint config from `rustflags` to the newly stabilized [workspace.lints](https://doc.rust-lang.org/stable/cargo/reference/workspaces.html#the-lints-table). One consequence is that we have to `unsafe_code = "warn"` instead of "forbid" because the latter now actually bans unsafe code: ``` error[E0453]: allow(unsafe_code) incompatible with previous forbid --> crates/ruff_source_file/src/newlines.rs:62:17 | 62 | #[allow(unsafe_code)] | ^^^^^^^^^^^ overruled by previous forbid | = note: `forbid` lint level was set on command line ``` --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
This commit is contained in:
parent
6d5d079a18
commit
14e65afdc6
71 changed files with 1124 additions and 1054 deletions
|
@ -55,3 +55,6 @@ required-features = ["serde"]
|
|||
default = ["serde"]
|
||||
serde = ["dep:serde", "ruff_formatter/serde", "ruff_source_file/serde", "ruff_python_ast/serde"]
|
||||
schemars = ["dep:schemars", "ruff_formatter/schemars"]
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
@ -198,11 +198,11 @@ mod tests {
|
|||
range: TextRange::default(),
|
||||
});
|
||||
|
||||
let source = r#"# leading comment
|
||||
let source = r"# leading comment
|
||||
continue; # trailing
|
||||
# break leading
|
||||
break;
|
||||
"#;
|
||||
";
|
||||
|
||||
let source_code = SourceCode::new(source);
|
||||
|
||||
|
|
|
@ -610,11 +610,11 @@ test(10, 20)
|
|||
|
||||
#[test]
|
||||
fn only_comments() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
# Some comment
|
||||
|
||||
# another comment
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -624,7 +624,7 @@ test(10, 20)
|
|||
|
||||
#[test]
|
||||
fn empty_file() {
|
||||
let source = r#""#;
|
||||
let source = r"";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -634,12 +634,12 @@ test(10, 20)
|
|||
|
||||
#[test]
|
||||
fn dangling_comment() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
def test(
|
||||
# Some comment
|
||||
):
|
||||
pass
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -649,12 +649,12 @@ def test(
|
|||
|
||||
#[test]
|
||||
fn parenthesized_expression() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
a = ( # Trailing comment
|
||||
10 + # More comments
|
||||
3
|
||||
)
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -664,11 +664,11 @@ a = ( # Trailing comment
|
|||
|
||||
#[test]
|
||||
fn parenthesized_trailing_comment() {
|
||||
let source = r#"(
|
||||
let source = r"(
|
||||
a
|
||||
# comment
|
||||
)
|
||||
"#;
|
||||
";
|
||||
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -728,7 +728,7 @@ print("test")
|
|||
|
||||
#[test]
|
||||
fn if_elif_else_comments() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
if x == y:
|
||||
pass # trailing `pass` comment
|
||||
# Root `if` trailing comment
|
||||
|
@ -741,7 +741,7 @@ elif x < y:
|
|||
else:
|
||||
pass
|
||||
# `else` trailing comment
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -751,7 +751,7 @@ else:
|
|||
|
||||
#[test]
|
||||
fn if_elif_if_else_comments() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
if x == y:
|
||||
pass
|
||||
elif x < y:
|
||||
|
@ -761,7 +761,7 @@ elif x < y:
|
|||
# Leading else comment
|
||||
else:
|
||||
pass
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -855,10 +855,10 @@ print("Next statement");
|
|||
|
||||
#[test]
|
||||
fn leading_most_outer() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
# leading comment
|
||||
x
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -869,10 +869,10 @@ x
|
|||
// Comment should be attached to the statement
|
||||
#[test]
|
||||
fn trailing_most_outer() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
x # trailing comment
|
||||
y # trailing last node
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -882,11 +882,11 @@ y # trailing last node
|
|||
|
||||
#[test]
|
||||
fn trailing_most_outer_nested() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
x + (
|
||||
3 # trailing comment
|
||||
) # outer
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -896,12 +896,12 @@ x + (
|
|||
|
||||
#[test]
|
||||
fn trailing_after_comma() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
def test(
|
||||
a, # Trailing comment for argument `a`
|
||||
b,
|
||||
): pass
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -911,7 +911,7 @@ def test(
|
|||
|
||||
#[test]
|
||||
fn positional_argument_only_comment() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
def test(
|
||||
a, # trailing positional comment
|
||||
# Positional arguments only after here
|
||||
|
@ -919,7 +919,7 @@ def test(
|
|||
# leading b comment
|
||||
b,
|
||||
): pass
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -929,7 +929,7 @@ def test(
|
|||
|
||||
#[test]
|
||||
fn positional_argument_only_leading_comma_comment() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
def test(
|
||||
a # trailing positional comment
|
||||
# Positional arguments only after here
|
||||
|
@ -937,7 +937,7 @@ def test(
|
|||
# leading b comment
|
||||
b,
|
||||
): pass
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -947,14 +947,14 @@ def test(
|
|||
|
||||
#[test]
|
||||
fn positional_argument_only_comment_without_following_node() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
def test(
|
||||
a, # trailing positional comment
|
||||
# Positional arguments only after here
|
||||
/, # trailing positional argument comment.
|
||||
# Trailing on new line
|
||||
): pass
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -964,7 +964,7 @@ def test(
|
|||
|
||||
#[test]
|
||||
fn non_positional_arguments_with_defaults() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
def test(
|
||||
a=10 # trailing positional comment
|
||||
# Positional arguments only after here
|
||||
|
@ -972,7 +972,7 @@ def test(
|
|||
# leading comment for b
|
||||
b=20
|
||||
): pass
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -982,12 +982,12 @@ def test(
|
|||
|
||||
#[test]
|
||||
fn non_positional_arguments_slash_on_same_line() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
def test(a=10,/, # trailing positional argument comment.
|
||||
# leading comment for b
|
||||
b=20
|
||||
): pass
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -997,7 +997,7 @@ def test(a=10,/, # trailing positional argument comment.
|
|||
|
||||
#[test]
|
||||
fn binary_expression_left_operand_comment() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
a = (
|
||||
5
|
||||
# trailing left comment
|
||||
|
@ -1005,7 +1005,7 @@ a = (
|
|||
# leading right comment
|
||||
3
|
||||
)
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -1015,14 +1015,14 @@ a = (
|
|||
|
||||
#[test]
|
||||
fn binary_expression_left_operand_trailing_end_of_line_comment() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
a = (
|
||||
5 # trailing left comment
|
||||
+ # trailing operator comment
|
||||
# leading right comment
|
||||
3
|
||||
)
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -1032,7 +1032,7 @@ a = (
|
|||
|
||||
#[test]
|
||||
fn nested_binary_expression() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
a = (
|
||||
(5 # trailing left comment
|
||||
*
|
||||
|
@ -1041,7 +1041,7 @@ a = (
|
|||
# leading right comment
|
||||
3
|
||||
)
|
||||
"#;
|
||||
";
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
let comments = test_case.to_comments();
|
||||
|
@ -1051,10 +1051,10 @@ a = (
|
|||
|
||||
#[test]
|
||||
fn while_trailing_end_of_line_comment() {
|
||||
let source = r#"while True:
|
||||
let source = r"while True:
|
||||
if something.changed:
|
||||
do.stuff() # trailing comment
|
||||
"#;
|
||||
";
|
||||
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
|
@ -1065,11 +1065,11 @@ a = (
|
|||
|
||||
#[test]
|
||||
fn while_trailing_else_end_of_line_comment() {
|
||||
let source = r#"while True:
|
||||
let source = r"while True:
|
||||
pass
|
||||
else: # trailing comment
|
||||
pass
|
||||
"#;
|
||||
";
|
||||
|
||||
let test_case = CommentsTestCase::from_code(source);
|
||||
|
||||
|
|
|
@ -2281,10 +2281,10 @@ mod tests {
|
|||
|
||||
assert_eq!(
|
||||
max_empty_lines(
|
||||
r#"# This multiline comments section
|
||||
r"# This multiline comments section
|
||||
# should be split from the statement
|
||||
# above by two lines.
|
||||
"#
|
||||
"
|
||||
),
|
||||
0
|
||||
);
|
||||
|
|
|
@ -51,7 +51,7 @@ impl<'a> AnyString<'a> {
|
|||
.slice(f_string.range)
|
||||
.trim_start_matches(|c| c != '"' && c != '\'');
|
||||
let triple_quoted =
|
||||
unprefixed.starts_with(r#"""""#) || unprefixed.starts_with(r#"'''"#);
|
||||
unprefixed.starts_with(r#"""""#) || unprefixed.starts_with(r"'''");
|
||||
if f_string.values.iter().any(|value| match value {
|
||||
Expr::FormattedValue(ast::ExprFormattedValue { range, .. }) => {
|
||||
let string_content = locator.slice(*range);
|
||||
|
|
|
@ -183,17 +183,17 @@ mod tests {
|
|||
/// Very basic test intentionally kept very similar to the CLI
|
||||
#[test]
|
||||
fn basic() -> Result<()> {
|
||||
let input = r#"
|
||||
let input = r"
|
||||
# preceding
|
||||
if True:
|
||||
pass
|
||||
# trailing
|
||||
"#;
|
||||
let expected = r#"# preceding
|
||||
";
|
||||
let expected = r"# preceding
|
||||
if True:
|
||||
pass
|
||||
# trailing
|
||||
"#;
|
||||
";
|
||||
let actual = format_module_source(input, PyFormatOptions::default())?
|
||||
.as_code()
|
||||
.to_string();
|
||||
|
@ -241,11 +241,11 @@ def main() -> None:
|
|||
|
||||
assert_eq!(
|
||||
printed.as_code(),
|
||||
r#"for converter in connection.ops.get_db_converters(
|
||||
r"for converter in connection.ops.get_db_converters(
|
||||
expression
|
||||
) + expression.get_db_converters(connection):
|
||||
...
|
||||
"#
|
||||
"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -304,9 +304,9 @@ def main() -> None:
|
|||
|
||||
// 77 after g group (leading quote)
|
||||
let fits =
|
||||
r#"aaaaaaaaaa bbbbbbbbbb cccccccccc dddddddddd eeeeeeeeee ffffffffff gggggggggg h"#;
|
||||
r"aaaaaaaaaa bbbbbbbbbb cccccccccc dddddddddd eeeeeeeeee ffffffffff gggggggggg h";
|
||||
let breaks =
|
||||
r#"aaaaaaaaaa bbbbbbbbbb cccccccccc dddddddddd eeeeeeeeee ffffffffff gggggggggg hh"#;
|
||||
r"aaaaaaaaaa bbbbbbbbbb cccccccccc dddddddddd eeeeeeeeee ffffffffff gggggggggg hh";
|
||||
|
||||
let output = format!(
|
||||
SimpleFormatContext::default(),
|
||||
|
|
|
@ -685,7 +685,7 @@ mod tests {
|
|||
use crate::PyFormatOptions;
|
||||
|
||||
fn format_suite(level: SuiteKind) -> String {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
a = 10
|
||||
|
||||
|
||||
|
@ -704,7 +704,7 @@ def func():
|
|||
pass
|
||||
def trailing_func():
|
||||
pass
|
||||
"#;
|
||||
";
|
||||
|
||||
let statements = parse_suite(source, "test.py").unwrap();
|
||||
|
||||
|
@ -730,7 +730,7 @@ def trailing_func():
|
|||
|
||||
assert_eq!(
|
||||
formatted,
|
||||
r#"a = 10
|
||||
r"a = 10
|
||||
|
||||
|
||||
three_leading_newlines = 80
|
||||
|
@ -755,7 +755,7 @@ def func():
|
|||
|
||||
def trailing_func():
|
||||
pass
|
||||
"#
|
||||
"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -765,7 +765,7 @@ def trailing_func():
|
|||
|
||||
assert_eq!(
|
||||
formatted,
|
||||
r#"a = 10
|
||||
r"a = 10
|
||||
|
||||
three_leading_newlines = 80
|
||||
|
||||
|
@ -784,7 +784,7 @@ def func():
|
|||
|
||||
def trailing_func():
|
||||
pass
|
||||
"#
|
||||
"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue