-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
try: | ||
y = 6 + "7" | ||
except TypeError: | ||
raise ValueError() # RSE102 | ||
|
||
try: | ||
x = 1 / 0 | ||
except ZeroDivisionError: | ||
raise | ||
|
||
raise TypeError() # RSE102 | ||
|
||
raise AssertionError | ||
|
||
raise AttributeError("test message") |
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 |
---|---|---|
|
@@ -1739,6 +1739,10 @@ | |
"RET506", | ||
"RET507", | ||
"RET508", | ||
"RSE", | ||
"RSE1", | ||
"RSE10", | ||
"RSE102", | ||
"RUF", | ||
"RUF0", | ||
"RUF00", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//! Rules from [flake8-raise](https://pypi.org/project/flake8-raise/). | ||
pub(crate) mod rules; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::convert::AsRef; | ||
use std::path::Path; | ||
|
||
use anyhow::Result; | ||
use test_case::test_case; | ||
|
||
use crate::linter::test_path; | ||
use crate::registry::Rule; | ||
use crate::{assert_yaml_snapshot, settings}; | ||
|
||
#[test_case(Rule::UnnecessaryParenOnRaiseException, Path::new("RSE102.py"); "RSE102")] | ||
fn rules(rule_code: Rule, path: &Path) -> Result<()> { | ||
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); | ||
let diagnostics = test_path( | ||
Path::new("./resources/test/fixtures/flake8_raise") | ||
.join(path) | ||
.as_path(), | ||
&settings::Settings::for_rule(rule_code), | ||
)?; | ||
assert_yaml_snapshot!(snapshot, diagnostics); | ||
Ok(()) | ||
} | ||
} |
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,5 @@ | ||
pub use unnecessary_paren_on_raise_exception::{ | ||
unnecessary_paren_on_raise_exception, UnnecessaryParenOnRaiseException, | ||
}; | ||
|
||
mod unnecessary_paren_on_raise_exception; |
31 changes: 31 additions & 0 deletions
31
src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.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,31 @@ | ||
use ruff_macros::derive_message_formats; | ||
|
||
use crate::ast::types::Range; | ||
use crate::checkers::ast::Checker; | ||
use crate::define_violation; | ||
use crate::registry::Diagnostic; | ||
use crate::violation::Violation; | ||
use rustpython_ast::{Expr, ExprKind}; | ||
|
||
define_violation!( | ||
pub struct UnnecessaryParenOnRaiseException; | ||
); | ||
impl Violation for UnnecessaryParenOnRaiseException { | ||
#[derive_message_formats] | ||
fn message(&self) -> String { | ||
format!("Unnecessary parentheses on raised exception") | ||
} | ||
} | ||
|
||
/// RSE102 | ||
pub fn unnecessary_paren_on_raise_exception(checker: &mut Checker, expr: &Expr) { | ||
match &expr.node { | ||
ExprKind::Call { args, keywords, .. } if args.is_empty() && keywords.is_empty() => { | ||
checker.diagnostics.push(Diagnostic::new( | ||
UnnecessaryParenOnRaiseException, | ||
Range::from_located(expr), | ||
)); | ||
} | ||
_ => (), | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ots/ruff__rules__flake8_raise__tests__unnecessary-paren-on-raise-exception_RSE102.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,25 @@ | ||
--- | ||
source: src/rules/flake8_raise/mod.rs | ||
expression: diagnostics | ||
--- | ||
- kind: | ||
UnnecessaryParenOnRaiseException: ~ | ||
location: | ||
row: 4 | ||
column: 10 | ||
end_location: | ||
row: 4 | ||
column: 22 | ||
fix: ~ | ||
parent: ~ | ||
- kind: | ||
UnnecessaryParenOnRaiseException: ~ | ||
location: | ||
row: 11 | ||
column: 6 | ||
end_location: | ||
row: 11 | ||
column: 17 | ||
fix: ~ | ||
parent: ~ | ||
|
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