Pretty print Diagnostics in snapshot tests (#3906)

This commit is contained in:
Micha Reiser 2023-04-11 11:03:00 +02:00 committed by GitHub
parent 210083bdd8
commit e8aebee3f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
901 changed files with 55367 additions and 66782 deletions

119
Cargo.lock generated
View file

@ -153,15 +153,6 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "block-buffer"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e"
dependencies = [
"generic-array",
]
[[package]] [[package]]
name = "bstr" name = "bstr"
version = "0.2.17" version = "0.2.17"
@ -446,15 +437,6 @@ version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]]
name = "cpufeatures"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "crc32fast" name = "crc32fast"
version = "1.3.2" version = "1.3.2"
@ -549,16 +531,6 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"typenum",
]
[[package]] [[package]]
name = "ctor" name = "ctor"
version = "0.1.26" version = "0.1.26"
@ -625,16 +597,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
[[package]]
name = "digest"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f"
dependencies = [
"block-buffer",
"crypto-common",
]
[[package]] [[package]]
name = "dirs" name = "dirs"
version = "4.0.0" version = "4.0.0"
@ -825,16 +787,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "generic-array"
version = "0.14.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
dependencies = [
"typenum",
"version_check",
]
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.8" version = "0.2.8"
@ -1018,9 +970,6 @@ dependencies = [
"console", "console",
"lazy_static", "lazy_static",
"linked-hash-map", "linked-hash-map",
"pest",
"pest_derive",
"serde",
"similar", "similar",
"yaml-rust", "yaml-rust",
] ]
@ -1560,50 +1509,6 @@ version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
[[package]]
name = "pest"
version = "2.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "028accff104c4e513bad663bbcd2ad7cfd5304144404c31ed0a77ac103d00660"
dependencies = [
"thiserror",
"ucd-trie",
]
[[package]]
name = "pest_derive"
version = "2.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ac3922aac69a40733080f53c1ce7f91dcf57e1a5f6c52f421fadec7fbdc4b69"
dependencies = [
"pest",
"pest_generator",
]
[[package]]
name = "pest_generator"
version = "2.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d06646e185566b5961b4058dd107e0a7f56e77c3f484549fb119867773c0f202"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "pest_meta"
version = "2.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6f60b2ba541577e2a0c307c8f39d1439108120eb7903adeb6497fa880c59616"
dependencies = [
"once_cell",
"pest",
"sha2",
]
[[package]] [[package]]
name = "petgraph" name = "petgraph"
version = "0.6.3" version = "0.6.3"
@ -2024,6 +1929,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"shellexpand", "shellexpand",
"similar",
"smallvec", "smallvec",
"strum", "strum",
"strum_macros", "strum_macros",
@ -2546,17 +2452,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "sha2"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]] [[package]]
name = "shellexpand" name = "shellexpand"
version = "3.0.0" version = "3.0.0"
@ -2939,18 +2834,6 @@ version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a"
[[package]]
name = "typenum"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]]
name = "ucd-trie"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81"
[[package]] [[package]]
name = "unic-char-property" name = "unic-char-property"
version = "0.9.0" version = "0.9.0"

View file

@ -60,6 +60,7 @@ schemars = { workspace = true }
semver = { version = "1.0.16" } semver = { version = "1.0.16" }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
similar = { workspace = true, features = ["inline"] }
shellexpand = { workspace = true } shellexpand = { workspace = true }
smallvec = { workspace = true } smallvec = { workspace = true }
strum = { workspace = true } strum = { workspace = true }
@ -71,7 +72,7 @@ typed-arena = { version = "2.0.2" }
unicode-width = { version = "0.1.10" } unicode-width = { version = "0.1.10" }
[dev-dependencies] [dev-dependencies]
insta = { workspace = true, features = ["yaml", "redactions"] } insta = { workspace = true }
pretty_assertions = "1.3.0" pretty_assertions = "1.3.0"
test-case = { workspace = true } test-case = { workspace = true }
# Disable colored output in tests # Disable colored output in tests

View file

@ -0,0 +1,194 @@
use crate::message::Message;
use colored::{Color, ColoredString, Colorize, Styles};
use ruff_diagnostics::Fix;
use ruff_python_ast::source_code::{OneIndexed, SourceCode};
use ruff_python_ast::types::Range;
use ruff_text_size::{TextRange, TextSize};
use similar::{ChangeTag, TextDiff};
use std::fmt::{Display, Formatter};
use std::num::NonZeroUsize;
/// Renders a diff that shows the code fixes.
///
/// The implementation isn't fully fledged out and only used by tests. Before using in production, try
/// * Improve layout
/// * Replace tabs with spaces for a consistent experience across terminals
/// * Replace zero-width whitespaces
/// * Print a simpler diff if only a single line has changed
/// * Compute the diff from the [`Edit`] because diff calculation is expensive.
pub(super) struct Diff<'a> {
fix: &'a Fix,
source_code: SourceCode<'a, 'a>,
}
impl<'a> Diff<'a> {
pub fn from_message(message: &'a Message) -> Option<Diff> {
match message.file.source_code() {
Some(source_code) if !message.fix.is_empty() => Some(Diff {
source_code,
fix: &message.fix,
}),
_ => None,
}
}
}
impl Display for Diff<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut output = String::with_capacity(self.source_code.text().len());
let mut last_end = TextSize::default();
for edit in self.fix.edits() {
let edit_range = self
.source_code
.text_range(Range::new(edit.location(), edit.end_location()));
output.push_str(&self.source_code.text()[TextRange::new(last_end, edit_range.start())]);
output.push_str(edit.content().unwrap_or_default());
last_end = edit_range.end();
}
output.push_str(&self.source_code.text()[usize::from(last_end)..]);
let diff = TextDiff::from_lines(self.source_code.text(), &output);
writeln!(f, "{}", " Suggested fix".blue())?;
let (largest_old, largest_new) = diff
.ops()
.last()
.map(|op| (op.old_range().start, op.new_range().start))
.unwrap_or_default();
let digit_with =
calculate_print_width(OneIndexed::from_zero_indexed(largest_new.max(largest_old)));
for (idx, group) in diff.grouped_ops(3).iter().enumerate() {
if idx > 0 {
writeln!(f, "{:-^1$}", "-", 80)?;
}
for op in group {
for change in diff.iter_inline_changes(op) {
let sign = match change.tag() {
ChangeTag::Delete => "-",
ChangeTag::Insert => "+",
ChangeTag::Equal => " ",
};
let line_style = LineStyle::from(change.tag());
let old_index = change.old_index().map(OneIndexed::from_zero_indexed);
let new_index = change.new_index().map(OneIndexed::from_zero_indexed);
write!(
f,
"{} {} |{}",
Line {
index: old_index,
width: digit_with
},
Line {
index: new_index,
width: digit_with
},
line_style.apply_to(sign).bold()
)?;
for (emphasized, value) in change.iter_strings_lossy() {
if emphasized {
write!(f, "{}", line_style.apply_to(&value).underline().on_black())?;
} else {
write!(f, "{}", line_style.apply_to(&value))?;
}
}
if change.missing_newline() {
writeln!(f)?;
}
}
}
}
Ok(())
}
}
struct LineStyle {
fgcolor: Option<Color>,
style: Option<Styles>,
}
impl LineStyle {
fn apply_to(&self, input: &str) -> ColoredString {
let mut colored = ColoredString::from(input);
if let Some(color) = self.fgcolor {
colored = colored.color(color);
}
if let Some(style) = self.style {
match style {
Styles::Clear => colored.clear(),
Styles::Bold => colored.bold(),
Styles::Dimmed => colored.dimmed(),
Styles::Underline => colored.underline(),
Styles::Reversed => colored.reversed(),
Styles::Italic => colored.italic(),
Styles::Blink => colored.blink(),
Styles::Hidden => colored.hidden(),
Styles::Strikethrough => colored.strikethrough(),
}
} else {
colored
}
}
}
impl From<ChangeTag> for LineStyle {
fn from(value: ChangeTag) -> Self {
match value {
ChangeTag::Equal => LineStyle {
fgcolor: None,
style: Some(Styles::Dimmed),
},
ChangeTag::Delete => LineStyle {
fgcolor: Some(Color::Red),
style: None,
},
ChangeTag::Insert => LineStyle {
fgcolor: Some(Color::Green),
style: None,
},
}
}
}
struct Line {
index: Option<OneIndexed>,
width: NonZeroUsize,
}
impl Display for Line {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
match self.index {
None => {
for _ in 0..self.width.get() {
f.write_str(" ")?;
}
Ok(())
}
Some(idx) => write!(f, "{:<width$}", idx, width = self.width.get()),
}
}
}
/// Calculate the length of the string representation of `value`
pub(super) fn calculate_print_width(mut value: OneIndexed) -> NonZeroUsize {
const TEN: OneIndexed = OneIndexed::from_zero_indexed(9);
let mut width = OneIndexed::ONE;
while value >= TEN {
value = OneIndexed::new(value.get() / 10).unwrap_or(OneIndexed::MIN);
width = width.checked_add(1).unwrap();
}
width
}

View file

@ -1,4 +1,5 @@
mod azure; mod azure;
mod diff;
mod github; mod github;
mod gitlab; mod gitlab;
mod grouped; mod grouped;

View file

@ -1,4 +1,5 @@
use crate::fs::relativize_path; use crate::fs::relativize_path;
use crate::message::diff::Diff;
use crate::message::{Emitter, EmitterContext, Message}; use crate::message::{Emitter, EmitterContext, Message};
use crate::registry::AsRule; use crate::registry::AsRule;
use annotate_snippets::display_list::{DisplayList, FormatOptions}; use annotate_snippets::display_list::{DisplayList, FormatOptions};
@ -14,6 +15,7 @@ use std::io::Write;
#[derive(Default)] #[derive(Default)]
pub struct TextEmitter { pub struct TextEmitter {
show_fix_status: bool, show_fix_status: bool,
show_fix: bool,
} }
impl TextEmitter { impl TextEmitter {
@ -22,6 +24,12 @@ impl TextEmitter {
self.show_fix_status = show_fix_status; self.show_fix_status = show_fix_status;
self self
} }
#[must_use]
pub fn with_show_fix(mut self, show_fix: bool) -> Self {
self.show_fix = show_fix;
self
}
} }
impl Emitter for TextEmitter { impl Emitter for TextEmitter {
@ -69,6 +77,12 @@ impl Emitter for TextEmitter {
if message.file.source_code().is_some() { if message.file.source_code().is_some() {
writeln!(writer, "{}", MessageCodeFrame { message })?; writeln!(writer, "{}", MessageCodeFrame { message })?;
if self.show_fix {
if let Some(diff) = Diff::from_message(message) {
writeln!(writer, "{diff}")?;
}
}
} }
} }

View file

@ -7,12 +7,12 @@ mod tests {
use std::path::Path; use std::path::Path;
use anyhow::Result; use anyhow::Result;
use insta::assert_yaml_snapshot;
use test_case::test_case; use test_case::test_case;
use crate::registry::Rule; use crate::registry::Rule;
use crate::settings;
use crate::test::test_path; use crate::test::test_path;
use crate::{assert_messages, settings};
#[test_case(Rule::CommentedOutCode, Path::new("ERA001.py"); "ERA001")] #[test_case(Rule::CommentedOutCode, Path::new("ERA001.py"); "ERA001")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> { fn rules(rule_code: Rule, path: &Path) -> Result<()> {
@ -21,7 +21,7 @@ mod tests {
Path::new("eradicate").join(path).as_path(), Path::new("eradicate").join(path).as_path(),
&settings::Settings::for_rule(rule_code), &settings::Settings::for_rule(rule_code),
)?; )?;
assert_yaml_snapshot!(snapshot, diagnostics); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())
} }
} }

View file

@ -1,110 +1,93 @@
--- ---
source: crates/ruff/src/rules/eradicate/mod.rs source: crates/ruff/src/rules/eradicate/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/eradicate/ERA001.py:1:1: ERA001 [*] Found commented-out code
name: CommentedOutCode |
body: Found commented-out code 1 | #import os
suggestion: Remove commented-out code | ^^^^^^^^^^ ERA001
fixable: true 2 | # from foo import junk
location: 3 | #a = 3
row: 1 |
column: 0 = help: Remove commented-out code
end_location:
row: 1 Suggested fix
column: 10 1 |-#import os
fix: 2 1 | # from foo import junk
edits: 3 2 | #a = 3
- location: 4 3 | a = 4
row: 1
column: 0 ./resources/test/fixtures/eradicate/ERA001.py:2:1: ERA001 [*] Found commented-out code
end_location: |
row: 2 2 | #import os
column: 0 3 | # from foo import junk
content: ~ | ^^^^^^^^^^^^^^^^^^^^^^ ERA001
parent: ~ 4 | #a = 3
- kind: 5 | a = 4
name: CommentedOutCode |
body: Found commented-out code = help: Remove commented-out code
suggestion: Remove commented-out code
fixable: true Suggested fix
location: 1 1 | #import os
row: 2 2 |-# from foo import junk
column: 0 3 2 | #a = 3
end_location: 4 3 | a = 4
row: 2 5 4 | #foo(1, 2, 3)
column: 22
fix: ./resources/test/fixtures/eradicate/ERA001.py:3:1: ERA001 [*] Found commented-out code
edits: |
- location: 3 | #import os
row: 2 4 | # from foo import junk
column: 0 5 | #a = 3
end_location: | ^^^^^^ ERA001
row: 3 6 | a = 4
column: 0 7 | #foo(1, 2, 3)
content: ~ |
parent: ~ = help: Remove commented-out code
- kind:
name: CommentedOutCode Suggested fix
body: Found commented-out code 1 1 | #import os
suggestion: Remove commented-out code 2 2 | # from foo import junk
fixable: true 3 |-#a = 3
location: 4 3 | a = 4
row: 3 5 4 | #foo(1, 2, 3)
column: 0 6 5 |
end_location:
row: 3 ./resources/test/fixtures/eradicate/ERA001.py:5:1: ERA001 [*] Found commented-out code
column: 6 |
fix: 5 | #a = 3
edits: 6 | a = 4
- location: 7 | #foo(1, 2, 3)
row: 3 | ^^^^^^^^^^^^^ ERA001
column: 0 8 |
end_location: 9 | def foo(x, y, z):
row: 4 |
column: 0 = help: Remove commented-out code
content: ~
parent: ~ Suggested fix
- kind: 2 2 | # from foo import junk
name: CommentedOutCode 3 3 | #a = 3
body: Found commented-out code 4 4 | a = 4
suggestion: Remove commented-out code 5 |-#foo(1, 2, 3)
fixable: true 6 5 |
location: 7 6 | def foo(x, y, z):
row: 5 8 7 | content = 1 # print('hello')
column: 0
end_location: ./resources/test/fixtures/eradicate/ERA001.py:12:5: ERA001 [*] Found commented-out code
row: 5 |
column: 13 12 | # This is a real comment.
fix: 13 | #return True
edits: | ^^^^^^^^^^^^ ERA001
- location: 14 | return False
row: 5 |
column: 0 = help: Remove commented-out code
end_location:
row: 6 Suggested fix
column: 0 9 9 | print(x, y, z)
content: ~ 10 10 |
parent: ~ 11 11 | # This is a real comment.
- kind: 12 |- #return True
name: CommentedOutCode 13 12 | return False
body: Found commented-out code 14 13 |
suggestion: Remove commented-out code 15 14 | #import os # noqa: ERA001
fixable: true
location:
row: 12
column: 4
end_location:
row: 12
column: 16
fix:
edits:
- location:
row: 12
column: 0
end_location:
row: 13
column: 0
content: ~
parent: ~

View file

@ -6,12 +6,12 @@ mod tests {
use std::path::Path; use std::path::Path;
use anyhow::Result; use anyhow::Result;
use insta::assert_yaml_snapshot;
use test_case::test_case; use test_case::test_case;
use crate::registry::Rule; use crate::registry::Rule;
use crate::settings;
use crate::test::test_path; use crate::test::test_path;
use crate::{assert_messages, settings};
#[test_case(Rule::SysVersionSlice3, Path::new("YTT101.py"); "YTT101")] #[test_case(Rule::SysVersionSlice3, Path::new("YTT101.py"); "YTT101")]
#[test_case(Rule::SysVersion2, Path::new("YTT102.py"); "YTT102")] #[test_case(Rule::SysVersion2, Path::new("YTT102.py"); "YTT102")]
@ -29,7 +29,7 @@ mod tests {
Path::new("flake8_2020").join(path).as_path(), Path::new("flake8_2020").join(path).as_path(),
&settings::Settings::for_rule(rule_code), &settings::Settings::for_rule(rule_code),
)?; )?;
assert_yaml_snapshot!(snapshot, diagnostics); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())
} }
} }

View file

@ -1,47 +1,32 @@
--- ---
source: crates/ruff/src/rules/flake8_2020/mod.rs source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_2020/YTT101.py:6:7: YTT101 `sys.version[:3]` referenced (python3.10), use `sys.version_info`
name: SysVersionSlice3 |
body: "`sys.version[:3]` referenced (python3.10), use `sys.version_info`" 6 | print(sys.version)
suggestion: ~ 7 |
fixable: false 8 | print(sys.version[:3])
location: | ^^^^^^^^^^^ YTT101
row: 6 9 | print(version[:3])
column: 6 10 | print(v[:3])
end_location: |
row: 6
column: 17 ./resources/test/fixtures/flake8_2020/YTT101.py:7:7: YTT101 `sys.version[:3]` referenced (python3.10), use `sys.version_info`
fix: |
edits: [] 7 | print(sys.version[:3])
parent: ~ 8 | print(version[:3])
- kind: | ^^^^^^^ YTT101
name: SysVersionSlice3 9 | print(v[:3])
body: "`sys.version[:3]` referenced (python3.10), use `sys.version_info`" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_2020/YTT101.py:8:7: YTT101 `sys.version[:3]` referenced (python3.10), use `sys.version_info`
location: |
row: 7 8 | print(sys.version[:3])
column: 6 9 | print(version[:3])
end_location: 10 | print(v[:3])
row: 7 | ^ YTT101
column: 13 11 |
fix: 12 | # the tool is timid and only flags certain numeric slices
edits: [] |
parent: ~
- kind:
name: SysVersionSlice3
body: "`sys.version[:3]` referenced (python3.10), use `sys.version_info`"
suggestion: ~
fixable: false
location:
row: 8
column: 6
end_location:
row: 8
column: 7
fix:
edits: []
parent: ~

View file

@ -1,33 +1,20 @@
--- ---
source: crates/ruff/src/rules/flake8_2020/mod.rs source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_2020/YTT102.py:4:12: YTT102 `sys.version[2]` referenced (python3.10), use `sys.version_info`
name: SysVersion2 |
body: "`sys.version[2]` referenced (python3.10), use `sys.version_info`" 4 | from sys import version
suggestion: ~ 5 |
fixable: false 6 | py_minor = sys.version[2]
location: | ^^^^^^^^^^^ YTT102
row: 4 7 | py_minor = version[2]
column: 11 |
end_location:
row: 4 ./resources/test/fixtures/flake8_2020/YTT102.py:5:12: YTT102 `sys.version[2]` referenced (python3.10), use `sys.version_info`
column: 22 |
fix: 5 | py_minor = sys.version[2]
edits: [] 6 | py_minor = version[2]
parent: ~ | ^^^^^^^ YTT102
- kind: |
name: SysVersion2
body: "`sys.version[2]` referenced (python3.10), use `sys.version_info`"
suggestion: ~
fixable: false
location:
row: 5
column: 11
end_location:
row: 5
column: 18
fix:
edits: []
parent: ~

View file

@ -1,75 +1,50 @@
--- ---
source: crates/ruff/src/rules/flake8_2020/mod.rs source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_2020/YTT103.py:4:1: YTT103 `sys.version` compared to string (python3.10), use `sys.version_info`
name: SysVersionCmpStr3 |
body: "`sys.version` compared to string (python3.10), use `sys.version_info`" 4 | from sys import version
suggestion: ~ 5 |
fixable: false 6 | version < "3.5"
location: | ^^^^^^^ YTT103
row: 4 7 | sys.version < "3.5"
column: 0 8 | sys.version <= "3.5"
end_location: |
row: 4
column: 7 ./resources/test/fixtures/flake8_2020/YTT103.py:5:1: YTT103 `sys.version` compared to string (python3.10), use `sys.version_info`
fix: |
edits: [] 5 | version < "3.5"
parent: ~ 6 | sys.version < "3.5"
- kind: | ^^^^^^^^^^^ YTT103
name: SysVersionCmpStr3 7 | sys.version <= "3.5"
body: "`sys.version` compared to string (python3.10), use `sys.version_info`" 8 | sys.version > "3.5"
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_2020/YTT103.py:6:1: YTT103 `sys.version` compared to string (python3.10), use `sys.version_info`
row: 5 |
column: 0 6 | version < "3.5"
end_location: 7 | sys.version < "3.5"
row: 5 8 | sys.version <= "3.5"
column: 11 | ^^^^^^^^^^^ YTT103
fix: 9 | sys.version > "3.5"
edits: [] 10 | sys.version >= "3.5"
parent: ~ |
- kind:
name: SysVersionCmpStr3 ./resources/test/fixtures/flake8_2020/YTT103.py:7:1: YTT103 `sys.version` compared to string (python3.10), use `sys.version_info`
body: "`sys.version` compared to string (python3.10), use `sys.version_info`" |
suggestion: ~ 7 | sys.version < "3.5"
fixable: false 8 | sys.version <= "3.5"
location: 9 | sys.version > "3.5"
row: 6 | ^^^^^^^^^^^ YTT103
column: 0 10 | sys.version >= "3.5"
end_location: |
row: 6
column: 11 ./resources/test/fixtures/flake8_2020/YTT103.py:8:1: YTT103 `sys.version` compared to string (python3.10), use `sys.version_info`
fix: |
edits: [] 8 | sys.version <= "3.5"
parent: ~ 9 | sys.version > "3.5"
- kind: 10 | sys.version >= "3.5"
name: SysVersionCmpStr3 | ^^^^^^^^^^^ YTT103
body: "`sys.version` compared to string (python3.10), use `sys.version_info`" |
suggestion: ~
fixable: false
location:
row: 7
column: 0
end_location:
row: 7
column: 11
fix:
edits: []
parent: ~
- kind:
name: SysVersionCmpStr3
body: "`sys.version` compared to string (python3.10), use `sys.version_info`"
suggestion: ~
fixable: false
location:
row: 8
column: 0
end_location:
row: 8
column: 11
fix:
edits: []
parent: ~

View file

@ -1,61 +1,40 @@
--- ---
source: crates/ruff/src/rules/flake8_2020/mod.rs source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_2020/YTT201.py:7:7: YTT201 `sys.version_info[0] == 3` referenced (python4), use `>=`
name: SysVersionInfo0Eq3 |
body: "`sys.version_info[0] == 3` referenced (python4), use `>=`" 7 | PY3 = sys.version_info[0] >= 3
suggestion: ~ 8 |
fixable: false 9 | PY3 = sys.version_info[0] == 3
location: | ^^^^^^^^^^^^^^^^^^^ YTT201
row: 7 10 | PY3 = version_info[0] == 3
column: 6 11 | PY2 = sys.version_info[0] != 3
end_location: |
row: 7
column: 25 ./resources/test/fixtures/flake8_2020/YTT201.py:8:7: YTT201 `sys.version_info[0] == 3` referenced (python4), use `>=`
fix: |
edits: [] 8 | PY3 = sys.version_info[0] == 3
parent: ~ 9 | PY3 = version_info[0] == 3
- kind: | ^^^^^^^^^^^^^^^ YTT201
name: SysVersionInfo0Eq3 10 | PY2 = sys.version_info[0] != 3
body: "`sys.version_info[0] == 3` referenced (python4), use `>=`" 11 | PY2 = version_info[0] != 3
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_2020/YTT201.py:9:7: YTT201 `sys.version_info[0] == 3` referenced (python4), use `>=`
row: 8 |
column: 6 9 | PY3 = sys.version_info[0] == 3
end_location: 10 | PY3 = version_info[0] == 3
row: 8 11 | PY2 = sys.version_info[0] != 3
column: 21 | ^^^^^^^^^^^^^^^^^^^ YTT201
fix: 12 | PY2 = version_info[0] != 3
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_2020/YTT201.py:10:7: YTT201 `sys.version_info[0] == 3` referenced (python4), use `>=`
name: SysVersionInfo0Eq3 |
body: "`sys.version_info[0] == 3` referenced (python4), use `>=`" 10 | PY3 = version_info[0] == 3
suggestion: ~ 11 | PY2 = sys.version_info[0] != 3
fixable: false 12 | PY2 = version_info[0] != 3
location: | ^^^^^^^^^^^^^^^ YTT201
row: 9 |
column: 6
end_location:
row: 9
column: 25
fix:
edits: []
parent: ~
- kind:
name: SysVersionInfo0Eq3
body: "`sys.version_info[0] == 3` referenced (python4), use `>=`"
suggestion: ~
fixable: false
location:
row: 10
column: 6
end_location:
row: 10
column: 21
fix:
edits: []
parent: ~

View file

@ -1,33 +1,23 @@
--- ---
source: crates/ruff/src/rules/flake8_2020/mod.rs source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_2020/YTT202.py:4:4: YTT202 `six.PY3` referenced (python4), use `not six.PY2`
name: SixPY3 |
body: "`six.PY3` referenced (python4), use `not six.PY2`" 4 | from six import PY3
suggestion: ~ 5 |
fixable: false 6 | if six.PY3:
location: | ^^^^^^^ YTT202
row: 4 7 | print("3")
column: 3 8 | if PY3:
end_location: |
row: 4
column: 10 ./resources/test/fixtures/flake8_2020/YTT202.py:6:4: YTT202 `six.PY3` referenced (python4), use `not six.PY2`
fix: |
edits: [] 6 | if six.PY3:
parent: ~ 7 | print("3")
- kind: 8 | if PY3:
name: SixPY3 | ^^^ YTT202
body: "`six.PY3` referenced (python4), use `not six.PY2`" 9 | print("3")
suggestion: ~ |
fixable: false
location:
row: 6
column: 3
end_location:
row: 6
column: 6
fix:
edits: []
parent: ~

View file

@ -1,33 +1,20 @@
--- ---
source: crates/ruff/src/rules/flake8_2020/mod.rs source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_2020/YTT203.py:4:1: YTT203 `sys.version_info[1]` compared to integer (python4), compare `sys.version_info` to tuple
name: SysVersionInfo1CmpInt |
body: "`sys.version_info[1]` compared to integer (python4), compare `sys.version_info` to tuple" 4 | from sys import version_info
suggestion: ~ 5 |
fixable: false 6 | sys.version_info[1] >= 5
location: | ^^^^^^^^^^^^^^^^^^^ YTT203
row: 4 7 | version_info[1] < 6
column: 0 |
end_location:
row: 4 ./resources/test/fixtures/flake8_2020/YTT203.py:5:1: YTT203 `sys.version_info[1]` compared to integer (python4), compare `sys.version_info` to tuple
column: 19 |
fix: 5 | sys.version_info[1] >= 5
edits: [] 6 | version_info[1] < 6
parent: ~ | ^^^^^^^^^^^^^^^ YTT203
- kind: |
name: SysVersionInfo1CmpInt
body: "`sys.version_info[1]` compared to integer (python4), compare `sys.version_info` to tuple"
suggestion: ~
fixable: false
location:
row: 5
column: 0
end_location:
row: 5
column: 15
fix:
edits: []
parent: ~

View file

@ -1,33 +1,20 @@
--- ---
source: crates/ruff/src/rules/flake8_2020/mod.rs source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_2020/YTT204.py:4:1: YTT204 `sys.version_info.minor` compared to integer (python4), compare `sys.version_info` to tuple
name: SysVersionInfoMinorCmpInt |
body: "`sys.version_info.minor` compared to integer (python4), compare `sys.version_info` to tuple" 4 | from sys import version_info
suggestion: ~ 5 |
fixable: false 6 | sys.version_info.minor <= 7
location: | ^^^^^^^^^^^^^^^^^^^^^^ YTT204
row: 4 7 | version_info.minor > 8
column: 0 |
end_location:
row: 4 ./resources/test/fixtures/flake8_2020/YTT204.py:5:1: YTT204 `sys.version_info.minor` compared to integer (python4), compare `sys.version_info` to tuple
column: 22 |
fix: 5 | sys.version_info.minor <= 7
edits: [] 6 | version_info.minor > 8
parent: ~ | ^^^^^^^^^^^^^^^^^^ YTT204
- kind: |
name: SysVersionInfoMinorCmpInt
body: "`sys.version_info.minor` compared to integer (python4), compare `sys.version_info` to tuple"
suggestion: ~
fixable: false
location:
row: 5
column: 0
end_location:
row: 5
column: 18
fix:
edits: []
parent: ~

View file

@ -1,33 +1,20 @@
--- ---
source: crates/ruff/src/rules/flake8_2020/mod.rs source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_2020/YTT301.py:4:12: YTT301 `sys.version[0]` referenced (python10), use `sys.version_info`
name: SysVersion0 |
body: "`sys.version[0]` referenced (python10), use `sys.version_info`" 4 | from sys import version
suggestion: ~ 5 |
fixable: false 6 | py_major = sys.version[0]
location: | ^^^^^^^^^^^ YTT301
row: 4 7 | py_major = version[0]
column: 11 |
end_location:
row: 4 ./resources/test/fixtures/flake8_2020/YTT301.py:5:12: YTT301 `sys.version[0]` referenced (python10), use `sys.version_info`
column: 22 |
fix: 5 | py_major = sys.version[0]
edits: [] 6 | py_major = version[0]
parent: ~ | ^^^^^^^ YTT301
- kind: |
name: SysVersion0
body: "`sys.version[0]` referenced (python10), use `sys.version_info`"
suggestion: ~
fixable: false
location:
row: 5
column: 11
end_location:
row: 5
column: 18
fix:
edits: []
parent: ~

View file

@ -1,75 +1,50 @@
--- ---
source: crates/ruff/src/rules/flake8_2020/mod.rs source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_2020/YTT302.py:4:1: YTT302 `sys.version` compared to string (python10), use `sys.version_info`
name: SysVersionCmpStr10 |
body: "`sys.version` compared to string (python10), use `sys.version_info`" 4 | from sys import version
suggestion: ~ 5 |
fixable: false 6 | version < "3"
location: | ^^^^^^^ YTT302
row: 4 7 | sys.version < "3"
column: 0 8 | sys.version <= "3"
end_location: |
row: 4
column: 7 ./resources/test/fixtures/flake8_2020/YTT302.py:5:1: YTT302 `sys.version` compared to string (python10), use `sys.version_info`
fix: |
edits: [] 5 | version < "3"
parent: ~ 6 | sys.version < "3"
- kind: | ^^^^^^^^^^^ YTT302
name: SysVersionCmpStr10 7 | sys.version <= "3"
body: "`sys.version` compared to string (python10), use `sys.version_info`" 8 | sys.version > "3"
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_2020/YTT302.py:6:1: YTT302 `sys.version` compared to string (python10), use `sys.version_info`
row: 5 |
column: 0 6 | version < "3"
end_location: 7 | sys.version < "3"
row: 5 8 | sys.version <= "3"
column: 11 | ^^^^^^^^^^^ YTT302
fix: 9 | sys.version > "3"
edits: [] 10 | sys.version >= "3"
parent: ~ |
- kind:
name: SysVersionCmpStr10 ./resources/test/fixtures/flake8_2020/YTT302.py:7:1: YTT302 `sys.version` compared to string (python10), use `sys.version_info`
body: "`sys.version` compared to string (python10), use `sys.version_info`" |
suggestion: ~ 7 | sys.version < "3"
fixable: false 8 | sys.version <= "3"
location: 9 | sys.version > "3"
row: 6 | ^^^^^^^^^^^ YTT302
column: 0 10 | sys.version >= "3"
end_location: |
row: 6
column: 11 ./resources/test/fixtures/flake8_2020/YTT302.py:8:1: YTT302 `sys.version` compared to string (python10), use `sys.version_info`
fix: |
edits: [] 8 | sys.version <= "3"
parent: ~ 9 | sys.version > "3"
- kind: 10 | sys.version >= "3"
name: SysVersionCmpStr10 | ^^^^^^^^^^^ YTT302
body: "`sys.version` compared to string (python10), use `sys.version_info`" |
suggestion: ~
fixable: false
location:
row: 7
column: 0
end_location:
row: 7
column: 11
fix:
edits: []
parent: ~
- kind:
name: SysVersionCmpStr10
body: "`sys.version` compared to string (python10), use `sys.version_info`"
suggestion: ~
fixable: false
location:
row: 8
column: 0
end_location:
row: 8
column: 11
fix:
edits: []
parent: ~

View file

@ -1,33 +1,20 @@
--- ---
source: crates/ruff/src/rules/flake8_2020/mod.rs source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_2020/YTT303.py:4:7: YTT303 `sys.version[:1]` referenced (python10), use `sys.version_info`
name: SysVersionSlice1 |
body: "`sys.version[:1]` referenced (python10), use `sys.version_info`" 4 | from sys import version
suggestion: ~ 5 |
fixable: false 6 | print(sys.version[:1])
location: | ^^^^^^^^^^^ YTT303
row: 4 7 | print(version[:1])
column: 6 |
end_location:
row: 4 ./resources/test/fixtures/flake8_2020/YTT303.py:5:7: YTT303 `sys.version[:1]` referenced (python10), use `sys.version_info`
column: 17 |
fix: 5 | print(sys.version[:1])
edits: [] 6 | print(version[:1])
parent: ~ | ^^^^^^^ YTT303
- kind: |
name: SysVersionSlice1
body: "`sys.version[:1]` referenced (python10), use `sys.version_info`"
suggestion: ~
fixable: false
location:
row: 5
column: 6
end_location:
row: 5
column: 13
fix:
edits: []
parent: ~

View file

@ -8,8 +8,8 @@ pub mod settings;
mod tests { mod tests {
use std::path::Path; use std::path::Path;
use crate::assert_messages;
use anyhow::Result; use anyhow::Result;
use insta::assert_yaml_snapshot;
use crate::registry::Rule; use crate::registry::Rule;
use crate::settings::Settings; use crate::settings::Settings;
@ -35,7 +35,7 @@ mod tests {
]) ])
}, },
)?; )?;
assert_yaml_snapshot!(diagnostics); assert_messages!(diagnostics);
Ok(()) Ok(())
} }
@ -63,7 +63,7 @@ mod tests {
]) ])
}, },
)?; )?;
assert_yaml_snapshot!(diagnostics); assert_messages!(diagnostics);
Ok(()) Ok(())
} }
@ -85,7 +85,7 @@ mod tests {
]) ])
}, },
)?; )?;
assert_yaml_snapshot!(diagnostics); assert_messages!(diagnostics);
Ok(()) Ok(())
} }
@ -107,7 +107,7 @@ mod tests {
]) ])
}, },
)?; )?;
insta::assert_yaml_snapshot!(diagnostics); assert_messages!(diagnostics);
Ok(()) Ok(())
} }
@ -135,7 +135,7 @@ mod tests {
]) ])
}, },
)?; )?;
assert_yaml_snapshot!(diagnostics); assert_messages!(diagnostics);
Ok(()) Ok(())
} }
@ -151,7 +151,7 @@ mod tests {
..Settings::for_rules(vec![Rule::AnyType]) ..Settings::for_rules(vec![Rule::AnyType])
}, },
)?; )?;
assert_yaml_snapshot!(diagnostics); assert_messages!(diagnostics);
Ok(()) Ok(())
} }
@ -169,7 +169,7 @@ mod tests {
]) ])
}, },
)?; )?;
assert_yaml_snapshot!(diagnostics); assert_messages!(diagnostics);
Ok(()) Ok(())
} }
@ -187,7 +187,7 @@ mod tests {
]) ])
}, },
)?; )?;
assert_yaml_snapshot!(diagnostics); assert_messages!(diagnostics);
Ok(()) Ok(())
} }
@ -197,7 +197,7 @@ mod tests {
Path::new("flake8_annotations/simple_magic_methods.py"), Path::new("flake8_annotations/simple_magic_methods.py"),
&Settings::for_rule(Rule::MissingReturnTypeSpecialMethod), &Settings::for_rule(Rule::MissingReturnTypeSpecialMethod),
)?; )?;
assert_yaml_snapshot!(diagnostics); assert_messages!(diagnostics);
Ok(()) Ok(())
} }
} }

View file

@ -1,6 +1,4 @@
--- ---
source: src/rules/flake8_annotations/mod.rs source: crates/ruff/src/rules/flake8_annotations/mod.rs
expression: diagnostics
--- ---
[]

View file

@ -1,19 +1,12 @@
--- ---
source: crates/ruff/src/rules/flake8_annotations/mod.rs source: crates/ruff/src/rules/flake8_annotations/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_annotations/allow_overload.py:29:9: ANN201 Missing return type annotation for public function `bar`
name: MissingReturnTypeUndocumentedPublicFunction |
body: "Missing return type annotation for public function `bar`" 29 | class X:
suggestion: ~ 30 | def bar(i):
fixable: false | ^^^ ANN201
location: 31 | return i
row: 29 |
column: 8
end_location:
row: 29
column: 11
fix:
edits: []
parent: ~

View file

@ -1,61 +1,36 @@
--- ---
source: crates/ruff/src/rules/flake8_annotations/mod.rs source: crates/ruff/src/rules/flake8_annotations/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_annotations/allow_star_arg_any.py:10:12: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
name: AnyType |
body: "Dynamically typed expressions (typing.Any) are disallowed in `a`" 10 | # ANN401
suggestion: ~ 11 | def foo(a: Any, *args: str, **kwargs: str) -> int:
fixable: false | ^^^ ANN401
location: 12 | pass
row: 10 |
column: 11
end_location: ./resources/test/fixtures/flake8_annotations/allow_star_arg_any.py:15:47: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `foo`
row: 10 |
column: 14 15 | # ANN401
fix: 16 | def foo(a: int, *args: str, **kwargs: str) -> Any:
edits: [] | ^^^ ANN401
parent: ~ 17 | pass
- kind: |
name: AnyType
body: "Dynamically typed expressions (typing.Any) are disallowed in `foo`" ./resources/test/fixtures/flake8_annotations/allow_star_arg_any.py:40:29: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
suggestion: ~ |
fixable: false 40 | # ANN401
location: 41 | def foo_method(self, a: Any, *params: str, **options: str) -> int:
row: 15 | ^^^ ANN401
column: 46 42 | pass
end_location: |
row: 15
column: 49 ./resources/test/fixtures/flake8_annotations/allow_star_arg_any.py:44:67: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `foo_method`
fix: |
edits: [] 44 | # ANN401
parent: ~ 45 | def foo_method(self, a: int, *params: str, **options: str) -> Any:
- kind: | ^^^ ANN401
name: AnyType 46 | pass
body: "Dynamically typed expressions (typing.Any) are disallowed in `a`" |
suggestion: ~
fixable: false
location:
row: 40
column: 28
end_location:
row: 40
column: 31
fix:
edits: []
parent: ~
- kind:
name: AnyType
body: "Dynamically typed expressions (typing.Any) are disallowed in `foo_method`"
suggestion: ~
fixable: false
location:
row: 44
column: 66
end_location:
row: 44
column: 69
fix:
edits: []
parent: ~

View file

@ -1,327 +1,189 @@
--- ---
source: crates/ruff/src/rules/flake8_annotations/mod.rs source: crates/ruff/src/rules/flake8_annotations/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_annotations/annotation_presence.py:4:5: ANN201 Missing return type annotation for public function `foo`
name: MissingReturnTypeUndocumentedPublicFunction |
body: "Missing return type annotation for public function `foo`" 4 | # Error
suggestion: ~ 5 | def foo(a, b):
fixable: false | ^^^ ANN201
location: 6 | pass
row: 4 |
column: 4
end_location: ./resources/test/fixtures/flake8_annotations/annotation_presence.py:4:9: ANN001 Missing type annotation for function argument `a`
row: 4 |
column: 7 4 | # Error
fix: 5 | def foo(a, b):
edits: [] | ^ ANN001
parent: ~ 6 | pass
- kind: |
name: MissingTypeFunctionArgument
body: "Missing type annotation for function argument `a`" ./resources/test/fixtures/flake8_annotations/annotation_presence.py:4:12: ANN001 Missing type annotation for function argument `b`
suggestion: ~ |
fixable: false 4 | # Error
location: 5 | def foo(a, b):
row: 4 | ^ ANN001
column: 8 6 | pass
end_location: |
row: 4
column: 9 ./resources/test/fixtures/flake8_annotations/annotation_presence.py:9:5: ANN201 Missing return type annotation for public function `foo`
fix: |
edits: [] 9 | # Error
parent: ~ 10 | def foo(a: int, b):
- kind: | ^^^ ANN201
name: MissingTypeFunctionArgument 11 | pass
body: "Missing type annotation for function argument `b`" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_annotations/annotation_presence.py:9:17: ANN001 Missing type annotation for function argument `b`
location: |
row: 4 9 | # Error
column: 11 10 | def foo(a: int, b):
end_location: | ^ ANN001
row: 4 11 | pass
column: 12 |
fix:
edits: [] ./resources/test/fixtures/flake8_annotations/annotation_presence.py:14:17: ANN001 Missing type annotation for function argument `b`
parent: ~ |
- kind: 14 | # Error
name: MissingReturnTypeUndocumentedPublicFunction 15 | def foo(a: int, b) -> int:
body: "Missing return type annotation for public function `foo`" | ^ ANN001
suggestion: ~ 16 | pass
fixable: false |
location:
row: 9 ./resources/test/fixtures/flake8_annotations/annotation_presence.py:19:5: ANN201 Missing return type annotation for public function `foo`
column: 4 |
end_location: 19 | # Error
row: 9 20 | def foo(a: int, b: int):
column: 7 | ^^^ ANN201
fix: 21 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_annotations/annotation_presence.py:24:5: ANN201 Missing return type annotation for public function `foo`
name: MissingTypeFunctionArgument |
body: "Missing type annotation for function argument `b`" 24 | # Error
suggestion: ~ 25 | def foo():
fixable: false | ^^^ ANN201
location: 26 | pass
row: 9 |
column: 16
end_location: ./resources/test/fixtures/flake8_annotations/annotation_presence.py:44:12: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
row: 9 |
column: 17 44 | # ANN401
fix: 45 | def foo(a: Any, *args: str, **kwargs: str) -> int:
edits: [] | ^^^ ANN401
parent: ~ 46 | pass
- kind: |
name: MissingTypeFunctionArgument
body: "Missing type annotation for function argument `b`" ./resources/test/fixtures/flake8_annotations/annotation_presence.py:49:47: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `foo`
suggestion: ~ |
fixable: false 49 | # ANN401
location: 50 | def foo(a: int, *args: str, **kwargs: str) -> Any:
row: 14 | ^^^ ANN401
column: 16 51 | pass
end_location: |
row: 14
column: 17 ./resources/test/fixtures/flake8_annotations/annotation_presence.py:54:24: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `*args`
fix: |
edits: [] 54 | # ANN401
parent: ~ 55 | def foo(a: int, *args: Any, **kwargs: Any) -> int:
- kind: | ^^^ ANN401
name: MissingReturnTypeUndocumentedPublicFunction 56 | pass
body: "Missing return type annotation for public function `foo`" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_annotations/annotation_presence.py:54:39: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`
location: |
row: 19 54 | # ANN401
column: 4 55 | def foo(a: int, *args: Any, **kwargs: Any) -> int:
end_location: | ^^^ ANN401
row: 19 56 | pass
column: 7 |
fix:
edits: [] ./resources/test/fixtures/flake8_annotations/annotation_presence.py:59:24: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `*args`
parent: ~ |
- kind: 59 | # ANN401
name: MissingReturnTypeUndocumentedPublicFunction 60 | def foo(a: int, *args: Any, **kwargs: str) -> int:
body: "Missing return type annotation for public function `foo`" | ^^^ ANN401
suggestion: ~ 61 | pass
fixable: false |
location:
row: 24 ./resources/test/fixtures/flake8_annotations/annotation_presence.py:64:39: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`
column: 4 |
end_location: 64 | # ANN401
row: 24 65 | def foo(a: int, *args: str, **kwargs: Any) -> int:
column: 7 | ^^^ ANN401
fix: 66 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_annotations/annotation_presence.py:74:13: ANN101 Missing type annotation for `self` in method
name: AnyType |
body: "Dynamically typed expressions (typing.Any) are disallowed in `a`" 74 | # ANN101
suggestion: ~ 75 | def foo(self, a: int, b: int) -> int:
fixable: false | ^^^^ ANN101
location: 76 | pass
row: 44 |
column: 11
end_location: ./resources/test/fixtures/flake8_annotations/annotation_presence.py:78:29: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a`
row: 44 |
column: 14 78 | # ANN401
fix: 79 | def foo(self: "Foo", a: Any, *params: str, **options: str) -> int:
edits: [] | ^^^ ANN401
parent: ~ 80 | pass
- kind: |
name: AnyType
body: "Dynamically typed expressions (typing.Any) are disallowed in `foo`" ./resources/test/fixtures/flake8_annotations/annotation_presence.py:82:67: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `foo`
suggestion: ~ |
fixable: false 82 | # ANN401
location: 83 | def foo(self: "Foo", a: int, *params: str, **options: str) -> Any:
row: 49 | ^^^ ANN401
column: 46 84 | pass
end_location: |
row: 49
column: 49 ./resources/test/fixtures/flake8_annotations/annotation_presence.py:86:43: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `*params`
fix: |
edits: [] 86 | # ANN401
parent: ~ 87 | def foo(self: "Foo", a: int, *params: Any, **options: Any) -> int:
- kind: | ^^^ ANN401
name: AnyType 88 | pass
body: "Dynamically typed expressions (typing.Any) are disallowed in `*args`" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_annotations/annotation_presence.py:86:59: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `**options`
location: |
row: 54 86 | # ANN401
column: 23 87 | def foo(self: "Foo", a: int, *params: Any, **options: Any) -> int:
end_location: | ^^^ ANN401
row: 54 88 | pass
column: 26 |
fix:
edits: [] ./resources/test/fixtures/flake8_annotations/annotation_presence.py:90:43: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `*params`
parent: ~ |
- kind: 90 | # ANN401
name: AnyType 91 | def foo(self: "Foo", a: int, *params: Any, **options: str) -> int:
body: "Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`" | ^^^ ANN401
suggestion: ~ 92 | pass
fixable: false |
location:
row: 54 ./resources/test/fixtures/flake8_annotations/annotation_presence.py:94:59: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `**options`
column: 38 |
end_location: 94 | # ANN401
row: 54 95 | def foo(self: "Foo", a: int, *params: str, **options: Any) -> int:
column: 41 | ^^^ ANN401
fix: 96 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_annotations/annotation_presence.py:104:13: ANN102 Missing type annotation for `cls` in classmethod
name: AnyType |
body: "Dynamically typed expressions (typing.Any) are disallowed in `*args`" 104 | # ANN102
suggestion: ~ 105 | @classmethod
fixable: false 106 | def foo(cls, a: int, b: int) -> int:
location: | ^^^ ANN102
row: 59 107 | pass
column: 23 |
end_location:
row: 59 ./resources/test/fixtures/flake8_annotations/annotation_presence.py:108:13: ANN101 Missing type annotation for `self` in method
column: 26 |
fix: 108 | # ANN101
edits: [] 109 | def foo(self, /, a: int, b: int) -> int:
parent: ~ | ^^^^ ANN101
- kind: 110 | pass
name: AnyType |
body: "Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`"
suggestion: ~
fixable: false
location:
row: 64
column: 38
end_location:
row: 64
column: 41
fix:
edits: []
parent: ~
- kind:
name: MissingTypeSelf
body: "Missing type annotation for `self` in method"
suggestion: ~
fixable: false
location:
row: 74
column: 12
end_location:
row: 74
column: 16
fix:
edits: []
parent: ~
- kind:
name: AnyType
body: "Dynamically typed expressions (typing.Any) are disallowed in `a`"
suggestion: ~
fixable: false
location:
row: 78
column: 28
end_location:
row: 78
column: 31
fix:
edits: []
parent: ~
- kind:
name: AnyType
body: "Dynamically typed expressions (typing.Any) are disallowed in `foo`"
suggestion: ~
fixable: false
location:
row: 82
column: 66
end_location:
row: 82
column: 69
fix:
edits: []
parent: ~
- kind:
name: AnyType
body: "Dynamically typed expressions (typing.Any) are disallowed in `*params`"
suggestion: ~
fixable: false
location:
row: 86
column: 42
end_location:
row: 86
column: 45
fix:
edits: []
parent: ~
- kind:
name: AnyType
body: "Dynamically typed expressions (typing.Any) are disallowed in `**options`"
suggestion: ~
fixable: false
location:
row: 86
column: 58
end_location:
row: 86
column: 61
fix:
edits: []
parent: ~
- kind:
name: AnyType
body: "Dynamically typed expressions (typing.Any) are disallowed in `*params`"
suggestion: ~
fixable: false
location:
row: 90
column: 42
end_location:
row: 90
column: 45
fix:
edits: []
parent: ~
- kind:
name: AnyType
body: "Dynamically typed expressions (typing.Any) are disallowed in `**options`"
suggestion: ~
fixable: false
location:
row: 94
column: 58
end_location:
row: 94
column: 61
fix:
edits: []
parent: ~
- kind:
name: MissingTypeCls
body: "Missing type annotation for `cls` in classmethod"
suggestion: ~
fixable: false
location:
row: 104
column: 12
end_location:
row: 104
column: 15
fix:
edits: []
parent: ~
- kind:
name: MissingTypeSelf
body: "Missing type annotation for `self` in method"
suggestion: ~
fixable: false
location:
row: 108
column: 12
end_location:
row: 108
column: 16
fix:
edits: []
parent: ~

View file

@ -1,75 +1,41 @@
--- ---
source: crates/ruff/src/rules/flake8_annotations/mod.rs source: crates/ruff/src/rules/flake8_annotations/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_annotations/ignore_fully_untyped.py:24:5: ANN201 Missing return type annotation for public function `error_partially_typed_1`
name: MissingReturnTypeUndocumentedPublicFunction |
body: "Missing return type annotation for public function `error_partially_typed_1`" 24 | def error_partially_typed_1(a: int, b):
suggestion: ~ | ^^^^^^^^^^^^^^^^^^^^^^^ ANN201
fixable: false 25 | pass
location: |
row: 24
column: 4 ./resources/test/fixtures/flake8_annotations/ignore_fully_untyped.py:24:37: ANN001 Missing type annotation for function argument `b`
end_location: |
row: 24 24 | def error_partially_typed_1(a: int, b):
column: 27 | ^ ANN001
fix: 25 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_annotations/ignore_fully_untyped.py:28:37: ANN001 Missing type annotation for function argument `b`
name: MissingTypeFunctionArgument |
body: "Missing type annotation for function argument `b`" 28 | def error_partially_typed_2(a: int, b) -> int:
suggestion: ~ | ^ ANN001
fixable: false 29 | pass
location: |
row: 24
column: 36 ./resources/test/fixtures/flake8_annotations/ignore_fully_untyped.py:32:5: ANN201 Missing return type annotation for public function `error_partially_typed_3`
end_location: |
row: 24 32 | def error_partially_typed_3(a: int, b: int):
column: 37 | ^^^^^^^^^^^^^^^^^^^^^^^ ANN201
fix: 33 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_annotations/ignore_fully_untyped.py:43:9: ANN201 Missing return type annotation for public function `error_typed_self`
name: MissingTypeFunctionArgument |
body: "Missing type annotation for function argument `b`" 43 | pass
suggestion: ~ 44 |
fixable: false 45 | def error_typed_self(self: X):
location: | ^^^^^^^^^^^^^^^^ ANN201
row: 28 46 | pass
column: 36 |
end_location:
row: 28
column: 37
fix:
edits: []
parent: ~
- kind:
name: MissingReturnTypeUndocumentedPublicFunction
body: "Missing return type annotation for public function `error_partially_typed_3`"
suggestion: ~
fixable: false
location:
row: 32
column: 4
end_location:
row: 32
column: 27
fix:
edits: []
parent: ~
- kind:
name: MissingReturnTypeUndocumentedPublicFunction
body: "Missing return type annotation for public function `error_typed_self`"
suggestion: ~
fixable: false
location:
row: 43
column: 8
end_location:
row: 43
column: 24
fix:
edits: []
parent: ~

View file

@ -1,82 +1,70 @@
--- ---
source: crates/ruff/src/rules/flake8_annotations/mod.rs source: crates/ruff/src/rules/flake8_annotations/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_annotations/mypy_init_return.py:5:9: ANN204 [*] Missing return type annotation for special method `__init__`
name: MissingReturnTypeSpecialMethod |
body: "Missing return type annotation for special method `__init__`" 5 | # Error
suggestion: "Add `None` return type" 6 | class Foo:
fixable: true 7 | def __init__(self):
location: | ^^^^^^^^ ANN204
row: 5 8 | ...
column: 8 |
end_location: = help: Add `None` return type
row: 5
column: 16 Suggested fix
fix: 2 2 |
edits: 3 3 | # Error
- location: 4 4 | class Foo:
row: 5 5 |- def __init__(self):
column: 22 5 |+ def __init__(self) -> None:
end_location: 6 6 | ...
row: 5 7 7 |
column: 22 8 8 |
content: " -> None"
parent: ~ ./resources/test/fixtures/flake8_annotations/mypy_init_return.py:11:9: ANN204 [*] Missing return type annotation for special method `__init__`
- kind: |
name: MissingReturnTypeSpecialMethod 11 | # Error
body: "Missing return type annotation for special method `__init__`" 12 | class Foo:
suggestion: "Add `None` return type" 13 | def __init__(self, foo):
fixable: true | ^^^^^^^^ ANN204
location: 14 | ...
row: 11 |
column: 8 = help: Add `None` return type
end_location:
row: 11 Suggested fix
column: 16 8 8 |
fix: 9 9 | # Error
edits: 10 10 | class Foo:
- location: 11 |- def __init__(self, foo):
row: 11 11 |+ def __init__(self, foo) -> None:
column: 27 12 12 | ...
end_location: 13 13 |
row: 11 14 14 |
column: 27
content: " -> None" ./resources/test/fixtures/flake8_annotations/mypy_init_return.py:40:5: ANN202 Missing return type annotation for private function `__init__`
parent: ~ |
- kind: 40 | # Error
name: MissingReturnTypePrivateFunction 41 | def __init__(self, foo: int):
body: "Missing return type annotation for private function `__init__`" | ^^^^^^^^ ANN202
suggestion: ~ 42 | ...
fixable: false |
location:
row: 40 ./resources/test/fixtures/flake8_annotations/mypy_init_return.py:47:9: ANN204 [*] Missing return type annotation for special method `__init__`
column: 4 |
end_location: 47 | # of a vararg falsely indicated that the function has a typed argument.
row: 40 48 | class Foo:
column: 12 49 | def __init__(self, *arg):
fix: | ^^^^^^^^ ANN204
edits: [] 50 | ...
parent: ~ |
- kind: = help: Add `None` return type
name: MissingReturnTypeSpecialMethod
body: "Missing return type annotation for special method `__init__`" Suggested fix
suggestion: "Add `None` return type" 44 44 | # Error used to be ok for a moment since the mere presence
fixable: true 45 45 | # of a vararg falsely indicated that the function has a typed argument.
location: 46 46 | class Foo:
row: 47 47 |- def __init__(self, *arg):
column: 8 47 |+ def __init__(self, *arg) -> None:
end_location: 48 48 | ...
row: 47
column: 16
fix:
edits:
- location:
row: 47
column: 28
end_location:
row: 47
column: 28
content: " -> None"
parent: ~

View file

@ -1,299 +1,279 @@
--- ---
source: crates/ruff/src/rules/flake8_annotations/mod.rs source: crates/ruff/src/rules/flake8_annotations/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:2:9: ANN204 [*] Missing return type annotation for special method `__str__`
name: MissingReturnTypeSpecialMethod |
body: "Missing return type annotation for special method `__str__`" 2 | class Foo:
suggestion: "Add `None` return type" 3 | def __str__(self):
fixable: true | ^^^^^^^ ANN204
location: 4 | ...
row: 2 |
column: 8 = help: Add `None` return type
end_location:
row: 2 Suggested fix
column: 15 1 1 | class Foo:
fix: 2 |- def __str__(self):
edits: 2 |+ def __str__(self) -> str:
- location: 3 3 | ...
row: 2 4 4 |
column: 21 5 5 | def __repr__(self):
end_location:
row: 2 ./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:5:9: ANN204 [*] Missing return type annotation for special method `__repr__`
column: 21 |
content: " -> str" 5 | ...
parent: ~ 6 |
- kind: 7 | def __repr__(self):
name: MissingReturnTypeSpecialMethod | ^^^^^^^^ ANN204
body: "Missing return type annotation for special method `__repr__`" 8 | ...
suggestion: "Add `None` return type" |
fixable: true = help: Add `None` return type
location:
row: 5 Suggested fix
column: 8 2 2 | def __str__(self):
end_location: 3 3 | ...
row: 5 4 4 |
column: 16 5 |- def __repr__(self):
fix: 5 |+ def __repr__(self) -> str:
edits: 6 6 | ...
- location: 7 7 |
row: 5 8 8 | def __len__(self):
column: 22
end_location: ./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:8:9: ANN204 [*] Missing return type annotation for special method `__len__`
row: 5 |
column: 22 8 | ...
content: " -> str" 9 |
parent: ~ 10 | def __len__(self):
- kind: | ^^^^^^^ ANN204
name: MissingReturnTypeSpecialMethod 11 | ...
body: "Missing return type annotation for special method `__len__`" |
suggestion: "Add `None` return type" = help: Add `None` return type
fixable: true
location: Suggested fix
row: 8 5 5 | def __repr__(self):
column: 8 6 6 | ...
end_location: 7 7 |
row: 8 8 |- def __len__(self):
column: 15 8 |+ def __len__(self) -> int:
fix: 9 9 | ...
edits: 10 10 |
- location: 11 11 | def __length_hint__(self):
row: 8
column: 21 ./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:11:9: ANN204 [*] Missing return type annotation for special method `__length_hint__`
end_location: |
row: 8 11 | ...
column: 21 12 |
content: " -> int" 13 | def __length_hint__(self):
parent: ~ | ^^^^^^^^^^^^^^^ ANN204
- kind: 14 | ...
name: MissingReturnTypeSpecialMethod |
body: "Missing return type annotation for special method `__length_hint__`" = help: Add `None` return type
suggestion: "Add `None` return type"
fixable: true Suggested fix
location: 8 8 | def __len__(self):
row: 11 9 9 | ...
column: 8 10 10 |
end_location: 11 |- def __length_hint__(self):
row: 11 11 |+ def __length_hint__(self) -> int:
column: 23 12 12 | ...
fix: 13 13 |
edits: 14 14 | def __init__(self):
- location:
row: 11 ./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:14:9: ANN204 [*] Missing return type annotation for special method `__init__`
column: 29 |
end_location: 14 | ...
row: 11 15 |
column: 29 16 | def __init__(self):
content: " -> int" | ^^^^^^^^ ANN204
parent: ~ 17 | ...
- kind: |
name: MissingReturnTypeSpecialMethod = help: Add `None` return type
body: "Missing return type annotation for special method `__init__`"
suggestion: "Add `None` return type" Suggested fix
fixable: true 11 11 | def __length_hint__(self):
location: 12 12 | ...
row: 14 13 13 |
column: 8 14 |- def __init__(self):
end_location: 14 |+ def __init__(self) -> None:
row: 14 15 15 | ...
column: 16 16 16 |
fix: 17 17 | def __del__(self):
edits:
- location: ./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:17:9: ANN204 [*] Missing return type annotation for special method `__del__`
row: 14 |
column: 22 17 | ...
end_location: 18 |
row: 14 19 | def __del__(self):
column: 22 | ^^^^^^^ ANN204
content: " -> None" 20 | ...
parent: ~ |
- kind: = help: Add `None` return type
name: MissingReturnTypeSpecialMethod
body: "Missing return type annotation for special method `__del__`" Suggested fix
suggestion: "Add `None` return type" 14 14 | def __init__(self):
fixable: true 15 15 | ...
location: 16 16 |
row: 17 17 |- def __del__(self):
column: 8 17 |+ def __del__(self) -> None:
end_location: 18 18 | ...
row: 17 19 19 |
column: 15 20 20 | def __bool__(self):
fix:
edits: ./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:20:9: ANN204 [*] Missing return type annotation for special method `__bool__`
- location: |
row: 17 20 | ...
column: 21 21 |
end_location: 22 | def __bool__(self):
row: 17 | ^^^^^^^^ ANN204
column: 21 23 | ...
content: " -> None" |
parent: ~ = help: Add `None` return type
- kind:
name: MissingReturnTypeSpecialMethod Suggested fix
body: "Missing return type annotation for special method `__bool__`" 17 17 | def __del__(self):
suggestion: "Add `None` return type" 18 18 | ...
fixable: true 19 19 |
location: 20 |- def __bool__(self):
row: 20 20 |+ def __bool__(self) -> bool:
column: 8 21 21 | ...
end_location: 22 22 |
row: 20 23 23 | def __bytes__(self):
column: 16
fix: ./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:23:9: ANN204 [*] Missing return type annotation for special method `__bytes__`
edits: |
- location: 23 | ...
row: 20 24 |
column: 22 25 | def __bytes__(self):
end_location: | ^^^^^^^^^ ANN204
row: 20 26 | ...
column: 22 |
content: " -> bool" = help: Add `None` return type
parent: ~
- kind: Suggested fix
name: MissingReturnTypeSpecialMethod 20 20 | def __bool__(self):
body: "Missing return type annotation for special method `__bytes__`" 21 21 | ...
suggestion: "Add `None` return type" 22 22 |
fixable: true 23 |- def __bytes__(self):
location: 23 |+ def __bytes__(self) -> bytes:
row: 23 24 24 | ...
column: 8 25 25 |
end_location: 26 26 | def __format__(self, format_spec):
row: 23
column: 17 ./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:26:9: ANN204 [*] Missing return type annotation for special method `__format__`
fix: |
edits: 26 | ...
- location: 27 |
row: 23 28 | def __format__(self, format_spec):
column: 23 | ^^^^^^^^^^ ANN204
end_location: 29 | ...
row: 23 |
column: 23 = help: Add `None` return type
content: " -> bytes"
parent: ~ Suggested fix
- kind: 23 23 | def __bytes__(self):
name: MissingReturnTypeSpecialMethod 24 24 | ...
body: "Missing return type annotation for special method `__format__`" 25 25 |
suggestion: "Add `None` return type" 26 |- def __format__(self, format_spec):
fixable: true 26 |+ def __format__(self, format_spec) -> str:
location: 27 27 | ...
row: 26 28 28 |
column: 8 29 29 | def __contains__(self, item):
end_location:
row: 26 ./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:29:9: ANN204 [*] Missing return type annotation for special method `__contains__`
column: 18 |
fix: 29 | ...
edits: 30 |
- location: 31 | def __contains__(self, item):
row: 26 | ^^^^^^^^^^^^ ANN204
column: 37 32 | ...
end_location: |
row: 26 = help: Add `None` return type
column: 37
content: " -> str" Suggested fix
parent: ~ 26 26 | def __format__(self, format_spec):
- kind: 27 27 | ...
name: MissingReturnTypeSpecialMethod 28 28 |
body: "Missing return type annotation for special method `__contains__`" 29 |- def __contains__(self, item):
suggestion: "Add `None` return type" 29 |+ def __contains__(self, item) -> bool:
fixable: true 30 30 | ...
location: 31 31 |
row: 29 32 32 | def __complex__(self):
column: 8
end_location: ./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:32:9: ANN204 [*] Missing return type annotation for special method `__complex__`
row: 29 |
column: 20 32 | ...
fix: 33 |
edits: 34 | def __complex__(self):
- location: | ^^^^^^^^^^^ ANN204
row: 29 35 | ...
column: 32 |
end_location: = help: Add `None` return type
row: 29
column: 32 Suggested fix
content: " -> bool" 29 29 | def __contains__(self, item):
parent: ~ 30 30 | ...
- kind: 31 31 |
name: MissingReturnTypeSpecialMethod 32 |- def __complex__(self):
body: "Missing return type annotation for special method `__complex__`" 32 |+ def __complex__(self) -> complex:
suggestion: "Add `None` return type" 33 33 | ...
fixable: true 34 34 |
location: 35 35 | def __int__(self):
row: 32
column: 8 ./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:35:9: ANN204 [*] Missing return type annotation for special method `__int__`
end_location: |
row: 32 35 | ...
column: 19 36 |
fix: 37 | def __int__(self):
edits: | ^^^^^^^ ANN204
- location: 38 | ...
row: 32 |
column: 25 = help: Add `None` return type
end_location:
row: 32 Suggested fix
column: 25 32 32 | def __complex__(self):
content: " -> complex" 33 33 | ...
parent: ~ 34 34 |
- kind: 35 |- def __int__(self):
name: MissingReturnTypeSpecialMethod 35 |+ def __int__(self) -> int:
body: "Missing return type annotation for special method `__int__`" 36 36 | ...
suggestion: "Add `None` return type" 37 37 |
fixable: true 38 38 | def __float__(self):
location:
row: 35 ./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:38:9: ANN204 [*] Missing return type annotation for special method `__float__`
column: 8 |
end_location: 38 | ...
row: 35 39 |
column: 15 40 | def __float__(self):
fix: | ^^^^^^^^^ ANN204
edits: 41 | ...
- location: |
row: 35 = help: Add `None` return type
column: 21
end_location: Suggested fix
row: 35 35 35 | def __int__(self):
column: 21 36 36 | ...
content: " -> int" 37 37 |
parent: ~ 38 |- def __float__(self):
- kind: 38 |+ def __float__(self) -> float:
name: MissingReturnTypeSpecialMethod 39 39 | ...
body: "Missing return type annotation for special method `__float__`" 40 40 |
suggestion: "Add `None` return type" 41 41 | def __index__(self):
fixable: true
location: ./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:41:9: ANN204 [*] Missing return type annotation for special method `__index__`
row: 38 |
column: 8 41 | ...
end_location: 42 |
row: 38 43 | def __index__(self):
column: 17 | ^^^^^^^^^ ANN204
fix: 44 | ...
edits: |
- location: = help: Add `None` return type
row: 38
column: 23 Suggested fix
end_location: 38 38 | def __float__(self):
row: 38 39 39 | ...
column: 23 40 40 |
content: " -> float" 41 |- def __index__(self):
parent: ~ 41 |+ def __index__(self) -> int:
- kind: 42 42 | ...
name: MissingReturnTypeSpecialMethod
body: "Missing return type annotation for special method `__index__`"
suggestion: "Add `None` return type"
fixable: true
location:
row: 41
column: 8
end_location:
row: 41
column: 17
fix:
edits:
- location:
row: 41
column: 23
end_location:
row: 41
column: 23
content: " -> int"
parent: ~

View file

@ -1,6 +1,4 @@
--- ---
source: src/rules/flake8_annotations/mod.rs source: crates/ruff/src/rules/flake8_annotations/mod.rs
expression: diagnostics
--- ---
[]

View file

@ -1,47 +1,29 @@
--- ---
source: crates/ruff/src/rules/flake8_annotations/mod.rs source: crates/ruff/src/rules/flake8_annotations/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_annotations/suppress_none_returning.py:45:5: ANN201 Missing return type annotation for public function `foo`
name: MissingReturnTypeUndocumentedPublicFunction |
body: "Missing return type annotation for public function `foo`" 45 | # Error
suggestion: ~ 46 | def foo():
fixable: false | ^^^ ANN201
location: 47 | return True
row: 45 |
column: 4
end_location: ./resources/test/fixtures/flake8_annotations/suppress_none_returning.py:50:5: ANN201 Missing return type annotation for public function `foo`
row: 45 |
column: 7 50 | # Error
fix: 51 | def foo():
edits: [] | ^^^ ANN201
parent: ~ 52 | a = 2 + 2
- kind: 53 | if a == 4:
name: MissingReturnTypeUndocumentedPublicFunction |
body: "Missing return type annotation for public function `foo`"
suggestion: ~ ./resources/test/fixtures/flake8_annotations/suppress_none_returning.py:59:9: ANN001 Missing type annotation for function argument `a`
fixable: false |
location: 59 | # Error (on the argument, but not the return type)
row: 50 60 | def foo(a):
column: 4 | ^ ANN001
end_location: 61 | a = 2 + 2
row: 50 |
column: 7
fix:
edits: []
parent: ~
- kind:
name: MissingTypeFunctionArgument
body: "Missing type annotation for function argument `a`"
suggestion: ~
fixable: false
location:
row: 59
column: 8
end_location:
row: 59
column: 9
fix:
edits: []
parent: ~

View file

@ -7,8 +7,9 @@ pub mod settings;
mod tests { mod tests {
use std::path::Path; use std::path::Path;
use crate::assert_messages;
use anyhow::Result; use anyhow::Result;
use insta::assert_yaml_snapshot;
use test_case::test_case; use test_case::test_case;
use crate::registry::Rule; use crate::registry::Rule;
@ -42,7 +43,7 @@ mod tests {
Path::new("flake8_bandit").join(path).as_path(), Path::new("flake8_bandit").join(path).as_path(),
&Settings::for_rule(rule_code), &Settings::for_rule(rule_code),
)?; )?;
assert_yaml_snapshot!(snapshot, diagnostics); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())
} }
@ -63,7 +64,7 @@ mod tests {
..Settings::for_rule(Rule::HardcodedTempFile) ..Settings::for_rule(Rule::HardcodedTempFile)
}, },
)?; )?;
assert_yaml_snapshot!("S108_extend", diagnostics); assert_messages!("S108_extend", diagnostics);
Ok(()) Ok(())
} }
@ -79,7 +80,7 @@ mod tests {
..Settings::for_rule(Rule::TryExceptPass) ..Settings::for_rule(Rule::TryExceptPass)
}, },
)?; )?;
assert_yaml_snapshot!("S110_typed", diagnostics); assert_messages!("S110_typed", diagnostics);
Ok(()) Ok(())
} }
} }

View file

@ -1,47 +1,29 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S101.py:2:1: S101 Use of `assert` detected
name: Assert |
body: "Use of `assert` detected" 2 | # Error
suggestion: ~ 3 | assert True
fixable: false | ^^^^^^ S101
location: 4 |
row: 2 5 | def fn():
column: 0 |
end_location:
row: 2 ./resources/test/fixtures/flake8_bandit/S101.py:8:5: S101 Use of `assert` detected
column: 6 |
fix: 8 | # Error
edits: [] 9 | assert x == 1
parent: ~ | ^^^^^^ S101
- kind: 10 |
name: Assert 11 | # Error
body: "Use of `assert` detected" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bandit/S101.py:11:5: S101 Use of `assert` detected
location: |
row: 8 11 | # Error
column: 4 12 | assert x == 2
end_location: | ^^^^^^ S101
row: 8 |
column: 10
fix:
edits: []
parent: ~
- kind:
name: Assert
body: "Use of `assert` detected"
suggestion: ~
fixable: false
location:
row: 11
column: 4
end_location:
row: 11
column: 10
fix:
edits: []
parent: ~

View file

@ -1,33 +1,22 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S102.py:3:5: S102 Use of `exec` detected
name: ExecBuiltin |
body: "Use of `exec` detected" 3 | def fn():
suggestion: ~ 4 | # Error
fixable: false 5 | exec('x = 2')
location: | ^^^^^^^^^^^^^ S102
row: 3 6 |
column: 4 7 | exec('y = 3')
end_location: |
row: 3
column: 17 ./resources/test/fixtures/flake8_bandit/S102.py:5:1: S102 Use of `exec` detected
fix: |
edits: [] 5 | exec('x = 2')
parent: ~ 6 |
- kind: 7 | exec('y = 3')
name: ExecBuiltin | ^^^^^^^^^^^^^ S102
body: "Use of `exec` detected" |
suggestion: ~
fixable: false
location:
row: 5
column: 0
end_location:
row: 5
column: 13
fix:
edits: []
parent: ~

View file

@ -1,187 +1,131 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S103.py:6:25: S103 `os.chmod` setting a permissive mask `0o227` on file or directory
name: BadFilePermissions |
body: "`os.chmod` setting a permissive mask `0o227` on file or directory" 6 | keyfile = "foo"
suggestion: ~ 7 |
fixable: false 8 | os.chmod("/etc/passwd", 0o227) # Error
location: | ^^^^^ S103
row: 6 9 | os.chmod("/etc/passwd", 0o7) # Error
column: 24 10 | os.chmod("/etc/passwd", 0o664) # OK
end_location: |
row: 6
column: 29 ./resources/test/fixtures/flake8_bandit/S103.py:7:25: S103 `os.chmod` setting a permissive mask `0o7` on file or directory
fix: |
edits: [] 7 | os.chmod("/etc/passwd", 0o227) # Error
parent: ~ 8 | os.chmod("/etc/passwd", 0o7) # Error
- kind: | ^^^ S103
name: BadFilePermissions 9 | os.chmod("/etc/passwd", 0o664) # OK
body: "`os.chmod` setting a permissive mask `0o7` on file or directory" 10 | os.chmod("/etc/passwd", 0o777) # Error
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bandit/S103.py:9:25: S103 `os.chmod` setting a permissive mask `0o777` on file or directory
row: 7 |
column: 24 9 | os.chmod("/etc/passwd", 0o7) # Error
end_location: 10 | os.chmod("/etc/passwd", 0o664) # OK
row: 7 11 | os.chmod("/etc/passwd", 0o777) # Error
column: 27 | ^^^^^ S103
fix: 12 | os.chmod("/etc/passwd", 0o770) # Error
edits: [] 13 | os.chmod("/etc/passwd", 0o776) # Error
parent: ~ |
- kind:
name: BadFilePermissions ./resources/test/fixtures/flake8_bandit/S103.py:10:25: S103 `os.chmod` setting a permissive mask `0o770` on file or directory
body: "`os.chmod` setting a permissive mask `0o777` on file or directory" |
suggestion: ~ 10 | os.chmod("/etc/passwd", 0o664) # OK
fixable: false 11 | os.chmod("/etc/passwd", 0o777) # Error
location: 12 | os.chmod("/etc/passwd", 0o770) # Error
row: 9 | ^^^^^ S103
column: 24 13 | os.chmod("/etc/passwd", 0o776) # Error
end_location: 14 | os.chmod("/etc/passwd", 0o760) # OK
row: 9 |
column: 29
fix: ./resources/test/fixtures/flake8_bandit/S103.py:11:25: S103 `os.chmod` setting a permissive mask `0o776` on file or directory
edits: [] |
parent: ~ 11 | os.chmod("/etc/passwd", 0o777) # Error
- kind: 12 | os.chmod("/etc/passwd", 0o770) # Error
name: BadFilePermissions 13 | os.chmod("/etc/passwd", 0o776) # Error
body: "`os.chmod` setting a permissive mask `0o770` on file or directory" | ^^^^^ S103
suggestion: ~ 14 | os.chmod("/etc/passwd", 0o760) # OK
fixable: false 15 | os.chmod("~/.bashrc", 511) # Error
location: |
row: 10
column: 24 ./resources/test/fixtures/flake8_bandit/S103.py:13:23: S103 `os.chmod` setting a permissive mask `0o777` on file or directory
end_location: |
row: 10 13 | os.chmod("/etc/passwd", 0o776) # Error
column: 29 14 | os.chmod("/etc/passwd", 0o760) # OK
fix: 15 | os.chmod("~/.bashrc", 511) # Error
edits: [] | ^^^ S103
parent: ~ 16 | os.chmod("/etc/hosts", 0o777) # Error
- kind: 17 | os.chmod("/tmp/oh_hai", 0x1FF) # Error
name: BadFilePermissions |
body: "`os.chmod` setting a permissive mask `0o776` on file or directory"
suggestion: ~ ./resources/test/fixtures/flake8_bandit/S103.py:14:24: S103 `os.chmod` setting a permissive mask `0o777` on file or directory
fixable: false |
location: 14 | os.chmod("/etc/passwd", 0o760) # OK
row: 11 15 | os.chmod("~/.bashrc", 511) # Error
column: 24 16 | os.chmod("/etc/hosts", 0o777) # Error
end_location: | ^^^^^ S103
row: 11 17 | os.chmod("/tmp/oh_hai", 0x1FF) # Error
column: 29 18 | os.chmod("/etc/passwd", stat.S_IRWXU) # OK
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bandit/S103.py:15:25: S103 `os.chmod` setting a permissive mask `0o777` on file or directory
- kind: |
name: BadFilePermissions 15 | os.chmod("~/.bashrc", 511) # Error
body: "`os.chmod` setting a permissive mask `0o777` on file or directory" 16 | os.chmod("/etc/hosts", 0o777) # Error
suggestion: ~ 17 | os.chmod("/tmp/oh_hai", 0x1FF) # Error
fixable: false | ^^^^^ S103
location: 18 | os.chmod("/etc/passwd", stat.S_IRWXU) # OK
row: 13 19 | os.chmod(keyfile, 0o777) # Error
column: 22 |
end_location:
row: 13 ./resources/test/fixtures/flake8_bandit/S103.py:17:19: S103 `os.chmod` setting a permissive mask `0o777` on file or directory
column: 25 |
fix: 17 | os.chmod("/tmp/oh_hai", 0x1FF) # Error
edits: [] 18 | os.chmod("/etc/passwd", stat.S_IRWXU) # OK
parent: ~ 19 | os.chmod(keyfile, 0o777) # Error
- kind: | ^^^^^ S103
name: BadFilePermissions 20 | os.chmod(keyfile, 0o7 | 0o70 | 0o700) # Error
body: "`os.chmod` setting a permissive mask `0o777` on file or directory" 21 | os.chmod(keyfile, stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU) # Error
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bandit/S103.py:18:19: S103 `os.chmod` setting a permissive mask `0o777` on file or directory
row: 14 |
column: 23 18 | os.chmod("/etc/passwd", stat.S_IRWXU) # OK
end_location: 19 | os.chmod(keyfile, 0o777) # Error
row: 14 20 | os.chmod(keyfile, 0o7 | 0o70 | 0o700) # Error
column: 28 | ^^^^^^^^^^^^^^^^^^ S103
fix: 21 | os.chmod(keyfile, stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU) # Error
edits: [] 22 | os.chmod("~/hidden_exec", stat.S_IXGRP) # Error
parent: ~ |
- kind:
name: BadFilePermissions ./resources/test/fixtures/flake8_bandit/S103.py:19:19: S103 `os.chmod` setting a permissive mask `0o777` on file or directory
body: "`os.chmod` setting a permissive mask `0o777` on file or directory" |
suggestion: ~ 19 | os.chmod(keyfile, 0o777) # Error
fixable: false 20 | os.chmod(keyfile, 0o7 | 0o70 | 0o700) # Error
location: 21 | os.chmod(keyfile, stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU) # Error
row: 15 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S103
column: 24 22 | os.chmod("~/hidden_exec", stat.S_IXGRP) # Error
end_location: 23 | os.chmod("~/hidden_exec", stat.S_IXOTH) # OK
row: 15 |
column: 29
fix: ./resources/test/fixtures/flake8_bandit/S103.py:20:27: S103 `os.chmod` setting a permissive mask `0o10` on file or directory
edits: [] |
parent: ~ 20 | os.chmod(keyfile, 0o7 | 0o70 | 0o700) # Error
- kind: 21 | os.chmod(keyfile, stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU) # Error
name: BadFilePermissions 22 | os.chmod("~/hidden_exec", stat.S_IXGRP) # Error
body: "`os.chmod` setting a permissive mask `0o777` on file or directory" | ^^^^^^^^^^^^ S103
suggestion: ~ 23 | os.chmod("~/hidden_exec", stat.S_IXOTH) # OK
fixable: false 24 | os.chmod("/etc/passwd", stat.S_IWOTH) # Error
location: |
row: 17
column: 18 ./resources/test/fixtures/flake8_bandit/S103.py:22:25: S103 `os.chmod` setting a permissive mask `0o2` on file or directory
end_location: |
row: 17 22 | os.chmod("~/hidden_exec", stat.S_IXGRP) # Error
column: 23 23 | os.chmod("~/hidden_exec", stat.S_IXOTH) # OK
fix: 24 | os.chmod("/etc/passwd", stat.S_IWOTH) # Error
edits: [] | ^^^^^^^^^^^^ S103
parent: ~ |
- kind:
name: BadFilePermissions
body: "`os.chmod` setting a permissive mask `0o777` on file or directory"
suggestion: ~
fixable: false
location:
row: 18
column: 18
end_location:
row: 18
column: 36
fix:
edits: []
parent: ~
- kind:
name: BadFilePermissions
body: "`os.chmod` setting a permissive mask `0o777` on file or directory"
suggestion: ~
fixable: false
location:
row: 19
column: 18
end_location:
row: 19
column: 60
fix:
edits: []
parent: ~
- kind:
name: BadFilePermissions
body: "`os.chmod` setting a permissive mask `0o10` on file or directory"
suggestion: ~
fixable: false
location:
row: 20
column: 26
end_location:
row: 20
column: 38
fix:
edits: []
parent: ~
- kind:
name: BadFilePermissions
body: "`os.chmod` setting a permissive mask `0o2` on file or directory"
suggestion: ~
fixable: false
location:
row: 22
column: 24
end_location:
row: 22
column: 36
fix:
edits: []
parent: ~

View file

@ -1,61 +1,35 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S104.py:9:1: S104 Possible binding to all interfaces
name: HardcodedBindAllInterfaces |
body: Possible binding to all interfaces 9 | # Error
suggestion: ~ 10 | "0.0.0.0"
fixable: false | ^^^^^^^^^ S104
location: 11 | '0.0.0.0'
row: 9 |
column: 0
end_location: ./resources/test/fixtures/flake8_bandit/S104.py:10:1: S104 Possible binding to all interfaces
row: 9 |
column: 9 10 | # Error
fix: 11 | "0.0.0.0"
edits: [] 12 | '0.0.0.0'
parent: ~ | ^^^^^^^^^ S104
- kind: |
name: HardcodedBindAllInterfaces
body: Possible binding to all interfaces ./resources/test/fixtures/flake8_bandit/S104.py:14:6: S104 Possible binding to all interfaces
suggestion: ~ |
fixable: false 14 | # Error
location: 15 | func("0.0.0.0")
row: 10 | ^^^^^^^^^ S104
column: 0 |
end_location:
row: 10 ./resources/test/fixtures/flake8_bandit/S104.py:18:9: S104 Possible binding to all interfaces
column: 9 |
fix: 18 | def my_func():
edits: [] 19 | x = "0.0.0.0"
parent: ~ | ^^^^^^^^^ S104
- kind: 20 | print(x)
name: HardcodedBindAllInterfaces |
body: Possible binding to all interfaces
suggestion: ~
fixable: false
location:
row: 14
column: 5
end_location:
row: 14
column: 14
fix:
edits: []
parent: ~
- kind:
name: HardcodedBindAllInterfaces
body: Possible binding to all interfaces
suggestion: ~
fixable: false
location:
row: 18
column: 8
end_location:
row: 18
column: 17
fix:
edits: []
parent: ~

View file

@ -1,551 +1,377 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S105.py:13:12: S105 Possible hardcoded password: "s3cr3t"
name: HardcodedPasswordString |
body: "Possible hardcoded password: \"s3cr3t\"" 13 | # Errors
suggestion: ~ 14 | password = "s3cr3t"
fixable: false | ^^^^^^^^ S105
location: 15 | _pass = "s3cr3t"
row: 13 16 | passwd = "s3cr3t"
column: 11 |
end_location:
row: 13 ./resources/test/fixtures/flake8_bandit/S105.py:14:9: S105 Possible hardcoded password: "s3cr3t"
column: 19 |
fix: 14 | # Errors
edits: [] 15 | password = "s3cr3t"
parent: ~ 16 | _pass = "s3cr3t"
- kind: | ^^^^^^^^ S105
name: HardcodedPasswordString 17 | passwd = "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" 18 | pwd = "s3cr3t"
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bandit/S105.py:15:10: S105 Possible hardcoded password: "s3cr3t"
row: 14 |
column: 8 15 | password = "s3cr3t"
end_location: 16 | _pass = "s3cr3t"
row: 14 17 | passwd = "s3cr3t"
column: 16 | ^^^^^^^^ S105
fix: 18 | pwd = "s3cr3t"
edits: [] 19 | secret = "s3cr3t"
parent: ~ |
- kind:
name: HardcodedPasswordString ./resources/test/fixtures/flake8_bandit/S105.py:16:7: S105 Possible hardcoded password: "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" |
suggestion: ~ 16 | _pass = "s3cr3t"
fixable: false 17 | passwd = "s3cr3t"
location: 18 | pwd = "s3cr3t"
row: 15 | ^^^^^^^^ S105
column: 9 19 | secret = "s3cr3t"
end_location: 20 | token = "s3cr3t"
row: 15 |
column: 17
fix: ./resources/test/fixtures/flake8_bandit/S105.py:17:10: S105 Possible hardcoded password: "s3cr3t"
edits: [] |
parent: ~ 17 | passwd = "s3cr3t"
- kind: 18 | pwd = "s3cr3t"
name: HardcodedPasswordString 19 | secret = "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" | ^^^^^^^^ S105
suggestion: ~ 20 | token = "s3cr3t"
fixable: false 21 | secrete = "s3cr3t"
location: |
row: 16
column: 6 ./resources/test/fixtures/flake8_bandit/S105.py:18:9: S105 Possible hardcoded password: "s3cr3t"
end_location: |
row: 16 18 | pwd = "s3cr3t"
column: 14 19 | secret = "s3cr3t"
fix: 20 | token = "s3cr3t"
edits: [] | ^^^^^^^^ S105
parent: ~ 21 | secrete = "s3cr3t"
- kind: 22 | safe = password = "s3cr3t"
name: HardcodedPasswordString |
body: "Possible hardcoded password: \"s3cr3t\""
suggestion: ~ ./resources/test/fixtures/flake8_bandit/S105.py:19:11: S105 Possible hardcoded password: "s3cr3t"
fixable: false |
location: 19 | secret = "s3cr3t"
row: 17 20 | token = "s3cr3t"
column: 9 21 | secrete = "s3cr3t"
end_location: | ^^^^^^^^ S105
row: 17 22 | safe = password = "s3cr3t"
column: 17 23 | password = safe = "s3cr3t"
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bandit/S105.py:20:19: S105 Possible hardcoded password: "s3cr3t"
- kind: |
name: HardcodedPasswordString 20 | token = "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" 21 | secrete = "s3cr3t"
suggestion: ~ 22 | safe = password = "s3cr3t"
fixable: false | ^^^^^^^^ S105
location: 23 | password = safe = "s3cr3t"
row: 18 24 | PASSWORD = "s3cr3t"
column: 8 |
end_location:
row: 18 ./resources/test/fixtures/flake8_bandit/S105.py:21:19: S105 Possible hardcoded password: "s3cr3t"
column: 16 |
fix: 21 | secrete = "s3cr3t"
edits: [] 22 | safe = password = "s3cr3t"
parent: ~ 23 | password = safe = "s3cr3t"
- kind: | ^^^^^^^^ S105
name: HardcodedPasswordString 24 | PASSWORD = "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" 25 | PassWord = "s3cr3t"
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bandit/S105.py:22:12: S105 Possible hardcoded password: "s3cr3t"
row: 19 |
column: 10 22 | safe = password = "s3cr3t"
end_location: 23 | password = safe = "s3cr3t"
row: 19 24 | PASSWORD = "s3cr3t"
column: 18 | ^^^^^^^^ S105
fix: 25 | PassWord = "s3cr3t"
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bandit/S105.py:23:12: S105 Possible hardcoded password: "s3cr3t"
name: HardcodedPasswordString |
body: "Possible hardcoded password: \"s3cr3t\"" 23 | password = safe = "s3cr3t"
suggestion: ~ 24 | PASSWORD = "s3cr3t"
fixable: false 25 | PassWord = "s3cr3t"
location: | ^^^^^^^^ S105
row: 20 26 |
column: 18 27 | d["password"] = "s3cr3t"
end_location: |
row: 20
column: 26 ./resources/test/fixtures/flake8_bandit/S105.py:25:17: S105 Possible hardcoded password: "s3cr3t"
fix: |
edits: [] 25 | PassWord = "s3cr3t"
parent: ~ 26 |
- kind: 27 | d["password"] = "s3cr3t"
name: HardcodedPasswordString | ^^^^^^^^ S105
body: "Possible hardcoded password: \"s3cr3t\"" 28 | d["pass"] = "s3cr3t"
suggestion: ~ 29 | d["passwd"] = "s3cr3t"
fixable: false |
location:
row: 21 ./resources/test/fixtures/flake8_bandit/S105.py:26:13: S105 Possible hardcoded password: "s3cr3t"
column: 18 |
end_location: 26 | d["password"] = "s3cr3t"
row: 21 27 | d["pass"] = "s3cr3t"
column: 26 | ^^^^^^^^ S105
fix: 28 | d["passwd"] = "s3cr3t"
edits: [] 29 | d["pwd"] = "s3cr3t"
parent: ~ |
- kind:
name: HardcodedPasswordString ./resources/test/fixtures/flake8_bandit/S105.py:27:15: S105 Possible hardcoded password: "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" |
suggestion: ~ 27 | d["password"] = "s3cr3t"
fixable: false 28 | d["pass"] = "s3cr3t"
location: 29 | d["passwd"] = "s3cr3t"
row: 22 | ^^^^^^^^ S105
column: 11 30 | d["pwd"] = "s3cr3t"
end_location: 31 | d["secret"] = "s3cr3t"
row: 22 |
column: 19
fix: ./resources/test/fixtures/flake8_bandit/S105.py:28:12: S105 Possible hardcoded password: "s3cr3t"
edits: [] |
parent: ~ 28 | d["pass"] = "s3cr3t"
- kind: 29 | d["passwd"] = "s3cr3t"
name: HardcodedPasswordString 30 | d["pwd"] = "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" | ^^^^^^^^ S105
suggestion: ~ 31 | d["secret"] = "s3cr3t"
fixable: false 32 | d["token"] = "s3cr3t"
location: |
row: 23
column: 11 ./resources/test/fixtures/flake8_bandit/S105.py:29:15: S105 Possible hardcoded password: "s3cr3t"
end_location: |
row: 23 29 | d["passwd"] = "s3cr3t"
column: 19 30 | d["pwd"] = "s3cr3t"
fix: 31 | d["secret"] = "s3cr3t"
edits: [] | ^^^^^^^^ S105
parent: ~ 32 | d["token"] = "s3cr3t"
- kind: 33 | d["secrete"] = "s3cr3t"
name: HardcodedPasswordString |
body: "Possible hardcoded password: \"s3cr3t\""
suggestion: ~ ./resources/test/fixtures/flake8_bandit/S105.py:30:14: S105 Possible hardcoded password: "s3cr3t"
fixable: false |
location: 30 | d["pwd"] = "s3cr3t"
row: 25 31 | d["secret"] = "s3cr3t"
column: 16 32 | d["token"] = "s3cr3t"
end_location: | ^^^^^^^^ S105
row: 25 33 | d["secrete"] = "s3cr3t"
column: 24 34 | safe = d["password"] = "s3cr3t"
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bandit/S105.py:31:16: S105 Possible hardcoded password: "s3cr3t"
- kind: |
name: HardcodedPasswordString 31 | d["secret"] = "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" 32 | d["token"] = "s3cr3t"
suggestion: ~ 33 | d["secrete"] = "s3cr3t"
fixable: false | ^^^^^^^^ S105
location: 34 | safe = d["password"] = "s3cr3t"
row: 26 35 | d["password"] = safe = "s3cr3t"
column: 12 |
end_location:
row: 26 ./resources/test/fixtures/flake8_bandit/S105.py:32:24: S105 Possible hardcoded password: "s3cr3t"
column: 20 |
fix: 32 | d["token"] = "s3cr3t"
edits: [] 33 | d["secrete"] = "s3cr3t"
parent: ~ 34 | safe = d["password"] = "s3cr3t"
- kind: | ^^^^^^^^ S105
name: HardcodedPasswordString 35 | d["password"] = safe = "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bandit/S105.py:33:24: S105 Possible hardcoded password: "s3cr3t"
location: |
row: 27 33 | d["secrete"] = "s3cr3t"
column: 14 34 | safe = d["password"] = "s3cr3t"
end_location: 35 | d["password"] = safe = "s3cr3t"
row: 27 | ^^^^^^^^ S105
column: 22 |
fix:
edits: [] ./resources/test/fixtures/flake8_bandit/S105.py:37:16: S105 Possible hardcoded password: "s3cr3t"
parent: ~ |
- kind: 37 | class MyClass:
name: HardcodedPasswordString 38 | password = "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" | ^^^^^^^^ S105
suggestion: ~ 39 | safe = password
fixable: false |
location:
row: 28 ./resources/test/fixtures/flake8_bandit/S105.py:41:20: S105 Possible hardcoded password: "s3cr3t"
column: 11 |
end_location: 41 | MyClass.password = "s3cr3t"
row: 28 | ^^^^^^^^ S105
column: 19 42 | MyClass._pass = "s3cr3t"
fix: 43 | MyClass.passwd = "s3cr3t"
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bandit/S105.py:42:17: S105 Possible hardcoded password: "s3cr3t"
name: HardcodedPasswordString |
body: "Possible hardcoded password: \"s3cr3t\"" 42 | MyClass.password = "s3cr3t"
suggestion: ~ 43 | MyClass._pass = "s3cr3t"
fixable: false | ^^^^^^^^ S105
location: 44 | MyClass.passwd = "s3cr3t"
row: 29 45 | MyClass.pwd = "s3cr3t"
column: 14 |
end_location:
row: 29 ./resources/test/fixtures/flake8_bandit/S105.py:43:18: S105 Possible hardcoded password: "s3cr3t"
column: 22 |
fix: 43 | MyClass.password = "s3cr3t"
edits: [] 44 | MyClass._pass = "s3cr3t"
parent: ~ 45 | MyClass.passwd = "s3cr3t"
- kind: | ^^^^^^^^ S105
name: HardcodedPasswordString 46 | MyClass.pwd = "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" 47 | MyClass.secret = "s3cr3t"
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bandit/S105.py:44:15: S105 Possible hardcoded password: "s3cr3t"
row: 30 |
column: 13 44 | MyClass._pass = "s3cr3t"
end_location: 45 | MyClass.passwd = "s3cr3t"
row: 30 46 | MyClass.pwd = "s3cr3t"
column: 21 | ^^^^^^^^ S105
fix: 47 | MyClass.secret = "s3cr3t"
edits: [] 48 | MyClass.token = "s3cr3t"
parent: ~ |
- kind:
name: HardcodedPasswordString ./resources/test/fixtures/flake8_bandit/S105.py:45:18: S105 Possible hardcoded password: "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" |
suggestion: ~ 45 | MyClass.passwd = "s3cr3t"
fixable: false 46 | MyClass.pwd = "s3cr3t"
location: 47 | MyClass.secret = "s3cr3t"
row: 31 | ^^^^^^^^ S105
column: 15 48 | MyClass.token = "s3cr3t"
end_location: 49 | MyClass.secrete = "s3cr3t"
row: 31 |
column: 23
fix: ./resources/test/fixtures/flake8_bandit/S105.py:46:17: S105 Possible hardcoded password: "s3cr3t"
edits: [] |
parent: ~ 46 | MyClass.pwd = "s3cr3t"
- kind: 47 | MyClass.secret = "s3cr3t"
name: HardcodedPasswordString 48 | MyClass.token = "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" | ^^^^^^^^ S105
suggestion: ~ 49 | MyClass.secrete = "s3cr3t"
fixable: false |
location:
row: 32 ./resources/test/fixtures/flake8_bandit/S105.py:47:19: S105 Possible hardcoded password: "s3cr3t"
column: 23 |
end_location: 47 | MyClass.secret = "s3cr3t"
row: 32 48 | MyClass.token = "s3cr3t"
column: 31 49 | MyClass.secrete = "s3cr3t"
fix: | ^^^^^^^^ S105
edits: [] 50 |
parent: ~ 51 | password == "s3cr3t"
- kind: |
name: HardcodedPasswordString
body: "Possible hardcoded password: \"s3cr3t\"" ./resources/test/fixtures/flake8_bandit/S105.py:49:13: S105 Possible hardcoded password: "s3cr3t"
suggestion: ~ |
fixable: false 49 | MyClass.secrete = "s3cr3t"
location: 50 |
row: 33 51 | password == "s3cr3t"
column: 23 | ^^^^^^^^ S105
end_location: 52 | _pass == "s3cr3t"
row: 33 53 | passwd == "s3cr3t"
column: 31 |
fix:
edits: [] ./resources/test/fixtures/flake8_bandit/S105.py:50:10: S105 Possible hardcoded password: "s3cr3t"
parent: ~ |
- kind: 50 | password == "s3cr3t"
name: HardcodedPasswordString 51 | _pass == "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" | ^^^^^^^^ S105
suggestion: ~ 52 | passwd == "s3cr3t"
fixable: false 53 | pwd == "s3cr3t"
location: |
row: 37
column: 15 ./resources/test/fixtures/flake8_bandit/S105.py:51:11: S105 Possible hardcoded password: "s3cr3t"
end_location: |
row: 37 51 | password == "s3cr3t"
column: 23 52 | _pass == "s3cr3t"
fix: 53 | passwd == "s3cr3t"
edits: [] | ^^^^^^^^ S105
parent: ~ 54 | pwd == "s3cr3t"
- kind: 55 | secret == "s3cr3t"
name: HardcodedPasswordString |
body: "Possible hardcoded password: \"s3cr3t\""
suggestion: ~ ./resources/test/fixtures/flake8_bandit/S105.py:52:8: S105 Possible hardcoded password: "s3cr3t"
fixable: false |
location: 52 | _pass == "s3cr3t"
row: 41 53 | passwd == "s3cr3t"
column: 19 54 | pwd == "s3cr3t"
end_location: | ^^^^^^^^ S105
row: 41 55 | secret == "s3cr3t"
column: 27 56 | token == "s3cr3t"
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bandit/S105.py:53:11: S105 Possible hardcoded password: "s3cr3t"
- kind: |
name: HardcodedPasswordString 53 | passwd == "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" 54 | pwd == "s3cr3t"
suggestion: ~ 55 | secret == "s3cr3t"
fixable: false | ^^^^^^^^ S105
location: 56 | token == "s3cr3t"
row: 42 57 | secrete == "s3cr3t"
column: 16 |
end_location:
row: 42 ./resources/test/fixtures/flake8_bandit/S105.py:54:10: S105 Possible hardcoded password: "s3cr3t"
column: 24 |
fix: 54 | pwd == "s3cr3t"
edits: [] 55 | secret == "s3cr3t"
parent: ~ 56 | token == "s3cr3t"
- kind: | ^^^^^^^^ S105
name: HardcodedPasswordString 57 | secrete == "s3cr3t"
body: "Possible hardcoded password: \"s3cr3t\"" 58 | password == safe == "s3cr3t"
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bandit/S105.py:55:12: S105 Possible hardcoded password: "s3cr3t"
row: 43 |
column: 17 55 | secret == "s3cr3t"
end_location: 56 | token == "s3cr3t"
row: 43 57 | secrete == "s3cr3t"
column: 25 | ^^^^^^^^ S105
fix: 58 | password == safe == "s3cr3t"
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bandit/S105.py:56:21: S105 Possible hardcoded password: "s3cr3t"
name: HardcodedPasswordString |
body: "Possible hardcoded password: \"s3cr3t\"" 56 | token == "s3cr3t"
suggestion: ~ 57 | secrete == "s3cr3t"
fixable: false 58 | password == safe == "s3cr3t"
location: | ^^^^^^^^ S105
row: 44 59 |
column: 14 60 | if token == "1\n2":
end_location: |
row: 44
column: 22 ./resources/test/fixtures/flake8_bandit/S105.py:58:13: S105 Possible hardcoded password: "1\n2"
fix: |
edits: [] 58 | password == safe == "s3cr3t"
parent: ~ 59 |
- kind: 60 | if token == "1\n2":
name: HardcodedPasswordString | ^^^^^^ S105
body: "Possible hardcoded password: \"s3cr3t\"" 61 | pass
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bandit/S105.py:61:13: S105 Possible hardcoded password: "3\t4"
row: 45 |
column: 17 61 | pass
end_location: 62 |
row: 45 63 | if token == "3\t4":
column: 25 | ^^^^^^ S105
fix: 64 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bandit/S105.py:64:13: S105 Possible hardcoded password: "5\r6"
name: HardcodedPasswordString |
body: "Possible hardcoded password: \"s3cr3t\"" 64 | pass
suggestion: ~ 65 |
fixable: false 66 | if token == "5\r6":
location: | ^^^^^^ S105
row: 46 67 | pass
column: 16 |
end_location:
row: 46
column: 24
fix:
edits: []
parent: ~
- kind:
name: HardcodedPasswordString
body: "Possible hardcoded password: \"s3cr3t\""
suggestion: ~
fixable: false
location:
row: 47
column: 18
end_location:
row: 47
column: 26
fix:
edits: []
parent: ~
- kind:
name: HardcodedPasswordString
body: "Possible hardcoded password: \"s3cr3t\""
suggestion: ~
fixable: false
location:
row: 49
column: 12
end_location:
row: 49
column: 20
fix:
edits: []
parent: ~
- kind:
name: HardcodedPasswordString
body: "Possible hardcoded password: \"s3cr3t\""
suggestion: ~
fixable: false
location:
row: 50
column: 9
end_location:
row: 50
column: 17
fix:
edits: []
parent: ~
- kind:
name: HardcodedPasswordString
body: "Possible hardcoded password: \"s3cr3t\""
suggestion: ~
fixable: false
location:
row: 51
column: 10
end_location:
row: 51
column: 18
fix:
edits: []
parent: ~
- kind:
name: HardcodedPasswordString
body: "Possible hardcoded password: \"s3cr3t\""
suggestion: ~
fixable: false
location:
row: 52
column: 7
end_location:
row: 52
column: 15
fix:
edits: []
parent: ~
- kind:
name: HardcodedPasswordString
body: "Possible hardcoded password: \"s3cr3t\""
suggestion: ~
fixable: false
location:
row: 53
column: 10
end_location:
row: 53
column: 18
fix:
edits: []
parent: ~
- kind:
name: HardcodedPasswordString
body: "Possible hardcoded password: \"s3cr3t\""
suggestion: ~
fixable: false
location:
row: 54
column: 9
end_location:
row: 54
column: 17
fix:
edits: []
parent: ~
- kind:
name: HardcodedPasswordString
body: "Possible hardcoded password: \"s3cr3t\""
suggestion: ~
fixable: false
location:
row: 55
column: 11
end_location:
row: 55
column: 19
fix:
edits: []
parent: ~
- kind:
name: HardcodedPasswordString
body: "Possible hardcoded password: \"s3cr3t\""
suggestion: ~
fixable: false
location:
row: 56
column: 20
end_location:
row: 56
column: 28
fix:
edits: []
parent: ~
- kind:
name: HardcodedPasswordString
body: "Possible hardcoded password: \"1\\n2\""
suggestion: ~
fixable: false
location:
row: 58
column: 12
end_location:
row: 58
column: 18
fix:
edits: []
parent: ~
- kind:
name: HardcodedPasswordString
body: "Possible hardcoded password: \"3\\t4\""
suggestion: ~
fixable: false
location:
row: 61
column: 12
end_location:
row: 61
column: 18
fix:
edits: []
parent: ~
- kind:
name: HardcodedPasswordString
body: "Possible hardcoded password: \"5\\r6\""
suggestion: ~
fixable: false
location:
row: 64
column: 12
end_location:
row: 64
column: 18
fix:
edits: []
parent: ~

View file

@ -1,19 +1,11 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S106.py:14:9: S106 Possible hardcoded password: "s3cr3t"
name: HardcodedPasswordFuncArg |
body: "Possible hardcoded password: \"s3cr3t\"" 14 | # Error
suggestion: ~ 15 | func(1, password="s3cr3t")
fixable: false | ^^^^^^^^^^^^^^^^^ S106
location: |
row: 14
column: 8
end_location:
row: 14
column: 25
fix:
edits: []
parent: ~

View file

@ -1,75 +1,39 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S107.py:5:29: S107 Possible hardcoded password: "default"
name: HardcodedPasswordDefault |
body: "Possible hardcoded password: \"default\"" 5 | def default(first, password="default"):
suggestion: ~ | ^^^^^^^^^ S107
fixable: false 6 | pass
location: |
row: 5
column: 28 ./resources/test/fixtures/flake8_bandit/S107.py:13:45: S107 Possible hardcoded password: "posonly"
end_location: |
row: 5 13 | def default_posonly(first, /, pos, password="posonly"):
column: 37 | ^^^^^^^^^ S107
fix: 14 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bandit/S107.py:21:39: S107 Possible hardcoded password: "kwonly"
name: HardcodedPasswordDefault |
body: "Possible hardcoded password: \"posonly\"" 21 | def default_kwonly(first, *, password="kwonly"):
suggestion: ~ | ^^^^^^^^ S107
fixable: false 22 | pass
location: |
row: 13
column: 44 ./resources/test/fixtures/flake8_bandit/S107.py:29:39: S107 Possible hardcoded password: "posonly"
end_location: |
row: 13 29 | def default_all(first, /, pos, secret="posonly", *, password="kwonly"):
column: 53 | ^^^^^^^^^ S107
fix: 30 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bandit/S107.py:29:62: S107 Possible hardcoded password: "kwonly"
name: HardcodedPasswordDefault |
body: "Possible hardcoded password: \"kwonly\"" 29 | def default_all(first, /, pos, secret="posonly", *, password="kwonly"):
suggestion: ~ | ^^^^^^^^ S107
fixable: false 30 | pass
location: |
row: 21
column: 38
end_location:
row: 21
column: 46
fix:
edits: []
parent: ~
- kind:
name: HardcodedPasswordDefault
body: "Possible hardcoded password: \"posonly\""
suggestion: ~
fixable: false
location:
row: 29
column: 38
end_location:
row: 29
column: 47
fix:
edits: []
parent: ~
- kind:
name: HardcodedPasswordDefault
body: "Possible hardcoded password: \"kwonly\""
suggestion: ~
fixable: false
location:
row: 29
column: 61
end_location:
row: 29
column: 69
fix:
edits: []
parent: ~

View file

@ -1,47 +1,31 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S108.py:5:11: S108 Probable insecure usage of temporary file or directory: "/tmp/abc"
name: HardcodedTempFile |
body: "Probable insecure usage of temporary file or directory: \"/tmp/abc\"" 5 | f.write("def")
suggestion: ~ 6 |
fixable: false 7 | with open("/tmp/abc", "w") as f:
location: | ^^^^^^^^^^ S108
row: 5 8 | f.write("def")
column: 10 |
end_location:
row: 5 ./resources/test/fixtures/flake8_bandit/S108.py:8:11: S108 Probable insecure usage of temporary file or directory: "/var/tmp/123"
column: 20 |
fix: 8 | f.write("def")
edits: [] 9 |
parent: ~ 10 | with open("/var/tmp/123", "w") as f:
- kind: | ^^^^^^^^^^^^^^ S108
name: HardcodedTempFile 11 | f.write("def")
body: "Probable insecure usage of temporary file or directory: \"/var/tmp/123\"" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bandit/S108.py:11:11: S108 Probable insecure usage of temporary file or directory: "/dev/shm/unit/test"
location: |
row: 8 11 | f.write("def")
column: 10 12 |
end_location: 13 | with open("/dev/shm/unit/test", "w") as f:
row: 8 | ^^^^^^^^^^^^^^^^^^^^ S108
column: 24 14 | f.write("def")
fix: |
edits: []
parent: ~
- kind:
name: HardcodedTempFile
body: "Probable insecure usage of temporary file or directory: \"/dev/shm/unit/test\""
suggestion: ~
fixable: false
location:
row: 11
column: 10
end_location:
row: 11
column: 30
fix:
edits: []
parent: ~

View file

@ -1,61 +1,39 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S108.py:5:11: S108 Probable insecure usage of temporary file or directory: "/tmp/abc"
name: HardcodedTempFile |
body: "Probable insecure usage of temporary file or directory: \"/tmp/abc\"" 5 | f.write("def")
suggestion: ~ 6 |
fixable: false 7 | with open("/tmp/abc", "w") as f:
location: | ^^^^^^^^^^ S108
row: 5 8 | f.write("def")
column: 10 |
end_location:
row: 5 ./resources/test/fixtures/flake8_bandit/S108.py:8:11: S108 Probable insecure usage of temporary file or directory: "/var/tmp/123"
column: 20 |
fix: 8 | f.write("def")
edits: [] 9 |
parent: ~ 10 | with open("/var/tmp/123", "w") as f:
- kind: | ^^^^^^^^^^^^^^ S108
name: HardcodedTempFile 11 | f.write("def")
body: "Probable insecure usage of temporary file or directory: \"/var/tmp/123\"" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bandit/S108.py:11:11: S108 Probable insecure usage of temporary file or directory: "/dev/shm/unit/test"
location: |
row: 8 11 | f.write("def")
column: 10 12 |
end_location: 13 | with open("/dev/shm/unit/test", "w") as f:
row: 8 | ^^^^^^^^^^^^^^^^^^^^ S108
column: 24 14 | f.write("def")
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bandit/S108.py:15:11: S108 Probable insecure usage of temporary file or directory: "/foo/bar"
- kind: |
name: HardcodedTempFile 15 | # not ok by config
body: "Probable insecure usage of temporary file or directory: \"/dev/shm/unit/test\"" 16 | with open("/foo/bar", "w") as f:
suggestion: ~ | ^^^^^^^^^^ S108
fixable: false 17 | f.write("def")
location: |
row: 11
column: 10
end_location:
row: 11
column: 30
fix:
edits: []
parent: ~
- kind:
name: HardcodedTempFile
body: "Probable insecure usage of temporary file or directory: \"/foo/bar\""
suggestion: ~
fixable: false
location:
row: 15
column: 10
end_location:
row: 15
column: 20
fix:
edits: []
parent: ~

View file

@ -1,33 +1,26 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S110.py:3:1: S110 `try`-`except`-`pass` detected, consider logging the exception
name: TryExceptPass |
body: "`try`-`except`-`pass` detected, consider logging the exception" 3 | try:
suggestion: ~ 4 | pass
fixable: false 5 | / except Exception:
location: 6 | | pass
row: 3 | |________^ S110
column: 0 7 |
end_location: 8 | try:
row: 4 |
column: 8
fix: ./resources/test/fixtures/flake8_bandit/S110.py:8:1: S110 `try`-`except`-`pass` detected, consider logging the exception
edits: [] |
parent: ~ 8 | try:
- kind: 9 | pass
name: TryExceptPass 10 | / except:
body: "`try`-`except`-`pass` detected, consider logging the exception" 11 | | pass
suggestion: ~ | |________^ S110
fixable: false 12 |
location: 13 | try:
row: 8 |
column: 0
end_location:
row: 9
column: 8
fix:
edits: []
parent: ~

View file

@ -1,47 +1,35 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S110.py:3:1: S110 `try`-`except`-`pass` detected, consider logging the exception
name: TryExceptPass |
body: "`try`-`except`-`pass` detected, consider logging the exception" 3 | try:
suggestion: ~ 4 | pass
fixable: false 5 | / except Exception:
location: 6 | | pass
row: 3 | |________^ S110
column: 0 7 |
end_location: 8 | try:
row: 4 |
column: 8
fix: ./resources/test/fixtures/flake8_bandit/S110.py:8:1: S110 `try`-`except`-`pass` detected, consider logging the exception
edits: [] |
parent: ~ 8 | try:
- kind: 9 | pass
name: TryExceptPass 10 | / except:
body: "`try`-`except`-`pass` detected, consider logging the exception" 11 | | pass
suggestion: ~ | |________^ S110
fixable: false 12 |
location: 13 | try:
row: 8 |
column: 0
end_location: ./resources/test/fixtures/flake8_bandit/S110.py:13:1: S110 `try`-`except`-`pass` detected, consider logging the exception
row: 9 |
column: 8 13 | try:
fix: 14 | pass
edits: [] 15 | / except ValueError:
parent: ~ 16 | | pass
- kind: | |________^ S110
name: TryExceptPass |
body: "`try`-`except`-`pass` detected, consider logging the exception"
suggestion: ~
fixable: false
location:
row: 13
column: 0
end_location:
row: 14
column: 8
fix:
edits: []
parent: ~

View file

@ -1,61 +1,48 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S112.py:3:1: S112 `try`-`except`-`continue` detected, consider logging the exception
name: TryExceptContinue |
body: "`try`-`except`-`continue` detected, consider logging the exception" 3 | try:
suggestion: ~ 4 | pass
fixable: false 5 | / except Exception:
location: 6 | | continue
row: 3 | |____________^ S112
column: 0 7 |
end_location: 8 | try:
row: 4 |
column: 12
fix: ./resources/test/fixtures/flake8_bandit/S112.py:8:1: S112 `try`-`except`-`continue` detected, consider logging the exception
edits: [] |
parent: ~ 8 | try:
- kind: 9 | pass
name: TryExceptContinue 10 | / except:
body: "`try`-`except`-`continue` detected, consider logging the exception" 11 | | continue
suggestion: ~ | |____________^ S112
fixable: false 12 |
location: 13 | try:
row: 8 |
column: 0
end_location: ./resources/test/fixtures/flake8_bandit/S112.py:13:1: S112 `try`-`except`-`continue` detected, consider logging the exception
row: 9 |
column: 12 13 | try:
fix: 14 | pass
edits: [] 15 | / except (Exception,):
parent: ~ 16 | | continue
- kind: | |____________^ S112
name: TryExceptContinue 17 |
body: "`try`-`except`-`continue` detected, consider logging the exception" 18 | try:
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bandit/S112.py:18:1: S112 `try`-`except`-`continue` detected, consider logging the exception
row: 13 |
column: 0 18 | try:
end_location: 19 | pass
row: 14 20 | / except (Exception, ValueError):
column: 12 21 | | continue
fix: | |____________^ S112
edits: [] 22 |
parent: ~ 23 | try:
- kind: |
name: TryExceptContinue
body: "`try`-`except`-`continue` detected, consider logging the exception"
suggestion: ~
fixable: false
location:
row: 18
column: 0
end_location:
row: 19
column: 12
fix:
edits: []
parent: ~

View file

@ -1,201 +1,142 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S113.py:3:1: S113 Probable use of requests call without timeout
name: RequestWithoutTimeout |
body: Probable use of requests call without timeout 3 | import requests
suggestion: ~ 4 |
fixable: false 5 | requests.get('https://gmail.com')
location: | ^^^^^^^^^^^^ S113
row: 3 6 | requests.get('https://gmail.com', timeout=None)
column: 0 7 | requests.get('https://gmail.com', timeout=5)
end_location: |
row: 3
column: 12 ./resources/test/fixtures/flake8_bandit/S113.py:4:43: S113 Probable use of requests call with timeout set to `None`
fix: |
edits: [] 4 | requests.get('https://gmail.com')
parent: ~ 5 | requests.get('https://gmail.com', timeout=None)
- kind: | ^^^^ S113
name: RequestWithoutTimeout 6 | requests.get('https://gmail.com', timeout=5)
body: "Probable use of requests call with timeout set to `None`" 7 | requests.post('https://gmail.com')
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bandit/S113.py:6:1: S113 Probable use of requests call without timeout
row: 4 |
column: 42 6 | requests.get('https://gmail.com', timeout=None)
end_location: 7 | requests.get('https://gmail.com', timeout=5)
row: 4 8 | requests.post('https://gmail.com')
column: 46 | ^^^^^^^^^^^^^ S113
fix: 9 | requests.post('https://gmail.com', timeout=None)
edits: [] 10 | requests.post('https://gmail.com', timeout=5)
parent: ~ |
- kind:
name: RequestWithoutTimeout ./resources/test/fixtures/flake8_bandit/S113.py:7:44: S113 Probable use of requests call with timeout set to `None`
body: Probable use of requests call without timeout |
suggestion: ~ 7 | requests.get('https://gmail.com', timeout=5)
fixable: false 8 | requests.post('https://gmail.com')
location: 9 | requests.post('https://gmail.com', timeout=None)
row: 6 | ^^^^ S113
column: 0 10 | requests.post('https://gmail.com', timeout=5)
end_location: 11 | requests.put('https://gmail.com')
row: 6 |
column: 13
fix: ./resources/test/fixtures/flake8_bandit/S113.py:9:1: S113 Probable use of requests call without timeout
edits: [] |
parent: ~ 9 | requests.post('https://gmail.com', timeout=None)
- kind: 10 | requests.post('https://gmail.com', timeout=5)
name: RequestWithoutTimeout 11 | requests.put('https://gmail.com')
body: "Probable use of requests call with timeout set to `None`" | ^^^^^^^^^^^^ S113
suggestion: ~ 12 | requests.put('https://gmail.com', timeout=None)
fixable: false 13 | requests.put('https://gmail.com', timeout=5)
location: |
row: 7
column: 43 ./resources/test/fixtures/flake8_bandit/S113.py:10:43: S113 Probable use of requests call with timeout set to `None`
end_location: |
row: 7 10 | requests.post('https://gmail.com', timeout=5)
column: 47 11 | requests.put('https://gmail.com')
fix: 12 | requests.put('https://gmail.com', timeout=None)
edits: [] | ^^^^ S113
parent: ~ 13 | requests.put('https://gmail.com', timeout=5)
- kind: 14 | requests.delete('https://gmail.com')
name: RequestWithoutTimeout |
body: Probable use of requests call without timeout
suggestion: ~ ./resources/test/fixtures/flake8_bandit/S113.py:12:1: S113 Probable use of requests call without timeout
fixable: false |
location: 12 | requests.put('https://gmail.com', timeout=None)
row: 9 13 | requests.put('https://gmail.com', timeout=5)
column: 0 14 | requests.delete('https://gmail.com')
end_location: | ^^^^^^^^^^^^^^^ S113
row: 9 15 | requests.delete('https://gmail.com', timeout=None)
column: 12 16 | requests.delete('https://gmail.com', timeout=5)
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bandit/S113.py:13:46: S113 Probable use of requests call with timeout set to `None`
- kind: |
name: RequestWithoutTimeout 13 | requests.put('https://gmail.com', timeout=5)
body: "Probable use of requests call with timeout set to `None`" 14 | requests.delete('https://gmail.com')
suggestion: ~ 15 | requests.delete('https://gmail.com', timeout=None)
fixable: false | ^^^^ S113
location: 16 | requests.delete('https://gmail.com', timeout=5)
row: 10 17 | requests.patch('https://gmail.com')
column: 42 |
end_location:
row: 10 ./resources/test/fixtures/flake8_bandit/S113.py:15:1: S113 Probable use of requests call without timeout
column: 46 |
fix: 15 | requests.delete('https://gmail.com', timeout=None)
edits: [] 16 | requests.delete('https://gmail.com', timeout=5)
parent: ~ 17 | requests.patch('https://gmail.com')
- kind: | ^^^^^^^^^^^^^^ S113
name: RequestWithoutTimeout 18 | requests.patch('https://gmail.com', timeout=None)
body: Probable use of requests call without timeout 19 | requests.patch('https://gmail.com', timeout=5)
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bandit/S113.py:16:45: S113 Probable use of requests call with timeout set to `None`
row: 12 |
column: 0 16 | requests.delete('https://gmail.com', timeout=5)
end_location: 17 | requests.patch('https://gmail.com')
row: 12 18 | requests.patch('https://gmail.com', timeout=None)
column: 15 | ^^^^ S113
fix: 19 | requests.patch('https://gmail.com', timeout=5)
edits: [] 20 | requests.options('https://gmail.com')
parent: ~ |
- kind:
name: RequestWithoutTimeout ./resources/test/fixtures/flake8_bandit/S113.py:18:1: S113 Probable use of requests call without timeout
body: "Probable use of requests call with timeout set to `None`" |
suggestion: ~ 18 | requests.patch('https://gmail.com', timeout=None)
fixable: false 19 | requests.patch('https://gmail.com', timeout=5)
location: 20 | requests.options('https://gmail.com')
row: 13 | ^^^^^^^^^^^^^^^^ S113
column: 45 21 | requests.options('https://gmail.com', timeout=None)
end_location: 22 | requests.options('https://gmail.com', timeout=5)
row: 13 |
column: 49
fix: ./resources/test/fixtures/flake8_bandit/S113.py:19:47: S113 Probable use of requests call with timeout set to `None`
edits: [] |
parent: ~ 19 | requests.patch('https://gmail.com', timeout=5)
- kind: 20 | requests.options('https://gmail.com')
name: RequestWithoutTimeout 21 | requests.options('https://gmail.com', timeout=None)
body: Probable use of requests call without timeout | ^^^^ S113
suggestion: ~ 22 | requests.options('https://gmail.com', timeout=5)
fixable: false 23 | requests.head('https://gmail.com')
location: |
row: 15
column: 0 ./resources/test/fixtures/flake8_bandit/S113.py:21:1: S113 Probable use of requests call without timeout
end_location: |
row: 15 21 | requests.options('https://gmail.com', timeout=None)
column: 14 22 | requests.options('https://gmail.com', timeout=5)
fix: 23 | requests.head('https://gmail.com')
edits: [] | ^^^^^^^^^^^^^ S113
parent: ~ 24 | requests.head('https://gmail.com', timeout=None)
- kind: 25 | requests.head('https://gmail.com', timeout=5)
name: RequestWithoutTimeout |
body: "Probable use of requests call with timeout set to `None`"
suggestion: ~ ./resources/test/fixtures/flake8_bandit/S113.py:22:44: S113 Probable use of requests call with timeout set to `None`
fixable: false |
location: 22 | requests.options('https://gmail.com', timeout=5)
row: 16 23 | requests.head('https://gmail.com')
column: 44 24 | requests.head('https://gmail.com', timeout=None)
end_location: | ^^^^ S113
row: 16 25 | requests.head('https://gmail.com', timeout=5)
column: 48 |
fix:
edits: []
parent: ~
- kind:
name: RequestWithoutTimeout
body: Probable use of requests call without timeout
suggestion: ~
fixable: false
location:
row: 18
column: 0
end_location:
row: 18
column: 16
fix:
edits: []
parent: ~
- kind:
name: RequestWithoutTimeout
body: "Probable use of requests call with timeout set to `None`"
suggestion: ~
fixable: false
location:
row: 19
column: 46
end_location:
row: 19
column: 50
fix:
edits: []
parent: ~
- kind:
name: RequestWithoutTimeout
body: Probable use of requests call without timeout
suggestion: ~
fixable: false
location:
row: 21
column: 0
end_location:
row: 21
column: 13
fix:
edits: []
parent: ~
- kind:
name: RequestWithoutTimeout
body: "Probable use of requests call with timeout set to `None`"
suggestion: ~
fixable: false
location:
row: 22
column: 43
end_location:
row: 22
column: 47
fix:
edits: []
parent: ~

View file

@ -1,19 +1,12 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S301.py:3:1: S301 `pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue
name: SuspiciousPickleUsage |
body: "`pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue" 3 | import pickle
suggestion: ~ 4 |
fixable: false 5 | pickle.loads()
location: | ^^^^^^^^^^^^^^ S301
row: 3 |
column: 0
end_location:
row: 3
column: 14
fix:
edits: []
parent: ~

View file

@ -1,19 +1,12 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S312.py:3:1: S312 Telnet-related functions are being called. Telnet is considered insecure. Use SSH or some other encrypted protocol.
name: SuspiciousTelnetUsage |
body: Telnet-related functions are being called. Telnet is considered insecure. Use SSH or some other encrypted protocol. 3 | from telnetlib import Telnet
suggestion: ~ 4 |
fixable: false 5 | Telnet("localhost", 23)
location: | ^^^^^^^^^^^^^^^^^^^^^^^ S312
row: 3 |
column: 0
end_location:
row: 3
column: 23
fix:
edits: []
parent: ~

View file

@ -1,187 +1,133 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S324.py:7:13: S324 Probable use of insecure hash functions in `hashlib`: `md5`
name: HashlibInsecureHashFunction |
body: "Probable use of insecure hash functions in `hashlib`: `md5`" 7 | # Invalid
suggestion: ~ 8 |
fixable: false 9 | hashlib.new('md5')
location: | ^^^^^ S324
row: 7 10 |
column: 12 11 | hashlib.new('md4', b'test')
end_location: |
row: 7
column: 17 ./resources/test/fixtures/flake8_bandit/S324.py:9:13: S324 Probable use of insecure hash functions in `hashlib`: `md4`
fix: |
edits: [] 9 | hashlib.new('md5')
parent: ~ 10 |
- kind: 11 | hashlib.new('md4', b'test')
name: HashlibInsecureHashFunction | ^^^^^ S324
body: "Probable use of insecure hash functions in `hashlib`: `md4`" 12 |
suggestion: ~ 13 | hashlib.new(name='md5', data=b'test')
fixable: false |
location:
row: 9 ./resources/test/fixtures/flake8_bandit/S324.py:11:18: S324 Probable use of insecure hash functions in `hashlib`: `md5`
column: 12 |
end_location: 11 | hashlib.new('md4', b'test')
row: 9 12 |
column: 17 13 | hashlib.new(name='md5', data=b'test')
fix: | ^^^^^ S324
edits: [] 14 |
parent: ~ 15 | hashlib.new('MD4', data=b'test')
- kind: |
name: HashlibInsecureHashFunction
body: "Probable use of insecure hash functions in `hashlib`: `md5`" ./resources/test/fixtures/flake8_bandit/S324.py:13:13: S324 Probable use of insecure hash functions in `hashlib`: `MD4`
suggestion: ~ |
fixable: false 13 | hashlib.new(name='md5', data=b'test')
location: 14 |
row: 11 15 | hashlib.new('MD4', data=b'test')
column: 17 | ^^^^^ S324
end_location: 16 |
row: 11 17 | hashlib.new('sha1')
column: 22 |
fix:
edits: [] ./resources/test/fixtures/flake8_bandit/S324.py:15:13: S324 Probable use of insecure hash functions in `hashlib`: `sha1`
parent: ~ |
- kind: 15 | hashlib.new('MD4', data=b'test')
name: HashlibInsecureHashFunction 16 |
body: "Probable use of insecure hash functions in `hashlib`: `MD4`" 17 | hashlib.new('sha1')
suggestion: ~ | ^^^^^^ S324
fixable: false 18 |
location: 19 | hashlib.new('sha1', data=b'test')
row: 13 |
column: 12
end_location: ./resources/test/fixtures/flake8_bandit/S324.py:17:13: S324 Probable use of insecure hash functions in `hashlib`: `sha1`
row: 13 |
column: 17 17 | hashlib.new('sha1')
fix: 18 |
edits: [] 19 | hashlib.new('sha1', data=b'test')
parent: ~ | ^^^^^^ S324
- kind: 20 |
name: HashlibInsecureHashFunction 21 | hashlib.new('sha', data=b'test')
body: "Probable use of insecure hash functions in `hashlib`: `sha1`" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bandit/S324.py:19:13: S324 Probable use of insecure hash functions in `hashlib`: `sha`
location: |
row: 15 19 | hashlib.new('sha1', data=b'test')
column: 12 20 |
end_location: 21 | hashlib.new('sha', data=b'test')
row: 15 | ^^^^^ S324
column: 18 22 |
fix: 23 | hashlib.new(name='SHA', data=b'test')
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bandit/S324.py:21:18: S324 Probable use of insecure hash functions in `hashlib`: `SHA`
name: HashlibInsecureHashFunction |
body: "Probable use of insecure hash functions in `hashlib`: `sha1`" 21 | hashlib.new('sha', data=b'test')
suggestion: ~ 22 |
fixable: false 23 | hashlib.new(name='SHA', data=b'test')
location: | ^^^^^ S324
row: 17 24 |
column: 12 25 | hashlib.sha(data=b'test')
end_location: |
row: 17
column: 18 ./resources/test/fixtures/flake8_bandit/S324.py:23:1: S324 Probable use of insecure hash functions in `hashlib`: `sha`
fix: |
edits: [] 23 | hashlib.new(name='SHA', data=b'test')
parent: ~ 24 |
- kind: 25 | hashlib.sha(data=b'test')
name: HashlibInsecureHashFunction | ^^^^^^^^^^^ S324
body: "Probable use of insecure hash functions in `hashlib`: `sha`" 26 |
suggestion: ~ 27 | hashlib.md5()
fixable: false |
location:
row: 19 ./resources/test/fixtures/flake8_bandit/S324.py:25:1: S324 Probable use of insecure hash functions in `hashlib`: `md5`
column: 12 |
end_location: 25 | hashlib.sha(data=b'test')
row: 19 26 |
column: 17 27 | hashlib.md5()
fix: | ^^^^^^^^^^^ S324
edits: [] 28 |
parent: ~ 29 | hashlib_new('sha1')
- kind: |
name: HashlibInsecureHashFunction
body: "Probable use of insecure hash functions in `hashlib`: `SHA`" ./resources/test/fixtures/flake8_bandit/S324.py:27:13: S324 Probable use of insecure hash functions in `hashlib`: `sha1`
suggestion: ~ |
fixable: false 27 | hashlib.md5()
location: 28 |
row: 21 29 | hashlib_new('sha1')
column: 17 | ^^^^^^ S324
end_location: 30 |
row: 21 31 | hashlib_sha1('sha1')
column: 22 |
fix:
edits: [] ./resources/test/fixtures/flake8_bandit/S324.py:29:1: S324 Probable use of insecure hash functions in `hashlib`: `sha1`
parent: ~ |
- kind: 29 | hashlib_new('sha1')
name: HashlibInsecureHashFunction 30 |
body: "Probable use of insecure hash functions in `hashlib`: `sha`" 31 | hashlib_sha1('sha1')
suggestion: ~ | ^^^^^^^^^^^^ S324
fixable: false 32 |
location: 33 | # usedforsecurity arg only available in Python 3.9+
row: 23 |
column: 0
end_location: ./resources/test/fixtures/flake8_bandit/S324.py:32:13: S324 Probable use of insecure hash functions in `hashlib`: `sha1`
row: 23 |
column: 11 32 | # usedforsecurity arg only available in Python 3.9+
fix: 33 | hashlib.new('sha1', usedforsecurity=True)
edits: [] | ^^^^^^ S324
parent: ~ 34 |
- kind: 35 | # Valid
name: HashlibInsecureHashFunction |
body: "Probable use of insecure hash functions in `hashlib`: `md5`"
suggestion: ~
fixable: false
location:
row: 25
column: 0
end_location:
row: 25
column: 11
fix:
edits: []
parent: ~
- kind:
name: HashlibInsecureHashFunction
body: "Probable use of insecure hash functions in `hashlib`: `sha1`"
suggestion: ~
fixable: false
location:
row: 27
column: 12
end_location:
row: 27
column: 18
fix:
edits: []
parent: ~
- kind:
name: HashlibInsecureHashFunction
body: "Probable use of insecure hash functions in `hashlib`: `sha1`"
suggestion: ~
fixable: false
location:
row: 29
column: 0
end_location:
row: 29
column: 12
fix:
edits: []
parent: ~
- kind:
name: HashlibInsecureHashFunction
body: "Probable use of insecure hash functions in `hashlib`: `sha1`"
suggestion: ~
fixable: false
location:
row: 32
column: 12
end_location:
row: 32
column: 18
fix:
edits: []
parent: ~

View file

@ -1,257 +1,180 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S501.py:5:54: S501 Probable use of `requests` call with `verify=False` disabling SSL certificate checks
name: RequestWithNoCertValidation |
body: "Probable use of `requests` call with `verify=False` disabling SSL certificate checks" 5 | requests.get('https://gmail.com', timeout=30, verify=True)
suggestion: ~ 6 | requests.get('https://gmail.com', timeout=30, verify=False)
fixable: false | ^^^^^ S501
location: 7 | requests.post('https://gmail.com', timeout=30, verify=True)
row: 5 8 | requests.post('https://gmail.com', timeout=30, verify=False)
column: 53 |
end_location:
row: 5 ./resources/test/fixtures/flake8_bandit/S501.py:7:55: S501 Probable use of `requests` call with `verify=False` disabling SSL certificate checks
column: 58 |
fix: 7 | requests.get('https://gmail.com', timeout=30, verify=False)
edits: [] 8 | requests.post('https://gmail.com', timeout=30, verify=True)
parent: ~ 9 | requests.post('https://gmail.com', timeout=30, verify=False)
- kind: | ^^^^^ S501
name: RequestWithNoCertValidation 10 | requests.put('https://gmail.com', timeout=30, verify=True)
body: "Probable use of `requests` call with `verify=False` disabling SSL certificate checks" 11 | requests.put('https://gmail.com', timeout=30, verify=False)
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bandit/S501.py:9:54: S501 Probable use of `requests` call with `verify=False` disabling SSL certificate checks
row: 7 |
column: 54 9 | requests.post('https://gmail.com', timeout=30, verify=False)
end_location: 10 | requests.put('https://gmail.com', timeout=30, verify=True)
row: 7 11 | requests.put('https://gmail.com', timeout=30, verify=False)
column: 59 | ^^^^^ S501
fix: 12 | requests.delete('https://gmail.com', timeout=30, verify=True)
edits: [] 13 | requests.delete('https://gmail.com', timeout=30, verify=False)
parent: ~ |
- kind:
name: RequestWithNoCertValidation ./resources/test/fixtures/flake8_bandit/S501.py:11:57: S501 Probable use of `requests` call with `verify=False` disabling SSL certificate checks
body: "Probable use of `requests` call with `verify=False` disabling SSL certificate checks" |
suggestion: ~ 11 | requests.put('https://gmail.com', timeout=30, verify=False)
fixable: false 12 | requests.delete('https://gmail.com', timeout=30, verify=True)
location: 13 | requests.delete('https://gmail.com', timeout=30, verify=False)
row: 9 | ^^^^^ S501
column: 53 14 | requests.patch('https://gmail.com', timeout=30, verify=True)
end_location: 15 | requests.patch('https://gmail.com', timeout=30, verify=False)
row: 9 |
column: 58
fix: ./resources/test/fixtures/flake8_bandit/S501.py:13:56: S501 Probable use of `requests` call with `verify=False` disabling SSL certificate checks
edits: [] |
parent: ~ 13 | requests.delete('https://gmail.com', timeout=30, verify=False)
- kind: 14 | requests.patch('https://gmail.com', timeout=30, verify=True)
name: RequestWithNoCertValidation 15 | requests.patch('https://gmail.com', timeout=30, verify=False)
body: "Probable use of `requests` call with `verify=False` disabling SSL certificate checks" | ^^^^^ S501
suggestion: ~ 16 | requests.options('https://gmail.com', timeout=30, verify=True)
fixable: false 17 | requests.options('https://gmail.com', timeout=30, verify=False)
location: |
row: 11
column: 56 ./resources/test/fixtures/flake8_bandit/S501.py:15:58: S501 Probable use of `requests` call with `verify=False` disabling SSL certificate checks
end_location: |
row: 11 15 | requests.patch('https://gmail.com', timeout=30, verify=False)
column: 61 16 | requests.options('https://gmail.com', timeout=30, verify=True)
fix: 17 | requests.options('https://gmail.com', timeout=30, verify=False)
edits: [] | ^^^^^ S501
parent: ~ 18 | requests.head('https://gmail.com', timeout=30, verify=True)
- kind: 19 | requests.head('https://gmail.com', timeout=30, verify=False)
name: RequestWithNoCertValidation |
body: "Probable use of `requests` call with `verify=False` disabling SSL certificate checks"
suggestion: ~ ./resources/test/fixtures/flake8_bandit/S501.py:17:55: S501 Probable use of `requests` call with `verify=False` disabling SSL certificate checks
fixable: false |
location: 17 | requests.options('https://gmail.com', timeout=30, verify=False)
row: 13 18 | requests.head('https://gmail.com', timeout=30, verify=True)
column: 55 19 | requests.head('https://gmail.com', timeout=30, verify=False)
end_location: | ^^^^^ S501
row: 13 20 |
column: 60 21 | httpx.request('GET', 'https://gmail.com', verify=True)
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bandit/S501.py:20:50: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks
- kind: |
name: RequestWithNoCertValidation 20 | httpx.request('GET', 'https://gmail.com', verify=True)
body: "Probable use of `requests` call with `verify=False` disabling SSL certificate checks" 21 | httpx.request('GET', 'https://gmail.com', verify=False)
suggestion: ~ | ^^^^^ S501
fixable: false 22 | httpx.get('https://gmail.com', verify=True)
location: 23 | httpx.get('https://gmail.com', verify=False)
row: 15 |
column: 57
end_location: ./resources/test/fixtures/flake8_bandit/S501.py:22:39: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks
row: 15 |
column: 62 22 | httpx.request('GET', 'https://gmail.com', verify=False)
fix: 23 | httpx.get('https://gmail.com', verify=True)
edits: [] 24 | httpx.get('https://gmail.com', verify=False)
parent: ~ | ^^^^^ S501
- kind: 25 | httpx.options('https://gmail.com', verify=True)
name: RequestWithNoCertValidation 26 | httpx.options('https://gmail.com', verify=False)
body: "Probable use of `requests` call with `verify=False` disabling SSL certificate checks" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bandit/S501.py:24:43: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks
location: |
row: 17 24 | httpx.get('https://gmail.com', verify=False)
column: 54 25 | httpx.options('https://gmail.com', verify=True)
end_location: 26 | httpx.options('https://gmail.com', verify=False)
row: 17 | ^^^^^ S501
column: 59 27 | httpx.head('https://gmail.com', verify=True)
fix: 28 | httpx.head('https://gmail.com', verify=False)
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bandit/S501.py:26:40: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks
name: RequestWithNoCertValidation |
body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" 26 | httpx.options('https://gmail.com', verify=False)
suggestion: ~ 27 | httpx.head('https://gmail.com', verify=True)
fixable: false 28 | httpx.head('https://gmail.com', verify=False)
location: | ^^^^^ S501
row: 20 29 | httpx.post('https://gmail.com', verify=True)
column: 49 30 | httpx.post('https://gmail.com', verify=False)
end_location: |
row: 20
column: 54 ./resources/test/fixtures/flake8_bandit/S501.py:28:40: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks
fix: |
edits: [] 28 | httpx.head('https://gmail.com', verify=False)
parent: ~ 29 | httpx.post('https://gmail.com', verify=True)
- kind: 30 | httpx.post('https://gmail.com', verify=False)
name: RequestWithNoCertValidation | ^^^^^ S501
body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" 31 | httpx.put('https://gmail.com', verify=True)
suggestion: ~ 32 | httpx.put('https://gmail.com', verify=False)
fixable: false |
location:
row: 22 ./resources/test/fixtures/flake8_bandit/S501.py:30:39: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks
column: 38 |
end_location: 30 | httpx.post('https://gmail.com', verify=False)
row: 22 31 | httpx.put('https://gmail.com', verify=True)
column: 43 32 | httpx.put('https://gmail.com', verify=False)
fix: | ^^^^^ S501
edits: [] 33 | httpx.patch('https://gmail.com', verify=True)
parent: ~ 34 | httpx.patch('https://gmail.com', verify=False)
- kind: |
name: RequestWithNoCertValidation
body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" ./resources/test/fixtures/flake8_bandit/S501.py:32:41: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks
suggestion: ~ |
fixable: false 32 | httpx.put('https://gmail.com', verify=False)
location: 33 | httpx.patch('https://gmail.com', verify=True)
row: 24 34 | httpx.patch('https://gmail.com', verify=False)
column: 42 | ^^^^^ S501
end_location: 35 | httpx.delete('https://gmail.com', verify=True)
row: 24 36 | httpx.delete('https://gmail.com', verify=False)
column: 47 |
fix:
edits: [] ./resources/test/fixtures/flake8_bandit/S501.py:34:42: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks
parent: ~ |
- kind: 34 | httpx.patch('https://gmail.com', verify=False)
name: RequestWithNoCertValidation 35 | httpx.delete('https://gmail.com', verify=True)
body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" 36 | httpx.delete('https://gmail.com', verify=False)
suggestion: ~ | ^^^^^ S501
fixable: false 37 | httpx.stream('https://gmail.com', verify=True)
location: 38 | httpx.stream('https://gmail.com', verify=False)
row: 26 |
column: 39
end_location: ./resources/test/fixtures/flake8_bandit/S501.py:36:42: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks
row: 26 |
column: 44 36 | httpx.delete('https://gmail.com', verify=False)
fix: 37 | httpx.stream('https://gmail.com', verify=True)
edits: [] 38 | httpx.stream('https://gmail.com', verify=False)
parent: ~ | ^^^^^ S501
- kind: 39 | httpx.Client()
name: RequestWithNoCertValidation 40 | httpx.Client(verify=False)
body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bandit/S501.py:38:21: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks
location: |
row: 28 38 | httpx.stream('https://gmail.com', verify=False)
column: 39 39 | httpx.Client()
end_location: 40 | httpx.Client(verify=False)
row: 28 | ^^^^^ S501
column: 44 41 | httpx.AsyncClient()
fix: 42 | httpx.AsyncClient(verify=False)
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bandit/S501.py:40:26: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks
name: RequestWithNoCertValidation |
body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" 40 | httpx.Client(verify=False)
suggestion: ~ 41 | httpx.AsyncClient()
fixable: false 42 | httpx.AsyncClient(verify=False)
location: | ^^^^^ S501
row: 30 |
column: 38
end_location:
row: 30
column: 43
fix:
edits: []
parent: ~
- kind:
name: RequestWithNoCertValidation
body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks"
suggestion: ~
fixable: false
location:
row: 32
column: 40
end_location:
row: 32
column: 45
fix:
edits: []
parent: ~
- kind:
name: RequestWithNoCertValidation
body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks"
suggestion: ~
fixable: false
location:
row: 34
column: 41
end_location:
row: 34
column: 46
fix:
edits: []
parent: ~
- kind:
name: RequestWithNoCertValidation
body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks"
suggestion: ~
fixable: false
location:
row: 36
column: 41
end_location:
row: 36
column: 46
fix:
edits: []
parent: ~
- kind:
name: RequestWithNoCertValidation
body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks"
suggestion: ~
fixable: false
location:
row: 38
column: 20
end_location:
row: 38
column: 25
fix:
edits: []
parent: ~
- kind:
name: RequestWithNoCertValidation
body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks"
suggestion: ~
fixable: false
location:
row: 40
column: 25
end_location:
row: 40
column: 30
fix:
edits: []
parent: ~

View file

@ -1,33 +1,22 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S506.py:10:9: S506 Probable use of unsafe `yaml.load`. Allows instantiation of arbitrary objects. Consider `yaml.safe_load`.
name: UnsafeYAMLLoad |
body: "Probable use of unsafe `yaml.load`. Allows instantiation of arbitrary objects. Consider `yaml.safe_load`." 10 | def test_yaml_load():
suggestion: ~ 11 | ystr = yaml.dump({"a": 1, "b": 2, "c": 3})
fixable: false 12 | y = yaml.load(ystr)
location: | ^^^^^^^^^ S506
row: 10 13 | yaml.dump(y)
column: 8 14 | try:
end_location: |
row: 10
column: 17 ./resources/test/fixtures/flake8_bandit/S506.py:24:24: S506 Probable use of unsafe loader `Loader` with `yaml.load`. Allows instantiation of arbitrary objects. Consider `yaml.safe_load`.
fix: |
edits: [] 24 | yaml.load("{}", Loader=yaml.Loader)
parent: ~ | ^^^^^^^^^^^ S506
- kind: 25 |
name: UnsafeYAMLLoad 26 | # no issue should be found
body: "Probable use of unsafe loader `Loader` with `yaml.load`. Allows instantiation of arbitrary objects. Consider `yaml.safe_load`." |
suggestion: ~
fixable: false
location:
row: 24
column: 23
end_location:
row: 24
column: 34
fix:
edits: []
parent: ~

View file

@ -1,33 +1,22 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S508.py:3:33: S508 The use of SNMPv1 and SNMPv2 is insecure. Use SNMPv3 if able.
name: SnmpInsecureVersion |
body: The use of SNMPv1 and SNMPv2 is insecure. Use SNMPv3 if able. 3 | from pysnmp.hlapi import CommunityData
suggestion: ~ 4 |
fixable: false 5 | CommunityData("public", mpModel=0) # S508
location: | ^ S508
row: 3 6 | CommunityData("public", mpModel=1) # S508
column: 32 |
end_location:
row: 3 ./resources/test/fixtures/flake8_bandit/S508.py:4:33: S508 The use of SNMPv1 and SNMPv2 is insecure. Use SNMPv3 if able.
column: 33 |
fix: 4 | CommunityData("public", mpModel=0) # S508
edits: [] 5 | CommunityData("public", mpModel=1) # S508
parent: ~ | ^ S508
- kind: 6 |
name: SnmpInsecureVersion 7 | CommunityData("public", mpModel=2) # OK
body: The use of SNMPv1 and SNMPv2 is insecure. Use SNMPv3 if able. |
suggestion: ~
fixable: false
location:
row: 4
column: 32
end_location:
row: 4
column: 33
fix:
edits: []
parent: ~

View file

@ -1,33 +1,20 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S509.py:4:12: S509 You should not use SNMPv3 without encryption. `noAuthNoPriv` & `authNoPriv` is insecure.
name: SnmpWeakCryptography |
body: "You should not use SNMPv3 without encryption. `noAuthNoPriv` & `authNoPriv` is insecure." 4 | insecure = UsmUserData("securityName") # S509
suggestion: ~ | ^^^^^^^^^^^ S509
fixable: false 5 | auth_no_priv = UsmUserData("securityName", "authName") # S509
location: |
row: 4
column: 11 ./resources/test/fixtures/flake8_bandit/S509.py:5:16: S509 You should not use SNMPv3 without encryption. `noAuthNoPriv` & `authNoPriv` is insecure.
end_location: |
row: 4 5 | insecure = UsmUserData("securityName") # S509
column: 22 6 | auth_no_priv = UsmUserData("securityName", "authName") # S509
fix: | ^^^^^^^^^^^ S509
edits: [] 7 |
parent: ~ 8 | less_insecure = UsmUserData("securityName", "authName", "privName") # OK
- kind: |
name: SnmpWeakCryptography
body: "You should not use SNMPv3 without encryption. `noAuthNoPriv` & `authNoPriv` is insecure."
suggestion: ~
fixable: false
location:
row: 5
column: 15
end_location:
row: 5
column: 26
fix:
edits: []
parent: ~

View file

@ -1,19 +1,14 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S612.py:3:5: S612 Use of insecure `logging.config.listen` detected
name: LoggingConfigInsecureListen |
body: "Use of insecure `logging.config.listen` detected" 3 | import logging.config
suggestion: ~ 4 |
fixable: false 5 | t = logging.config.listen(9999)
location: | ^^^^^^^^^^^^^^^^^^^^^ S612
row: 3 6 |
column: 4 7 | def verify_func():
end_location: |
row: 3
column: 25
fix:
edits: []
parent: ~

View file

@ -1,75 +1,51 @@
--- ---
source: crates/ruff/src/rules/flake8_bandit/mod.rs source: crates/ruff/src/rules/flake8_bandit/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bandit/S701.py:9:68: S701 Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function.
name: Jinja2AutoescapeFalse |
body: "Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function." 9 | templateEnv = jinja2.Environment(autoescape=True,
suggestion: ~ 10 | loader=templateLoader )
fixable: false 11 | Environment(loader=templateLoader, load=templateLoader, autoescape=something) # S701
location: | ^^^^^^^^^ S701
row: 9 12 | templateEnv = jinja2.Environment(autoescape=False, loader=templateLoader ) # S701
column: 67 13 | Environment(loader=templateLoader,
end_location: |
row: 9
column: 76 ./resources/test/fixtures/flake8_bandit/S701.py:10:45: S701 Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function.
fix: |
edits: [] 10 | loader=templateLoader )
parent: ~ 11 | Environment(loader=templateLoader, load=templateLoader, autoescape=something) # S701
- kind: 12 | templateEnv = jinja2.Environment(autoescape=False, loader=templateLoader ) # S701
name: Jinja2AutoescapeFalse | ^^^^^ S701
body: "Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function." 13 | Environment(loader=templateLoader,
suggestion: ~ 14 | load=templateLoader,
fixable: false |
location:
row: 10 ./resources/test/fixtures/flake8_bandit/S701.py:13:24: S701 Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function.
column: 44 |
end_location: 13 | Environment(loader=templateLoader,
row: 10 14 | load=templateLoader,
column: 49 15 | autoescape=False) # S701
fix: | ^^^^^ S701
edits: [] 16 |
parent: ~ 17 | Environment(loader=templateLoader, # S701
- kind: |
name: Jinja2AutoescapeFalse
body: "Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function." ./resources/test/fixtures/flake8_bandit/S701.py:15:1: S701 By default, jinja2 sets `autoescape` to `False`. Consider using `autoescape=True` or the `select_autoescape` function to mitigate XSS vulnerabilities.
suggestion: ~ |
fixable: false 15 | autoescape=False) # S701
location: 16 |
row: 13 17 | Environment(loader=templateLoader, # S701
column: 23 | ^^^^^^^^^^^ S701
end_location: 18 | load=templateLoader)
row: 13 |
column: 28
fix: ./resources/test/fixtures/flake8_bandit/S701.py:29:47: S701 Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function.
edits: [] |
parent: ~ 29 | def fake_func():
- kind: 30 | return 'foobar'
name: Jinja2AutoescapeFalse 31 | Environment(loader=templateLoader, autoescape=fake_func()) # S701
body: "By default, jinja2 sets `autoescape` to `False`. Consider using `autoescape=True` or the `select_autoescape` function to mitigate XSS vulnerabilities." | ^^^^^^^^^^^ S701
suggestion: ~ |
fixable: false
location:
row: 15
column: 0
end_location:
row: 15
column: 11
fix:
edits: []
parent: ~
- kind:
name: Jinja2AutoescapeFalse
body: "Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function."
suggestion: ~
fixable: false
location:
row: 29
column: 46
end_location:
row: 29
column: 57
fix:
edits: []
parent: ~

View file

@ -6,12 +6,12 @@ mod tests {
use std::path::Path; use std::path::Path;
use anyhow::Result; use anyhow::Result;
use insta::assert_yaml_snapshot;
use test_case::test_case; use test_case::test_case;
use crate::registry::Rule; use crate::registry::Rule;
use crate::settings;
use crate::test::test_path; use crate::test::test_path;
use crate::{assert_messages, settings};
#[test_case(Rule::BlindExcept, Path::new("BLE.py"); "BLE001")] #[test_case(Rule::BlindExcept, Path::new("BLE.py"); "BLE001")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> { fn rules(rule_code: Rule, path: &Path) -> Result<()> {
@ -20,7 +20,7 @@ mod tests {
Path::new("flake8_blind_except").join(path).as_path(), Path::new("flake8_blind_except").join(path).as_path(),
&settings::Settings::for_rule(rule_code), &settings::Settings::for_rule(rule_code),
)?; )?;
assert_yaml_snapshot!(snapshot, diagnostics); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())
} }
} }

View file

@ -1,145 +1,97 @@
--- ---
source: crates/ruff/src/rules/flake8_blind_except/mod.rs source: crates/ruff/src/rules/flake8_blind_except/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_blind_except/BLE.py:25:8: BLE001 Do not catch blind exception: `BaseException`
name: BlindExcept |
body: "Do not catch blind exception: `BaseException`" 25 | except Exception as e:
suggestion: ~ 26 | raise e
fixable: false 27 | except BaseException:
location: | ^^^^^^^^^^^^^ BLE001
row: 25 28 | pass
column: 7 |
end_location:
row: 25 ./resources/test/fixtures/flake8_blind_except/BLE.py:31:8: BLE001 Do not catch blind exception: `Exception`
column: 20 |
fix: 31 | try:
edits: [] 32 | pass
parent: ~ 33 | except Exception:
- kind: | ^^^^^^^^^ BLE001
name: BlindExcept 34 | pass
body: "Do not catch blind exception: `Exception`" 35 | finally:
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_blind_except/BLE.py:42:8: BLE001 Do not catch blind exception: `Exception`
row: 31 |
column: 7 42 | try:
end_location: 43 | pass
row: 31 44 | except Exception as e:
column: 16 | ^^^^^^^^^ BLE001
fix: 45 | try:
edits: [] 46 | raise e
parent: ~ |
- kind:
name: BlindExcept ./resources/test/fixtures/flake8_blind_except/BLE.py:45:12: BLE001 Do not catch blind exception: `BaseException`
body: "Do not catch blind exception: `Exception`" |
suggestion: ~ 45 | try:
fixable: false 46 | raise e
location: 47 | except BaseException:
row: 42 | ^^^^^^^^^^^^^ BLE001
column: 7 48 | pass
end_location: |
row: 42
column: 16 ./resources/test/fixtures/flake8_blind_except/BLE.py:54:8: BLE001 Do not catch blind exception: `Exception`
fix: |
edits: [] 54 | except BaseException as e:
parent: ~ 55 | raise e
- kind: 56 | except Exception:
name: BlindExcept | ^^^^^^^^^ BLE001
body: "Do not catch blind exception: `BaseException`" 57 | pass
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_blind_except/BLE.py:60:8: BLE001 Do not catch blind exception: `Exception`
row: 45 |
column: 11 60 | try:
end_location: 61 | pass
row: 45 62 | except Exception as e:
column: 24 | ^^^^^^^^^ BLE001
fix: 63 | raise bad
edits: [] 64 | except BaseException:
parent: ~ |
- kind:
name: BlindExcept ./resources/test/fixtures/flake8_blind_except/BLE.py:62:8: BLE001 Do not catch blind exception: `BaseException`
body: "Do not catch blind exception: `Exception`" |
suggestion: ~ 62 | except Exception as e:
fixable: false 63 | raise bad
location: 64 | except BaseException:
row: 54 | ^^^^^^^^^^^^^ BLE001
column: 7 65 | pass
end_location: |
row: 54
column: 16 ./resources/test/fixtures/flake8_blind_except/BLE.py:69:8: BLE001 Do not catch blind exception: `Exception`
fix: |
edits: [] 69 | try:
parent: ~ 70 | pass
- kind: 71 | except Exception:
name: BlindExcept | ^^^^^^^^^ BLE001
body: "Do not catch blind exception: `Exception`" 72 | logging.error("...")
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_blind_except/BLE.py:75:8: BLE001 Do not catch blind exception: `Exception`
row: 60 |
column: 7 75 | try:
end_location: 76 | pass
row: 60 77 | except Exception:
column: 16 | ^^^^^^^^^ BLE001
fix: 78 | logging.error("...", exc_info=False)
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_blind_except/BLE.py:81:8: BLE001 Do not catch blind exception: `Exception`
name: BlindExcept |
body: "Do not catch blind exception: `BaseException`" 81 | try:
suggestion: ~ 82 | pass
fixable: false 83 | except Exception:
location: | ^^^^^^^^^ BLE001
row: 62 84 | logging.error("...", exc_info=None)
column: 7 |
end_location:
row: 62
column: 20
fix:
edits: []
parent: ~
- kind:
name: BlindExcept
body: "Do not catch blind exception: `Exception`"
suggestion: ~
fixable: false
location:
row: 69
column: 7
end_location:
row: 69
column: 16
fix:
edits: []
parent: ~
- kind:
name: BlindExcept
body: "Do not catch blind exception: `Exception`"
suggestion: ~
fixable: false
location:
row: 75
column: 7
end_location:
row: 75
column: 16
fix:
edits: []
parent: ~
- kind:
name: BlindExcept
body: "Do not catch blind exception: `Exception`"
suggestion: ~
fixable: false
location:
row: 81
column: 7
end_location:
row: 81
column: 16
fix:
edits: []
parent: ~

View file

@ -6,12 +6,12 @@ mod tests {
use std::path::Path; use std::path::Path;
use anyhow::Result; use anyhow::Result;
use insta::assert_yaml_snapshot;
use test_case::test_case; use test_case::test_case;
use crate::registry::Rule; use crate::registry::Rule;
use crate::settings;
use crate::test::test_path; use crate::test::test_path;
use crate::{assert_messages, settings};
#[test_case(Rule::BooleanPositionalArgInFunctionDefinition, Path::new("FBT.py"); "FBT001")] #[test_case(Rule::BooleanPositionalArgInFunctionDefinition, Path::new("FBT.py"); "FBT001")]
#[test_case(Rule::BooleanDefaultValueInFunctionDefinition, Path::new("FBT.py"); "FBT002")] #[test_case(Rule::BooleanDefaultValueInFunctionDefinition, Path::new("FBT.py"); "FBT002")]
@ -22,7 +22,7 @@ mod tests {
Path::new("flake8_boolean_trap").join(path).as_path(), Path::new("flake8_boolean_trap").join(path).as_path(),
&settings::Settings::for_rule(rule_code), &settings::Settings::for_rule(rule_code),
)?; )?;
assert_yaml_snapshot!(snapshot, diagnostics); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())
} }
} }

View file

@ -1,131 +1,92 @@
--- ---
source: crates/ruff/src/rules/flake8_boolean_trap/mod.rs source: crates/ruff/src/rules/flake8_boolean_trap/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_boolean_trap/FBT.py:4:5: FBT001 Boolean positional arg in function definition
name: BooleanPositionalArgInFunctionDefinition |
body: Boolean positional arg in function definition 4 | posonly_nohint,
suggestion: ~ 5 | posonly_nonboolhint: int,
fixable: false 6 | posonly_boolhint: bool,
location: | ^^^^^^^^^^^^^^^^^^^^^^ FBT001
row: 4 7 | posonly_boolstrhint: "bool",
column: 4 8 | /,
end_location: |
row: 4
column: 26 ./resources/test/fixtures/flake8_boolean_trap/FBT.py:5:5: FBT001 Boolean positional arg in function definition
fix: |
edits: [] 5 | posonly_nonboolhint: int,
parent: ~ 6 | posonly_boolhint: bool,
- kind: 7 | posonly_boolstrhint: "bool",
name: BooleanPositionalArgInFunctionDefinition | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001
body: Boolean positional arg in function definition 8 | /,
suggestion: ~ 9 | offset,
fixable: false |
location:
row: 5 ./resources/test/fixtures/flake8_boolean_trap/FBT.py:10:5: FBT001 Boolean positional arg in function definition
column: 4 |
end_location: 10 | posorkw_nonvalued_nohint,
row: 5 11 | posorkw_nonvalued_nonboolhint: int,
column: 31 12 | posorkw_nonvalued_boolhint: bool,
fix: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001
edits: [] 13 | posorkw_nonvalued_boolstrhint: "bool",
parent: ~ 14 | posorkw_boolvalued_nohint=True,
- kind: |
name: BooleanPositionalArgInFunctionDefinition
body: Boolean positional arg in function definition ./resources/test/fixtures/flake8_boolean_trap/FBT.py:11:5: FBT001 Boolean positional arg in function definition
suggestion: ~ |
fixable: false 11 | posorkw_nonvalued_nonboolhint: int,
location: 12 | posorkw_nonvalued_boolhint: bool,
row: 10 13 | posorkw_nonvalued_boolstrhint: "bool",
column: 4 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001
end_location: 14 | posorkw_boolvalued_nohint=True,
row: 10 15 | posorkw_boolvalued_nonboolhint: int = True,
column: 36 |
fix:
edits: [] ./resources/test/fixtures/flake8_boolean_trap/FBT.py:14:5: FBT001 Boolean positional arg in function definition
parent: ~ |
- kind: 14 | posorkw_boolvalued_nohint=True,
name: BooleanPositionalArgInFunctionDefinition 15 | posorkw_boolvalued_nonboolhint: int = True,
body: Boolean positional arg in function definition 16 | posorkw_boolvalued_boolhint: bool = True,
suggestion: ~ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001
fixable: false 17 | posorkw_boolvalued_boolstrhint: "bool" = True,
location: 18 | posorkw_nonboolvalued_nohint=1,
row: 11 |
column: 4
end_location: ./resources/test/fixtures/flake8_boolean_trap/FBT.py:15:5: FBT001 Boolean positional arg in function definition
row: 11 |
column: 41 15 | posorkw_boolvalued_nonboolhint: int = True,
fix: 16 | posorkw_boolvalued_boolhint: bool = True,
edits: [] 17 | posorkw_boolvalued_boolstrhint: "bool" = True,
parent: ~ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001
- kind: 18 | posorkw_nonboolvalued_nohint=1,
name: BooleanPositionalArgInFunctionDefinition 19 | posorkw_nonboolvalued_nonboolhint: int = 2,
body: Boolean positional arg in function definition |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_boolean_trap/FBT.py:18:5: FBT001 Boolean positional arg in function definition
location: |
row: 14 18 | posorkw_nonboolvalued_nohint=1,
column: 4 19 | posorkw_nonboolvalued_nonboolhint: int = 2,
end_location: 20 | posorkw_nonboolvalued_boolhint: bool = 3,
row: 14 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001
column: 37 21 | posorkw_nonboolvalued_boolstrhint: "bool" = 4,
fix: 22 | *,
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_boolean_trap/FBT.py:19:5: FBT001 Boolean positional arg in function definition
name: BooleanPositionalArgInFunctionDefinition |
body: Boolean positional arg in function definition 19 | posorkw_nonboolvalued_nonboolhint: int = 2,
suggestion: ~ 20 | posorkw_nonboolvalued_boolhint: bool = 3,
fixable: false 21 | posorkw_nonboolvalued_boolstrhint: "bool" = 4,
location: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001
row: 15 22 | *,
column: 4 23 | kwonly_nonvalued_nohint,
end_location: |
row: 15
column: 42 ./resources/test/fixtures/flake8_boolean_trap/FBT.py:81:19: FBT001 Boolean positional arg in function definition
fix: |
edits: [] 81 | # FBT001: Boolean positional arg in function definition
parent: ~ 82 | def foo(self, value: bool) -> None:
- kind: | ^^^^^^^^^^^ FBT001
name: BooleanPositionalArgInFunctionDefinition 83 | pass
body: Boolean positional arg in function definition |
suggestion: ~
fixable: false
location:
row: 18
column: 4
end_location:
row: 18
column: 40
fix:
edits: []
parent: ~
- kind:
name: BooleanPositionalArgInFunctionDefinition
body: Boolean positional arg in function definition
suggestion: ~
fixable: false
location:
row: 19
column: 4
end_location:
row: 19
column: 45
fix:
edits: []
parent: ~
- kind:
name: BooleanPositionalArgInFunctionDefinition
body: Boolean positional arg in function definition
suggestion: ~
fixable: false
location:
row: 81
column: 18
end_location:
row: 81
column: 29
fix:
edits: []
parent: ~

View file

@ -1,61 +1,44 @@
--- ---
source: crates/ruff/src/rules/flake8_boolean_trap/mod.rs source: crates/ruff/src/rules/flake8_boolean_trap/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_boolean_trap/FBT.py:12:31: FBT002 Boolean default value in function definition
name: BooleanDefaultValueInFunctionDefinition |
body: Boolean default value in function definition 12 | posorkw_nonvalued_boolhint: bool,
suggestion: ~ 13 | posorkw_nonvalued_boolstrhint: "bool",
fixable: false 14 | posorkw_boolvalued_nohint=True,
location: | ^^^^ FBT002
row: 12 15 | posorkw_boolvalued_nonboolhint: int = True,
column: 30 16 | posorkw_boolvalued_boolhint: bool = True,
end_location: |
row: 12
column: 34 ./resources/test/fixtures/flake8_boolean_trap/FBT.py:13:43: FBT002 Boolean default value in function definition
fix: |
edits: [] 13 | posorkw_nonvalued_boolstrhint: "bool",
parent: ~ 14 | posorkw_boolvalued_nohint=True,
- kind: 15 | posorkw_boolvalued_nonboolhint: int = True,
name: BooleanDefaultValueInFunctionDefinition | ^^^^ FBT002
body: Boolean default value in function definition 16 | posorkw_boolvalued_boolhint: bool = True,
suggestion: ~ 17 | posorkw_boolvalued_boolstrhint: "bool" = True,
fixable: false |
location:
row: 13 ./resources/test/fixtures/flake8_boolean_trap/FBT.py:14:41: FBT002 Boolean default value in function definition
column: 42 |
end_location: 14 | posorkw_boolvalued_nohint=True,
row: 13 15 | posorkw_boolvalued_nonboolhint: int = True,
column: 46 16 | posorkw_boolvalued_boolhint: bool = True,
fix: | ^^^^ FBT002
edits: [] 17 | posorkw_boolvalued_boolstrhint: "bool" = True,
parent: ~ 18 | posorkw_nonboolvalued_nohint=1,
- kind: |
name: BooleanDefaultValueInFunctionDefinition
body: Boolean default value in function definition ./resources/test/fixtures/flake8_boolean_trap/FBT.py:15:46: FBT002 Boolean default value in function definition
suggestion: ~ |
fixable: false 15 | posorkw_boolvalued_nonboolhint: int = True,
location: 16 | posorkw_boolvalued_boolhint: bool = True,
row: 14 17 | posorkw_boolvalued_boolstrhint: "bool" = True,
column: 40 | ^^^^ FBT002
end_location: 18 | posorkw_nonboolvalued_nohint=1,
row: 14 19 | posorkw_nonboolvalued_nonboolhint: int = 2,
column: 44 |
fix:
edits: []
parent: ~
- kind:
name: BooleanDefaultValueInFunctionDefinition
body: Boolean default value in function definition
suggestion: ~
fixable: false
location:
row: 15
column: 45
end_location:
row: 15
column: 49
fix:
edits: []
parent: ~

View file

@ -1,47 +1,31 @@
--- ---
source: crates/ruff/src/rules/flake8_boolean_trap/mod.rs source: crates/ruff/src/rules/flake8_boolean_trap/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_boolean_trap/FBT.py:42:11: FBT003 Boolean positional value in function call
name: BooleanPositionalValueInFunctionCall |
body: Boolean positional value in function call 42 | used("a", True)
suggestion: ~ | ^^^^ FBT003
fixable: false 43 | used(do=True)
location: |
row: 42
column: 10 ./resources/test/fixtures/flake8_boolean_trap/FBT.py:57:11: FBT003 Boolean positional value in function call
end_location: |
row: 42 57 | {}.pop(True, False)
column: 14 58 | dict.fromkeys(("world",), True)
fix: 59 | {}.deploy(True, False)
edits: [] | ^^^^ FBT003
parent: ~ 60 | getattr(someobj, attrname, False)
- kind: 61 | mylist.index(True)
name: BooleanPositionalValueInFunctionCall |
body: Boolean positional value in function call
suggestion: ~ ./resources/test/fixtures/flake8_boolean_trap/FBT.py:57:17: FBT003 Boolean positional value in function call
fixable: false |
location: 57 | {}.pop(True, False)
row: 57 58 | dict.fromkeys(("world",), True)
column: 10 59 | {}.deploy(True, False)
end_location: | ^^^^^ FBT003
row: 57 60 | getattr(someobj, attrname, False)
column: 14 61 | mylist.index(True)
fix: |
edits: []
parent: ~
- kind:
name: BooleanPositionalValueInFunctionCall
body: Boolean positional value in function call
suggestion: ~
fixable: false
location:
row: 57
column: 16
end_location:
row: 57
column: 21
fix:
edits: []
parent: ~

View file

@ -6,8 +6,9 @@ pub mod settings;
mod tests { mod tests {
use std::path::Path; use std::path::Path;
use crate::assert_messages;
use anyhow::Result; use anyhow::Result;
use insta::assert_yaml_snapshot;
use test_case::test_case; use test_case::test_case;
use crate::registry::Rule; use crate::registry::Rule;
@ -54,7 +55,7 @@ mod tests {
Path::new("flake8_bugbear").join(path).as_path(), Path::new("flake8_bugbear").join(path).as_path(),
&Settings::for_rule(rule_code), &Settings::for_rule(rule_code),
)?; )?;
assert_yaml_snapshot!(snapshot, diagnostics); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())
} }
@ -73,7 +74,7 @@ mod tests {
..Settings::for_rules(vec![Rule::FunctionCallInDefaultArgument]) ..Settings::for_rules(vec![Rule::FunctionCallInDefaultArgument])
}, },
)?; )?;
assert_yaml_snapshot!(snapshot, diagnostics); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())
} }
} }

View file

@ -1,33 +1,19 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B002.py:15:9: B002 Python does not support the unary prefix increment
name: UnaryPrefixIncrement |
body: Python does not support the unary prefix increment 15 | def this_is_buggy(n):
suggestion: ~ 16 | x = ++n
fixable: false | ^^^ B002
location: 17 | return x
row: 15 |
column: 8
end_location: ./resources/test/fixtures/flake8_bugbear/B002.py:20:12: B002 Python does not support the unary prefix increment
row: 15 |
column: 11 20 | def this_is_buggy_too(n):
fix: 21 | return ++n
edits: [] | ^^^ B002
parent: ~ |
- kind:
name: UnaryPrefixIncrement
body: Python does not support the unary prefix increment
suggestion: ~
fixable: false
location:
row: 20
column: 11
end_location:
row: 20
column: 14
fix:
edits: []
parent: ~

View file

@ -1,19 +1,13 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B003.py:9:1: B003 Assigning to `os.environ` doesn't clear the environment
name: AssignmentToOsEnviron |
body: "Assigning to `os.environ` doesn't clear the environment" 9 | from os import environ
suggestion: ~ 10 |
fixable: false 11 | os.environ = {}
location: | ^^^^^^^^^^ B003
row: 9 12 | environ = {} # that's fine, assigning a new meaning to the module-level name
column: 0 |
end_location:
row: 9
column: 10
fix:
edits: []
parent: ~

View file

@ -1,33 +1,23 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B004.py:3:8: B004 Using `hasattr(x, '__call__')` to test if x is callable is unreliable. Use `callable(x)` for consistent results.
name: UnreliableCallableCheck |
body: "Using `hasattr(x, '__call__')` to test if x is callable is unreliable. Use `callable(x)` for consistent results." 3 | def this_is_a_bug():
suggestion: ~ 4 | o = object()
fixable: false 5 | if hasattr(o, "__call__"):
location: | ^^^^^^^^^^^^^^^^^^^^^^ B004
row: 3 6 | print("Ooh, callable! Or is it?")
column: 7 7 | if getattr(o, "__call__", False):
end_location: |
row: 3
column: 29 ./resources/test/fixtures/flake8_bugbear/B004.py:5:8: B004 Using `hasattr(x, '__call__')` to test if x is callable is unreliable. Use `callable(x)` for consistent results.
fix: |
edits: [] 5 | if hasattr(o, "__call__"):
parent: ~ 6 | print("Ooh, callable! Or is it?")
- kind: 7 | if getattr(o, "__call__", False):
name: UnreliableCallableCheck | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B004
body: "Using `hasattr(x, '__call__')` to test if x is callable is unreliable. Use `callable(x)` for consistent results." 8 | print("Ooh, callable! Or is it?")
suggestion: ~ |
fixable: false
location:
row: 5
column: 7
end_location:
row: 5
column: 36
fix:
edits: []
parent: ~

View file

@ -1,117 +1,84 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B005.py:4:1: B005 Using `.strip()` with multi-character strings is misleading the reader
name: StripWithMultiCharacters |
body: "Using `.strip()` with multi-character strings is misleading the reader" 4 | s.strip(s) # no warning
suggestion: ~ 5 | s.strip("we") # no warning
fixable: false 6 | s.strip(".facebook.com") # warning
location: | ^^^^^^^^^^^^^^^^^^^^^^^^ B005
row: 4 7 | s.strip("e") # no warning
column: 0 8 | s.strip("\n\t ") # no warning
end_location: |
row: 4
column: 24 ./resources/test/fixtures/flake8_bugbear/B005.py:7:1: B005 Using `.strip()` with multi-character strings is misleading the reader
fix: |
edits: [] 7 | s.strip("e") # no warning
parent: ~ 8 | s.strip("\n\t ") # no warning
- kind: 9 | s.strip(r"\n\t ") # warning
name: StripWithMultiCharacters | ^^^^^^^^^^^^^^^^^ B005
body: "Using `.strip()` with multi-character strings is misleading the reader" 10 | s.lstrip(s) # no warning
suggestion: ~ 11 | s.lstrip("we") # no warning
fixable: false |
location:
row: 7 ./resources/test/fixtures/flake8_bugbear/B005.py:10:1: B005 Using `.strip()` with multi-character strings is misleading the reader
column: 0 |
end_location: 10 | s.lstrip(s) # no warning
row: 7 11 | s.lstrip("we") # no warning
column: 17 12 | s.lstrip(".facebook.com") # warning
fix: | ^^^^^^^^^^^^^^^^^^^^^^^^^ B005
edits: [] 13 | s.lstrip("e") # no warning
parent: ~ 14 | s.lstrip("\n\t ") # no warning
- kind: |
name: StripWithMultiCharacters
body: "Using `.strip()` with multi-character strings is misleading the reader" ./resources/test/fixtures/flake8_bugbear/B005.py:13:1: B005 Using `.strip()` with multi-character strings is misleading the reader
suggestion: ~ |
fixable: false 13 | s.lstrip("e") # no warning
location: 14 | s.lstrip("\n\t ") # no warning
row: 10 15 | s.lstrip(r"\n\t ") # warning
column: 0 | ^^^^^^^^^^^^^^^^^^ B005
end_location: 16 | s.rstrip(s) # no warning
row: 10 17 | s.rstrip("we") # warning
column: 25 |
fix:
edits: [] ./resources/test/fixtures/flake8_bugbear/B005.py:16:1: B005 Using `.strip()` with multi-character strings is misleading the reader
parent: ~ |
- kind: 16 | s.rstrip(s) # no warning
name: StripWithMultiCharacters 17 | s.rstrip("we") # warning
body: "Using `.strip()` with multi-character strings is misleading the reader" 18 | s.rstrip(".facebook.com") # warning
suggestion: ~ | ^^^^^^^^^^^^^^^^^^^^^^^^^ B005
fixable: false 19 | s.rstrip("e") # no warning
location: 20 | s.rstrip("\n\t ") # no warning
row: 13 |
column: 0
end_location: ./resources/test/fixtures/flake8_bugbear/B005.py:19:1: B005 Using `.strip()` with multi-character strings is misleading the reader
row: 13 |
column: 18 19 | s.rstrip("e") # no warning
fix: 20 | s.rstrip("\n\t ") # no warning
edits: [] 21 | s.rstrip(r"\n\t ") # warning
parent: ~ | ^^^^^^^^^^^^^^^^^^ B005
- kind: 22 | s.strip("a") # no warning
name: StripWithMultiCharacters 23 | s.strip("あ") # no warning
body: "Using `.strip()` with multi-character strings is misleading the reader" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B005.py:22:1: B005 Using `.strip()` with multi-character strings is misleading the reader
location: |
row: 16 22 | s.strip("a") # no warning
column: 0 23 | s.strip("あ") # no warning
end_location: 24 | s.strip("ああ") # warning
row: 16 | ^^^^^^^^^^^^^^^ B005
column: 25 25 | s.strip("\ufeff") # no warning
fix: 26 | s.strip("\u0074\u0065\u0073\u0074") # warning
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B005.py:24:1: B005 Using `.strip()` with multi-character strings is misleading the reader
name: StripWithMultiCharacters |
body: "Using `.strip()` with multi-character strings is misleading the reader" 24 | s.strip("ああ") # warning
suggestion: ~ 25 | s.strip("\ufeff") # no warning
fixable: false 26 | s.strip("\u0074\u0065\u0073\u0074") # warning
location: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B005
row: 19 27 |
column: 0 28 | from somewhere import other_type, strip
end_location: |
row: 19
column: 18
fix:
edits: []
parent: ~
- kind:
name: StripWithMultiCharacters
body: "Using `.strip()` with multi-character strings is misleading the reader"
suggestion: ~
fixable: false
location:
row: 22
column: 0
end_location:
row: 22
column: 13
fix:
edits: []
parent: ~
- kind:
name: StripWithMultiCharacters
body: "Using `.strip()` with multi-character strings is misleading the reader"
suggestion: ~
fixable: false
location:
row: 24
column: 0
end_location:
row: 24
column: 35
fix:
edits: []
parent: ~

View file

@ -1,201 +1,113 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B006_B008.py:62:25: B006 Do not use mutable data structures for argument defaults
name: MutableArgumentDefault |
body: Do not use mutable data structures for argument defaults 62 | def this_is_wrong(value=[1, 2, 3]):
suggestion: ~ | ^^^^^^^^^ B006
fixable: false 63 | ...
location: |
row: 62
column: 24 ./resources/test/fixtures/flake8_bugbear/B006_B008.py:66:30: B006 Do not use mutable data structures for argument defaults
end_location: |
row: 62 66 | def this_is_also_wrong(value={}):
column: 33 | ^^ B006
fix: 67 | ...
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B006_B008.py:70:20: B006 Do not use mutable data structures for argument defaults
name: MutableArgumentDefault |
body: Do not use mutable data structures for argument defaults 70 | def and_this(value=set()):
suggestion: ~ | ^^^^^ B006
fixable: false 71 | ...
location: |
row: 66
column: 29 ./resources/test/fixtures/flake8_bugbear/B006_B008.py:74:20: B006 Do not use mutable data structures for argument defaults
end_location: |
row: 66 74 | def this_too(value=collections.OrderedDict()):
column: 31 | ^^^^^^^^^^^^^^^^^^^^^^^^^ B006
fix: 75 | ...
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B006_B008.py:78:32: B006 Do not use mutable data structures for argument defaults
name: MutableArgumentDefault |
body: Do not use mutable data structures for argument defaults 78 | async def async_this_too(value=collections.defaultdict()):
suggestion: ~ | ^^^^^^^^^^^^^^^^^^^^^^^^^ B006
fixable: false 79 | ...
location: |
row: 70
column: 19 ./resources/test/fixtures/flake8_bugbear/B006_B008.py:82:26: B006 Do not use mutable data structures for argument defaults
end_location: |
row: 70 82 | def dont_forget_me(value=collections.deque()):
column: 24 | ^^^^^^^^^^^^^^^^^^^ B006
fix: 83 | ...
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B006_B008.py:87:46: B006 Do not use mutable data structures for argument defaults
name: MutableArgumentDefault |
body: Do not use mutable data structures for argument defaults 87 | # N.B. we're also flagging the function call in the comprehension
suggestion: ~ 88 | def list_comprehension_also_not_okay(default=[i**2 for i in range(3)]):
fixable: false | ^^^^^^^^^^^^^^^^^^^^^^^^ B006
location: 89 | pass
row: 74 |
column: 19
end_location: ./resources/test/fixtures/flake8_bugbear/B006_B008.py:91:46: B006 Do not use mutable data structures for argument defaults
row: 74 |
column: 44 91 | def dict_comprehension_also_not_okay(default={i: i**2 for i in range(3)}):
fix: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ B006
edits: [] 92 | pass
parent: ~ |
- kind:
name: MutableArgumentDefault ./resources/test/fixtures/flake8_bugbear/B006_B008.py:95:45: B006 Do not use mutable data structures for argument defaults
body: Do not use mutable data structures for argument defaults |
suggestion: ~ 95 | def set_comprehension_also_not_okay(default={i**2 for i in range(3)}):
fixable: false | ^^^^^^^^^^^^^^^^^^^^^^^^ B006
location: 96 | pass
row: 78 |
column: 31
end_location: ./resources/test/fixtures/flake8_bugbear/B006_B008.py:99:33: B006 Do not use mutable data structures for argument defaults
row: 78 |
column: 56 99 | def kwonlyargs_mutable(*, value=[]):
fix: | ^^ B006
edits: [] 100 | ...
parent: ~ |
- kind:
name: MutableArgumentDefault ./resources/test/fixtures/flake8_bugbear/B006_B008.py:192:20: B006 Do not use mutable data structures for argument defaults
body: Do not use mutable data structures for argument defaults |
suggestion: ~ 192 | # B006 and B008
fixable: false 193 | # We should handle arbitrary nesting of these B008.
location: 194 | def nested_combo(a=[float(3), dt.datetime.now()]):
row: 82 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B006
column: 25 195 | pass
end_location: |
row: 82
column: 44 ./resources/test/fixtures/flake8_bugbear/B006_B008.py:225:27: B006 Do not use mutable data structures for argument defaults
fix: |
edits: [] 225 | def mutable_annotations(
parent: ~ 226 | a: list[int] | None = [],
- kind: | ^^ B006
name: MutableArgumentDefault 227 | b: Optional[Dict[int, int]] = {},
body: Do not use mutable data structures for argument defaults 228 | c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bugbear/B006_B008.py:226:35: B006 Do not use mutable data structures for argument defaults
row: 87 |
column: 45 226 | def mutable_annotations(
end_location: 227 | a: list[int] | None = [],
row: 87 228 | b: Optional[Dict[int, int]] = {},
column: 69 | ^^ B006
fix: 229 | c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
edits: [] 230 | ):
parent: ~ |
- kind:
name: MutableArgumentDefault ./resources/test/fixtures/flake8_bugbear/B006_B008.py:227:62: B006 Do not use mutable data structures for argument defaults
body: Do not use mutable data structures for argument defaults |
suggestion: ~ 227 | a: list[int] | None = [],
fixable: false 228 | b: Optional[Dict[int, int]] = {},
location: 229 | c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
row: 91 | ^^^^^ B006
column: 45 230 | ):
end_location: 231 | pass
row: 91 |
column: 72
fix:
edits: []
parent: ~
- kind:
name: MutableArgumentDefault
body: Do not use mutable data structures for argument defaults
suggestion: ~
fixable: false
location:
row: 95
column: 44
end_location:
row: 95
column: 68
fix:
edits: []
parent: ~
- kind:
name: MutableArgumentDefault
body: Do not use mutable data structures for argument defaults
suggestion: ~
fixable: false
location:
row: 99
column: 32
end_location:
row: 99
column: 34
fix:
edits: []
parent: ~
- kind:
name: MutableArgumentDefault
body: Do not use mutable data structures for argument defaults
suggestion: ~
fixable: false
location:
row: 192
column: 19
end_location:
row: 192
column: 48
fix:
edits: []
parent: ~
- kind:
name: MutableArgumentDefault
body: Do not use mutable data structures for argument defaults
suggestion: ~
fixable: false
location:
row: 225
column: 26
end_location:
row: 225
column: 28
fix:
edits: []
parent: ~
- kind:
name: MutableArgumentDefault
body: Do not use mutable data structures for argument defaults
suggestion: ~
fixable: false
location:
row: 226
column: 34
end_location:
row: 226
column: 36
fix:
edits: []
parent: ~
- kind:
name: MutableArgumentDefault
body: Do not use mutable data structures for argument defaults
suggestion: ~
fixable: false
location:
row: 227
column: 61
end_location:
row: 227
column: 66
fix:
edits: []
parent: ~

View file

@ -1,222 +1,181 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B007.py:6:5: B007 [*] Loop control variable `i` not used within loop body
name: UnusedLoopControlVariable |
body: "Loop control variable `i` not used within loop body" 6 | print(i) # name no longer defined on Python 3; no warning yet
suggestion: "Rename unused `i` to `_i`" 7 |
fixable: true 8 | for i in range(10): # name not used within the loop; B007
location: | ^ B007
row: 6 9 | print(10)
column: 4 |
end_location: = help: Rename unused `i` to `_i`
row: 6
column: 5 ./resources/test/fixtures/flake8_bugbear/B007.py:18:13: B007 [*] Loop control variable `k` not used within loop body
fix: |
edits: [] 18 | for i in range(10):
parent: ~ 19 | for j in range(10):
- kind: 20 | for k in range(10): # k not used, i and j used transitively
name: UnusedLoopControlVariable | ^ B007
body: "Loop control variable `k` not used within loop body" 21 | print(i + j)
suggestion: "Rename unused `k` to `_k`" |
fixable: true = help: Rename unused `k` to `_k`
location:
row: 18 Suggested fix
column: 12 15 15 |
end_location: 16 16 | for i in range(10):
row: 18 17 17 | for j in range(10):
column: 13 18 |- for k in range(10): # k not used, i and j used transitively
fix: 18 |+ for _k in range(10): # k not used, i and j used transitively
edits: 19 19 | print(i + j)
- location: 20 20 |
row: 18 21 21 |
column: 12
end_location: ./resources/test/fixtures/flake8_bugbear/B007.py:30:5: B007 [*] Loop control variable `i` not used within loop body
row: 18 |
column: 13 30 | for i, (j, (k, l)) in strange_generator(): # i, k not used
content: _k | ^ B007
parent: ~ 31 | print(j, l)
- kind: |
name: UnusedLoopControlVariable = help: Rename unused `i` to `_i`
body: "Loop control variable `i` not used within loop body"
suggestion: "Rename unused `i` to `_i`" ./resources/test/fixtures/flake8_bugbear/B007.py:30:13: B007 [*] Loop control variable `k` not used within loop body
fixable: true |
location: 30 | for i, (j, (k, l)) in strange_generator(): # i, k not used
row: 30 | ^ B007
column: 4 31 | print(j, l)
end_location: |
row: 30 = help: Rename unused `k` to `_k`
column: 5
fix: Suggested fix
edits: [] 27 27 | yield i, (j, (k, l))
parent: ~ 28 28 |
- kind: 29 29 |
name: UnusedLoopControlVariable 30 |-for i, (j, (k, l)) in strange_generator(): # i, k not used
body: "Loop control variable `k` not used within loop body" 30 |+for i, (j, (_k, l)) in strange_generator(): # i, k not used
suggestion: "Rename unused `k` to `_k`" 31 31 | print(j, l)
fixable: true 32 32 |
location: 33 33 | FMT = "{foo} {bar}"
row: 30
column: 12 ./resources/test/fixtures/flake8_bugbear/B007.py:34:10: B007 Loop control variable `bar` may not be used within loop body
end_location: |
row: 30 34 | FMT = "{foo} {bar}"
column: 13 35 | for foo, bar in [(1, 2)]:
fix: | ^^^ B007
edits: 36 | if foo:
- location: 37 | print(FMT.format(**locals()))
row: 30 |
column: 12
end_location: ./resources/test/fixtures/flake8_bugbear/B007.py:38:10: B007 Loop control variable `bar` may not be used within loop body
row: 30 |
column: 13 38 | print(FMT.format(**locals()))
content: _k 39 |
parent: ~ 40 | for foo, bar in [(1, 2)]:
- kind: | ^^^ B007
name: UnusedLoopControlVariable 41 | if foo:
body: "Loop control variable `bar` may not be used within loop body" 42 | print(FMT.format(**globals()))
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bugbear/B007.py:42:10: B007 Loop control variable `bar` may not be used within loop body
row: 34 |
column: 9 42 | print(FMT.format(**globals()))
end_location: 43 |
row: 34 44 | for foo, bar in [(1, 2)]:
column: 12 | ^^^ B007
fix: 45 | if foo:
edits: [] 46 | print(FMT.format(**vars()))
parent: ~ |
- kind:
name: UnusedLoopControlVariable ./resources/test/fixtures/flake8_bugbear/B007.py:46:10: B007 Loop control variable `bar` may not be used within loop body
body: "Loop control variable `bar` may not be used within loop body" |
suggestion: ~ 46 | print(FMT.format(**vars()))
fixable: false 47 |
location: 48 | for foo, bar in [(1, 2)]:
row: 38 | ^^^ B007
column: 9 49 | print(FMT.format(foo=foo, bar=eval("bar")))
end_location: |
row: 38
column: 12 ./resources/test/fixtures/flake8_bugbear/B007.py:52:14: B007 [*] Loop control variable `bar` not used within loop body
fix: |
edits: [] 52 | def f():
parent: ~ 53 | # Fixable.
- kind: 54 | for foo, bar, baz in (["1", "2", "3"],):
name: UnusedLoopControlVariable | ^^^ B007
body: "Loop control variable `bar` may not be used within loop body" 55 | if foo or baz:
suggestion: ~ 56 | break
fixable: false |
location: = help: Rename unused `bar` to `_bar`
row: 42
column: 9 Suggested fix
end_location: 49 49 |
row: 42 50 50 | def f():
column: 12 51 51 | # Fixable.
fix: 52 |- for foo, bar, baz in (["1", "2", "3"],):
edits: [] 52 |+ for foo, _bar, baz in (["1", "2", "3"],):
parent: ~ 53 53 | if foo or baz:
- kind: 54 54 | break
name: UnusedLoopControlVariable 55 55 |
body: "Loop control variable `bar` may not be used within loop body"
suggestion: ~ ./resources/test/fixtures/flake8_bugbear/B007.py:59:14: B007 [*] Loop control variable `bar` not used within loop body
fixable: false |
location: 59 | def f():
row: 46 60 | # Unfixable due to usage of `bar` outside of loop.
column: 9 61 | for foo, bar, baz in (["1", "2", "3"],):
end_location: | ^^^ B007
row: 46 62 | if foo or baz:
column: 12 63 | break
fix: |
edits: [] = help: Rename unused `bar` to `_bar`
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B007.py:68:14: B007 [*] Loop control variable `bar` not used within loop body
name: UnusedLoopControlVariable |
body: "Loop control variable `bar` not used within loop body" 68 | def f():
suggestion: "Rename unused `bar` to `_bar`" 69 | # Fixable.
fixable: true 70 | for foo, bar, baz in (["1", "2", "3"],):
location: | ^^^ B007
row: 52 71 | if foo or baz:
column: 13 72 | break
end_location: |
row: 52 = help: Rename unused `bar` to `_bar`
column: 16
fix: Suggested fix
edits: 65 65 |
- location: 66 66 | def f():
row: 52 67 67 | # Fixable.
column: 13 68 |- for foo, bar, baz in (["1", "2", "3"],):
end_location: 68 |+ for foo, _bar, baz in (["1", "2", "3"],):
row: 52 69 69 | if foo or baz:
column: 16 70 70 | break
content: _bar 71 71 |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B007.py:77:14: B007 [*] Loop control variable `bar` not used within loop body
name: UnusedLoopControlVariable |
body: "Loop control variable `bar` not used within loop body" 77 | def f():
suggestion: "Rename unused `bar` to `_bar`" 78 | # Fixable.
fixable: true 79 | for foo, bar, baz in (["1", "2", "3"],):
location: | ^^^ B007
row: 59 80 | if foo or baz:
column: 13 81 | break
end_location: |
row: 59 = help: Rename unused `bar` to `_bar`
column: 16
fix: Suggested fix
edits: [] 74 74 |
parent: ~ 75 75 | def f():
- kind: 76 76 | # Fixable.
name: UnusedLoopControlVariable 77 |- for foo, bar, baz in (["1", "2", "3"],):
body: "Loop control variable `bar` not used within loop body" 77 |+ for foo, _bar, baz in (["1", "2", "3"],):
suggestion: "Rename unused `bar` to `_bar`" 78 78 | if foo or baz:
fixable: true 79 79 | break
location: 80 80 |
row: 68
column: 13 ./resources/test/fixtures/flake8_bugbear/B007.py:87:5: B007 Loop control variable `line_` not used within loop body
end_location: |
row: 68 87 | # Unfixable due to trailing underscore (`_line_` wouldn't be considered an ignorable
column: 16 88 | # variable name).
fix: 89 | for line_ in range(self.header_lines):
edits: | ^^^^^ B007
- location: 90 | fp.readline()
row: 68 |
column: 13
end_location:
row: 68
column: 16
content: _bar
parent: ~
- kind:
name: UnusedLoopControlVariable
body: "Loop control variable `bar` not used within loop body"
suggestion: "Rename unused `bar` to `_bar`"
fixable: true
location:
row: 77
column: 13
end_location:
row: 77
column: 16
fix:
edits:
- location:
row: 77
column: 13
end_location:
row: 77
column: 16
content: _bar
parent: ~
- kind:
name: UnusedLoopControlVariable
body: "Loop control variable `line_` not used within loop body"
suggestion: ~
fixable: false
location:
row: 87
column: 4
end_location:
row: 87
column: 9
fix:
edits: []
parent: ~

View file

@ -1,201 +1,114 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B006_B008.py:87:61: B008 Do not perform function call `range` in argument defaults
name: FunctionCallInDefaultArgument |
body: "Do not perform function call `range` in argument defaults" 87 | # N.B. we're also flagging the function call in the comprehension
suggestion: ~ 88 | def list_comprehension_also_not_okay(default=[i**2 for i in range(3)]):
fixable: false | ^^^^^^^^ B008
location: 89 | pass
row: 87 |
column: 60
end_location: ./resources/test/fixtures/flake8_bugbear/B006_B008.py:91:64: B008 Do not perform function call `range` in argument defaults
row: 87 |
column: 68 91 | def dict_comprehension_also_not_okay(default={i: i**2 for i in range(3)}):
fix: | ^^^^^^^^ B008
edits: [] 92 | pass
parent: ~ |
- kind:
name: FunctionCallInDefaultArgument ./resources/test/fixtures/flake8_bugbear/B006_B008.py:95:60: B008 Do not perform function call `range` in argument defaults
body: "Do not perform function call `range` in argument defaults" |
suggestion: ~ 95 | def set_comprehension_also_not_okay(default={i**2 for i in range(3)}):
fixable: false | ^^^^^^^^ B008
location: 96 | pass
row: 91 |
column: 63
end_location: ./resources/test/fixtures/flake8_bugbear/B006_B008.py:111:39: B008 Do not perform function call `time.time` in argument defaults
row: 91 |
column: 71 111 | # B008
fix: 112 | # Flag function calls as default args (including if they are part of a sub-expression)
edits: [] 113 | def in_fact_all_calls_are_wrong(value=time.time()):
parent: ~ | ^^^^^^^^^^^ B008
- kind: 114 | ...
name: FunctionCallInDefaultArgument |
body: "Do not perform function call `range` in argument defaults"
suggestion: ~ ./resources/test/fixtures/flake8_bugbear/B006_B008.py:115:12: B008 Do not perform function call `dt.datetime.now` in argument defaults
fixable: false |
location: 115 | def f(when=dt.datetime.now() + dt.timedelta(days=7)):
row: 95 | ^^^^^^^^^^^^^^^^^ B008
column: 59 116 | pass
end_location: |
row: 95
column: 67 ./resources/test/fixtures/flake8_bugbear/B006_B008.py:119:30: B008 Do not perform function call in argument defaults
fix: |
edits: [] 119 | def can_even_catch_lambdas(a=(lambda x: x)()):
parent: ~ | ^^^^^^^^^^^^^^^ B008
- kind: 120 | ...
name: FunctionCallInDefaultArgument |
body: "Do not perform function call `time.time` in argument defaults"
suggestion: ~ ./resources/test/fixtures/flake8_bugbear/B006_B008.py:157:34: B008 Do not perform function call `float` in argument defaults
fixable: false |
location: 157 | def float_infinity_literal(value=float("1e999")):
row: 111 | ^^^^^^^^^^^^^^ B008
column: 38 158 | pass
end_location: |
row: 111
column: 49 ./resources/test/fixtures/flake8_bugbear/B006_B008.py:162:30: B008 Do not perform function call `float` in argument defaults
fix: |
edits: [] 162 | # But don't allow standard floats
parent: ~ 163 | def float_int_is_wrong(value=float(3)):
- kind: | ^^^^^^^^ B008
name: FunctionCallInDefaultArgument 164 | pass
body: "Do not perform function call `dt.datetime.now` in argument defaults" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B006_B008.py:166:45: B008 Do not perform function call `float` in argument defaults
location: |
row: 115 166 | def float_str_not_inf_or_nan_is_wrong(value=float("3.14")):
column: 11 | ^^^^^^^^^^^^^ B008
end_location: 167 | pass
row: 115 |
column: 28
fix: ./resources/test/fixtures/flake8_bugbear/B006_B008.py:192:21: B008 Do not perform function call `float` in argument defaults
edits: [] |
parent: ~ 192 | # B006 and B008
- kind: 193 | # We should handle arbitrary nesting of these B008.
name: FunctionCallInDefaultArgument 194 | def nested_combo(a=[float(3), dt.datetime.now()]):
body: Do not perform function call in argument defaults | ^^^^^^^^ B008
suggestion: ~ 195 | pass
fixable: false |
location:
row: 119 ./resources/test/fixtures/flake8_bugbear/B006_B008.py:192:31: B008 Do not perform function call `dt.datetime.now` in argument defaults
column: 29 |
end_location: 192 | # B006 and B008
row: 119 193 | # We should handle arbitrary nesting of these B008.
column: 44 194 | def nested_combo(a=[float(3), dt.datetime.now()]):
fix: | ^^^^^^^^^^^^^^^^^ B008
edits: [] 195 | pass
parent: ~ |
- kind:
name: FunctionCallInDefaultArgument ./resources/test/fixtures/flake8_bugbear/B006_B008.py:198:22: B008 Do not perform function call `map` in argument defaults
body: "Do not perform function call `float` in argument defaults" |
suggestion: ~ 198 | # Don't flag nested B006 since we can't guarantee that
fixable: false 199 | # it isn't made mutable by the outer operation.
location: 200 | def no_nested_b006(a=map(lambda s: s.upper(), ["a", "b", "c"])):
row: 157 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B008
column: 33 201 | pass
end_location: |
row: 157
column: 47 ./resources/test/fixtures/flake8_bugbear/B006_B008.py:203:19: B008 Do not perform function call `random.randint` in argument defaults
fix: |
edits: [] 203 | # B008-ception.
parent: ~ 204 | def nested_b008(a=random.randint(0, dt.datetime.now().year)):
- kind: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B008
name: FunctionCallInDefaultArgument 205 | pass
body: "Do not perform function call `float` in argument defaults" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B006_B008.py:203:37: B008 Do not perform function call `dt.datetime.now` in argument defaults
location: |
row: 162 203 | # B008-ception.
column: 29 204 | def nested_b008(a=random.randint(0, dt.datetime.now().year)):
end_location: | ^^^^^^^^^^^^^^^^^ B008
row: 162 205 | pass
column: 37 |
fix:
edits: []
parent: ~
- kind:
name: FunctionCallInDefaultArgument
body: "Do not perform function call `float` in argument defaults"
suggestion: ~
fixable: false
location:
row: 166
column: 44
end_location:
row: 166
column: 57
fix:
edits: []
parent: ~
- kind:
name: FunctionCallInDefaultArgument
body: "Do not perform function call `float` in argument defaults"
suggestion: ~
fixable: false
location:
row: 192
column: 20
end_location:
row: 192
column: 28
fix:
edits: []
parent: ~
- kind:
name: FunctionCallInDefaultArgument
body: "Do not perform function call `dt.datetime.now` in argument defaults"
suggestion: ~
fixable: false
location:
row: 192
column: 30
end_location:
row: 192
column: 47
fix:
edits: []
parent: ~
- kind:
name: FunctionCallInDefaultArgument
body: "Do not perform function call `map` in argument defaults"
suggestion: ~
fixable: false
location:
row: 198
column: 21
end_location:
row: 198
column: 62
fix:
edits: []
parent: ~
- kind:
name: FunctionCallInDefaultArgument
body: "Do not perform function call `random.randint` in argument defaults"
suggestion: ~
fixable: false
location:
row: 203
column: 18
end_location:
row: 203
column: 59
fix:
edits: []
parent: ~
- kind:
name: FunctionCallInDefaultArgument
body: "Do not perform function call `dt.datetime.now` in argument defaults"
suggestion: ~
fixable: false
location:
row: 203
column: 36
end_location:
row: 203
column: 53
fix:
edits: []
parent: ~

View file

@ -1,152 +1,149 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B009_B010.py:19:1: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access.
name: GetAttrWithConstant |
body: "Do not call `getattr` with a constant attribute value. It is not any safer than normal property access." 19 | # Invalid usage
suggestion: "Replace `getattr` with attribute access" 20 | getattr(foo, "bar")
fixable: true | ^^^^^^^^^^^^^^^^^^^ B009
location: 21 | getattr(foo, "_123abc")
row: 19 22 | getattr(foo, "__123abc__")
column: 0 |
end_location: = help: Replace `getattr` with attribute access
row: 19
column: 19 Suggested fix
fix: 16 16 | getattr(foo, "__123abc")
edits: 17 17 |
- location: 18 18 | # Invalid usage
row: 19 19 |-getattr(foo, "bar")
column: 0 19 |+foo.bar
end_location: 20 20 | getattr(foo, "_123abc")
row: 19 21 21 | getattr(foo, "__123abc__")
column: 19 22 22 | getattr(foo, "abc123")
content: foo.bar
parent: ~ ./resources/test/fixtures/flake8_bugbear/B009_B010.py:20:1: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access.
- kind: |
name: GetAttrWithConstant 20 | # Invalid usage
body: "Do not call `getattr` with a constant attribute value. It is not any safer than normal property access." 21 | getattr(foo, "bar")
suggestion: "Replace `getattr` with attribute access" 22 | getattr(foo, "_123abc")
fixable: true | ^^^^^^^^^^^^^^^^^^^^^^^ B009
location: 23 | getattr(foo, "__123abc__")
row: 20 24 | getattr(foo, "abc123")
column: 0 |
end_location: = help: Replace `getattr` with attribute access
row: 20
column: 23 Suggested fix
fix: 17 17 |
edits: 18 18 | # Invalid usage
- location: 19 19 | getattr(foo, "bar")
row: 20 20 |-getattr(foo, "_123abc")
column: 0 20 |+foo._123abc
end_location: 21 21 | getattr(foo, "__123abc__")
row: 20 22 22 | getattr(foo, "abc123")
column: 23 23 23 | getattr(foo, r"abc123")
content: foo._123abc
parent: ~ ./resources/test/fixtures/flake8_bugbear/B009_B010.py:21:1: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access.
- kind: |
name: GetAttrWithConstant 21 | getattr(foo, "bar")
body: "Do not call `getattr` with a constant attribute value. It is not any safer than normal property access." 22 | getattr(foo, "_123abc")
suggestion: "Replace `getattr` with attribute access" 23 | getattr(foo, "__123abc__")
fixable: true | ^^^^^^^^^^^^^^^^^^^^^^^^^^ B009
location: 24 | getattr(foo, "abc123")
row: 21 25 | getattr(foo, r"abc123")
column: 0 |
end_location: = help: Replace `getattr` with attribute access
row: 21
column: 26 Suggested fix
fix: 18 18 | # Invalid usage
edits: 19 19 | getattr(foo, "bar")
- location: 20 20 | getattr(foo, "_123abc")
row: 21 21 |-getattr(foo, "__123abc__")
column: 0 21 |+foo.__123abc__
end_location: 22 22 | getattr(foo, "abc123")
row: 21 23 23 | getattr(foo, r"abc123")
column: 26 24 24 | _ = lambda x: getattr(x, "bar")
content: foo.__123abc__
parent: ~ ./resources/test/fixtures/flake8_bugbear/B009_B010.py:22:1: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access.
- kind: |
name: GetAttrWithConstant 22 | getattr(foo, "_123abc")
body: "Do not call `getattr` with a constant attribute value. It is not any safer than normal property access." 23 | getattr(foo, "__123abc__")
suggestion: "Replace `getattr` with attribute access" 24 | getattr(foo, "abc123")
fixable: true | ^^^^^^^^^^^^^^^^^^^^^^ B009
location: 25 | getattr(foo, r"abc123")
row: 22 26 | _ = lambda x: getattr(x, "bar")
column: 0 |
end_location: = help: Replace `getattr` with attribute access
row: 22
column: 22 Suggested fix
fix: 19 19 | getattr(foo, "bar")
edits: 20 20 | getattr(foo, "_123abc")
- location: 21 21 | getattr(foo, "__123abc__")
row: 22 22 |-getattr(foo, "abc123")
column: 0 22 |+foo.abc123
end_location: 23 23 | getattr(foo, r"abc123")
row: 22 24 24 | _ = lambda x: getattr(x, "bar")
column: 22 25 25 | if getattr(x, "bar"):
content: foo.abc123
parent: ~ ./resources/test/fixtures/flake8_bugbear/B009_B010.py:23:1: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access.
- kind: |
name: GetAttrWithConstant 23 | getattr(foo, "__123abc__")
body: "Do not call `getattr` with a constant attribute value. It is not any safer than normal property access." 24 | getattr(foo, "abc123")
suggestion: "Replace `getattr` with attribute access" 25 | getattr(foo, r"abc123")
fixable: true | ^^^^^^^^^^^^^^^^^^^^^^^ B009
location: 26 | _ = lambda x: getattr(x, "bar")
row: 23 27 | if getattr(x, "bar"):
column: 0 |
end_location: = help: Replace `getattr` with attribute access
row: 23
column: 23 Suggested fix
fix: 20 20 | getattr(foo, "_123abc")
edits: 21 21 | getattr(foo, "__123abc__")
- location: 22 22 | getattr(foo, "abc123")
row: 23 23 |-getattr(foo, r"abc123")
column: 0 23 |+foo.abc123
end_location: 24 24 | _ = lambda x: getattr(x, "bar")
row: 23 25 25 | if getattr(x, "bar"):
column: 23 26 26 | pass
content: foo.abc123
parent: ~ ./resources/test/fixtures/flake8_bugbear/B009_B010.py:24:15: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access.
- kind: |
name: GetAttrWithConstant 24 | getattr(foo, "abc123")
body: "Do not call `getattr` with a constant attribute value. It is not any safer than normal property access." 25 | getattr(foo, r"abc123")
suggestion: "Replace `getattr` with attribute access" 26 | _ = lambda x: getattr(x, "bar")
fixable: true | ^^^^^^^^^^^^^^^^^ B009
location: 27 | if getattr(x, "bar"):
row: 24 28 | pass
column: 14 |
end_location: = help: Replace `getattr` with attribute access
row: 24
column: 31 Suggested fix
fix: 21 21 | getattr(foo, "__123abc__")
edits: 22 22 | getattr(foo, "abc123")
- location: 23 23 | getattr(foo, r"abc123")
row: 24 24 |-_ = lambda x: getattr(x, "bar")
column: 14 24 |+_ = lambda x: x.bar
end_location: 25 25 | if getattr(x, "bar"):
row: 24 26 26 | pass
column: 31 27 27 |
content: x.bar
parent: ~ ./resources/test/fixtures/flake8_bugbear/B009_B010.py:25:4: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access.
- kind: |
name: GetAttrWithConstant 25 | getattr(foo, r"abc123")
body: "Do not call `getattr` with a constant attribute value. It is not any safer than normal property access." 26 | _ = lambda x: getattr(x, "bar")
suggestion: "Replace `getattr` with attribute access" 27 | if getattr(x, "bar"):
fixable: true | ^^^^^^^^^^^^^^^^^ B009
location: 28 | pass
row: 25 |
column: 3 = help: Replace `getattr` with attribute access
end_location:
row: 25 Suggested fix
column: 20 22 22 | getattr(foo, "abc123")
fix: 23 23 | getattr(foo, r"abc123")
edits: 24 24 | _ = lambda x: getattr(x, "bar")
- location: 25 |-if getattr(x, "bar"):
row: 25 25 |+if x.bar:
column: 3 26 26 | pass
end_location: 27 27 |
row: 25 28 28 | # Valid setattr usage
column: 20
content: x.bar
parent: ~

View file

@ -1,131 +1,120 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B009_B010.py:40:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
name: SetAttrWithConstant |
body: "Do not call `setattr` with a constant attribute value. It is not any safer than normal property access." 40 | # Invalid usage
suggestion: "Replace `setattr` with assignment" 41 | setattr(foo, "bar", None)
fixable: true | ^^^^^^^^^^^^^^^^^^^^^^^^^ B010
location: 42 | setattr(foo, "_123abc", None)
row: 40 43 | setattr(foo, "__123abc__", None)
column: 0 |
end_location: = help: Replace `setattr` with assignment
row: 40
column: 25 Suggested fix
fix: 37 37 | pass
edits: 38 38 |
- location: 39 39 | # Invalid usage
row: 40 40 |-setattr(foo, "bar", None)
column: 0 40 |+foo.bar = None
end_location: 41 41 | setattr(foo, "_123abc", None)
row: 40 42 42 | setattr(foo, "__123abc__", None)
column: 25 43 43 | setattr(foo, "abc123", None)
content: foo.bar = None
parent: ~ ./resources/test/fixtures/flake8_bugbear/B009_B010.py:41:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
- kind: |
name: SetAttrWithConstant 41 | # Invalid usage
body: "Do not call `setattr` with a constant attribute value. It is not any safer than normal property access." 42 | setattr(foo, "bar", None)
suggestion: "Replace `setattr` with assignment" 43 | setattr(foo, "_123abc", None)
fixable: true | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010
location: 44 | setattr(foo, "__123abc__", None)
row: 41 45 | setattr(foo, "abc123", None)
column: 0 |
end_location: = help: Replace `setattr` with assignment
row: 41
column: 29 Suggested fix
fix: 38 38 |
edits: 39 39 | # Invalid usage
- location: 40 40 | setattr(foo, "bar", None)
row: 41 41 |-setattr(foo, "_123abc", None)
column: 0 41 |+foo._123abc = None
end_location: 42 42 | setattr(foo, "__123abc__", None)
row: 41 43 43 | setattr(foo, "abc123", None)
column: 29 44 44 | setattr(foo, r"abc123", None)
content: foo._123abc = None
parent: ~ ./resources/test/fixtures/flake8_bugbear/B009_B010.py:42:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
- kind: |
name: SetAttrWithConstant 42 | setattr(foo, "bar", None)
body: "Do not call `setattr` with a constant attribute value. It is not any safer than normal property access." 43 | setattr(foo, "_123abc", None)
suggestion: "Replace `setattr` with assignment" 44 | setattr(foo, "__123abc__", None)
fixable: true | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010
location: 45 | setattr(foo, "abc123", None)
row: 42 46 | setattr(foo, r"abc123", None)
column: 0 |
end_location: = help: Replace `setattr` with assignment
row: 42
column: 32 Suggested fix
fix: 39 39 | # Invalid usage
edits: 40 40 | setattr(foo, "bar", None)
- location: 41 41 | setattr(foo, "_123abc", None)
row: 42 42 |-setattr(foo, "__123abc__", None)
column: 0 42 |+foo.__123abc__ = None
end_location: 43 43 | setattr(foo, "abc123", None)
row: 42 44 44 | setattr(foo, r"abc123", None)
column: 32 45 45 | setattr(foo.bar, r"baz", None)
content: foo.__123abc__ = None
parent: ~ ./resources/test/fixtures/flake8_bugbear/B009_B010.py:43:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
- kind: |
name: SetAttrWithConstant 43 | setattr(foo, "_123abc", None)
body: "Do not call `setattr` with a constant attribute value. It is not any safer than normal property access." 44 | setattr(foo, "__123abc__", None)
suggestion: "Replace `setattr` with assignment" 45 | setattr(foo, "abc123", None)
fixable: true | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010
location: 46 | setattr(foo, r"abc123", None)
row: 43 47 | setattr(foo.bar, r"baz", None)
column: 0 |
end_location: = help: Replace `setattr` with assignment
row: 43
column: 28 Suggested fix
fix: 40 40 | setattr(foo, "bar", None)
edits: 41 41 | setattr(foo, "_123abc", None)
- location: 42 42 | setattr(foo, "__123abc__", None)
row: 43 43 |-setattr(foo, "abc123", None)
column: 0 43 |+foo.abc123 = None
end_location: 44 44 | setattr(foo, r"abc123", None)
row: 43 45 45 | setattr(foo.bar, r"baz", None)
column: 28
content: foo.abc123 = None ./resources/test/fixtures/flake8_bugbear/B009_B010.py:44:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
parent: ~ |
- kind: 44 | setattr(foo, "__123abc__", None)
name: SetAttrWithConstant 45 | setattr(foo, "abc123", None)
body: "Do not call `setattr` with a constant attribute value. It is not any safer than normal property access." 46 | setattr(foo, r"abc123", None)
suggestion: "Replace `setattr` with assignment" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010
fixable: true 47 | setattr(foo.bar, r"baz", None)
location: |
row: 44 = help: Replace `setattr` with assignment
column: 0
end_location: Suggested fix
row: 44 41 41 | setattr(foo, "_123abc", None)
column: 29 42 42 | setattr(foo, "__123abc__", None)
fix: 43 43 | setattr(foo, "abc123", None)
edits: 44 |-setattr(foo, r"abc123", None)
- location: 44 |+foo.abc123 = None
row: 44 45 45 | setattr(foo.bar, r"baz", None)
column: 0
end_location: ./resources/test/fixtures/flake8_bugbear/B009_B010.py:45:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
row: 44 |
column: 29 45 | setattr(foo, "abc123", None)
content: foo.abc123 = None 46 | setattr(foo, r"abc123", None)
parent: ~ 47 | setattr(foo.bar, r"baz", None)
- kind: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010
name: SetAttrWithConstant |
body: "Do not call `setattr` with a constant attribute value. It is not any safer than normal property access." = help: Replace `setattr` with assignment
suggestion: "Replace `setattr` with assignment"
fixable: true Suggested fix
location: 42 42 | setattr(foo, "__123abc__", None)
row: 45 43 43 | setattr(foo, "abc123", None)
column: 0 44 44 | setattr(foo, r"abc123", None)
end_location: 45 |-setattr(foo.bar, r"baz", None)
row: 45 45 |+foo.bar.baz = None
column: 30
fix:
edits:
- location:
row: 45
column: 0
end_location:
row: 45
column: 30
content: foo.bar.baz = None
parent: ~

View file

@ -1,47 +1,39 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B011.py:8:8: B011 [*] Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`
name: AssertFalse |
body: "Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`" 8 | assert 1 != 2
suggestion: "Replace `assert False`" 9 | assert False
fixable: true | ^^^^^ B011
location: 10 | assert 1 != 2, "message"
row: 8 11 | assert False, "message"
column: 7 |
end_location: = help: Replace `assert False`
row: 8
column: 12 Suggested fix
fix: 5 5 | """
edits: 6 6 |
- location: 7 7 | assert 1 != 2
row: 8 8 |-assert False
column: 0 8 |+raise AssertionError()
end_location: 9 9 | assert 1 != 2, "message"
row: 8 10 10 | assert False, "message"
column: 12
content: raise AssertionError() ./resources/test/fixtures/flake8_bugbear/B011.py:10:8: B011 [*] Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`
parent: ~ |
- kind: 10 | assert False
name: AssertFalse 11 | assert 1 != 2, "message"
body: "Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`" 12 | assert False, "message"
suggestion: "Replace `assert False`" | ^^^^^ B011
fixable: true |
location: = help: Replace `assert False`
row: 10
column: 7 Suggested fix
end_location: 7 7 | assert 1 != 2
row: 10 8 8 | assert False
column: 12 9 9 | assert 1 != 2, "message"
fix: 10 |-assert False, "message"
edits: 10 |+raise AssertionError("message")
- location:
row: 10
column: 0
end_location:
row: 10
column: 23
content: "raise AssertionError(\"message\")"
parent: ~

View file

@ -1,159 +1,104 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B012.py:5:9: B012 `return` inside `finally` blocks cause exceptions to be silenced
name: JumpStatementInFinally |
body: "`return` inside `finally` blocks cause exceptions to be silenced" 5 | pass
suggestion: ~ 6 | finally:
fixable: false 7 | return # warning
location: | ^^^^^^ B012
row: 5 |
column: 8
end_location: ./resources/test/fixtures/flake8_bugbear/B012.py:13:13: B012 `return` inside `finally` blocks cause exceptions to be silenced
row: 5 |
column: 14 13 | finally:
fix: 14 | if 1 + 0 == 2 - 1:
edits: [] 15 | return # warning
parent: ~ | ^^^^^^ B012
- kind: |
name: JumpStatementInFinally
body: "`return` inside `finally` blocks cause exceptions to be silenced" ./resources/test/fixtures/flake8_bugbear/B012.py:21:13: B012 `return` inside `finally` blocks cause exceptions to be silenced
suggestion: ~ |
fixable: false 21 | finally:
location: 22 | try:
row: 13 23 | return # warning
column: 12 | ^^^^^^ B012
end_location: 24 | except Exception:
row: 13 25 | pass
column: 18 |
fix:
edits: [] ./resources/test/fixtures/flake8_bugbear/B012.py:31:13: B012 `return` inside `finally` blocks cause exceptions to be silenced
parent: ~ |
- kind: 31 | pass
name: JumpStatementInFinally 32 | finally:
body: "`return` inside `finally` blocks cause exceptions to be silenced" 33 | return # warning
suggestion: ~ | ^^^^^^ B012
fixable: false 34 | finally:
location: 35 | pass
row: 21 |
column: 12
end_location: ./resources/test/fixtures/flake8_bugbear/B012.py:44:21: B012 `return` inside `finally` blocks cause exceptions to be silenced
row: 21 |
column: 18 44 | pass
fix: 45 | finally:
edits: [] 46 | return # warning
parent: ~ | ^^^^^^ B012
- kind: 47 |
name: JumpStatementInFinally 48 | finally:
body: "`return` inside `finally` blocks cause exceptions to be silenced" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B012.py:66:13: B012 `break` inside `finally` blocks cause exceptions to be silenced
location: |
row: 31 66 | pass
column: 12 67 | finally:
end_location: 68 | break # warning
row: 31 | ^^^^^ B012
column: 18 69 |
fix: 70 | def j():
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B012.py:78:13: B012 `continue` inside `finally` blocks cause exceptions to be silenced
name: JumpStatementInFinally |
body: "`return` inside `finally` blocks cause exceptions to be silenced" 78 | pass
suggestion: ~ 79 | finally:
fixable: false 80 | continue # warning
location: | ^^^^^^^^ B012
row: 44 81 |
column: 20 82 | def j():
end_location: |
row: 44
column: 26 ./resources/test/fixtures/flake8_bugbear/B012.py:94:13: B012 `return` inside `finally` blocks cause exceptions to be silenced
fix: |
edits: [] 94 | continue # no warning
parent: ~ 95 | while True:
- kind: 96 | return # warning
name: JumpStatementInFinally | ^^^^^^ B012
body: "`break` inside `finally` blocks cause exceptions to be silenced" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B012.py:101:9: B012 `continue` inside `finally` blocks cause exceptions to be silenced
location: |
row: 66 101 | pass
column: 12 102 | finally:
end_location: 103 | continue # warning
row: 66 | ^^^^^^^^ B012
column: 17 104 |
fix: 105 | while True:
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B012.py:107:9: B012 `break` inside `finally` blocks cause exceptions to be silenced
name: JumpStatementInFinally |
body: "`continue` inside `finally` blocks cause exceptions to be silenced" 107 | pass
suggestion: ~ 108 | finally:
fixable: false 109 | break # warning
location: | ^^^^^ B012
row: 78 |
column: 12
end_location: ./resources/test/fixtures/flake8_bugbear/B012.py:118:17: B012 `break` inside `finally` blocks cause exceptions to be silenced
row: 78 |
column: 20 118 | y = 0
fix: 119 | case 0, *x:
edits: [] 120 | break # warning
parent: ~ | ^^^^^ B012
- kind: |
name: JumpStatementInFinally
body: "`return` inside `finally` blocks cause exceptions to be silenced"
suggestion: ~
fixable: false
location:
row: 94
column: 12
end_location:
row: 94
column: 18
fix:
edits: []
parent: ~
- kind:
name: JumpStatementInFinally
body: "`continue` inside `finally` blocks cause exceptions to be silenced"
suggestion: ~
fixable: false
location:
row: 101
column: 8
end_location:
row: 101
column: 16
fix:
edits: []
parent: ~
- kind:
name: JumpStatementInFinally
body: "`break` inside `finally` blocks cause exceptions to be silenced"
suggestion: ~
fixable: false
location:
row: 107
column: 8
end_location:
row: 107
column: 13
fix:
edits: []
parent: ~
- kind:
name: JumpStatementInFinally
body: "`break` inside `finally` blocks cause exceptions to be silenced"
suggestion: ~
fixable: false
location:
row: 118
column: 16
end_location:
row: 118
column: 21
fix:
edits: []
parent: ~

View file

@ -1,26 +1,24 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B013.py:3:8: B013 [*] A length-one tuple literal is redundant. Write `except ValueError` instead of `except (ValueError,)`.
name: RedundantTupleInExceptionHandler |
body: "A length-one tuple literal is redundant. Write `except ValueError` instead of `except (ValueError,)`." 3 | try:
suggestion: "Replace with `except ValueError`" 4 | pass
fixable: true 5 | except (ValueError,):
location: | ^^^^^^^^^^^^^ B013
row: 3 6 | pass
column: 7 7 | except AttributeError:
end_location: |
row: 3 = help: Replace with `except ValueError`
column: 20
fix: Suggested fix
edits: 1 1 | try:
- location: 2 2 | pass
row: 3 3 |-except (ValueError,):
column: 7 3 |+except ValueError:
end_location: 4 4 | pass
row: 3 5 5 | except AttributeError:
column: 20 6 6 | pass
content: ValueError
parent: ~

View file

@ -1,68 +1,67 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B014.py:17:8: B014 [*] Exception handler with duplicate exception: `OSError`
name: DuplicateHandlerException |
body: "Exception handler with duplicate exception: `OSError`" 17 | try:
suggestion: De-duplicate exceptions 18 | pass
fixable: true 19 | except (OSError, OSError) as err:
location: | ^^^^^^^^^^^^^^^^^^ B014
row: 17 20 | # Duplicate exception types are useless
column: 7 21 | pass
end_location: |
row: 17 = help: De-duplicate exceptions
column: 25
fix: Suggested fix
edits: 14 14 |
- location: 15 15 | try:
row: 17 16 16 | pass
column: 7 17 |-except (OSError, OSError) as err:
end_location: 17 |+except OSError as err:
row: 17 18 18 | # Duplicate exception types are useless
column: 25 19 19 | pass
content: OSError 20 20 |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B014.py:28:8: B014 [*] Exception handler with duplicate exception: `MyError`
name: DuplicateHandlerException |
body: "Exception handler with duplicate exception: `MyError`" 28 | try:
suggestion: De-duplicate exceptions 29 | pass
fixable: true 30 | except (MyError, MyError):
location: | ^^^^^^^^^^^^^^^^^^ B014
row: 28 31 | # Detect duplicate non-builtin errors
column: 7 32 | pass
end_location: |
row: 28 = help: De-duplicate exceptions
column: 25
fix: Suggested fix
edits: 25 25 |
- location: 26 26 | try:
row: 28 27 27 | pass
column: 7 28 |-except (MyError, MyError):
end_location: 28 |+except MyError:
row: 28 29 29 | # Detect duplicate non-builtin errors
column: 25 30 30 | pass
content: MyError 31 31 |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B014.py:49:8: B014 [*] Exception handler with duplicate exception: `re.error`
name: DuplicateHandlerException |
body: "Exception handler with duplicate exception: `re.error`" 49 | try:
suggestion: De-duplicate exceptions 50 | pass
fixable: true 51 | except (re.error, re.error):
location: | ^^^^^^^^^^^^^^^^^^^^ B014
row: 49 52 | # Duplicate exception types as attributes
column: 7 53 | pass
end_location: |
row: 49 = help: De-duplicate exceptions
column: 27
fix: Suggested fix
edits: 46 46 |
- location: 47 47 | try:
row: 49 48 48 | pass
column: 7 49 |-except (re.error, re.error):
end_location: 49 |+except re.error:
row: 49 50 50 | # Duplicate exception types as attributes
column: 27 51 51 | pass
content: re.error 52 52 |
parent: ~

View file

@ -1,61 +1,37 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B015.py:3:1: B015 Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it.
name: UselessComparison |
body: "Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it." 3 | assert 1 == 1
suggestion: ~ 4 |
fixable: false 5 | 1 == 1
location: | ^^^^^^ B015
row: 3 6 |
column: 0 7 | assert 1 in (1, 2)
end_location: |
row: 3
column: 6 ./resources/test/fixtures/flake8_bugbear/B015.py:7:1: B015 Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it.
fix: |
edits: [] 7 | assert 1 in (1, 2)
parent: ~ 8 |
- kind: 9 | 1 in (1, 2)
name: UselessComparison | ^^^^^^^^^^^ B015
body: "Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it." |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B015.py:17:5: B015 Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it.
location: |
row: 7 17 | assert 1 in (1, 2)
column: 0 18 |
end_location: 19 | 1 in (1, 2)
row: 7 | ^^^^^^^^^^^ B015
column: 11 |
fix:
edits: [] ./resources/test/fixtures/flake8_bugbear/B015.py:24:5: B015 Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it.
parent: ~ |
- kind: 24 | class TestClass:
name: UselessComparison 25 | 1 == 1
body: "Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it." | ^^^^^^ B015
suggestion: ~ |
fixable: false
location:
row: 17
column: 4
end_location:
row: 17
column: 15
fix:
edits: []
parent: ~
- kind:
name: UselessComparison
body: "Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it."
suggestion: ~
fixable: false
location:
row: 24
column: 4
end_location:
row: 24
column: 10
fix:
edits: []
parent: ~

View file

@ -1,47 +1,33 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B016.py:6:7: B016 Cannot raise a literal. Did you intend to return it or raise an Exception?
name: CannotRaiseLiteral |
body: Cannot raise a literal. Did you intend to return it or raise an Exception? 6 | """
suggestion: ~ 7 |
fixable: false 8 | raise False
location: | ^^^^^ B016
row: 6 9 | raise 1
column: 6 10 | raise "string"
end_location: |
row: 6
column: 11 ./resources/test/fixtures/flake8_bugbear/B016.py:7:7: B016 Cannot raise a literal. Did you intend to return it or raise an Exception?
fix: |
edits: [] 7 | raise False
parent: ~ 8 | raise 1
- kind: | ^ B016
name: CannotRaiseLiteral 9 | raise "string"
body: Cannot raise a literal. Did you intend to return it or raise an Exception? 10 | raise Exception(False)
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bugbear/B016.py:8:7: B016 Cannot raise a literal. Did you intend to return it or raise an Exception?
row: 7 |
column: 6 8 | raise False
end_location: 9 | raise 1
row: 7 10 | raise "string"
column: 7 | ^^^^^^^^ B016
fix: 11 | raise Exception(False)
edits: [] 12 | raise Exception(1)
parent: ~ |
- kind:
name: CannotRaiseLiteral
body: Cannot raise a literal. Did you intend to return it or raise an Exception?
suggestion: ~
fixable: false
location:
row: 8
column: 6
end_location:
row: 8
column: 14
fix:
edits: []
parent: ~

View file

@ -1,19 +1,16 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B017.py:22:9: B017 `assertRaises(Exception)` should be considered evil
name: AssertRaisesException |
body: "`assertRaises(Exception)` should be considered evil" 22 | class Foobar(unittest.TestCase):
suggestion: ~ 23 | def evil_raises(self) -> None:
fixable: false 24 | with self.assertRaises(Exception):
location: | _________^
row: 22 25 | | raise Exception("Evil I say!")
column: 8 | |__________________________________________^ B017
end_location: 26 |
row: 23 27 | def context_manager_raises(self) -> None:
column: 42 |
fix:
edits: []
parent: ~

View file

@ -1,383 +1,258 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B018.py:11:5: B018 Found useless expression. Either assign it to a variable or remove it.
name: UselessExpression |
body: Found useless expression. Either assign it to a variable or remove it. 11 | "str" # Str (no raise)
suggestion: ~ 12 | f"{int}" # JoinedStr (no raise)
fixable: false 13 | 1j # Number (complex)
location: | ^^ B018
row: 11 14 | 1 # Number (int)
column: 4 15 | 1.0 # Number (float)
end_location: |
row: 11
column: 6 ./resources/test/fixtures/flake8_bugbear/B018.py:12:5: B018 Found useless expression. Either assign it to a variable or remove it.
fix: |
edits: [] 12 | f"{int}" # JoinedStr (no raise)
parent: ~ 13 | 1j # Number (complex)
- kind: 14 | 1 # Number (int)
name: UselessExpression | ^ B018
body: Found useless expression. Either assign it to a variable or remove it. 15 | 1.0 # Number (float)
suggestion: ~ 16 | b"foo" # Binary
fixable: false |
location:
row: 12 ./resources/test/fixtures/flake8_bugbear/B018.py:13:5: B018 Found useless expression. Either assign it to a variable or remove it.
column: 4 |
end_location: 13 | 1j # Number (complex)
row: 12 14 | 1 # Number (int)
column: 5 15 | 1.0 # Number (float)
fix: | ^^^ B018
edits: [] 16 | b"foo" # Binary
parent: ~ 17 | True # NameConstant (True)
- kind: |
name: UselessExpression
body: Found useless expression. Either assign it to a variable or remove it. ./resources/test/fixtures/flake8_bugbear/B018.py:14:5: B018 Found useless expression. Either assign it to a variable or remove it.
suggestion: ~ |
fixable: false 14 | 1 # Number (int)
location: 15 | 1.0 # Number (float)
row: 13 16 | b"foo" # Binary
column: 4 | ^^^^^^ B018
end_location: 17 | True # NameConstant (True)
row: 13 18 | False # NameConstant (False)
column: 7 |
fix:
edits: [] ./resources/test/fixtures/flake8_bugbear/B018.py:15:5: B018 Found useless expression. Either assign it to a variable or remove it.
parent: ~ |
- kind: 15 | 1.0 # Number (float)
name: UselessExpression 16 | b"foo" # Binary
body: Found useless expression. Either assign it to a variable or remove it. 17 | True # NameConstant (True)
suggestion: ~ | ^^^^ B018
fixable: false 18 | False # NameConstant (False)
location: 19 | None # NameConstant (None)
row: 14 |
column: 4
end_location: ./resources/test/fixtures/flake8_bugbear/B018.py:16:5: B018 Found useless expression. Either assign it to a variable or remove it.
row: 14 |
column: 10 16 | b"foo" # Binary
fix: 17 | True # NameConstant (True)
edits: [] 18 | False # NameConstant (False)
parent: ~ | ^^^^^ B018
- kind: 19 | None # NameConstant (None)
name: UselessExpression 20 | [1, 2] # list
body: Found useless expression. Either assign it to a variable or remove it. |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B018.py:17:5: B018 Found useless expression. Either assign it to a variable or remove it.
location: |
row: 15 17 | True # NameConstant (True)
column: 4 18 | False # NameConstant (False)
end_location: 19 | None # NameConstant (None)
row: 15 | ^^^^ B018
column: 8 20 | [1, 2] # list
fix: 21 | {1, 2} # set
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B018.py:18:5: B018 Found useless expression. Either assign it to a variable or remove it.
name: UselessExpression |
body: Found useless expression. Either assign it to a variable or remove it. 18 | False # NameConstant (False)
suggestion: ~ 19 | None # NameConstant (None)
fixable: false 20 | [1, 2] # list
location: | ^^^^^^ B018
row: 16 21 | {1, 2} # set
column: 4 22 | {"foo": "bar"} # dict
end_location: |
row: 16
column: 9 ./resources/test/fixtures/flake8_bugbear/B018.py:19:5: B018 Found useless expression. Either assign it to a variable or remove it.
fix: |
edits: [] 19 | None # NameConstant (None)
parent: ~ 20 | [1, 2] # list
- kind: 21 | {1, 2} # set
name: UselessExpression | ^^^^^^ B018
body: Found useless expression. Either assign it to a variable or remove it. 22 | {"foo": "bar"} # dict
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bugbear/B018.py:20:5: B018 Found useless expression. Either assign it to a variable or remove it.
row: 17 |
column: 4 20 | [1, 2] # list
end_location: 21 | {1, 2} # set
row: 17 22 | {"foo": "bar"} # dict
column: 8 | ^^^^^^^^^^^^^^ B018
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bugbear/B018.py:24:5: B018 Found useless expression. Either assign it to a variable or remove it.
- kind: |
name: UselessExpression 24 | class Foo3:
body: Found useless expression. Either assign it to a variable or remove it. 25 | 123
suggestion: ~ | ^^^ B018
fixable: false 26 | a = 2
location: 27 | "str"
row: 18 |
column: 4
end_location: ./resources/test/fixtures/flake8_bugbear/B018.py:27:5: B018 Found useless expression. Either assign it to a variable or remove it.
row: 18 |
column: 10 27 | a = 2
fix: 28 | "str"
edits: [] 29 | 1
parent: ~ | ^ B018
- kind: |
name: UselessExpression
body: Found useless expression. Either assign it to a variable or remove it. ./resources/test/fixtures/flake8_bugbear/B018.py:39:5: B018 Found useless expression. Either assign it to a variable or remove it.
suggestion: ~ |
fixable: false 39 | "str" # Str (no raise)
location: 40 | f"{int}" # JoinedStr (no raise)
row: 19 41 | 1j # Number (complex)
column: 4 | ^^ B018
end_location: 42 | 1 # Number (int)
row: 19 43 | 1.0 # Number (float)
column: 10 |
fix:
edits: [] ./resources/test/fixtures/flake8_bugbear/B018.py:40:5: B018 Found useless expression. Either assign it to a variable or remove it.
parent: ~ |
- kind: 40 | f"{int}" # JoinedStr (no raise)
name: UselessExpression 41 | 1j # Number (complex)
body: Found useless expression. Either assign it to a variable or remove it. 42 | 1 # Number (int)
suggestion: ~ | ^ B018
fixable: false 43 | 1.0 # Number (float)
location: 44 | b"foo" # Binary
row: 20 |
column: 4
end_location: ./resources/test/fixtures/flake8_bugbear/B018.py:41:5: B018 Found useless expression. Either assign it to a variable or remove it.
row: 20 |
column: 18 41 | 1j # Number (complex)
fix: 42 | 1 # Number (int)
edits: [] 43 | 1.0 # Number (float)
parent: ~ | ^^^ B018
- kind: 44 | b"foo" # Binary
name: UselessExpression 45 | True # NameConstant (True)
body: Found useless expression. Either assign it to a variable or remove it. |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B018.py:42:5: B018 Found useless expression. Either assign it to a variable or remove it.
location: |
row: 24 42 | 1 # Number (int)
column: 4 43 | 1.0 # Number (float)
end_location: 44 | b"foo" # Binary
row: 24 | ^^^^^^ B018
column: 7 45 | True # NameConstant (True)
fix: 46 | False # NameConstant (False)
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B018.py:43:5: B018 Found useless expression. Either assign it to a variable or remove it.
name: UselessExpression |
body: Found useless expression. Either assign it to a variable or remove it. 43 | 1.0 # Number (float)
suggestion: ~ 44 | b"foo" # Binary
fixable: false 45 | True # NameConstant (True)
location: | ^^^^ B018
row: 27 46 | False # NameConstant (False)
column: 4 47 | None # NameConstant (None)
end_location: |
row: 27
column: 5 ./resources/test/fixtures/flake8_bugbear/B018.py:44:5: B018 Found useless expression. Either assign it to a variable or remove it.
fix: |
edits: [] 44 | b"foo" # Binary
parent: ~ 45 | True # NameConstant (True)
- kind: 46 | False # NameConstant (False)
name: UselessExpression | ^^^^^ B018
body: Found useless expression. Either assign it to a variable or remove it. 47 | None # NameConstant (None)
suggestion: ~ 48 | [1, 2] # list
fixable: false |
location:
row: 39 ./resources/test/fixtures/flake8_bugbear/B018.py:45:5: B018 Found useless expression. Either assign it to a variable or remove it.
column: 4 |
end_location: 45 | True # NameConstant (True)
row: 39 46 | False # NameConstant (False)
column: 6 47 | None # NameConstant (None)
fix: | ^^^^ B018
edits: [] 48 | [1, 2] # list
parent: ~ 49 | {1, 2} # set
- kind: |
name: UselessExpression
body: Found useless expression. Either assign it to a variable or remove it. ./resources/test/fixtures/flake8_bugbear/B018.py:46:5: B018 Found useless expression. Either assign it to a variable or remove it.
suggestion: ~ |
fixable: false 46 | False # NameConstant (False)
location: 47 | None # NameConstant (None)
row: 40 48 | [1, 2] # list
column: 4 | ^^^^^^ B018
end_location: 49 | {1, 2} # set
row: 40 50 | {"foo": "bar"} # dict
column: 5 |
fix:
edits: [] ./resources/test/fixtures/flake8_bugbear/B018.py:47:5: B018 Found useless expression. Either assign it to a variable or remove it.
parent: ~ |
- kind: 47 | None # NameConstant (None)
name: UselessExpression 48 | [1, 2] # list
body: Found useless expression. Either assign it to a variable or remove it. 49 | {1, 2} # set
suggestion: ~ | ^^^^^^ B018
fixable: false 50 | {"foo": "bar"} # dict
location: |
row: 41
column: 4 ./resources/test/fixtures/flake8_bugbear/B018.py:48:5: B018 Found useless expression. Either assign it to a variable or remove it.
end_location: |
row: 41 48 | [1, 2] # list
column: 7 49 | {1, 2} # set
fix: 50 | {"foo": "bar"} # dict
edits: [] | ^^^^^^^^^^^^^^ B018
parent: ~ |
- kind:
name: UselessExpression ./resources/test/fixtures/flake8_bugbear/B018.py:52:5: B018 Found useless expression. Either assign it to a variable or remove it.
body: Found useless expression. Either assign it to a variable or remove it. |
suggestion: ~ 52 | def foo3():
fixable: false 53 | 123
location: | ^^^ B018
row: 42 54 | a = 2
column: 4 55 | "str"
end_location: |
row: 42
column: 10 ./resources/test/fixtures/flake8_bugbear/B018.py:55:5: B018 Found useless expression. Either assign it to a variable or remove it.
fix: |
edits: [] 55 | a = 2
parent: ~ 56 | "str"
- kind: 57 | 3
name: UselessExpression | ^ B018
body: Found useless expression. Either assign it to a variable or remove it. |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B018.py:63:5: B018 Found useless expression. Either assign it to a variable or remove it.
location: |
row: 43 63 | def foo5():
column: 4 64 | foo.bar # Attribute (raise)
end_location: | ^^^^^^^ B018
row: 43 65 | object().__class__ # Attribute (raise)
column: 8 66 | "foo" + "bar" # BinOp (raise)
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bugbear/B018.py:64:5: B018 Found useless attribute access. Either assign it to a variable or remove it.
- kind: |
name: UselessExpression 64 | def foo5():
body: Found useless expression. Either assign it to a variable or remove it. 65 | foo.bar # Attribute (raise)
suggestion: ~ 66 | object().__class__ # Attribute (raise)
fixable: false | ^^^^^^^^^^^^^^^^^^ B018
location: 67 | "foo" + "bar" # BinOp (raise)
row: 44 |
column: 4
end_location: ./resources/test/fixtures/flake8_bugbear/B018.py:65:5: B018 Found useless expression. Either assign it to a variable or remove it.
row: 44 |
column: 9 65 | foo.bar # Attribute (raise)
fix: 66 | object().__class__ # Attribute (raise)
edits: [] 67 | "foo" + "bar" # BinOp (raise)
parent: ~ | ^^^^^^^^^^^^^ B018
- kind: |
name: UselessExpression
body: Found useless expression. Either assign it to a variable or remove it.
suggestion: ~
fixable: false
location:
row: 45
column: 4
end_location:
row: 45
column: 8
fix:
edits: []
parent: ~
- kind:
name: UselessExpression
body: Found useless expression. Either assign it to a variable or remove it.
suggestion: ~
fixable: false
location:
row: 46
column: 4
end_location:
row: 46
column: 10
fix:
edits: []
parent: ~
- kind:
name: UselessExpression
body: Found useless expression. Either assign it to a variable or remove it.
suggestion: ~
fixable: false
location:
row: 47
column: 4
end_location:
row: 47
column: 10
fix:
edits: []
parent: ~
- kind:
name: UselessExpression
body: Found useless expression. Either assign it to a variable or remove it.
suggestion: ~
fixable: false
location:
row: 48
column: 4
end_location:
row: 48
column: 18
fix:
edits: []
parent: ~
- kind:
name: UselessExpression
body: Found useless expression. Either assign it to a variable or remove it.
suggestion: ~
fixable: false
location:
row: 52
column: 4
end_location:
row: 52
column: 7
fix:
edits: []
parent: ~
- kind:
name: UselessExpression
body: Found useless expression. Either assign it to a variable or remove it.
suggestion: ~
fixable: false
location:
row: 55
column: 4
end_location:
row: 55
column: 5
fix:
edits: []
parent: ~
- kind:
name: UselessExpression
body: Found useless expression. Either assign it to a variable or remove it.
suggestion: ~
fixable: false
location:
row: 63
column: 4
end_location:
row: 63
column: 11
fix:
edits: []
parent: ~
- kind:
name: UselessExpression
body: Found useless attribute access. Either assign it to a variable or remove it.
suggestion: ~
fixable: false
location:
row: 64
column: 4
end_location:
row: 64
column: 22
fix:
edits: []
parent: ~
- kind:
name: UselessExpression
body: Found useless expression. Either assign it to a variable or remove it.
suggestion: ~
fixable: false
location:
row: 65
column: 4
end_location:
row: 65
column: 17
fix:
edits: []
parent: ~

View file

@ -1,117 +1,83 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B019.py:78:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks
name: CachedInstanceMethod |
body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks" 78 | # Remaining methods should emit B019
suggestion: ~ 79 | @functools.cache
fixable: false | ^^^^^^^^^^^^^^^ B019
location: 80 | def cached_instance_method(self, y):
row: 78 81 | ...
column: 5 |
end_location:
row: 78 ./resources/test/fixtures/flake8_bugbear/B019.py:82:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks
column: 20 |
fix: 82 | ...
edits: [] 83 |
parent: ~ 84 | @cache
- kind: | ^^^^^ B019
name: CachedInstanceMethod 85 | def another_cached_instance_method(self, y):
body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks" 86 | ...
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bugbear/B019.py:86:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks
row: 82 |
column: 5 86 | ...
end_location: 87 |
row: 82 88 | @functools.cache()
column: 10 | ^^^^^^^^^^^^^^^^^ B019
fix: 89 | def called_cached_instance_method(self, y):
edits: [] 90 | ...
parent: ~ |
- kind:
name: CachedInstanceMethod ./resources/test/fixtures/flake8_bugbear/B019.py:90:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks
body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks" |
suggestion: ~ 90 | ...
fixable: false 91 |
location: 92 | @cache()
row: 86 | ^^^^^^^ B019
column: 5 93 | def another_called_cached_instance_method(self, y):
end_location: 94 | ...
row: 86 |
column: 22
fix: ./resources/test/fixtures/flake8_bugbear/B019.py:94:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks
edits: [] |
parent: ~ 94 | ...
- kind: 95 |
name: CachedInstanceMethod 96 | @functools.lru_cache
body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks" | ^^^^^^^^^^^^^^^^^^^ B019
suggestion: ~ 97 | def lru_cached_instance_method(self, y):
fixable: false 98 | ...
location: |
row: 90
column: 5 ./resources/test/fixtures/flake8_bugbear/B019.py:98:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks
end_location: |
row: 90 98 | ...
column: 12 99 |
fix: 100 | @lru_cache
edits: [] | ^^^^^^^^^ B019
parent: ~ 101 | def another_lru_cached_instance_method(self, y):
- kind: 102 | ...
name: CachedInstanceMethod |
body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks"
suggestion: ~ ./resources/test/fixtures/flake8_bugbear/B019.py:102:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks
fixable: false |
location: 102 | ...
row: 94 103 |
column: 5 104 | @functools.lru_cache()
end_location: | ^^^^^^^^^^^^^^^^^^^^^ B019
row: 94 105 | def called_lru_cached_instance_method(self, y):
column: 24 106 | ...
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bugbear/B019.py:106:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks
- kind: |
name: CachedInstanceMethod 106 | ...
body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks" 107 |
suggestion: ~ 108 | @lru_cache()
fixable: false | ^^^^^^^^^^^ B019
location: 109 | def another_called_lru_cached_instance_method(self, y):
row: 98 110 | ...
column: 5 |
end_location:
row: 98
column: 14
fix:
edits: []
parent: ~
- kind:
name: CachedInstanceMethod
body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks"
suggestion: ~
fixable: false
location:
row: 102
column: 5
end_location:
row: 102
column: 26
fix:
edits: []
parent: ~
- kind:
name: CachedInstanceMethod
body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks"
suggestion: ~
fixable: false
location:
row: 106
column: 5
end_location:
row: 106
column: 16
fix:
edits: []
parent: ~

View file

@ -1,47 +1,30 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B020.py:8:5: B020 Loop control variable `items` overrides iterable it iterates
name: LoopVariableOverridesIterator |
body: "Loop control variable `items` overrides iterable it iterates" 8 | items = [1, 2, 3]
suggestion: ~ 9 |
fixable: false 10 | for items in items:
location: | ^^^^^ B020
row: 8 11 | print(items)
column: 4 |
end_location:
row: 8 ./resources/test/fixtures/flake8_bugbear/B020.py:21:10: B020 Loop control variable `values` overrides iterable it iterates
column: 9 |
fix: 21 | print(f"{key}, {value}")
edits: [] 22 |
parent: ~ 23 | for key, values in values.items():
- kind: | ^^^^^^ B020
name: LoopVariableOverridesIterator 24 | print(f"{key}, {values}")
body: "Loop control variable `values` overrides iterable it iterates" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B020.py:36:5: B020 Loop control variable `vars` overrides iterable it iterates
location: |
row: 21 36 | # However we still call out reassigning the iterable in the comprehension.
column: 9 37 | for vars in [i for i in vars]:
end_location: | ^^^^ B020
row: 21 38 | print(vars)
column: 15 |
fix:
edits: []
parent: ~
- kind:
name: LoopVariableOverridesIterator
body: "Loop control variable `vars` overrides iterable it iterates"
suggestion: ~
fixable: false
location:
row: 36
column: 4
end_location:
row: 36
column: 8
fix:
edits: []
parent: ~

View file

@ -1,145 +1,80 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B021.py:1:1: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.
name: FStringDocstring |
body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. 1 | / f"""
suggestion: ~ 2 | | Should emit:
fixable: false 3 | | B021 - on lines 14, 22, 30, 38, 46, 54, 62, 70, 73
location: 4 | | """
row: 1 | |___^ B021
column: 0 5 |
end_location: 6 | VARIABLE = "world"
row: 4 |
column: 3
fix: ./resources/test/fixtures/flake8_bugbear/B021.py:14:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.
edits: [] |
parent: ~ 14 | def foo2():
- kind: 15 | f"""hello {VARIABLE}!"""
name: FStringDocstring | ^^^^^^^^^^^^^^^^^^^^^^^^ B021
body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B021.py:22:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.
location: |
row: 14 22 | class bar2:
column: 4 23 | f"""hello {VARIABLE}!"""
end_location: | ^^^^^^^^^^^^^^^^^^^^^^^^ B021
row: 14 |
column: 28
fix: ./resources/test/fixtures/flake8_bugbear/B021.py:30:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.
edits: [] |
parent: ~ 30 | def foo2():
- kind: 31 | f"""hello {VARIABLE}!"""
name: FStringDocstring | ^^^^^^^^^^^^^^^^^^^^^^^^ B021
body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B021.py:38:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.
location: |
row: 22 38 | class bar2:
column: 4 39 | f"""hello {VARIABLE}!"""
end_location: | ^^^^^^^^^^^^^^^^^^^^^^^^ B021
row: 22 |
column: 28
fix: ./resources/test/fixtures/flake8_bugbear/B021.py:46:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.
edits: [] |
parent: ~ 46 | def foo2():
- kind: 47 | f"hello {VARIABLE}!"
name: FStringDocstring | ^^^^^^^^^^^^^^^^^^^^ B021
body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B021.py:54:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.
location: |
row: 30 54 | class bar2:
column: 4 55 | f"hello {VARIABLE}!"
end_location: | ^^^^^^^^^^^^^^^^^^^^ B021
row: 30 |
column: 28
fix: ./resources/test/fixtures/flake8_bugbear/B021.py:62:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.
edits: [] |
parent: ~ 62 | def foo2():
- kind: 63 | f"hello {VARIABLE}!"
name: FStringDocstring | ^^^^^^^^^^^^^^^^^^^^ B021
body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B021.py:70:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.
location: |
row: 38 70 | class bar2:
column: 4 71 | f"hello {VARIABLE}!"
end_location: | ^^^^^^^^^^^^^^^^^^^^ B021
row: 38 |
column: 28
fix: ./resources/test/fixtures/flake8_bugbear/B021.py:74:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.
edits: [] |
parent: ~ 74 | def baz():
- kind: 75 | f"""I'm probably a docstring: {VARIABLE}!"""
name: FStringDocstring | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B021
body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. 76 | print(f"""I'm a normal string""")
suggestion: ~ 77 | f"""Don't detect me!"""
fixable: false |
location:
row: 46
column: 4
end_location:
row: 46
column: 24
fix:
edits: []
parent: ~
- kind:
name: FStringDocstring
body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.
suggestion: ~
fixable: false
location:
row: 54
column: 4
end_location:
row: 54
column: 24
fix:
edits: []
parent: ~
- kind:
name: FStringDocstring
body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.
suggestion: ~
fixable: false
location:
row: 62
column: 4
end_location:
row: 62
column: 24
fix:
edits: []
parent: ~
- kind:
name: FStringDocstring
body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.
suggestion: ~
fixable: false
location:
row: 70
column: 4
end_location:
row: 70
column: 24
fix:
edits: []
parent: ~
- kind:
name: FStringDocstring
body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring.
suggestion: ~
fixable: false
location:
row: 74
column: 4
end_location:
row: 74
column: 48
fix:
edits: []
parent: ~

View file

@ -1,33 +1,22 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B022.py:9:6: B022 No arguments passed to `contextlib.suppress`. No exceptions will be suppressed and therefore this context manager is redundant
name: UselessContextlibSuppress |
body: "No arguments passed to `contextlib.suppress`. No exceptions will be suppressed and therefore this context manager is redundant" 9 | from contextlib import suppress
suggestion: ~ 10 |
fixable: false 11 | with contextlib.suppress():
location: | ^^^^^^^^^^^^^^^^^^^^^ B022
row: 9 12 | raise ValueError
column: 5 |
end_location:
row: 9 ./resources/test/fixtures/flake8_bugbear/B022.py:12:6: B022 No arguments passed to `contextlib.suppress`. No exceptions will be suppressed and therefore this context manager is redundant
column: 26 |
fix: 12 | raise ValueError
edits: [] 13 |
parent: ~ 14 | with suppress():
- kind: | ^^^^^^^^^^ B022
name: UselessContextlibSuppress 15 | raise ValueError
body: "No arguments passed to `contextlib.suppress`. No exceptions will be suppressed and therefore this context manager is redundant" |
suggestion: ~
fixable: false
location:
row: 12
column: 5
end_location:
row: 12
column: 15
fix:
edits: []
parent: ~

View file

@ -1,341 +1,224 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B023.py:12:30: B023 Function definition does not bind loop variable `x`
name: FunctionUsesLoopVariable |
body: "Function definition does not bind loop variable `x`" 12 | y = x + 1
suggestion: ~ 13 | # Subject to late-binding problems
fixable: false 14 | functions.append(lambda: x)
location: | ^ B023
row: 12 15 | functions.append(lambda: y) # not just the loop var
column: 29 |
end_location:
row: 12 ./resources/test/fixtures/flake8_bugbear/B023.py:13:30: B023 Function definition does not bind loop variable `y`
column: 30 |
fix: 13 | # Subject to late-binding problems
edits: [] 14 | functions.append(lambda: x)
parent: ~ 15 | functions.append(lambda: y) # not just the loop var
- kind: | ^ B023
name: FunctionUsesLoopVariable 16 |
body: "Function definition does not bind loop variable `y`" 17 | def f_bad_1():
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bugbear/B023.py:16:16: B023 Function definition does not bind loop variable `x`
row: 13 |
column: 29 16 | def f_bad_1():
end_location: 17 | return x
row: 13 | ^ B023
column: 30 18 |
fix: 19 | # Actually OK
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B023.py:28:19: B023 Function definition does not bind loop variable `x`
name: FunctionUsesLoopVariable |
body: "Function definition does not bind loop variable `x`" 28 | def check_inside_functions_too():
suggestion: ~ 29 | ls = [lambda: x for x in range(2)] # error
fixable: false | ^ B023
location: 30 | st = {lambda: x for x in range(2)} # error
row: 16 31 | gn = (lambda: x for x in range(2)) # error
column: 15 |
end_location:
row: 16 ./resources/test/fixtures/flake8_bugbear/B023.py:29:19: B023 Function definition does not bind loop variable `x`
column: 16 |
fix: 29 | def check_inside_functions_too():
edits: [] 30 | ls = [lambda: x for x in range(2)] # error
parent: ~ 31 | st = {lambda: x for x in range(2)} # error
- kind: | ^ B023
name: FunctionUsesLoopVariable 32 | gn = (lambda: x for x in range(2)) # error
body: "Function definition does not bind loop variable `x`" 33 | dt = {x: lambda: x for x in range(2)} # error
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bugbear/B023.py:30:19: B023 Function definition does not bind loop variable `x`
row: 28 |
column: 18 30 | ls = [lambda: x for x in range(2)] # error
end_location: 31 | st = {lambda: x for x in range(2)} # error
row: 28 32 | gn = (lambda: x for x in range(2)) # error
column: 19 | ^ B023
fix: 33 | dt = {x: lambda: x for x in range(2)} # error
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B023.py:31:22: B023 Function definition does not bind loop variable `x`
name: FunctionUsesLoopVariable |
body: "Function definition does not bind loop variable `x`" 31 | st = {lambda: x for x in range(2)} # error
suggestion: ~ 32 | gn = (lambda: x for x in range(2)) # error
fixable: false 33 | dt = {x: lambda: x for x in range(2)} # error
location: | ^ B023
row: 29 |
column: 18
end_location: ./resources/test/fixtures/flake8_bugbear/B023.py:40:34: B023 Function definition does not bind loop variable `x`
row: 29 |
column: 19 40 | async def container_for_problems():
fix: 41 | async for x in pointless_async_iterable():
edits: [] 42 | functions.append(lambda: x) # error
parent: ~ | ^ B023
- kind: 43 |
name: FunctionUsesLoopVariable 44 | [lambda: x async for x in pointless_async_iterable()] # error
body: "Function definition does not bind loop variable `x`" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B023.py:42:14: B023 Function definition does not bind loop variable `x`
location: |
row: 30 42 | functions.append(lambda: x) # error
column: 18 43 |
end_location: 44 | [lambda: x async for x in pointless_async_iterable()] # error
row: 30 | ^ B023
column: 19 |
fix:
edits: [] ./resources/test/fixtures/flake8_bugbear/B023.py:50:30: B023 Function definition does not bind loop variable `a`
parent: ~ |
- kind: 50 | a = a_ = a - 1
name: FunctionUsesLoopVariable 51 | b += 1
body: "Function definition does not bind loop variable `x`" 52 | functions.append(lambda: a) # error
suggestion: ~ | ^ B023
fixable: false 53 | functions.append(lambda: a_) # error
location: 54 | functions.append(lambda: b) # error
row: 31 |
column: 21
end_location: ./resources/test/fixtures/flake8_bugbear/B023.py:51:30: B023 Function definition does not bind loop variable `a_`
row: 31 |
column: 22 51 | b += 1
fix: 52 | functions.append(lambda: a) # error
edits: [] 53 | functions.append(lambda: a_) # error
parent: ~ | ^^ B023
- kind: 54 | functions.append(lambda: b) # error
name: FunctionUsesLoopVariable 55 | functions.append(lambda: c) # error, but not a name error due to late binding
body: "Function definition does not bind loop variable `x`" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B023.py:52:30: B023 Function definition does not bind loop variable `b`
location: |
row: 40 52 | functions.append(lambda: a) # error
column: 33 53 | functions.append(lambda: a_) # error
end_location: 54 | functions.append(lambda: b) # error
row: 40 | ^ B023
column: 34 55 | functions.append(lambda: c) # error, but not a name error due to late binding
fix: 56 | c: bool = a > 3
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B023.py:53:30: B023 Function definition does not bind loop variable `c`
name: FunctionUsesLoopVariable |
body: "Function definition does not bind loop variable `x`" 53 | functions.append(lambda: a_) # error
suggestion: ~ 54 | functions.append(lambda: b) # error
fixable: false 55 | functions.append(lambda: c) # error, but not a name error due to late binding
location: | ^ B023
row: 42 56 | c: bool = a > 3
column: 13 57 | if not c:
end_location: |
row: 42
column: 14 ./resources/test/fixtures/flake8_bugbear/B023.py:61:17: B023 Function definition does not bind loop variable `j`
fix: |
edits: [] 61 | for j in range(2):
parent: ~ 62 | for k in range(3):
- kind: 63 | lambda: j * k # error
name: FunctionUsesLoopVariable | ^ B023
body: "Function definition does not bind loop variable `a`" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B023.py:61:21: B023 Function definition does not bind loop variable `k`
location: |
row: 50 61 | for j in range(2):
column: 29 62 | for k in range(3):
end_location: 63 | lambda: j * k # error
row: 50 | ^ B023
column: 30 |
fix:
edits: [] ./resources/test/fixtures/flake8_bugbear/B023.py:68:10: B023 Function definition does not bind loop variable `l`
parent: ~ |
- kind: 68 | def f():
name: FunctionUsesLoopVariable 69 | j = None # OK because it's an assignment
body: "Function definition does not bind loop variable `a_`" 70 | [l for k in range(2)] # error for l, not for k
suggestion: ~ | ^ B023
fixable: false 71 |
location: 72 | assert a and functions
row: 51 |
column: 29
end_location: ./resources/test/fixtures/flake8_bugbear/B023.py:82:16: B023 Function definition does not bind loop variable `i`
row: 51 |
column: 31 82 | for i in range(3):
fix: 83 | lambda: f"{i}"
edits: [] | ^ B023
parent: ~ |
- kind:
name: FunctionUsesLoopVariable ./resources/test/fixtures/flake8_bugbear/B023.py:117:24: B023 Function definition does not bind loop variable `x`
body: "Function definition does not bind loop variable `b`" |
suggestion: ~ 117 | for x in range(2):
fixable: false 118 | # It's not a complete get-out-of-linting-free construct - these should fail:
location: 119 | min([None, lambda: x], key=repr)
row: 52 | ^ B023
column: 29 120 | sorted([None, lambda: x], key=repr)
end_location: 121 | any(filter(bool, [None, lambda: x]))
row: 52 |
column: 30
fix: ./resources/test/fixtures/flake8_bugbear/B023.py:118:27: B023 Function definition does not bind loop variable `x`
edits: [] |
parent: ~ 118 | # It's not a complete get-out-of-linting-free construct - these should fail:
- kind: 119 | min([None, lambda: x], key=repr)
name: FunctionUsesLoopVariable 120 | sorted([None, lambda: x], key=repr)
body: "Function definition does not bind loop variable `c`" | ^ B023
suggestion: ~ 121 | any(filter(bool, [None, lambda: x]))
fixable: false 122 | list(filter(bool, [None, lambda: x]))
location: |
row: 53
column: 29 ./resources/test/fixtures/flake8_bugbear/B023.py:119:37: B023 Function definition does not bind loop variable `x`
end_location: |
row: 53 119 | min([None, lambda: x], key=repr)
column: 30 120 | sorted([None, lambda: x], key=repr)
fix: 121 | any(filter(bool, [None, lambda: x]))
edits: [] | ^ B023
parent: ~ 122 | list(filter(bool, [None, lambda: x]))
- kind: 123 | all(reduce(bool, [None, lambda: x]))
name: FunctionUsesLoopVariable |
body: "Function definition does not bind loop variable `j`"
suggestion: ~ ./resources/test/fixtures/flake8_bugbear/B023.py:120:38: B023 Function definition does not bind loop variable `x`
fixable: false |
location: 120 | sorted([None, lambda: x], key=repr)
row: 61 121 | any(filter(bool, [None, lambda: x]))
column: 16 122 | list(filter(bool, [None, lambda: x]))
end_location: | ^ B023
row: 61 123 | all(reduce(bool, [None, lambda: x]))
column: 17 |
fix:
edits: [] ./resources/test/fixtures/flake8_bugbear/B023.py:121:37: B023 Function definition does not bind loop variable `x`
parent: ~ |
- kind: 121 | any(filter(bool, [None, lambda: x]))
name: FunctionUsesLoopVariable 122 | list(filter(bool, [None, lambda: x]))
body: "Function definition does not bind loop variable `k`" 123 | all(reduce(bool, [None, lambda: x]))
suggestion: ~ | ^ B023
fixable: false 124 |
location: 125 | # But all these should be OK:
row: 61 |
column: 20
end_location: ./resources/test/fixtures/flake8_bugbear/B023.py:171:29: B023 Function definition does not bind loop variable `name`
row: 61 |
column: 21 171 | if foo(name):
fix: 172 | return [lambda: name] # known false alarm
edits: [] | ^^^^ B023
parent: ~ 173 |
- kind: 174 | if False:
name: FunctionUsesLoopVariable |
body: "Function definition does not bind loop variable `l`"
suggestion: ~ ./resources/test/fixtures/flake8_bugbear/B023.py:174:29: B023 Function definition does not bind loop variable `i`
fixable: false |
location: 174 | if False:
row: 68 175 | return [lambda: i for i in range(3)] # error
column: 9 | ^ B023
end_location: |
row: 68
column: 10
fix:
edits: []
parent: ~
- kind:
name: FunctionUsesLoopVariable
body: "Function definition does not bind loop variable `i`"
suggestion: ~
fixable: false
location:
row: 82
column: 15
end_location:
row: 82
column: 16
fix:
edits: []
parent: ~
- kind:
name: FunctionUsesLoopVariable
body: "Function definition does not bind loop variable `x`"
suggestion: ~
fixable: false
location:
row: 117
column: 23
end_location:
row: 117
column: 24
fix:
edits: []
parent: ~
- kind:
name: FunctionUsesLoopVariable
body: "Function definition does not bind loop variable `x`"
suggestion: ~
fixable: false
location:
row: 118
column: 26
end_location:
row: 118
column: 27
fix:
edits: []
parent: ~
- kind:
name: FunctionUsesLoopVariable
body: "Function definition does not bind loop variable `x`"
suggestion: ~
fixable: false
location:
row: 119
column: 36
end_location:
row: 119
column: 37
fix:
edits: []
parent: ~
- kind:
name: FunctionUsesLoopVariable
body: "Function definition does not bind loop variable `x`"
suggestion: ~
fixable: false
location:
row: 120
column: 37
end_location:
row: 120
column: 38
fix:
edits: []
parent: ~
- kind:
name: FunctionUsesLoopVariable
body: "Function definition does not bind loop variable `x`"
suggestion: ~
fixable: false
location:
row: 121
column: 36
end_location:
row: 121
column: 37
fix:
edits: []
parent: ~
- kind:
name: FunctionUsesLoopVariable
body: "Function definition does not bind loop variable `name`"
suggestion: ~
fixable: false
location:
row: 171
column: 28
end_location:
row: 171
column: 32
fix:
edits: []
parent: ~
- kind:
name: FunctionUsesLoopVariable
body: "Function definition does not bind loop variable `i`"
suggestion: ~
fixable: false
location:
row: 174
column: 28
end_location:
row: 174
column: 29
fix:
edits: []
parent: ~

View file

@ -1,89 +1,52 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B024.py:18:1: B024 `Base_1` is an abstract base class, but it has no abstract methods
name: AbstractBaseClassWithoutAbstractMethod |
body: "`Base_1` is an abstract base class, but it has no abstract methods" 18 | / class Base_1(ABC): # error
suggestion: ~ 19 | | def method(self):
fixable: false 20 | | foo()
location: | |_____________^ B024
row: 18 |
column: 0
end_location: ./resources/test/fixtures/flake8_bugbear/B024.py:71:1: B024 `MetaBase_1` is an abstract base class, but it has no abstract methods
row: 20 |
column: 13 71 | / class MetaBase_1(metaclass=ABCMeta): # error
fix: 72 | | def method(self):
edits: [] 73 | | foo()
parent: ~ | |_____________^ B024
- kind: |
name: AbstractBaseClassWithoutAbstractMethod
body: "`MetaBase_1` is an abstract base class, but it has no abstract methods" ./resources/test/fixtures/flake8_bugbear/B024.py:82:1: B024 `abc_Base_1` is an abstract base class, but it has no abstract methods
suggestion: ~ |
fixable: false 82 | / class abc_Base_1(abc.ABC): # error
location: 83 | | def method(self):
row: 71 84 | | foo()
column: 0 | |_____________^ B024
end_location: |
row: 73
column: 13 ./resources/test/fixtures/flake8_bugbear/B024.py:87:1: B024 `abc_Base_2` is an abstract base class, but it has no abstract methods
fix: |
edits: [] 87 | / class abc_Base_2(metaclass=abc.ABCMeta): # error
parent: ~ 88 | | def method(self):
- kind: 89 | | foo()
name: AbstractBaseClassWithoutAbstractMethod | |_____________^ B024
body: "`abc_Base_1` is an abstract base class, but it has no abstract methods" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B024.py:92:1: B024 `notabc_Base_1` is an abstract base class, but it has no abstract methods
location: |
row: 82 92 | / class notabc_Base_1(notabc.ABC): # error
column: 0 93 | | def method(self):
end_location: 94 | | foo()
row: 84 | |_____________^ B024
column: 13 |
fix:
edits: [] ./resources/test/fixtures/flake8_bugbear/B024.py:141:1: B024 `abc_set_class_variable_4` is an abstract base class, but it has no abstract methods
parent: ~ |
- kind: 141 | # this doesn't actually declare a class variable, it's just an expression
name: AbstractBaseClassWithoutAbstractMethod 142 | / class abc_set_class_variable_4(ABC): # error
body: "`abc_Base_2` is an abstract base class, but it has no abstract methods" 143 | | foo
suggestion: ~ | |_______^ B024
fixable: false |
location:
row: 87
column: 0
end_location:
row: 89
column: 13
fix:
edits: []
parent: ~
- kind:
name: AbstractBaseClassWithoutAbstractMethod
body: "`notabc_Base_1` is an abstract base class, but it has no abstract methods"
suggestion: ~
fixable: false
location:
row: 92
column: 0
end_location:
row: 94
column: 13
fix:
edits: []
parent: ~
- kind:
name: AbstractBaseClassWithoutAbstractMethod
body: "`abc_set_class_variable_4` is an abstract base class, but it has no abstract methods"
suggestion: ~
fixable: false
location:
row: 141
column: 0
end_location:
row: 142
column: 7
fix:
edits: []
parent: ~

View file

@ -1,61 +1,41 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B025.py:19:8: B025 try-except block with duplicate exception `ValueError`
name: DuplicateTryBlockException |
body: "try-except block with duplicate exception `ValueError`" 19 | except ValueError:
suggestion: ~ 20 | a = 2
fixable: false 21 | except ValueError:
location: | ^^^^^^^^^^ B025
row: 19 22 | a = 2
column: 7 |
end_location:
row: 19 ./resources/test/fixtures/flake8_bugbear/B025.py:28:8: B025 try-except block with duplicate exception `pickle.PickleError`
column: 17 |
fix: 28 | except ValueError:
edits: [] 29 | a = 2
parent: ~ 30 | except pickle.PickleError:
- kind: | ^^^^^^^^^^^^^^^^^^ B025
name: DuplicateTryBlockException 31 | a = 2
body: "try-except block with duplicate exception `pickle.PickleError`" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B025.py:35:8: B025 try-except block with duplicate exception `ValueError`
location: |
row: 28 35 | except (ValueError, TypeError):
column: 7 36 | a = 2
end_location: 37 | except ValueError:
row: 28 | ^^^^^^^^^^ B025
column: 25 38 | a = 2
fix: 39 | except (OSError, TypeError):
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B025.py:37:18: B025 try-except block with duplicate exception `TypeError`
name: DuplicateTryBlockException |
body: "try-except block with duplicate exception `ValueError`" 37 | except ValueError:
suggestion: ~ 38 | a = 2
fixable: false 39 | except (OSError, TypeError):
location: | ^^^^^^^^^ B025
row: 35 40 | a = 2
column: 7 |
end_location:
row: 35
column: 17
fix:
edits: []
parent: ~
- kind:
name: DuplicateTryBlockException
body: "try-except block with duplicate exception `TypeError`"
suggestion: ~
fixable: false
location:
row: 37
column: 17
end_location:
row: 37
column: 26
fix:
edits: []
parent: ~

View file

@ -1,103 +1,70 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B026.py:16:16: B026 Star-arg unpacking after a keyword argument is strongly discouraged
name: StarArgUnpackingAfterKeywordArg |
body: Star-arg unpacking after a keyword argument is strongly discouraged 16 | foo("bar", baz="baz", bam="bam")
suggestion: ~ 17 | foo(bar="bar", baz="baz", bam="bam")
fixable: false 18 | foo(bam="bam", *["bar", "baz"])
location: | ^^^^^^^^^^^^^^^ B026
row: 16 19 | foo(bam="bam", *bar_baz)
column: 15 20 | foo(baz="baz", bam="bam", *["bar"])
end_location: |
row: 16
column: 30 ./resources/test/fixtures/flake8_bugbear/B026.py:17:16: B026 Star-arg unpacking after a keyword argument is strongly discouraged
fix: |
edits: [] 17 | foo(bar="bar", baz="baz", bam="bam")
parent: ~ 18 | foo(bam="bam", *["bar", "baz"])
- kind: 19 | foo(bam="bam", *bar_baz)
name: StarArgUnpackingAfterKeywordArg | ^^^^^^^^ B026
body: Star-arg unpacking after a keyword argument is strongly discouraged 20 | foo(baz="baz", bam="bam", *["bar"])
suggestion: ~ 21 | foo(bar="bar", baz="baz", bam="bam", *[])
fixable: false |
location:
row: 17 ./resources/test/fixtures/flake8_bugbear/B026.py:18:27: B026 Star-arg unpacking after a keyword argument is strongly discouraged
column: 15 |
end_location: 18 | foo(bam="bam", *["bar", "baz"])
row: 17 19 | foo(bam="bam", *bar_baz)
column: 23 20 | foo(baz="baz", bam="bam", *["bar"])
fix: | ^^^^^^^^ B026
edits: [] 21 | foo(bar="bar", baz="baz", bam="bam", *[])
parent: ~ 22 | foo(bam="bam", *["bar"], *["baz"])
- kind: |
name: StarArgUnpackingAfterKeywordArg
body: Star-arg unpacking after a keyword argument is strongly discouraged ./resources/test/fixtures/flake8_bugbear/B026.py:19:38: B026 Star-arg unpacking after a keyword argument is strongly discouraged
suggestion: ~ |
fixable: false 19 | foo(bam="bam", *bar_baz)
location: 20 | foo(baz="baz", bam="bam", *["bar"])
row: 18 21 | foo(bar="bar", baz="baz", bam="bam", *[])
column: 26 | ^^^ B026
end_location: 22 | foo(bam="bam", *["bar"], *["baz"])
row: 18 23 | foo(*["bar"], bam="bam", *["baz"])
column: 34 |
fix:
edits: [] ./resources/test/fixtures/flake8_bugbear/B026.py:20:16: B026 Star-arg unpacking after a keyword argument is strongly discouraged
parent: ~ |
- kind: 20 | foo(baz="baz", bam="bam", *["bar"])
name: StarArgUnpackingAfterKeywordArg 21 | foo(bar="bar", baz="baz", bam="bam", *[])
body: Star-arg unpacking after a keyword argument is strongly discouraged 22 | foo(bam="bam", *["bar"], *["baz"])
suggestion: ~ | ^^^^^^^^ B026
fixable: false 23 | foo(*["bar"], bam="bam", *["baz"])
location: |
row: 19
column: 37 ./resources/test/fixtures/flake8_bugbear/B026.py:20:26: B026 Star-arg unpacking after a keyword argument is strongly discouraged
end_location: |
row: 19 20 | foo(baz="baz", bam="bam", *["bar"])
column: 40 21 | foo(bar="bar", baz="baz", bam="bam", *[])
fix: 22 | foo(bam="bam", *["bar"], *["baz"])
edits: [] | ^^^^^^^^ B026
parent: ~ 23 | foo(*["bar"], bam="bam", *["baz"])
- kind: |
name: StarArgUnpackingAfterKeywordArg
body: Star-arg unpacking after a keyword argument is strongly discouraged ./resources/test/fixtures/flake8_bugbear/B026.py:21:26: B026 Star-arg unpacking after a keyword argument is strongly discouraged
suggestion: ~ |
fixable: false 21 | foo(bar="bar", baz="baz", bam="bam", *[])
location: 22 | foo(bam="bam", *["bar"], *["baz"])
row: 20 23 | foo(*["bar"], bam="bam", *["baz"])
column: 15 | ^^^^^^^^ B026
end_location: |
row: 20
column: 23
fix:
edits: []
parent: ~
- kind:
name: StarArgUnpackingAfterKeywordArg
body: Star-arg unpacking after a keyword argument is strongly discouraged
suggestion: ~
fixable: false
location:
row: 20
column: 25
end_location:
row: 20
column: 33
fix:
edits: []
parent: ~
- kind:
name: StarArgUnpackingAfterKeywordArg
body: Star-arg unpacking after a keyword argument is strongly discouraged
suggestion: ~
fixable: false
location:
row: 21
column: 25
end_location:
row: 21
column: 33
fix:
edits: []
parent: ~

View file

@ -1,61 +1,56 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B027.py:13:5: B027 `AbstractClass.empty_1` is an empty method in an abstract base class, but has no abstract decorator
name: EmptyMethodWithoutAbstractDecorator |
body: "`AbstractClass.empty_1` is an empty method in an abstract base class, but has no abstract decorator" 13 | class AbstractClass(ABC):
suggestion: ~ 14 | def empty_1(self): # error
fixable: false | _____^
location: 15 | | ...
row: 13 | |___________^ B027
column: 4 16 |
end_location: 17 | def empty_2(self): # error
row: 14 |
column: 11
fix: ./resources/test/fixtures/flake8_bugbear/B027.py:16:5: B027 `AbstractClass.empty_2` is an empty method in an abstract base class, but has no abstract decorator
edits: [] |
parent: ~ 16 | ...
- kind: 17 |
name: EmptyMethodWithoutAbstractDecorator 18 | def empty_2(self): # error
body: "`AbstractClass.empty_2` is an empty method in an abstract base class, but has no abstract decorator" | _____^
suggestion: ~ 19 | | pass
fixable: false | |____________^ B027
location: 20 |
row: 16 21 | def empty_3(self): # error
column: 4 |
end_location:
row: 17 ./resources/test/fixtures/flake8_bugbear/B027.py:19:5: B027 `AbstractClass.empty_3` is an empty method in an abstract base class, but has no abstract decorator
column: 12 |
fix: 19 | pass
edits: [] 20 |
parent: ~ 21 | def empty_3(self): # error
- kind: | _____^
name: EmptyMethodWithoutAbstractDecorator 22 | | """docstring"""
body: "`AbstractClass.empty_3` is an empty method in an abstract base class, but has no abstract decorator" 23 | | ...
suggestion: ~ | |___________^ B027
fixable: false 24 |
location: 25 | def empty_4(self): # error
row: 19 |
column: 4
end_location: ./resources/test/fixtures/flake8_bugbear/B027.py:23:5: B027 `AbstractClass.empty_4` is an empty method in an abstract base class, but has no abstract decorator
row: 21 |
column: 11 23 | ...
fix: 24 |
edits: [] 25 | def empty_4(self): # error
parent: ~ | _____^
- kind: 26 | | """multiple ellipsis/pass"""
name: EmptyMethodWithoutAbstractDecorator 27 | | ...
body: "`AbstractClass.empty_4` is an empty method in an abstract base class, but has no abstract decorator" 28 | | pass
suggestion: ~ 29 | | ...
fixable: false 30 | | pass
location: | |____________^ B027
row: 23 31 |
column: 4 32 | @notabstract
end_location: |
row: 28
column: 12
fix:
edits: []
parent: ~

View file

@ -1,6 +1,4 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
[]

View file

@ -1,33 +1,23 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B028.py:8:1: B028 No explicit `stacklevel` keyword argument found
name: NoExplicitStacklevel |
body: "No explicit `stacklevel` keyword argument found" 8 | """
suggestion: ~ 9 |
fixable: false 10 | warnings.warn(DeprecationWarning("test"))
location: | ^^^^^^^^^^^^^ B028
row: 8 11 | warnings.warn(DeprecationWarning("test"), source=None)
column: 0 12 | warnings.warn(DeprecationWarning("test"), source=None, stacklevel=2)
end_location: |
row: 8
column: 13 ./resources/test/fixtures/flake8_bugbear/B028.py:9:1: B028 No explicit `stacklevel` keyword argument found
fix: |
edits: [] 9 | warnings.warn(DeprecationWarning("test"))
parent: ~ 10 | warnings.warn(DeprecationWarning("test"), source=None)
- kind: | ^^^^^^^^^^^^^ B028
name: NoExplicitStacklevel 11 | warnings.warn(DeprecationWarning("test"), source=None, stacklevel=2)
body: "No explicit `stacklevel` keyword argument found" 12 | warnings.warn(DeprecationWarning("test"), stacklevel=1)
suggestion: ~ |
fixable: false
location:
row: 9
column: 0
end_location:
row: 9
column: 13
fix:
edits: []
parent: ~

View file

@ -1,33 +1,24 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B029.py:8:1: B029 Using `except ():` with an empty tuple does not catch anything; add exceptions to handle
name: ExceptWithEmptyTuple |
body: "Using `except ():` with an empty tuple does not catch anything; add exceptions to handle" 8 | try:
suggestion: ~ 9 | pass
fixable: false 10 | / except ():
location: 11 | | pass
row: 8 | |________^ B029
column: 0 12 |
end_location: 13 | try:
row: 9 |
column: 8
fix: ./resources/test/fixtures/flake8_bugbear/B029.py:13:1: B029 Using `except ():` with an empty tuple does not catch anything; add exceptions to handle
edits: [] |
parent: ~ 13 | try:
- kind: 14 | pass
name: ExceptWithEmptyTuple 15 | / except () as e:
body: "Using `except ():` with an empty tuple does not catch anything; add exceptions to handle" 16 | | pass
suggestion: ~ | |________^ B029
fixable: false |
location:
row: 13
column: 0
end_location:
row: 14
column: 8
fix:
edits: []
parent: ~

View file

@ -1,75 +1,49 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B030.py:12:8: B030 `except` handlers should only be exception classes or tuples of exception classes
name: ExceptWithNonExceptionClasses |
body: "`except` handlers should only be exception classes or tuples of exception classes" 12 | try:
suggestion: ~ 13 | pass
fixable: false 14 | except 1: # error
location: | ^ B030
row: 12 15 | pass
column: 7 |
end_location:
row: 12 ./resources/test/fixtures/flake8_bugbear/B030.py:17:9: B030 `except` handlers should only be exception classes or tuples of exception classes
column: 8 |
fix: 17 | try:
edits: [] 18 | pass
parent: ~ 19 | except (1, ValueError): # error
- kind: | ^ B030
name: ExceptWithNonExceptionClasses 20 | pass
body: "`except` handlers should only be exception classes or tuples of exception classes" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B030.py:22:21: B030 `except` handlers should only be exception classes or tuples of exception classes
location: |
row: 17 22 | try:
column: 8 23 | pass
end_location: 24 | except (ValueError, (RuntimeError, (KeyError, TypeError))): # error
row: 17 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B030
column: 9 25 | pass
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bugbear/B030.py:27:37: B030 `except` handlers should only be exception classes or tuples of exception classes
- kind: |
name: ExceptWithNonExceptionClasses 27 | try:
body: "`except` handlers should only be exception classes or tuples of exception classes" 28 | pass
suggestion: ~ 29 | except (ValueError, *(RuntimeError, (KeyError, TypeError))): # error
fixable: false | ^^^^^^^^^^^^^^^^^^^^^ B030
location: 30 | pass
row: 22 |
column: 20
end_location: ./resources/test/fixtures/flake8_bugbear/B030.py:33:29: B030 `except` handlers should only be exception classes or tuples of exception classes
row: 22 |
column: 57 33 | try:
fix: 34 | pass
edits: [] 35 | except (*a, *(RuntimeError, (KeyError, TypeError))): # error
parent: ~ | ^^^^^^^^^^^^^^^^^^^^^ B030
- kind: 36 | pass
name: ExceptWithNonExceptionClasses |
body: "`except` handlers should only be exception classes or tuples of exception classes"
suggestion: ~
fixable: false
location:
row: 27
column: 36
end_location:
row: 27
column: 57
fix:
edits: []
parent: ~
- kind:
name: ExceptWithNonExceptionClasses
body: "`except` handlers should only be exception classes or tuples of exception classes"
suggestion: ~
fixable: false
location:
row: 33
column: 28
end_location:
row: 33
column: 49
fix:
edits: []
parent: ~

View file

@ -1,285 +1,198 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B031.py:27:37: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
name: ReuseOfGroupbyGenerator |
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" 27 | for shopper in shoppers:
suggestion: ~ 28 | shopper = shopper.title()
fixable: false 29 | collect_shop_items(shopper, section_items) # B031
location: | ^^^^^^^^^^^^^ B031
row: 27 30 | # We're outside the nested loop and used the group again.
column: 36 31 | collect_shop_items(shopper, section_items) # B031
end_location: |
row: 27
column: 49 ./resources/test/fixtures/flake8_bugbear/B031.py:29:33: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
fix: |
edits: [] 29 | collect_shop_items(shopper, section_items) # B031
parent: ~ 30 | # We're outside the nested loop and used the group again.
- kind: 31 | collect_shop_items(shopper, section_items) # B031
name: ReuseOfGroupbyGenerator | ^^^^^^^^^^^^^ B031
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" 32 |
suggestion: ~ 33 | for _section, section_items in groupby(items, key=lambda p: p[1]):
fixable: false |
location:
row: 29 ./resources/test/fixtures/flake8_bugbear/B031.py:33:31: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
column: 32 |
end_location: 33 | for _section, section_items in groupby(items, key=lambda p: p[1]):
row: 29 34 | collect_shop_items("Jane", section_items)
column: 45 35 | collect_shop_items("Joe", section_items) # B031
fix: | ^^^^^^^^^^^^^ B031
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B031.py:40:37: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
name: ReuseOfGroupbyGenerator |
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" 40 | countdown = 3
suggestion: ~ 41 | while countdown > 0:
fixable: false 42 | collect_shop_items(shopper, section_items) # B031
location: | ^^^^^^^^^^^^^ B031
row: 33 43 | countdown -= 1
column: 30 |
end_location:
row: 33 ./resources/test/fixtures/flake8_bugbear/B031.py:46:29: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
column: 43 |
fix: 46 | collection = []
edits: [] 47 | for _section, section_items in groupby(items, key=lambda p: p[1]):
parent: ~ 48 | collection.append([list(section_items) for _ in range(3)]) # B031
- kind: | ^^^^^^^^^^^^^ B031
name: ReuseOfGroupbyGenerator 49 |
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" 50 | unique_items = set()
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bugbear/B031.py:56:17: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
row: 40 |
column: 36 56 | # But it should be detected when used again
end_location: 57 | for item in section_items: # B031
row: 40 | ^^^^^^^^^^^^^ B031
column: 49 58 | another_set.add(item)
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bugbear/B031.py:79:37: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
- kind: |
name: ReuseOfGroupbyGenerator 79 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" 80 | for shopper in shoppers:
suggestion: ~ 81 | collect_shop_items(shopper, section_items) # B031
fixable: false | ^^^^^^^^^^^^^ B031
location: 82 |
row: 46 83 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
column: 28 |
end_location:
row: 46 ./resources/test/fixtures/flake8_bugbear/B031.py:82:38: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
column: 41 |
fix: 82 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
edits: [] 83 | _ = [collect_shop_items(shopper, section_items) for shopper in shoppers] # B031
parent: ~ | ^^^^^^^^^^^^^ B031
- kind: 84 |
name: ReuseOfGroupbyGenerator 85 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B031.py:94:65: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
location: |
row: 56 94 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
column: 16 95 | # The iterator is being used for the second time.
end_location: 96 | _ = [(item1, item2) for item1 in section_items for item2 in section_items] # B031
row: 56 | ^^^^^^^^^^^^^ B031
column: 29 97 |
fix: 98 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B031.py:101:37: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
name: ReuseOfGroupbyGenerator |
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" 101 | else:
suggestion: ~ 102 | collect_shop_items(shopper, section_items)
fixable: false 103 | collect_shop_items(shopper, section_items) # B031
location: | ^^^^^^^^^^^^^ B031
row: 79 104 |
column: 36 105 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
end_location: |
row: 79
column: 49 ./resources/test/fixtures/flake8_bugbear/B031.py:108:41: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
fix: |
edits: [] 108 | collect_shop_items(shopper, section_items)
parent: ~ 109 | if _section == "greens":
- kind: 110 | collect_shop_items(shopper, section_items) # B031
name: ReuseOfGroupbyGenerator | ^^^^^^^^^^^^^ B031
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" 111 | elif _section == "frozen items":
suggestion: ~ 112 | collect_shop_items(shopper, section_items) # B031
fixable: false |
location:
row: 82 ./resources/test/fixtures/flake8_bugbear/B031.py:110:41: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
column: 37 |
end_location: 110 | collect_shop_items(shopper, section_items) # B031
row: 82 111 | elif _section == "frozen items":
column: 50 112 | collect_shop_items(shopper, section_items) # B031
fix: | ^^^^^^^^^^^^^ B031
edits: [] 113 | else:
parent: ~ 114 | collect_shop_items(shopper, section_items) # B031
- kind: |
name: ReuseOfGroupbyGenerator
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" ./resources/test/fixtures/flake8_bugbear/B031.py:112:41: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
suggestion: ~ |
fixable: false 112 | collect_shop_items(shopper, section_items) # B031
location: 113 | else:
row: 94 114 | collect_shop_items(shopper, section_items) # B031
column: 64 | ^^^^^^^^^^^^^ B031
end_location: 115 | collect_shop_items(shopper, section_items) # B031
row: 94 116 | elif _section == "frozen items":
column: 77 |
fix:
edits: [] ./resources/test/fixtures/flake8_bugbear/B031.py:113:37: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
parent: ~ |
- kind: 113 | else:
name: ReuseOfGroupbyGenerator 114 | collect_shop_items(shopper, section_items) # B031
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" 115 | collect_shop_items(shopper, section_items) # B031
suggestion: ~ | ^^^^^^^^^^^^^ B031
fixable: false 116 | elif _section == "frozen items":
location: 117 | # Mix `match` and `if` statements
row: 101 |
column: 36
end_location: ./resources/test/fixtures/flake8_bugbear/B031.py:120:49: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
row: 101 |
column: 49 120 | collect_shop_items(shopper, section_items)
fix: 121 | if _section == "fourth":
edits: [] 122 | collect_shop_items(shopper, section_items) # B031
parent: ~ | ^^^^^^^^^^^^^ B031
- kind: 123 | case _:
name: ReuseOfGroupbyGenerator 124 | collect_shop_items(shopper, section_items)
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B031.py:126:33: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
location: |
row: 108 126 | collect_shop_items(shopper, section_items)
column: 40 127 | # Now, it should detect
end_location: 128 | collect_shop_items(shopper, section_items) # B031
row: 108 | ^^^^^^^^^^^^^ B031
column: 53 129 |
fix: 130 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B031.py:135:49: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
name: ReuseOfGroupbyGenerator |
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" 135 | match shopper:
suggestion: ~ 136 | case "Jane":
fixable: false 137 | collect_shop_items(shopper, section_items) # B031
location: | ^^^^^^^^^^^^^ B031
row: 110 138 | case _:
column: 40 139 | collect_shop_items(shopper, section_items) # B031
end_location: |
row: 110
column: 53 ./resources/test/fixtures/flake8_bugbear/B031.py:137:49: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
fix: |
edits: [] 137 | collect_shop_items(shopper, section_items) # B031
parent: ~ 138 | case _:
- kind: 139 | collect_shop_items(shopper, section_items) # B031
name: ReuseOfGroupbyGenerator | ^^^^^^^^^^^^^ B031
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" 140 | case "frozen items":
suggestion: ~ 141 | collect_shop_items(shopper, section_items)
fixable: false |
location:
row: 112 ./resources/test/fixtures/flake8_bugbear/B031.py:140:41: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
column: 40 |
end_location: 140 | case "frozen items":
row: 112 141 | collect_shop_items(shopper, section_items)
column: 53 142 | collect_shop_items(shopper, section_items) # B031
fix: | ^^^^^^^^^^^^^ B031
edits: [] 143 | case _:
parent: ~ 144 | collect_shop_items(shopper, section_items)
- kind: |
name: ReuseOfGroupbyGenerator
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" ./resources/test/fixtures/flake8_bugbear/B031.py:144:33: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage
suggestion: ~ |
fixable: false 144 | collect_shop_items(shopper, section_items)
location: 145 | # Now, it should detect
row: 113 146 | collect_shop_items(shopper, section_items) # B031
column: 36 | ^^^^^^^^^^^^^ B031
end_location: 147 |
row: 113 148 | for group in groupby(items, key=lambda p: p[1]):
column: 49 |
fix:
edits: []
parent: ~
- kind:
name: ReuseOfGroupbyGenerator
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage"
suggestion: ~
fixable: false
location:
row: 120
column: 48
end_location:
row: 120
column: 61
fix:
edits: []
parent: ~
- kind:
name: ReuseOfGroupbyGenerator
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage"
suggestion: ~
fixable: false
location:
row: 126
column: 32
end_location:
row: 126
column: 45
fix:
edits: []
parent: ~
- kind:
name: ReuseOfGroupbyGenerator
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage"
suggestion: ~
fixable: false
location:
row: 135
column: 48
end_location:
row: 135
column: 61
fix:
edits: []
parent: ~
- kind:
name: ReuseOfGroupbyGenerator
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage"
suggestion: ~
fixable: false
location:
row: 137
column: 48
end_location:
row: 137
column: 61
fix:
edits: []
parent: ~
- kind:
name: ReuseOfGroupbyGenerator
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage"
suggestion: ~
fixable: false
location:
row: 140
column: 40
end_location:
row: 140
column: 53
fix:
edits: []
parent: ~
- kind:
name: ReuseOfGroupbyGenerator
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage"
suggestion: ~
fixable: false
location:
row: 144
column: 32
end_location:
row: 144
column: 45
fix:
edits: []
parent: ~

View file

@ -1,117 +1,78 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B032.py:9:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?
name: UnintentionalTypeAnnotation |
body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?" 9 | dct = {"a": 1}
suggestion: ~ 10 |
fixable: false 11 | dct["b"]: 2
location: | ^^^^^^^^^^^ B032
row: 9 12 | dct.b: 2
column: 0 |
end_location:
row: 9 ./resources/test/fixtures/flake8_bugbear/B032.py:10:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?
column: 11 |
fix: 10 | dct["b"]: 2
edits: [] 11 | dct.b: 2
parent: ~ | ^^^^^^^^ B032
- kind: 12 |
name: UnintentionalTypeAnnotation 13 | dct["b"]: "test"
body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_bugbear/B032.py:12:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?
location: |
row: 10 12 | dct.b: 2
column: 0 13 |
end_location: 14 | dct["b"]: "test"
row: 10 | ^^^^^^^^^^^^^^^^ B032
column: 8 15 | dct.b: "test"
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bugbear/B032.py:13:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?
- kind: |
name: UnintentionalTypeAnnotation 13 | dct["b"]: "test"
body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?" 14 | dct.b: "test"
suggestion: ~ | ^^^^^^^^^^^^^ B032
fixable: false 15 |
location: 16 | test = "test"
row: 12 |
column: 0
end_location: ./resources/test/fixtures/flake8_bugbear/B032.py:16:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?
row: 12 |
column: 16 16 | test = "test"
fix: 17 | dct["b"]: test
edits: [] | ^^^^^^^^^^^^^^ B032
parent: ~ 18 | dct["b"]: test.lower()
- kind: 19 | dct.b: test
name: UnintentionalTypeAnnotation |
body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?"
suggestion: ~ ./resources/test/fixtures/flake8_bugbear/B032.py:17:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?
fixable: false |
location: 17 | test = "test"
row: 13 18 | dct["b"]: test
column: 0 19 | dct["b"]: test.lower()
end_location: | ^^^^^^^^^^^^^^^^^^^^^^ B032
row: 13 20 | dct.b: test
column: 13 21 | dct.b: test.lower()
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bugbear/B032.py:18:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?
- kind: |
name: UnintentionalTypeAnnotation 18 | dct["b"]: test
body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?" 19 | dct["b"]: test.lower()
suggestion: ~ 20 | dct.b: test
fixable: false | ^^^^^^^^^^^ B032
location: 21 | dct.b: test.lower()
row: 16 |
column: 0
end_location: ./resources/test/fixtures/flake8_bugbear/B032.py:19:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?
row: 16 |
column: 14 19 | dct["b"]: test.lower()
fix: 20 | dct.b: test
edits: [] 21 | dct.b: test.lower()
parent: ~ | ^^^^^^^^^^^^^^^^^^^ B032
- kind: 22 |
name: UnintentionalTypeAnnotation 23 | # Do not flag below
body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?" |
suggestion: ~
fixable: false
location:
row: 17
column: 0
end_location:
row: 17
column: 22
fix:
edits: []
parent: ~
- kind:
name: UnintentionalTypeAnnotation
body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?"
suggestion: ~
fixable: false
location:
row: 18
column: 0
end_location:
row: 18
column: 11
fix:
edits: []
parent: ~
- kind:
name: UnintentionalTypeAnnotation
body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?"
suggestion: ~
fixable: false
location:
row: 19
column: 0
end_location:
row: 19
column: 19
fix:
edits: []
parent: ~

View file

@ -1,89 +1,60 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B904.py:10:9: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
name: RaiseWithoutFromInsideExcept |
body: "Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling" 10 | except ValueError:
suggestion: ~ 11 | if "abc":
fixable: false 12 | raise TypeError
location: | ^^^^^^^^^^^^^^^ B904
row: 10 13 | raise UserWarning
column: 8 14 | except AssertionError:
end_location: |
row: 10
column: 23 ./resources/test/fixtures/flake8_bugbear/B904.py:11:5: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
fix: |
edits: [] 11 | if "abc":
parent: ~ 12 | raise TypeError
- kind: 13 | raise UserWarning
name: RaiseWithoutFromInsideExcept | ^^^^^^^^^^^^^^^^^ B904
body: "Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling" 14 | except AssertionError:
suggestion: ~ 15 | raise # Bare `raise` should not be an error
fixable: false |
location:
row: 11 ./resources/test/fixtures/flake8_bugbear/B904.py:16:5: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
column: 4 |
end_location: 16 | except Exception as err:
row: 11 17 | assert err
column: 21 18 | raise Exception("No cause here...")
fix: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B904
edits: [] 19 | except BaseException as base_err:
parent: ~ 20 | # Might use this instead of bare raise with the `.with_traceback()` method
- kind: |
name: RaiseWithoutFromInsideExcept
body: "Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling" ./resources/test/fixtures/flake8_bugbear/B904.py:62:9: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
suggestion: ~ |
fixable: false 62 | except Exception as e:
location: 63 | if ...:
row: 16 64 | raise RuntimeError("boom!")
column: 4 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ B904
end_location: 65 | else:
row: 16 66 | raise RuntimeError("bang!")
column: 39 |
fix:
edits: [] ./resources/test/fixtures/flake8_bugbear/B904.py:64:9: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
parent: ~ |
- kind: 64 | raise RuntimeError("boom!")
name: RaiseWithoutFromInsideExcept 65 | else:
body: "Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling" 66 | raise RuntimeError("bang!")
suggestion: ~ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ B904
fixable: false |
location:
row: 62 ./resources/test/fixtures/flake8_bugbear/B904.py:72:13: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
column: 8 |
end_location: 72 | match 0:
row: 62 73 | case 0:
column: 35 74 | raise RuntimeError("boom!")
fix: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ B904
edits: [] |
parent: ~
- kind:
name: RaiseWithoutFromInsideExcept
body: "Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling"
suggestion: ~
fixable: false
location:
row: 64
column: 8
end_location:
row: 64
column: 35
fix:
edits: []
parent: ~
- kind:
name: RaiseWithoutFromInsideExcept
body: "Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling"
suggestion: ~
fixable: false
location:
row: 72
column: 12
end_location:
row: 72
column: 39
fix:
edits: []
parent: ~

View file

@ -1,103 +1,70 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B905.py:1:1: B905 `zip()` without an explicit `strict=` parameter
name: ZipWithoutExplicitStrict |
body: "`zip()` without an explicit `strict=` parameter" 1 | zip()
suggestion: ~ | ^^^^^ B905
fixable: false 2 | zip(range(3))
location: 3 | zip("a", "b")
row: 1 |
column: 0
end_location: ./resources/test/fixtures/flake8_bugbear/B905.py:2:1: B905 `zip()` without an explicit `strict=` parameter
row: 1 |
column: 5 2 | zip()
fix: 3 | zip(range(3))
edits: [] | ^^^^^^^^^^^^^ B905
parent: ~ 4 | zip("a", "b")
- kind: 5 | zip("a", "b", *zip("c"))
name: ZipWithoutExplicitStrict |
body: "`zip()` without an explicit `strict=` parameter"
suggestion: ~ ./resources/test/fixtures/flake8_bugbear/B905.py:3:1: B905 `zip()` without an explicit `strict=` parameter
fixable: false |
location: 3 | zip()
row: 2 4 | zip(range(3))
column: 0 5 | zip("a", "b")
end_location: | ^^^^^^^^^^^^^ B905
row: 2 6 | zip("a", "b", *zip("c"))
column: 13 7 | zip(zip("a"), strict=False)
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_bugbear/B905.py:4:1: B905 `zip()` without an explicit `strict=` parameter
- kind: |
name: ZipWithoutExplicitStrict 4 | zip(range(3))
body: "`zip()` without an explicit `strict=` parameter" 5 | zip("a", "b")
suggestion: ~ 6 | zip("a", "b", *zip("c"))
fixable: false | ^^^^^^^^^^^^^^^^^^^^^^^^ B905
location: 7 | zip(zip("a"), strict=False)
row: 3 8 | zip(zip("a", strict=True))
column: 0 |
end_location:
row: 3 ./resources/test/fixtures/flake8_bugbear/B905.py:4:16: B905 `zip()` without an explicit `strict=` parameter
column: 13 |
fix: 4 | zip(range(3))
edits: [] 5 | zip("a", "b")
parent: ~ 6 | zip("a", "b", *zip("c"))
- kind: | ^^^^^^^^ B905
name: ZipWithoutExplicitStrict 7 | zip(zip("a"), strict=False)
body: "`zip()` without an explicit `strict=` parameter" 8 | zip(zip("a", strict=True))
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_bugbear/B905.py:5:5: B905 `zip()` without an explicit `strict=` parameter
row: 4 |
column: 0 5 | zip("a", "b")
end_location: 6 | zip("a", "b", *zip("c"))
row: 4 7 | zip(zip("a"), strict=False)
column: 24 | ^^^^^^^^ B905
fix: 8 | zip(zip("a", strict=True))
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_bugbear/B905.py:6:1: B905 `zip()` without an explicit `strict=` parameter
name: ZipWithoutExplicitStrict |
body: "`zip()` without an explicit `strict=` parameter" 6 | zip("a", "b", *zip("c"))
suggestion: ~ 7 | zip(zip("a"), strict=False)
fixable: false 8 | zip(zip("a", strict=True))
location: | ^^^^^^^^^^^^^^^^^^^^^^^^^^ B905
row: 4 9 |
column: 15 10 | zip(range(3), strict=True)
end_location: |
row: 4
column: 23
fix:
edits: []
parent: ~
- kind:
name: ZipWithoutExplicitStrict
body: "`zip()` without an explicit `strict=` parameter"
suggestion: ~
fixable: false
location:
row: 5
column: 4
end_location:
row: 5
column: 12
fix:
edits: []
parent: ~
- kind:
name: ZipWithoutExplicitStrict
body: "`zip()` without an explicit `strict=` parameter"
suggestion: ~
fixable: false
location:
row: 6
column: 0
end_location:
row: 6
column: 26
fix:
edits: []
parent: ~

View file

@ -1,19 +1,11 @@
--- ---
source: crates/ruff/src/rules/flake8_bugbear/mod.rs source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_bugbear/B008_extended.py:19:51: B008 Do not perform function call `Depends` in argument defaults
name: FunctionCallInDefaultArgument |
body: "Do not perform function call `Depends` in argument defaults" 19 | def error_due_to_missing_import(data: List[str] = Depends(None)):
suggestion: ~ | ^^^^^^^^^^^^^ B008
fixable: false 20 | ...
location: |
row: 19
column: 50
end_location:
row: 19
column: 63
fix:
edits: []
parent: ~

View file

@ -7,8 +7,9 @@ pub(crate) mod types;
mod tests { mod tests {
use std::path::Path; use std::path::Path;
use crate::assert_messages;
use anyhow::Result; use anyhow::Result;
use insta::assert_yaml_snapshot;
use test_case::test_case; use test_case::test_case;
use crate::registry::Rule; use crate::registry::Rule;
@ -24,7 +25,7 @@ mod tests {
Path::new("flake8_builtins").join(path).as_path(), Path::new("flake8_builtins").join(path).as_path(),
&Settings::for_rule(rule_code), &Settings::for_rule(rule_code),
)?; )?;
assert_yaml_snapshot!(snapshot, diagnostics); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())
} }
@ -48,7 +49,7 @@ mod tests {
}, },
)?; )?;
assert_yaml_snapshot!(snapshot, diagnostics); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())
} }
} }

View file

@ -1,285 +1,193 @@
--- ---
source: crates/ruff/src/rules/flake8_builtins/mod.rs source: crates/ruff/src/rules/flake8_builtins/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_builtins/A001.py:1:1: A001 Variable `sum` is shadowing a python builtin
name: BuiltinVariableShadowing |
body: "Variable `sum` is shadowing a python builtin" 1 | import some as sum
suggestion: ~ | ^^^^^^^^^^^^^^^^^^ A001
fixable: false 2 | from some import other as int
location: 3 | from directory import new as dir
row: 1 |
column: 0
end_location: ./resources/test/fixtures/flake8_builtins/A001.py:2:1: A001 Variable `int` is shadowing a python builtin
row: 1 |
column: 18 2 | import some as sum
fix: 3 | from some import other as int
edits: [] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A001
parent: ~ 4 | from directory import new as dir
- kind: |
name: BuiltinVariableShadowing
body: "Variable `int` is shadowing a python builtin" ./resources/test/fixtures/flake8_builtins/A001.py:3:1: A001 Variable `dir` is shadowing a python builtin
suggestion: ~ |
fixable: false 3 | import some as sum
location: 4 | from some import other as int
row: 2 5 | from directory import new as dir
column: 0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A001
end_location: 6 |
row: 2 7 | print = 1
column: 29 |
fix:
edits: [] ./resources/test/fixtures/flake8_builtins/A001.py:5:1: A001 Variable `print` is shadowing a python builtin
parent: ~ |
- kind: 5 | from directory import new as dir
name: BuiltinVariableShadowing 6 |
body: "Variable `dir` is shadowing a python builtin" 7 | print = 1
suggestion: ~ | ^^^^^ A001
fixable: false 8 | copyright: 'annotation' = 2
location: 9 | (complex := 3)
row: 3 |
column: 0
end_location: ./resources/test/fixtures/flake8_builtins/A001.py:6:1: A001 Variable `copyright` is shadowing a python builtin
row: 3 |
column: 32 6 | print = 1
fix: 7 | copyright: 'annotation' = 2
edits: [] | ^^^^^^^^^ A001
parent: ~ 8 | (complex := 3)
- kind: 9 | float = object = 4
name: BuiltinVariableShadowing |
body: "Variable `print` is shadowing a python builtin"
suggestion: ~ ./resources/test/fixtures/flake8_builtins/A001.py:7:2: A001 Variable `complex` is shadowing a python builtin
fixable: false |
location: 7 | print = 1
row: 5 8 | copyright: 'annotation' = 2
column: 0 9 | (complex := 3)
end_location: | ^^^^^^^ A001
row: 5 10 | float = object = 4
column: 5 11 | min, max = 5, 6
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_builtins/A001.py:8:1: A001 Variable `float` is shadowing a python builtin
- kind: |
name: BuiltinVariableShadowing 8 | copyright: 'annotation' = 2
body: "Variable `copyright` is shadowing a python builtin" 9 | (complex := 3)
suggestion: ~ 10 | float = object = 4
fixable: false | ^^^^^ A001
location: 11 | min, max = 5, 6
row: 6 |
column: 0
end_location: ./resources/test/fixtures/flake8_builtins/A001.py:8:9: A001 Variable `object` is shadowing a python builtin
row: 6 |
column: 9 8 | copyright: 'annotation' = 2
fix: 9 | (complex := 3)
edits: [] 10 | float = object = 4
parent: ~ | ^^^^^^ A001
- kind: 11 | min, max = 5, 6
name: BuiltinVariableShadowing |
body: "Variable `complex` is shadowing a python builtin"
suggestion: ~ ./resources/test/fixtures/flake8_builtins/A001.py:9:1: A001 Variable `min` is shadowing a python builtin
fixable: false |
location: 9 | (complex := 3)
row: 7 10 | float = object = 4
column: 1 11 | min, max = 5, 6
end_location: | ^^^ A001
row: 7 12 |
column: 8 13 | id = 4
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_builtins/A001.py:9:6: A001 Variable `max` is shadowing a python builtin
- kind: |
name: BuiltinVariableShadowing 9 | (complex := 3)
body: "Variable `float` is shadowing a python builtin" 10 | float = object = 4
suggestion: ~ 11 | min, max = 5, 6
fixable: false | ^^^ A001
location: 12 |
row: 8 13 | id = 4
column: 0 |
end_location:
row: 8 ./resources/test/fixtures/flake8_builtins/A001.py:11:1: A001 Variable `id` is shadowing a python builtin
column: 5 |
fix: 11 | min, max = 5, 6
edits: [] 12 |
parent: ~ 13 | id = 4
- kind: | ^^ A001
name: BuiltinVariableShadowing 14 |
body: "Variable `object` is shadowing a python builtin" 15 | def bytes():
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_builtins/A001.py:13:1: A001 Variable `bytes` is shadowing a python builtin
row: 8 |
column: 8 13 | id = 4
end_location: 14 |
row: 8 15 | / def bytes():
column: 14 16 | | pass
fix: | |________^ A001
edits: [] 17 |
parent: ~ 18 | class slice:
- kind: |
name: BuiltinVariableShadowing
body: "Variable `min` is shadowing a python builtin" ./resources/test/fixtures/flake8_builtins/A001.py:16:1: A001 Variable `slice` is shadowing a python builtin
suggestion: ~ |
fixable: false 16 | pass
location: 17 |
row: 9 18 | / class slice:
column: 0 19 | | pass
end_location: | |________^ A001
row: 9 20 |
column: 3 21 | try:
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_builtins/A001.py:21:1: A001 Variable `ValueError` is shadowing a python builtin
- kind: |
name: BuiltinVariableShadowing 21 | try:
body: "Variable `max` is shadowing a python builtin" 22 | ...
suggestion: ~ 23 | / except ImportError as ValueError:
fixable: false 24 | | ...
location: | |_______^ A001
row: 9 25 |
column: 5 26 | for memoryview, *bytearray in []:
end_location: |
row: 9
column: 8 ./resources/test/fixtures/flake8_builtins/A001.py:24:5: A001 Variable `memoryview` is shadowing a python builtin
fix: |
edits: [] 24 | ...
parent: ~ 25 |
- kind: 26 | for memoryview, *bytearray in []:
name: BuiltinVariableShadowing | ^^^^^^^^^^ A001
body: "Variable `id` is shadowing a python builtin" 27 | pass
suggestion: ~ |
fixable: false
location: ./resources/test/fixtures/flake8_builtins/A001.py:24:18: A001 Variable `bytearray` is shadowing a python builtin
row: 11 |
column: 0 24 | ...
end_location: 25 |
row: 11 26 | for memoryview, *bytearray in []:
column: 2 | ^^^^^^^^^ A001
fix: 27 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_builtins/A001.py:27:22: A001 Variable `str` is shadowing a python builtin
name: BuiltinVariableShadowing |
body: "Variable `bytes` is shadowing a python builtin" 27 | pass
suggestion: ~ 28 |
fixable: false 29 | with open('file') as str, open('file2') as (all, any):
location: | ^^^ A001
row: 13 30 | pass
column: 0 |
end_location:
row: 14 ./resources/test/fixtures/flake8_builtins/A001.py:27:45: A001 Variable `all` is shadowing a python builtin
column: 8 |
fix: 27 | pass
edits: [] 28 |
parent: ~ 29 | with open('file') as str, open('file2') as (all, any):
- kind: | ^^^ A001
name: BuiltinVariableShadowing 30 | pass
body: "Variable `slice` is shadowing a python builtin" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_builtins/A001.py:27:50: A001 Variable `any` is shadowing a python builtin
location: |
row: 16 27 | pass
column: 0 28 |
end_location: 29 | with open('file') as str, open('file2') as (all, any):
row: 17 | ^^^ A001
column: 8 30 | pass
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_builtins/A001.py:30:8: A001 Variable `sum` is shadowing a python builtin
- kind: |
name: BuiltinVariableShadowing 30 | pass
body: "Variable `ValueError` is shadowing a python builtin" 31 |
suggestion: ~ 32 | [0 for sum in ()]
fixable: false | ^^^ A001
location: |
row: 21
column: 0
end_location:
row: 22
column: 7
fix:
edits: []
parent: ~
- kind:
name: BuiltinVariableShadowing
body: "Variable `memoryview` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 24
column: 4
end_location:
row: 24
column: 14
fix:
edits: []
parent: ~
- kind:
name: BuiltinVariableShadowing
body: "Variable `bytearray` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 24
column: 17
end_location:
row: 24
column: 26
fix:
edits: []
parent: ~
- kind:
name: BuiltinVariableShadowing
body: "Variable `str` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 27
column: 21
end_location:
row: 27
column: 24
fix:
edits: []
parent: ~
- kind:
name: BuiltinVariableShadowing
body: "Variable `all` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 27
column: 44
end_location:
row: 27
column: 47
fix:
edits: []
parent: ~
- kind:
name: BuiltinVariableShadowing
body: "Variable `any` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 27
column: 49
end_location:
row: 27
column: 52
fix:
edits: []
parent: ~
- kind:
name: BuiltinVariableShadowing
body: "Variable `sum` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 30
column: 7
end_location:
row: 30
column: 10
fix:
edits: []
parent: ~

View file

@ -1,257 +1,173 @@
--- ---
source: crates/ruff/src/rules/flake8_builtins/mod.rs source: crates/ruff/src/rules/flake8_builtins/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_builtins/A001.py:1:1: A001 Variable `sum` is shadowing a python builtin
name: BuiltinVariableShadowing |
body: "Variable `sum` is shadowing a python builtin" 1 | import some as sum
suggestion: ~ | ^^^^^^^^^^^^^^^^^^ A001
fixable: false 2 | from some import other as int
location: 3 | from directory import new as dir
row: 1 |
column: 0
end_location: ./resources/test/fixtures/flake8_builtins/A001.py:2:1: A001 Variable `int` is shadowing a python builtin
row: 1 |
column: 18 2 | import some as sum
fix: 3 | from some import other as int
edits: [] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A001
parent: ~ 4 | from directory import new as dir
- kind: |
name: BuiltinVariableShadowing
body: "Variable `int` is shadowing a python builtin" ./resources/test/fixtures/flake8_builtins/A001.py:5:1: A001 Variable `print` is shadowing a python builtin
suggestion: ~ |
fixable: false 5 | from directory import new as dir
location: 6 |
row: 2 7 | print = 1
column: 0 | ^^^^^ A001
end_location: 8 | copyright: 'annotation' = 2
row: 2 9 | (complex := 3)
column: 29 |
fix:
edits: [] ./resources/test/fixtures/flake8_builtins/A001.py:6:1: A001 Variable `copyright` is shadowing a python builtin
parent: ~ |
- kind: 6 | print = 1
name: BuiltinVariableShadowing 7 | copyright: 'annotation' = 2
body: "Variable `print` is shadowing a python builtin" | ^^^^^^^^^ A001
suggestion: ~ 8 | (complex := 3)
fixable: false 9 | float = object = 4
location: |
row: 5
column: 0 ./resources/test/fixtures/flake8_builtins/A001.py:7:2: A001 Variable `complex` is shadowing a python builtin
end_location: |
row: 5 7 | print = 1
column: 5 8 | copyright: 'annotation' = 2
fix: 9 | (complex := 3)
edits: [] | ^^^^^^^ A001
parent: ~ 10 | float = object = 4
- kind: 11 | min, max = 5, 6
name: BuiltinVariableShadowing |
body: "Variable `copyright` is shadowing a python builtin"
suggestion: ~ ./resources/test/fixtures/flake8_builtins/A001.py:8:1: A001 Variable `float` is shadowing a python builtin
fixable: false |
location: 8 | copyright: 'annotation' = 2
row: 6 9 | (complex := 3)
column: 0 10 | float = object = 4
end_location: | ^^^^^ A001
row: 6 11 | min, max = 5, 6
column: 9 |
fix:
edits: [] ./resources/test/fixtures/flake8_builtins/A001.py:8:9: A001 Variable `object` is shadowing a python builtin
parent: ~ |
- kind: 8 | copyright: 'annotation' = 2
name: BuiltinVariableShadowing 9 | (complex := 3)
body: "Variable `complex` is shadowing a python builtin" 10 | float = object = 4
suggestion: ~ | ^^^^^^ A001
fixable: false 11 | min, max = 5, 6
location: |
row: 7
column: 1 ./resources/test/fixtures/flake8_builtins/A001.py:9:1: A001 Variable `min` is shadowing a python builtin
end_location: |
row: 7 9 | (complex := 3)
column: 8 10 | float = object = 4
fix: 11 | min, max = 5, 6
edits: [] | ^^^ A001
parent: ~ 12 |
- kind: 13 | id = 4
name: BuiltinVariableShadowing |
body: "Variable `float` is shadowing a python builtin"
suggestion: ~ ./resources/test/fixtures/flake8_builtins/A001.py:9:6: A001 Variable `max` is shadowing a python builtin
fixable: false |
location: 9 | (complex := 3)
row: 8 10 | float = object = 4
column: 0 11 | min, max = 5, 6
end_location: | ^^^ A001
row: 8 12 |
column: 5 13 | id = 4
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_builtins/A001.py:13:1: A001 Variable `bytes` is shadowing a python builtin
- kind: |
name: BuiltinVariableShadowing 13 | id = 4
body: "Variable `object` is shadowing a python builtin" 14 |
suggestion: ~ 15 | / def bytes():
fixable: false 16 | | pass
location: | |________^ A001
row: 8 17 |
column: 8 18 | class slice:
end_location: |
row: 8
column: 14 ./resources/test/fixtures/flake8_builtins/A001.py:16:1: A001 Variable `slice` is shadowing a python builtin
fix: |
edits: [] 16 | pass
parent: ~ 17 |
- kind: 18 | / class slice:
name: BuiltinVariableShadowing 19 | | pass
body: "Variable `min` is shadowing a python builtin" | |________^ A001
suggestion: ~ 20 |
fixable: false 21 | try:
location: |
row: 9
column: 0 ./resources/test/fixtures/flake8_builtins/A001.py:21:1: A001 Variable `ValueError` is shadowing a python builtin
end_location: |
row: 9 21 | try:
column: 3 22 | ...
fix: 23 | / except ImportError as ValueError:
edits: [] 24 | | ...
parent: ~ | |_______^ A001
- kind: 25 |
name: BuiltinVariableShadowing 26 | for memoryview, *bytearray in []:
body: "Variable `max` is shadowing a python builtin" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_builtins/A001.py:24:5: A001 Variable `memoryview` is shadowing a python builtin
location: |
row: 9 24 | ...
column: 5 25 |
end_location: 26 | for memoryview, *bytearray in []:
row: 9 | ^^^^^^^^^^ A001
column: 8 27 | pass
fix: |
edits: []
parent: ~ ./resources/test/fixtures/flake8_builtins/A001.py:24:18: A001 Variable `bytearray` is shadowing a python builtin
- kind: |
name: BuiltinVariableShadowing 24 | ...
body: "Variable `bytes` is shadowing a python builtin" 25 |
suggestion: ~ 26 | for memoryview, *bytearray in []:
fixable: false | ^^^^^^^^^ A001
location: 27 | pass
row: 13 |
column: 0
end_location: ./resources/test/fixtures/flake8_builtins/A001.py:27:22: A001 Variable `str` is shadowing a python builtin
row: 14 |
column: 8 27 | pass
fix: 28 |
edits: [] 29 | with open('file') as str, open('file2') as (all, any):
parent: ~ | ^^^ A001
- kind: 30 | pass
name: BuiltinVariableShadowing |
body: "Variable `slice` is shadowing a python builtin"
suggestion: ~ ./resources/test/fixtures/flake8_builtins/A001.py:27:45: A001 Variable `all` is shadowing a python builtin
fixable: false |
location: 27 | pass
row: 16 28 |
column: 0 29 | with open('file') as str, open('file2') as (all, any):
end_location: | ^^^ A001
row: 17 30 | pass
column: 8 |
fix:
edits: [] ./resources/test/fixtures/flake8_builtins/A001.py:27:50: A001 Variable `any` is shadowing a python builtin
parent: ~ |
- kind: 27 | pass
name: BuiltinVariableShadowing 28 |
body: "Variable `ValueError` is shadowing a python builtin" 29 | with open('file') as str, open('file2') as (all, any):
suggestion: ~ | ^^^ A001
fixable: false 30 | pass
location: |
row: 21
column: 0 ./resources/test/fixtures/flake8_builtins/A001.py:30:8: A001 Variable `sum` is shadowing a python builtin
end_location: |
row: 22 30 | pass
column: 7 31 |
fix: 32 | [0 for sum in ()]
edits: [] | ^^^ A001
parent: ~ |
- kind:
name: BuiltinVariableShadowing
body: "Variable `memoryview` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 24
column: 4
end_location:
row: 24
column: 14
fix:
edits: []
parent: ~
- kind:
name: BuiltinVariableShadowing
body: "Variable `bytearray` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 24
column: 17
end_location:
row: 24
column: 26
fix:
edits: []
parent: ~
- kind:
name: BuiltinVariableShadowing
body: "Variable `str` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 27
column: 21
end_location:
row: 27
column: 24
fix:
edits: []
parent: ~
- kind:
name: BuiltinVariableShadowing
body: "Variable `all` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 27
column: 44
end_location:
row: 27
column: 47
fix:
edits: []
parent: ~
- kind:
name: BuiltinVariableShadowing
body: "Variable `any` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 27
column: 49
end_location:
row: 27
column: 52
fix:
edits: []
parent: ~
- kind:
name: BuiltinVariableShadowing
body: "Variable `sum` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 30
column: 7
end_location:
row: 30
column: 10
fix:
edits: []
parent: ~

View file

@ -1,131 +1,72 @@
--- ---
source: crates/ruff/src/rules/flake8_builtins/mod.rs source: crates/ruff/src/rules/flake8_builtins/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_builtins/A002.py:1:11: A002 Argument `str` is shadowing a python builtin
name: BuiltinArgumentShadowing |
body: "Argument `str` is shadowing a python builtin" 1 | def func1(str, /, type, *complex, Exception, **getattr):
suggestion: ~ | ^^^ A002
fixable: false 2 | pass
location: |
row: 1
column: 10 ./resources/test/fixtures/flake8_builtins/A002.py:1:19: A002 Argument `type` is shadowing a python builtin
end_location: |
row: 1 1 | def func1(str, /, type, *complex, Exception, **getattr):
column: 13 | ^^^^ A002
fix: 2 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_builtins/A002.py:1:26: A002 Argument `complex` is shadowing a python builtin
name: BuiltinArgumentShadowing |
body: "Argument `type` is shadowing a python builtin" 1 | def func1(str, /, type, *complex, Exception, **getattr):
suggestion: ~ | ^^^^^^^ A002
fixable: false 2 | pass
location: |
row: 1
column: 18 ./resources/test/fixtures/flake8_builtins/A002.py:1:35: A002 Argument `Exception` is shadowing a python builtin
end_location: |
row: 1 1 | def func1(str, /, type, *complex, Exception, **getattr):
column: 22 | ^^^^^^^^^ A002
fix: 2 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_builtins/A002.py:1:48: A002 Argument `getattr` is shadowing a python builtin
name: BuiltinArgumentShadowing |
body: "Argument `complex` is shadowing a python builtin" 1 | def func1(str, /, type, *complex, Exception, **getattr):
suggestion: ~ | ^^^^^^^ A002
fixable: false 2 | pass
location: |
row: 1
column: 25 ./resources/test/fixtures/flake8_builtins/A002.py:5:17: A002 Argument `bytes` is shadowing a python builtin
end_location: |
row: 1 5 | async def func2(bytes):
column: 32 | ^^^^^ A002
fix: 6 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_builtins/A002.py:8:17: A002 Argument `id` is shadowing a python builtin
name: BuiltinArgumentShadowing |
body: "Argument `Exception` is shadowing a python builtin" 8 | pass
suggestion: ~ 9 |
fixable: false 10 | async def func3(id, dir):
location: | ^^ A002
row: 1 11 | pass
column: 34 |
end_location:
row: 1 ./resources/test/fixtures/flake8_builtins/A002.py:8:21: A002 Argument `dir` is shadowing a python builtin
column: 43 |
fix: 8 | pass
edits: [] 9 |
parent: ~ 10 | async def func3(id, dir):
- kind: | ^^^ A002
name: BuiltinArgumentShadowing 11 | pass
body: "Argument `getattr` is shadowing a python builtin" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_builtins/A002.py:11:16: A002 Argument `float` is shadowing a python builtin
location: |
row: 1 11 | pass
column: 47 12 |
end_location: 13 | map([], lambda float: ...)
row: 1 | ^^^^^ A002
column: 54 |
fix:
edits: []
parent: ~
- kind:
name: BuiltinArgumentShadowing
body: "Argument `bytes` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 5
column: 16
end_location:
row: 5
column: 21
fix:
edits: []
parent: ~
- kind:
name: BuiltinArgumentShadowing
body: "Argument `id` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 8
column: 16
end_location:
row: 8
column: 18
fix:
edits: []
parent: ~
- kind:
name: BuiltinArgumentShadowing
body: "Argument `dir` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 8
column: 20
end_location:
row: 8
column: 23
fix:
edits: []
parent: ~
- kind:
name: BuiltinArgumentShadowing
body: "Argument `float` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 11
column: 15
end_location:
row: 11
column: 20
fix:
edits: []
parent: ~

View file

@ -1,103 +1,54 @@
--- ---
source: crates/ruff/src/rules/flake8_builtins/mod.rs source: crates/ruff/src/rules/flake8_builtins/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_builtins/A002.py:1:11: A002 Argument `str` is shadowing a python builtin
name: BuiltinArgumentShadowing |
body: "Argument `str` is shadowing a python builtin" 1 | def func1(str, /, type, *complex, Exception, **getattr):
suggestion: ~ | ^^^ A002
fixable: false 2 | pass
location: |
row: 1
column: 10 ./resources/test/fixtures/flake8_builtins/A002.py:1:19: A002 Argument `type` is shadowing a python builtin
end_location: |
row: 1 1 | def func1(str, /, type, *complex, Exception, **getattr):
column: 13 | ^^^^ A002
fix: 2 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_builtins/A002.py:1:26: A002 Argument `complex` is shadowing a python builtin
name: BuiltinArgumentShadowing |
body: "Argument `type` is shadowing a python builtin" 1 | def func1(str, /, type, *complex, Exception, **getattr):
suggestion: ~ | ^^^^^^^ A002
fixable: false 2 | pass
location: |
row: 1
column: 18 ./resources/test/fixtures/flake8_builtins/A002.py:1:35: A002 Argument `Exception` is shadowing a python builtin
end_location: |
row: 1 1 | def func1(str, /, type, *complex, Exception, **getattr):
column: 22 | ^^^^^^^^^ A002
fix: 2 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_builtins/A002.py:1:48: A002 Argument `getattr` is shadowing a python builtin
name: BuiltinArgumentShadowing |
body: "Argument `complex` is shadowing a python builtin" 1 | def func1(str, /, type, *complex, Exception, **getattr):
suggestion: ~ | ^^^^^^^ A002
fixable: false 2 | pass
location: |
row: 1
column: 25 ./resources/test/fixtures/flake8_builtins/A002.py:5:17: A002 Argument `bytes` is shadowing a python builtin
end_location: |
row: 1 5 | async def func2(bytes):
column: 32 | ^^^^^ A002
fix: 6 | pass
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_builtins/A002.py:11:16: A002 Argument `float` is shadowing a python builtin
name: BuiltinArgumentShadowing |
body: "Argument `Exception` is shadowing a python builtin" 11 | pass
suggestion: ~ 12 |
fixable: false 13 | map([], lambda float: ...)
location: | ^^^^^ A002
row: 1 |
column: 34
end_location:
row: 1
column: 43
fix:
edits: []
parent: ~
- kind:
name: BuiltinArgumentShadowing
body: "Argument `getattr` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 1
column: 47
end_location:
row: 1
column: 54
fix:
edits: []
parent: ~
- kind:
name: BuiltinArgumentShadowing
body: "Argument `bytes` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 5
column: 16
end_location:
row: 5
column: 21
fix:
edits: []
parent: ~
- kind:
name: BuiltinArgumentShadowing
body: "Argument `float` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 11
column: 15
end_location:
row: 11
column: 20
fix:
edits: []
parent: ~

View file

@ -1,61 +1,42 @@
--- ---
source: crates/ruff/src/rules/flake8_builtins/mod.rs source: crates/ruff/src/rules/flake8_builtins/mod.rs
expression: diagnostics
--- ---
- kind: ./resources/test/fixtures/flake8_builtins/A003.py:2:5: A003 Class attribute `ImportError` is shadowing a python builtin
name: BuiltinAttributeShadowing |
body: "Class attribute `ImportError` is shadowing a python builtin" 2 | class MyClass:
suggestion: ~ 3 | ImportError = 4
fixable: false | ^^^^^^^^^^^ A003
location: 4 | id = 5
row: 2 5 | dir = "/"
column: 4 |
end_location:
row: 2 ./resources/test/fixtures/flake8_builtins/A003.py:3:5: A003 Class attribute `id` is shadowing a python builtin
column: 15 |
fix: 3 | class MyClass:
edits: [] 4 | ImportError = 4
parent: ~ 5 | id = 5
- kind: | ^^ A003
name: BuiltinAttributeShadowing 6 | dir = "/"
body: "Class attribute `id` is shadowing a python builtin" |
suggestion: ~
fixable: false ./resources/test/fixtures/flake8_builtins/A003.py:4:5: A003 Class attribute `dir` is shadowing a python builtin
location: |
row: 3 4 | ImportError = 4
column: 4 5 | id = 5
end_location: 6 | dir = "/"
row: 3 | ^^^ A003
column: 6 7 |
fix: 8 | def __init__(self):
edits: [] |
parent: ~
- kind: ./resources/test/fixtures/flake8_builtins/A003.py:11:5: A003 Class attribute `str` is shadowing a python builtin
name: BuiltinAttributeShadowing |
body: "Class attribute `dir` is shadowing a python builtin" 11 | self.dir = "."
suggestion: ~ 12 |
fixable: false 13 | def str(self):
location: | _____^
row: 4 14 | | pass
column: 4 | |____________^ A003
end_location: |
row: 4
column: 7
fix:
edits: []
parent: ~
- kind:
name: BuiltinAttributeShadowing
body: "Class attribute `str` is shadowing a python builtin"
suggestion: ~
fixable: false
location:
row: 11
column: 4
end_location:
row: 12
column: 12
fix:
edits: []
parent: ~

Some files were not shown because too many files have changed in this diff Show more