-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- v0.4.10
- v0.4.9
- v0.4.8
- v0.4.7
- v0.4.6
- v0.4.5
- v0.4.4
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.7
- v0.3.6
- v0.3.5
- v0.3.4
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.15
- v0.1.14
- v0.1.13
- v0.1.12
- v0.1.11
- v0.1.10
- v0.1.9
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- v0.0.292
- v0.0.291
- v0.0.290
- v0.0.289
- v0.0.288
- v0.0.287
- v0.0.286
- v0.0.285
- v0.0.284
- v0.0.283
- v0.0.282
- v0.0.281
- v0.0.280
- v0.0.279
- v0.0.278
- v0.0.277
- v0.0.276
- v0.0.275
- v0.0.274
- v0.0.273
- v0.0.272
- v0.0.271
- v0.0.270
- v0.0.269
- v0.0.268
- v0.0.267
- v0.0.266
- v0.0.265
- v0.0.264
- v0.0.263
- v0.0.262
- v0.0.261
- v0.0.260
- v0.0.259
- v0.0.258
- v0.0.257
- 0.8.4
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.4
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.9
- 0.6.8
- 0.6.7
- 0.6.6
- 0.6.5
- 0.6.4
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.7
- 0.5.6
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
Showing
9 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
crates/ruff/resources/test/fixtures/flake8_bugbear/B028.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import warnings | ||
|
||
""" | ||
Should emit: | ||
B028 - on lines 8 and 9 | ||
""" | ||
|
||
warnings.warn(DeprecationWarning("test")) | ||
warnings.warn(DeprecationWarning("test"), source=None) | ||
warnings.warn(DeprecationWarning("test"), source=None, stacklevel=2) | ||
warnings.warn(DeprecationWarning("test"), stacklevel=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
crates/ruff/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use rustpython_parser::ast::{Expr, Keyword}; | ||
|
||
use ruff_diagnostics::{Diagnostic, Violation}; | ||
use ruff_macros::{derive_message_formats, violation}; | ||
use ruff_python_ast::helpers::SimpleCallArgs; | ||
use ruff_python_ast::types::Range; | ||
|
||
use crate::checkers::ast::Checker; | ||
|
||
/// ## What it does | ||
/// Checks for `warnings.warn` calls without an explicit `stacklevel` keyword | ||
/// argument. | ||
/// | ||
/// ## Why is this bad? | ||
/// The `warnings.warn` method uses a `stacklevel` of 1 by default, which | ||
/// limits the rendered stack trace to that of the line on which the | ||
/// `warn` method is called. | ||
/// | ||
/// It's recommended to use a `stacklevel` of 2 or higher, give the caller | ||
/// more context about the warning. | ||
/// | ||
/// ## Example | ||
/// ```python | ||
/// warnings.warn("This is a warning") | ||
/// ``` | ||
/// | ||
/// Use instead: | ||
/// ```python | ||
/// warnings.warn("This is a warning", stacklevel=2) | ||
/// ``` | ||
#[violation] | ||
pub struct NoExplicitStacklevel; | ||
|
||
impl Violation for NoExplicitStacklevel { | ||
#[derive_message_formats] | ||
fn message(&self) -> String { | ||
format!("No explicit `stacklevel` keyword argument found") | ||
} | ||
} | ||
|
||
/// B028 | ||
pub fn no_explicit_stacklevel( | ||
checker: &mut Checker, | ||
func: &Expr, | ||
args: &[Expr], | ||
keywords: &[Keyword], | ||
) { | ||
if !checker | ||
.ctx | ||
.resolve_call_path(func) | ||
.map_or(false, |call_path| { | ||
call_path.as_slice() == ["warnings", "warn"] | ||
}) | ||
{ | ||
return; | ||
} | ||
|
||
if SimpleCallArgs::new(args, keywords) | ||
.keyword_argument("stacklevel") | ||
.is_some() | ||
{ | ||
return; | ||
} | ||
|
||
checker | ||
.diagnostics | ||
.push(Diagnostic::new(NoExplicitStacklevel, Range::from(func))); | ||
} |
31 changes: 31 additions & 0 deletions
31
.../src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B028_B028.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_bugbear/mod.rs | ||
expression: diagnostics | ||
--- | ||
- kind: | ||
name: NoExplicitStacklevel | ||
body: "No explicit `stacklevel` keyword argument found" | ||
suggestion: ~ | ||
fixable: false | ||
location: | ||
row: 8 | ||
column: 0 | ||
end_location: | ||
row: 8 | ||
column: 13 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
name: NoExplicitStacklevel | ||
body: "No explicit `stacklevel` keyword argument found" | ||
suggestion: ~ | ||
fixable: false | ||
location: | ||
row: 9 | ||
column: 0 | ||
end_location: | ||
row: 9 | ||
column: 13 | ||
fix: ~ | ||
parent: ~ | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.