Update CONTRIBUTING.md guide (#5017)

This commit is contained in:
Charlie Marsh 2023-06-11 20:20:59 -04:00 committed by GitHub
parent 31067e6ce2
commit eac3a0cc3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 41 deletions

View file

@ -1356,9 +1356,9 @@ where
pyflakes::rules::raise_not_implemented(self, expr);
}
}
if self.enabled(Rule::CannotRaiseLiteral) {
if self.enabled(Rule::RaiseLiteral) {
if let Some(exc) = exc {
flake8_bugbear::rules::cannot_raise_literal(self, exc);
flake8_bugbear::rules::raise_literal(self, exc);
}
}
if self.any_enabled(&[

View file

@ -232,7 +232,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
(Flake8Bugbear, "013") => (RuleGroup::Unspecified, rules::flake8_bugbear::rules::RedundantTupleInExceptionHandler),
(Flake8Bugbear, "014") => (RuleGroup::Unspecified, rules::flake8_bugbear::rules::DuplicateHandlerException),
(Flake8Bugbear, "015") => (RuleGroup::Unspecified, rules::flake8_bugbear::rules::UselessComparison),
(Flake8Bugbear, "016") => (RuleGroup::Unspecified, rules::flake8_bugbear::rules::CannotRaiseLiteral),
(Flake8Bugbear, "016") => (RuleGroup::Unspecified, rules::flake8_bugbear::rules::RaiseLiteral),
(Flake8Bugbear, "017") => (RuleGroup::Unspecified, rules::flake8_bugbear::rules::AssertRaisesException),
(Flake8Bugbear, "018") => (RuleGroup::Unspecified, rules::flake8_bugbear::rules::UselessExpression),
(Flake8Bugbear, "019") => (RuleGroup::Unspecified, rules::flake8_bugbear::rules::CachedInstanceMethod),

View file

@ -19,7 +19,7 @@ mod tests {
#[test_case(Rule::AssertRaisesException, Path::new("B017.py"))]
#[test_case(Rule::AssignmentToOsEnviron, Path::new("B003.py"))]
#[test_case(Rule::CachedInstanceMethod, Path::new("B019.py"))]
#[test_case(Rule::CannotRaiseLiteral, Path::new("B016.py"))]
#[test_case(Rule::RaiseLiteral, Path::new("B016.py"))]
#[test_case(Rule::DuplicateHandlerException, Path::new("B014.py"))]
#[test_case(Rule::DuplicateTryBlockException, Path::new("B025.py"))]
#[test_case(Rule::DuplicateValue, Path::new("B033.py"))]

View file

@ -6,7 +6,6 @@ pub(crate) use assert_false::{assert_false, AssertFalse};
pub(crate) use assert_raises_exception::{assert_raises_exception, AssertRaisesException};
pub(crate) use assignment_to_os_environ::{assignment_to_os_environ, AssignmentToOsEnviron};
pub(crate) use cached_instance_method::{cached_instance_method, CachedInstanceMethod};
pub(crate) use cannot_raise_literal::{cannot_raise_literal, CannotRaiseLiteral};
pub(crate) use duplicate_exceptions::{
duplicate_exceptions, DuplicateHandlerException, DuplicateTryBlockException,
};
@ -29,6 +28,7 @@ pub(crate) use loop_variable_overrides_iterator::{
};
pub(crate) use mutable_argument_default::{mutable_argument_default, MutableArgumentDefault};
pub(crate) use no_explicit_stacklevel::{no_explicit_stacklevel, NoExplicitStacklevel};
pub(crate) use raise_literal::{raise_literal, RaiseLiteral};
pub(crate) use raise_without_from_inside_except::{
raise_without_from_inside_except, RaiseWithoutFromInsideExcept,
};
@ -65,7 +65,6 @@ mod assert_false;
mod assert_raises_exception;
mod assignment_to_os_environ;
mod cached_instance_method;
mod cannot_raise_literal;
mod duplicate_exceptions;
mod duplicate_value;
mod except_with_empty_tuple;
@ -78,6 +77,7 @@ mod jump_statement_in_finally;
mod loop_variable_overrides_iterator;
mod mutable_argument_default;
mod no_explicit_stacklevel;
mod raise_literal;
mod raise_without_from_inside_except;
mod redundant_tuple_in_exception_handler;
mod reuse_of_groupby_generator;

View file

@ -6,9 +6,9 @@ use ruff_macros::{derive_message_formats, violation};
use crate::checkers::ast::Checker;
#[violation]
pub struct CannotRaiseLiteral;
pub struct RaiseLiteral;
impl Violation for CannotRaiseLiteral {
impl Violation for RaiseLiteral {
#[derive_message_formats]
fn message(&self) -> String {
format!("Cannot raise a literal. Did you intend to return it or raise an Exception?")
@ -16,11 +16,10 @@ impl Violation for CannotRaiseLiteral {
}
/// B016
pub(crate) fn cannot_raise_literal(checker: &mut Checker, expr: &Expr) {
let Expr::Constant ( _) = expr else {
return;
};
checker
.diagnostics
.push(Diagnostic::new(CannotRaiseLiteral, expr.range()));
pub(crate) fn raise_literal(checker: &mut Checker, expr: &Expr) {
if expr.is_constant_expr() {
checker
.diagnostics
.push(Diagnostic::new(RaiseLiteral, expr.range()));
}
}