Reorder imports (#2638)

This commit is contained in:
Charlie Marsh 2023-02-07 16:22:47 -05:00 committed by GitHub
parent 0355ba571e
commit 67e9ff7cc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
233 changed files with 626 additions and 593 deletions

View file

@ -667,8 +667,8 @@ pub fn to_call_path(target: &str) -> CallPath {
/// Create a module path from a (package, path) pair.
///
/// For example, if the package is `foo/bar` and the path is `foo/bar/baz.py`, the call path is
/// `["baz"]`.
/// For example, if the package is `foo/bar` and the path is `foo/bar/baz.py`,
/// the call path is `["baz"]`.
pub fn to_module_path(package: &Path, path: &Path) -> Option<Vec<String>> {
path.strip_prefix(package.parent()?)
.ok()?

View file

@ -89,8 +89,9 @@ pub struct Scope<'a> {
pub uses_locals: bool,
/// A map from bound name to binding index, for live bindings.
pub bindings: FxHashMap<&'a str, usize>,
/// A map from bound name to binding index, for bindings that were created in the scope but
/// rebound (and thus overridden) later on in the same scope.
/// A map from bound name to binding index, for bindings that were created
/// in the scope but rebound (and thus overridden) later on in the same
/// scope.
pub rebounds: FxHashMap<&'a str, Vec<usize>>,
}

View file

@ -1,6 +1,5 @@
use rustpython_ast::{Expr, ExprKind};
use ruff_python::typing::{PEP_585_BUILTINS_ELIGIBLE, PEP_593_SUBSCRIPTS, SUBSCRIPTS};
use rustpython_ast::{Expr, ExprKind};
use crate::ast::types::CallPath;

View file

@ -6,6 +6,8 @@ use std::path::Path;
use itertools::Itertools;
use log::error;
use nohash_hasher::IntMap;
use ruff_python::builtins::{BUILTINS, MAGIC_GLOBALS};
use ruff_python::typing::TYPING_EXTENSIONS;
use rustc_hash::{FxHashMap, FxHashSet};
use rustpython_ast::{Comprehension, Located, Location};
use rustpython_common::cformat::{CFormatError, CFormatErrorType};
@ -16,9 +18,6 @@ use rustpython_parser::ast::{
use rustpython_parser::parser;
use smallvec::smallvec;
use ruff_python::builtins::{BUILTINS, MAGIC_GLOBALS};
use ruff_python::typing::TYPING_EXTENSIONS;
use crate::ast::helpers::{
binding_range, collect_call_path, extract_handler_names, from_relative_import, to_module_path,
};
@ -3955,8 +3954,8 @@ impl<'a> Checker<'a> {
// Avoid overriding builtins.
binding
} else if matches!(self.bindings[*index].kind, BindingKind::Global) {
// If the original binding was a global, and the new binding conflicts within the
// current scope, then the new binding is also a global.
// If the original binding was a global, and the new binding conflicts within
// the current scope, then the new binding is also a global.
Binding {
runtime_usage: self.bindings[*index].runtime_usage,
synthetic_usage: self.bindings[*index].synthetic_usage,
@ -3965,8 +3964,8 @@ impl<'a> Checker<'a> {
..binding
}
} else if matches!(self.bindings[*index].kind, BindingKind::Nonlocal) {
// If the original binding was a nonlocal, and the new binding conflicts within the
// current scope, then the new binding is also a nonlocal.
// If the original binding was a nonlocal, and the new binding conflicts within
// the current scope, then the new binding is also a nonlocal.
Binding {
runtime_usage: self.bindings[*index].runtime_usage,
synthetic_usage: self.bindings[*index].synthetic_usage,

View file

@ -27,8 +27,9 @@ use crate::{directives, fs, rustpython_helpers};
const CARGO_PKG_NAME: &str = env!("CARGO_PKG_NAME");
const CARGO_PKG_REPOSITORY: &str = env!("CARGO_PKG_REPOSITORY");
/// A [`Result`]-like type that returns both data and an error. Used to return diagnostics even in
/// the face of parse errors, since many diagnostics can be generated without a full AST.
/// A [`Result`]-like type that returns both data and an error. Used to return
/// diagnostics even in the face of parse errors, since many diagnostics can be
/// generated without a full AST.
pub struct LinterResult<T> {
pub data: T,
pub error: Option<ParseError>,
@ -270,7 +271,8 @@ pub fn add_noqa_to_path(path: &Path, settings: &Settings) -> Result<usize> {
)
}
/// Generate a [`Message`] for each [`Diagnostic`] triggered by the given source code.
/// Generate a [`Message`] for each [`Diagnostic`] triggered by the given source
/// code.
pub fn lint_only(
contents: &str,
path: &Path,

View file

@ -50,7 +50,8 @@ macro_rules! notify_user {
pub enum LogLevel {
/// No output ([`log::LevelFilter::Off`]).
Silent,
/// Only show lint violations, with no decorative output ([`log::LevelFilter::Off`]).
/// Only show lint violations, with no decorative output
/// ([`log::LevelFilter::Off`]).
Quiet,
/// All user-facing output ([`log::LevelFilter::Info`]).
#[default]

View file

@ -119,7 +119,8 @@ pub fn detect_package_roots<'a>(
mod tests {
use std::path::PathBuf;
use crate::{packaging::detect_package_root, test::test_resource_path};
use crate::packaging::detect_package_root;
use crate::test::test_resource_path;
#[test]
fn package_detection() {

View file

@ -587,15 +587,16 @@ mod tests {
&Relativity::Parent,
&NoOpProcessor,
)?);
// src/app.py should not be excluded even if it lives in a hierarchy that should be
// excluded by virtue of the pyproject.toml having `resources/*` in it.
// src/app.py should not be excluded even if it lives in a hierarchy that should
// be excluded by virtue of the pyproject.toml having `resources/*` in
// it.
assert!(!is_file_excluded(
&package_root.join("src/app.py"),
&resolver,
&ppd,
));
// However, resources/ignored.py should be ignored, since that `resources` is beneath
// the package root.
// However, resources/ignored.py should be ignored, since that `resources` is
// beneath the package root.
assert!(is_file_excluded(
&package_root.join("resources/ignored.py"),
&resolver,

View file

@ -1,14 +1,13 @@
use num_bigint::BigInt;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Cmpop, Constant, Expr, ExprKind, Located};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::{Diagnostic, Rule};
use crate::violation::Violation;
use crate::define_violation;
use ruff_macros::derive_message_formats;
define_violation!(
pub struct SysVersionSlice3Referenced;
);

View file

@ -1,22 +1,19 @@
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind, Stmt};
use ruff_macros::derive_message_formats;
use super::fixes;
use super::helpers::match_function_def;
use crate::ast::helpers::ReturnStatementVisitor;
use crate::ast::types::Range;
use crate::ast::visitor::Visitor;
use crate::ast::{cast, helpers};
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::docstrings::definition::{Definition, DefinitionKind};
use crate::registry::{Diagnostic, Rule};
use crate::violation::{AlwaysAutofixableViolation, Violation};
use crate::visibility;
use crate::visibility::Visibility;
use super::fixes;
use super::helpers::match_function_def;
use crate::{define_violation, visibility};
define_violation!(
pub struct MissingTypeFunctionArgument {

View file

@ -1,10 +1,10 @@
use crate::define_violation;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Located, StmtKind};
use crate::ast::types::Range;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct AssertUsed;

View file

@ -1,5 +1,3 @@
use crate::define_violation;
use crate::violation::Violation;
use num_traits::ToPrimitive;
use once_cell::sync::Lazy;
use ruff_macros::derive_message_formats;
@ -9,7 +7,9 @@ use rustpython_ast::{Constant, Expr, ExprKind, Keyword, Operator};
use crate::ast::helpers::{compose_call_path, SimpleCallArgs};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct BadFilePermissions {

View file

@ -1,10 +1,10 @@
use crate::define_violation;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
use crate::ast::types::Range;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct ExecUsed;

View file

@ -1,10 +1,10 @@
use ruff_macros::derive_message_formats;
use crate::ast::types::Range;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use crate::define_violation;
use ruff_macros::derive_message_formats;
define_violation!(
pub struct HardcodedBindAllInterfaces;
);

View file

@ -1,11 +1,11 @@
use crate::define_violation;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{ArgData, Arguments, Expr, Located};
use super::super::helpers::{matches_password_name, string_literal};
use crate::ast::types::Range;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct HardcodedPasswordDefault {

View file

@ -1,11 +1,11 @@
use crate::define_violation;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::Keyword;
use super::super::helpers::{matches_password_name, string_literal};
use crate::ast::types::Range;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct HardcodedPasswordFuncArg {

View file

@ -1,11 +1,11 @@
use crate::define_violation;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind};
use super::super::helpers::{matches_password_name, string_literal};
use crate::ast::types::Range;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct HardcodedPasswordString {

View file

@ -1,10 +1,10 @@
use crate::define_violation;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::Expr;
use crate::ast::types::Range;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct HardcodedTempFile {

View file

@ -1,5 +1,3 @@
use crate::define_violation;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind, Keyword};
@ -7,7 +5,9 @@ use super::super::helpers::string_literal;
use crate::ast::helpers::SimpleCallArgs;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct HashlibInsecureHashFunction {

View file

@ -1,5 +1,3 @@
use crate::define_violation;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
use rustpython_parser::ast::Constant;
@ -7,7 +5,9 @@ use rustpython_parser::ast::Constant;
use crate::ast::helpers::SimpleCallArgs;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct Jinja2AutoescapeFalse {

View file

@ -1,6 +1,5 @@
use rustpython_ast::{Expr, Keyword};
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, Keyword};
use crate::ast::helpers::SimpleCallArgs;
use crate::ast::types::Range;

View file

@ -1,5 +1,3 @@
use crate::define_violation;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
use rustpython_parser::ast::Constant;
@ -7,7 +5,9 @@ use rustpython_parser::ast::Constant;
use crate::ast::helpers::SimpleCallArgs;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct RequestWithNoCertValidation {

View file

@ -1,5 +1,3 @@
use crate::define_violation;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
use rustpython_parser::ast::Constant;
@ -7,7 +5,9 @@ use rustpython_parser::ast::Constant;
use crate::ast::helpers::SimpleCallArgs;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct RequestWithoutTimeout {

View file

@ -1,5 +1,3 @@
use crate::define_violation;
use crate::violation::Violation;
use num_traits::{One, Zero};
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
@ -8,7 +6,9 @@ use rustpython_parser::ast::Constant;
use crate::ast::helpers::SimpleCallArgs;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct SnmpInsecureVersion;

View file

@ -1,12 +1,12 @@
use crate::define_violation;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, Keyword};
use crate::ast::helpers::SimpleCallArgs;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct SnmpWeakCryptography;

View file

@ -1,6 +1,5 @@
use rustpython_ast::{Expr, ExprKind, Keyword};
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
use crate::ast::helpers::SimpleCallArgs;
use crate::ast::types::Range;

View file

@ -39,8 +39,9 @@ pub struct Options {
value_type = "bool",
example = "check-typed-exception = true"
)]
/// Whether to disallow `try`-`except`-`pass` (`S110`) for specific exception types. By default,
/// `try`-`except`-`pass` is only disallowed for `Exception` and `BaseException`.
/// Whether to disallow `try`-`except`-`pass` (`S110`) for specific
/// exception types. By default, `try`-`except`-`pass` is only
/// disallowed for `Exception` and `BaseException`.
pub check_typed_exception: Option<bool>,
}

View file

@ -1,3 +1,6 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Stmt, StmtKind};
use crate::ast::helpers;
use crate::ast::helpers::{find_keyword, is_const_true};
use crate::ast::types::Range;
@ -5,8 +8,6 @@ use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Stmt, StmtKind};
define_violation!(
pub struct BlindExcept {

View file

@ -1,11 +1,12 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind, Keyword, Stmt, StmtKind};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::{Diagnostic, Rule};
use crate::violation::Violation;
use crate::visibility::{is_abstract, is_overload};
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind, Keyword, Stmt, StmtKind};
define_violation!(
pub struct AbstractBaseClassWithoutAbstractMethod {

View file

@ -1,3 +1,6 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprContext, ExprKind, Location, Stmt, StmtKind};
use crate::ast::helpers::unparse_stmt;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,8 +8,6 @@ use crate::define_violation;
use crate::fix::Fix;
use crate::registry::Diagnostic;
use crate::violation::AlwaysAutofixableViolation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprContext, ExprKind, Location, Stmt, StmtKind};
define_violation!(
pub struct DoNotAssertFalse;

View file

@ -7,13 +7,14 @@
//! typo. Either assert for a more specific exception (builtin or
//! custom), use `assertRaisesRegex`, or use the context manager form of
//! `assertRaises`.
use ruff_macros::derive_message_formats;
use rustpython_ast::{ExprKind, Stmt, Withitem};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{ExprKind, Stmt, Withitem};
define_violation!(
pub struct NoAssertRaisesException;

View file

@ -1,10 +1,11 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
define_violation!(
pub struct AssignmentToOsEnviron;

View file

@ -1,10 +1,11 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
use crate::ast::types::{Range, ScopeKind};
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
define_violation!(
pub struct CachedInstanceMethod;

View file

@ -1,10 +1,11 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
define_violation!(
pub struct CannotRaiseLiteral;

View file

@ -1,3 +1,8 @@
use itertools::Itertools;
use ruff_macros::derive_message_formats;
use rustc_hash::{FxHashMap, FxHashSet};
use rustpython_ast::{Excepthandler, ExcepthandlerKind, Expr, ExprContext, ExprKind, Location};
use crate::ast::helpers;
use crate::ast::helpers::unparse_expr;
use crate::ast::types::{CallPath, Range};
@ -6,10 +11,6 @@ use crate::define_violation;
use crate::fix::Fix;
use crate::registry::{Diagnostic, Rule};
use crate::violation::{AlwaysAutofixableViolation, Violation};
use itertools::Itertools;
use ruff_macros::derive_message_formats;
use rustc_hash::{FxHashMap, FxHashSet};
use rustpython_ast::{Excepthandler, ExcepthandlerKind, Expr, ExprContext, ExprKind, Location};
define_violation!(
pub struct DuplicateTryBlockException {

View file

@ -1,10 +1,11 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{ExprKind, Stmt, StmtKind};
use crate::ast::helpers;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{ExprKind, Stmt, StmtKind};
define_violation!(
pub struct FStringDocstring;

View file

@ -1,3 +1,6 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Arguments, Constant, Expr, ExprKind};
use super::mutable_argument_default::is_mutable_func;
use crate::ast::helpers::{compose_call_path, to_call_path};
use crate::ast::types::{CallPath, Range};
@ -7,8 +10,6 @@ use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::{Diagnostic, DiagnosticKind};
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Arguments, Constant, Expr, ExprKind};
define_violation!(
pub struct FunctionCallArgumentDefault {

View file

@ -1,3 +1,7 @@
use ruff_macros::derive_message_formats;
use rustc_hash::FxHashSet;
use rustpython_ast::{Comprehension, Expr, ExprContext, ExprKind, Stmt, StmtKind};
use crate::ast::helpers::collect_arg_names;
use crate::ast::types::{Node, Range};
use crate::ast::visitor;
@ -6,9 +10,6 @@ use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustc_hash::FxHashSet;
use rustpython_ast::{Comprehension, Expr, ExprContext, ExprKind, Stmt, StmtKind};
define_violation!(
pub struct FunctionUsesLoopVariable {

View file

@ -1,3 +1,8 @@
use ruff_macros::derive_message_formats;
use ruff_python::identifiers::{is_identifier, is_mangled_private};
use ruff_python::keyword::KWLIST;
use rustpython_ast::{Constant, Expr, ExprContext, ExprKind, Location};
use crate::ast::helpers::unparse_expr;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,10 +10,6 @@ use crate::define_violation;
use crate::fix::Fix;
use crate::registry::Diagnostic;
use crate::violation::AlwaysAutofixableViolation;
use ruff_macros::derive_message_formats;
use ruff_python::identifiers::{is_identifier, is_mangled_private};
use ruff_python::keyword::KWLIST;
use rustpython_ast::{Constant, Expr, ExprContext, ExprKind, Location};
define_violation!(
pub struct GetAttrWithConstant;

View file

@ -1,10 +1,11 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Stmt, StmtKind};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Stmt, StmtKind};
define_violation!(
pub struct JumpStatementInFinally {

View file

@ -1,3 +1,7 @@
use ruff_macros::derive_message_formats;
use rustc_hash::FxHashMap;
use rustpython_ast::{Expr, ExprKind};
use crate::ast::types::Range;
use crate::ast::visitor;
use crate::ast::visitor::Visitor;
@ -5,9 +9,6 @@ use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustc_hash::FxHashMap;
use rustpython_ast::{Expr, ExprKind};
define_violation!(
pub struct LoopVariableOverridesIterator {

View file

@ -27,7 +27,6 @@ pub use raise_without_from_inside_except::{
pub use redundant_tuple_in_exception_handler::{
redundant_tuple_in_exception_handler, RedundantTupleInExceptionHandler,
};
pub use setattr_with_constant::{setattr_with_constant, SetAttrWithConstant};
pub use star_arg_unpacking_after_keyword_arg::{
star_arg_unpacking_after_keyword_arg, StarArgUnpackingAfterKeywordArg,

View file

@ -1,10 +1,11 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Arguments, Constant, Expr, ExprKind, Operator};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Arguments, Constant, Expr, ExprKind, Operator};
define_violation!(
pub struct MutableArgumentDefault;

View file

@ -1,12 +1,13 @@
use ruff_macros::derive_message_formats;
use ruff_python::string::is_lower;
use rustpython_ast::{ExprKind, Stmt, StmtKind};
use crate::ast::types::Range;
use crate::ast::visitor::Visitor;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use ruff_python::string::is_lower;
use rustpython_ast::{ExprKind, Stmt, StmtKind};
define_violation!(
pub struct RaiseWithoutFromInsideExcept;

View file

@ -1,3 +1,6 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Excepthandler, ExcepthandlerKind, ExprKind};
use crate::ast::helpers::unparse_expr;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,8 +8,6 @@ use crate::define_violation;
use crate::fix::Fix;
use crate::registry::Diagnostic;
use crate::violation::AlwaysAutofixableViolation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Excepthandler, ExcepthandlerKind, ExprKind};
define_violation!(
pub struct RedundantTupleInExceptionHandler {

View file

@ -1,3 +1,8 @@
use ruff_macros::derive_message_formats;
use ruff_python::identifiers::{is_identifier, is_mangled_private};
use ruff_python::keyword::KWLIST;
use rustpython_ast::{Constant, Expr, ExprContext, ExprKind, Location, Stmt, StmtKind};
use crate::ast::helpers::unparse_stmt;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -6,10 +11,6 @@ use crate::fix::Fix;
use crate::registry::Diagnostic;
use crate::source_code::Stylist;
use crate::violation::AlwaysAutofixableViolation;
use ruff_macros::derive_message_formats;
use ruff_python::identifiers::{is_identifier, is_mangled_private};
use ruff_python::keyword::KWLIST;
use rustpython_ast::{Constant, Expr, ExprContext, ExprKind, Location, Stmt, StmtKind};
define_violation!(
pub struct SetAttrWithConstant;

View file

@ -7,13 +7,14 @@
//! by the unpacked sequence, and this change of ordering can surprise and
//! mislead readers.
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
define_violation!(
pub struct StarArgUnpackingAfterKeywordArg;

View file

@ -1,11 +1,12 @@
use itertools::Itertools;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use itertools::Itertools;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind};
define_violation!(
pub struct StripWithMultiCharacters;

View file

@ -17,13 +17,14 @@
//! n += 1
//! ```
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Unaryop};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Unaryop};
define_violation!(
pub struct UnaryPrefixIncrement;

View file

@ -1,10 +1,11 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind};
define_violation!(
pub struct UnreliableCallableCheck;

View file

@ -18,12 +18,12 @@
//! method()
//! ```
use rustc_hash::FxHashMap;
use rustpython_ast::{Expr, ExprKind, Stmt};
use serde::{Deserialize, Serialize};
use std::iter;
use ruff_macros::derive_message_formats;
use rustc_hash::FxHashMap;
use rustpython_ast::{Expr, ExprKind, Stmt};
use serde::{Deserialize, Serialize};
use crate::ast::types::{BindingKind, Range, RefEquality};
use crate::ast::visitor::Visitor;
@ -44,11 +44,13 @@ define_violation!(
pub struct UnusedLoopControlVariable {
/// The name of the loop control variable.
pub name: String,
/// The name to which the variable should be renamed, if it can be safely renamed.
/// The name to which the variable should be renamed, if it can be
/// safely renamed.
pub rename: Option<String>,
/// Whether the variable is certain to be unused in the loop body, or merely suspect.
/// A variable _may_ be used, but undetectably so, if the loop incorporates
/// by magic control flow (e.g., `locals()`).
/// Whether the variable is certain to be unused in the loop body, or
/// merely suspect. A variable _may_ be used, but undetectably
/// so, if the loop incorporates by magic control flow (e.g.,
/// `locals()`).
pub certainty: Certainty,
}
);
@ -147,8 +149,9 @@ pub fn unused_loop_control_variable(
Certainty::Certain
};
// Attempt to rename the variable by prepending an underscore, but avoid applying the fix
// if doing so wouldn't actually cause us to ignore the violation in the next pass.
// Attempt to rename the variable by prepending an underscore, but avoid
// applying the fix if doing so wouldn't actually cause us to ignore the
// violation in the next pass.
let rename = format!("_{name}");
let rename = if checker
.settings

View file

@ -1,10 +1,11 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
define_violation!(
pub struct UselessComparison;

View file

@ -1,10 +1,11 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::Expr;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::Expr;
define_violation!(
pub struct UselessContextlibSuppress;

View file

@ -1,10 +1,11 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, ExprKind, Stmt, StmtKind};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, ExprKind, Stmt, StmtKind};
define_violation!(
pub struct UselessExpression;

View file

@ -1,10 +1,11 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
define_violation!(
pub struct ZipWithoutExplicitStrict;

View file

@ -1,11 +1,12 @@
use ruff_macros::derive_message_formats;
use ruff_python::builtins::BUILTINS;
use rustpython_ast::Located;
use super::types::ShadowingType;
use crate::ast::types::Range;
use crate::define_violation;
use crate::registry::{Diagnostic, DiagnosticKind};
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use ruff_python::builtins::BUILTINS;
use rustpython_ast::Located;
define_violation!(
pub struct BuiltinVariableShadowing {

View file

@ -1,3 +1,7 @@
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,9 +9,6 @@ use crate::define_violation;
use crate::registry::Diagnostic;
use crate::rules::flake8_comprehensions::fixes;
use crate::violation::AlwaysAutofixableViolation;
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
define_violation!(
pub struct UnnecessaryCallAroundSorted {

View file

@ -1,3 +1,7 @@
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, Keyword};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,9 +9,6 @@ use crate::define_violation;
use crate::registry::Diagnostic;
use crate::rules::flake8_comprehensions::fixes;
use crate::violation::AlwaysAutofixableViolation;
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, Keyword};
define_violation!(
pub struct UnnecessaryCollectionCall {

View file

@ -1,3 +1,7 @@
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Comprehension, Expr, ExprKind};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,9 +9,6 @@ use crate::define_violation;
use crate::registry::Diagnostic;
use crate::rules::flake8_comprehensions::fixes;
use crate::violation::AlwaysAutofixableViolation;
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Comprehension, Expr, ExprKind};
define_violation!(
pub struct UnnecessaryComprehension {

View file

@ -1,12 +1,12 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
define_violation!(
pub struct UnnecessaryDoubleCastOrProcess {

View file

@ -1,3 +1,7 @@
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,9 +9,6 @@ use crate::define_violation;
use crate::registry::Diagnostic;
use crate::rules::flake8_comprehensions::fixes;
use crate::violation::AlwaysAutofixableViolation;
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
define_violation!(
pub struct UnnecessaryGeneratorDict;

View file

@ -1,3 +1,7 @@
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,9 +9,6 @@ use crate::define_violation;
use crate::registry::Diagnostic;
use crate::rules::flake8_comprehensions::fixes;
use crate::violation::AlwaysAutofixableViolation;
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
define_violation!(
pub struct UnnecessaryGeneratorList;

View file

@ -1,3 +1,7 @@
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,9 +9,6 @@ use crate::define_violation;
use crate::registry::Diagnostic;
use crate::rules::flake8_comprehensions::fixes;
use crate::violation::AlwaysAutofixableViolation;
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
define_violation!(
pub struct UnnecessaryGeneratorSet;

View file

@ -1,3 +1,7 @@
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,9 +9,6 @@ use crate::define_violation;
use crate::registry::Diagnostic;
use crate::rules::flake8_comprehensions::fixes;
use crate::violation::AlwaysAutofixableViolation;
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
define_violation!(
pub struct UnnecessaryListCall;

View file

@ -1,3 +1,7 @@
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,9 +9,6 @@ use crate::define_violation;
use crate::registry::Diagnostic;
use crate::rules::flake8_comprehensions::fixes;
use crate::violation::AlwaysAutofixableViolation;
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
define_violation!(
pub struct UnnecessaryListComprehensionDict;

View file

@ -1,3 +1,7 @@
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,9 +9,6 @@ use crate::define_violation;
use crate::registry::Diagnostic;
use crate::rules::flake8_comprehensions::fixes;
use crate::violation::AlwaysAutofixableViolation;
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
define_violation!(
pub struct UnnecessaryListComprehensionSet;

View file

@ -1,3 +1,7 @@
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,9 +9,6 @@ use crate::define_violation;
use crate::registry::Diagnostic;
use crate::rules::flake8_comprehensions::fixes;
use crate::violation::AlwaysAutofixableViolation;
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
define_violation!(
pub struct UnnecessaryLiteralDict {

View file

@ -1,3 +1,7 @@
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,9 +9,6 @@ use crate::define_violation;
use crate::registry::Diagnostic;
use crate::rules::flake8_comprehensions::fixes;
use crate::violation::AlwaysAutofixableViolation;
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword};
define_violation!(
pub struct UnnecessaryLiteralSet {

View file

@ -1,3 +1,7 @@
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,9 +9,6 @@ use crate::define_violation;
use crate::registry::Diagnostic;
use crate::rules::flake8_comprehensions::fixes;
use crate::violation::AlwaysAutofixableViolation;
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
define_violation!(
pub struct UnnecessaryLiteralWithinListCall {

View file

@ -1,3 +1,7 @@
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,9 +9,6 @@ use crate::define_violation;
use crate::registry::Diagnostic;
use crate::rules::flake8_comprehensions::fixes;
use crate::violation::AlwaysAutofixableViolation;
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
define_violation!(
pub struct UnnecessaryLiteralWithinTupleCall {

View file

@ -1,12 +1,12 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
define_violation!(
pub struct UnnecessaryMap {

View file

@ -1,13 +1,13 @@
use num_bigint::BigInt;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind, Unaryop};
use super::helpers;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use num_bigint::BigInt;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind, Unaryop};
define_violation!(
pub struct UnnecessarySubscriptReversal {

View file

@ -1,6 +1,5 @@
use rustpython_ast::{Constant, Expr, ExprKind, Keyword};
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind, Keyword};
use crate::ast::helpers::{has_non_none_keyword, is_const_none};
use crate::ast::types::Range;

View file

@ -1,3 +1,4 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, Stmt};
use super::types::DebuggerUsingType;
@ -8,8 +9,6 @@ use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
// flake8-debugger
define_violation!(

View file

@ -1,13 +1,12 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::{Diagnostic, Rule};
use crate::violation::Violation;
use crate::define_violation;
use ruff_macros::derive_message_formats;
define_violation!(
pub struct RawStringInException;
);

View file

@ -1,9 +1,8 @@
use itertools::Itertools;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind, Operator};
use rustpython_parser::lexer::{LexResult, Tok};
use ruff_macros::derive_message_formats;
use crate::ast::types::Range;
use crate::define_violation;
use crate::registry::Diagnostic;

View file

@ -1,10 +1,9 @@
use log::error;
use rustc_hash::FxHashSet;
use rustpython_ast::{Boolop, Constant, Expr, ExprKind, Keyword, Stmt, StmtKind};
use ruff_macros::derive_message_formats;
use ruff_python::identifiers::is_identifier;
use ruff_python::keyword::KWLIST;
use rustc_hash::FxHashSet;
use rustpython_ast::{Boolop, Constant, Expr, ExprKind, Keyword, Stmt, StmtKind};
use crate::ast::comparable::ComparableExpr;
use crate::ast::helpers::{match_trailing_comment, unparse_expr};

View file

@ -1,7 +1,6 @@
use log::error;
use rustpython_ast::{Expr, Keyword, Stmt, StmtKind};
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, Keyword, Stmt, StmtKind};
use crate::ast::helpers::is_const_none;
use crate::ast::types::Range;

View file

@ -1,3 +1,4 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{
Boolop, Excepthandler, ExcepthandlerKind, Expr, ExprKind, Keyword, Stmt, StmtKind, Unaryop,
};
@ -13,7 +14,6 @@ use crate::define_violation;
use crate::fix::Fix;
use crate::registry::Diagnostic;
use crate::violation::{AlwaysAutofixableViolation, Violation};
use ruff_macros::derive_message_formats;
define_violation!(
pub struct CompositeAssertion;

View file

@ -1,3 +1,4 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, Keyword};
use super::helpers::{is_empty_or_null_string, is_pytest_fail};
@ -7,7 +8,6 @@ use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
define_violation!(
pub struct FailWithoutMessage;

View file

@ -1,10 +1,10 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::Stmt;
use crate::ast::types::Range;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
define_violation!(
pub struct IncorrectPytestImport;

View file

@ -1,3 +1,6 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Location};
use super::helpers::{get_mark_decorators, get_mark_name};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
@ -5,8 +8,6 @@ use crate::define_violation;
use crate::fix::Fix;
use crate::registry::{Diagnostic, Rule};
use crate::violation::AlwaysAutofixableViolation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Location};
define_violation!(
pub struct IncorrectMarkParenthesesStyle {

View file

@ -1,3 +1,6 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprContext, ExprKind};
use super::super::types;
use super::helpers::{is_pytest_parametrize, split_names};
use crate::ast::helpers::{create_expr, unparse_expr};
@ -8,8 +11,6 @@ use crate::fix::Fix;
use crate::registry::{Diagnostic, Rule};
use crate::source_code::Generator;
use crate::violation::{AlwaysAutofixableViolation, Violation};
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprContext, ExprKind};
define_violation!(
pub struct ParametrizeNamesWrongType {

View file

@ -1,3 +1,4 @@
use ruff_macros::derive_message_formats;
use rustc_hash::FxHashSet;
use rustpython_ast::{Expr, ExprKind, Keyword};
@ -8,7 +9,6 @@ use crate::ast::visitor::Visitor;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
define_violation!(
pub struct PatchWithLambda;

View file

@ -1,3 +1,4 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind, Keyword, Stmt, StmtKind, Withitem};
use super::helpers::is_empty_or_null_string;
@ -7,7 +8,6 @@ use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::{Diagnostic, Rule};
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
define_violation!(
pub struct RaisesWithMultipleStatements;

View file

@ -50,8 +50,8 @@ pub struct Options {
///
/// * `csv` — a comma-separated list, e.g.
/// `@pytest.mark.parametrize('name1,name2', ...)`
/// * `tuple` (default) — e.g.
/// `@pytest.mark.parametrize(('name1', 'name2'), ...)`
/// * `tuple` (default) — e.g. `@pytest.mark.parametrize(('name1', 'name2'),
/// ...)`
/// * `list` — e.g. `@pytest.mark.parametrize(['name1', 'name2'], ...)`
pub parametrize_names_type: Option<types::ParametrizeNameType>,
#[option(
@ -73,10 +73,10 @@ pub struct Options {
/// Expected type for each row of values in `@pytest.mark.parametrize` in
/// case of multiple parameters. The following values are supported:
///
/// * `tuple` (default) — e.g.
/// `@pytest.mark.parametrize(('name1', 'name2'), [(1, 2), (3, 4)])`
/// * `list` — e.g.
/// `@pytest.mark.parametrize(('name1', 'name2'), [[1, 2], [3, 4]])`
/// * `tuple` (default) — e.g. `@pytest.mark.parametrize(('name1', 'name2'),
/// [(1, 2), (3, 4)])`
/// * `list` — e.g. `@pytest.mark.parametrize(('name1', 'name2'), [[1, 2],
/// [3, 4]])`
pub parametrize_values_row_type: Option<types::ParametrizeValuesRowType>,
#[option(
default = r#"["BaseException", "Exception", "ValueError", "OSError", "IOError", "EnvironmentError", "socket.error"]"#,

View file

@ -1,3 +1,7 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::Location;
use rustpython_parser::lexer::{LexResult, Tok};
use super::settings::Quote;
use crate::ast::types::Range;
use crate::define_violation;
@ -8,10 +12,6 @@ use crate::settings::{flags, Settings};
use crate::source_code::Locator;
use crate::violation::AlwaysAutofixableViolation;
use ruff_macros::derive_message_formats;
use rustpython_ast::Location;
use rustpython_parser::lexer::{LexResult, Tok};
define_violation!(
pub struct BadQuotesInlineString {
pub quote: Quote,
@ -231,8 +231,8 @@ fn strings(
})
.collect::<Vec<_>>();
// Return `true` if any of the strings are inline strings that contain the quote character in
// the body.
// Return `true` if any of the strings are inline strings that contain the quote
// character in the body.
let relax_quote = trivia.iter().any(|trivia| {
if trivia.is_multiline {
return false;
@ -393,15 +393,15 @@ pub fn from_tokens(
) -> Vec<Diagnostic> {
let mut diagnostics = vec![];
// Keep track of sequences of strings, which represent implicit string concatenation, and
// should thus be handled as a single unit.
// Keep track of sequences of strings, which represent implicit string
// concatenation, and should thus be handled as a single unit.
let mut sequence = vec![];
let mut state_machine = StateMachine::default();
for &(start, ref tok, end) in lxr.iter().flatten() {
let is_docstring = state_machine.consume(tok);
// If this is a docstring, consume the existing sequence, then consume the docstring, then
// move on.
// If this is a docstring, consume the existing sequence, then consume the
// docstring, then move on.
if is_docstring {
if !sequence.is_empty() {
diagnostics.extend(strings(locator, &sequence, settings, autofix));

View file

@ -1,6 +1,5 @@
use rustpython_ast::{Expr, ExprKind};
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
use crate::ast::helpers::match_parens;
use crate::checkers::ast::Checker;

View file

@ -1,4 +1,5 @@
use itertools::Itertools;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind, Location, Stmt, StmtKind};
use super::branch::Branch;
@ -13,7 +14,6 @@ use crate::define_violation;
use crate::fix::Fix;
use crate::registry::{Diagnostic, Rule};
use crate::violation::{AlwaysAutofixableViolation, Violation};
use ruff_macros::derive_message_formats;
define_violation!(
pub struct UnnecessaryReturnNone;

View file

@ -1,11 +1,11 @@
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
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 PrivateMemberAccess {

View file

@ -1,18 +1,17 @@
use crate::define_violation;
use crate::violation::AlwaysAutofixableViolation;
use ruff_macros::derive_message_formats;
use std::collections::BTreeMap;
use std::iter;
use itertools::Either::{Left, Right};
use ruff_macros::derive_message_formats;
use rustpython_ast::{Boolop, Cmpop, Constant, Expr, ExprContext, ExprKind, Unaryop};
use crate::ast::helpers::{contains_effect, create_expr, has_comments, unparse_expr};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::fix::Fix;
use crate::registry::Diagnostic;
use crate::violation::AlwaysAutofixableViolation;
define_violation!(
pub struct DuplicateIsinstanceCall {

View file

@ -1,13 +1,13 @@
use crate::define_violation;
use crate::violation::AlwaysAutofixableViolation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprKind};
use crate::ast::helpers::{create_expr, unparse_expr};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::fix::Fix;
use crate::registry::Diagnostic;
use crate::violation::AlwaysAutofixableViolation;
define_violation!(
pub struct UseCapitalEnvironmentVariables {

View file

@ -1,5 +1,3 @@
use crate::define_violation;
use crate::violation::AlwaysAutofixableViolation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{
Comprehension, Constant, Expr, ExprContext, ExprKind, Location, Stmt, StmtKind, Unaryop,
@ -8,9 +6,11 @@ use rustpython_ast::{
use crate::ast::helpers::{create_expr, create_stmt, unparse_stmt};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::fix::Fix;
use crate::registry::{Diagnostic, Rule};
use crate::source_code::Stylist;
use crate::violation::AlwaysAutofixableViolation;
define_violation!(
pub struct ConvertLoopToAny {

View file

@ -1,5 +1,3 @@
use crate::violation::{AlwaysAutofixableViolation, Availability, Violation};
use crate::{define_violation, AutofixKind};
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Cmpop, Constant, Expr, ExprContext, ExprKind, Stmt, StmtKind};
@ -14,6 +12,8 @@ use crate::checkers::ast::Checker;
use crate::fix::Fix;
use crate::registry::Diagnostic;
use crate::rules::flake8_simplify::rules::fix_if;
use crate::violation::{AlwaysAutofixableViolation, Availability, Violation};
use crate::{define_violation, AutofixKind};
define_violation!(
pub struct NestedIfStatements;
@ -240,7 +240,8 @@ pub fn return_bool_condition_directly(checker: &mut Checker, stmt: &Stmt) {
return;
};
// If the branches have the same condition, abort (although the code could be simplified).
// If the branches have the same condition, abort (although the code could be
// simplified).
if if_return == else_return {
return;
}

View file

@ -1,13 +1,13 @@
use crate::define_violation;
use crate::violation::AlwaysAutofixableViolation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Constant, Expr, ExprContext, ExprKind, Unaryop};
use crate::ast::helpers::{create_expr, unparse_expr};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::fix::Fix;
use crate::registry::Diagnostic;
use crate::violation::AlwaysAutofixableViolation;
define_violation!(
pub struct IfExprWithTrueFalse {

View file

@ -1,13 +1,13 @@
use crate::define_violation;
use crate::violation::AlwaysAutofixableViolation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Cmpop, Expr, ExprKind, Stmt, StmtKind, Unaryop};
use crate::ast::helpers::{create_expr, unparse_expr};
use crate::ast::types::{Range, ScopeKind};
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::fix::Fix;
use crate::registry::Diagnostic;
use crate::violation::AlwaysAutofixableViolation;
define_violation!(
pub struct NegateEqualOp {

View file

@ -1,5 +1,3 @@
use crate::define_violation;
use crate::violation::AlwaysAutofixableViolation;
use log::error;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Located, Stmt, StmtKind, Withitem};
@ -8,7 +6,9 @@ use super::fix_with;
use crate::ast::helpers::{first_colon_range, has_comments_in};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::AlwaysAutofixableViolation;
define_violation!(
pub struct MultipleWithStatements;

View file

@ -1,12 +1,12 @@
use crate::define_violation;
use crate::violation::AlwaysAutofixableViolation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Cmpop, Expr, ExprKind};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::fix::Fix;
use crate::registry::Diagnostic;
use crate::violation::AlwaysAutofixableViolation;
define_violation!(
pub struct KeyInDict {

View file

@ -1,12 +1,12 @@
use crate::define_violation;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Expr, ExprKind};
use rustpython_parser::ast::StmtKind;
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct OpenFileWithContextHandler;

View file

@ -1,11 +1,11 @@
use crate::define_violation;
use crate::violation::Violation;
use ruff_macros::derive_message_formats;
use rustpython_ast::{Excepthandler, ExcepthandlerKind, Stmt, StmtKind};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::define_violation;
use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
pub struct ReturnInTryExceptFinally;

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