Rename a variety of rules to match updated conventions (#3283)

This commit is contained in:
Charlie Marsh 2023-03-18 17:35:59 -04:00 committed by GitHub
parent dfb772c6f1
commit 4ffcd8366a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
225 changed files with 1962 additions and 1801 deletions

View file

@ -2,3 +2,6 @@ avoid-*
do-not-*
uses-*
*-used
rewrite-*
prefer-*
consider-*

View file

@ -113,14 +113,14 @@ mod tests {
use ruff_python_ast::source_code::Locator;
use crate::autofix::{apply_fix, apply_fixes};
use crate::rules::pycodestyle::rules::NoNewLineAtEndOfFile;
use crate::rules::pycodestyle::rules::MissingNewlineAtEndOfFile;
fn create_diagnostics(fixes: impl IntoIterator<Item = Fix>) -> Vec<Diagnostic> {
fixes
.into_iter()
.map(|fix| Diagnostic {
// The choice of rule here is arbitrary.
kind: NoNewLineAtEndOfFile.into(),
kind: MissingNewlineAtEndOfFile.into(),
location: fix.location,
end_location: fix.end_location,
fix: Some(fix),

View file

@ -316,7 +316,7 @@ where
if self
.settings
.rules
.enabled(Rule::NonLeadingReceiverDecorator)
.enabled(Rule::DjangoNonLeadingReceiverDecorator)
{
self.diagnostics
.extend(flake8_django::rules::non_leading_receiver_decorator(
@ -410,10 +410,10 @@ where
{
pyupgrade::rules::lru_cache_without_parameters(self, decorator_list);
}
if self.settings.rules.enabled(Rule::FunctoolsCache)
if self.settings.rules.enabled(Rule::LRUCacheWithMaxsizeNone)
&& self.settings.target_version >= PythonVersion::Py39
{
pyupgrade::rules::functools_cache(self, decorator_list);
pyupgrade::rules::lru_cache_with_maxsize_none(self, decorator_list);
}
if self.settings.rules.enabled(Rule::UselessExpression) {
@ -501,29 +501,44 @@ where
if self
.settings
.rules
.enabled(Rule::IncorrectFixtureParenthesesStyle)
|| self.settings.rules.enabled(Rule::FixturePositionalArgs)
|| self.settings.rules.enabled(Rule::ExtraneousScopeFunction)
.enabled(Rule::PytestFixtureIncorrectParenthesesStyle)
|| self
.settings
.rules
.enabled(Rule::MissingFixtureNameUnderscore)
.enabled(Rule::PytestFixturePositionalArgs)
|| self
.settings
.rules
.enabled(Rule::IncorrectFixtureNameUnderscore)
|| self.settings.rules.enabled(Rule::FixtureParamWithoutValue)
|| self.settings.rules.enabled(Rule::DeprecatedYieldFixture)
|| self.settings.rules.enabled(Rule::FixtureFinalizerCallback)
|| self.settings.rules.enabled(Rule::UselessYieldFixture)
.enabled(Rule::PytestExtraneousScopeFunction)
|| self
.settings
.rules
.enabled(Rule::UnnecessaryAsyncioMarkOnFixture)
.enabled(Rule::PytestMissingFixtureNameUnderscore)
|| self
.settings
.rules
.enabled(Rule::ErroneousUseFixturesOnFixture)
.enabled(Rule::PytestIncorrectFixtureNameUnderscore)
|| self
.settings
.rules
.enabled(Rule::PytestFixtureParamWithoutValue)
|| self
.settings
.rules
.enabled(Rule::PytestDeprecatedYieldFixture)
|| self
.settings
.rules
.enabled(Rule::PytestFixtureFinalizerCallback)
|| self.settings.rules.enabled(Rule::PytestUselessYieldFixture)
|| self
.settings
.rules
.enabled(Rule::PytestUnnecessaryAsyncioMarkOnFixture)
|| self
.settings
.rules
.enabled(Rule::PytestErroneousUseFixturesOnFixture)
{
flake8_pytest_style::rules::fixture(
self,
@ -535,11 +550,14 @@ where
);
}
if self.settings.rules.enabled(Rule::ParametrizeNamesWrongType)
if self
.settings
.rules
.enabled(Rule::PytestParametrizeNamesWrongType)
|| self
.settings
.rules
.enabled(Rule::ParametrizeValuesWrongType)
.enabled(Rule::PytestParametrizeValuesWrongType)
{
flake8_pytest_style::rules::parametrize(self, decorator_list);
}
@ -547,11 +565,11 @@ where
if self
.settings
.rules
.enabled(Rule::IncorrectMarkParenthesesStyle)
.enabled(Rule::PytestIncorrectMarkParenthesesStyle)
|| self
.settings
.rules
.enabled(Rule::UseFixturesWithoutParameters)
.enabled(Rule::PytestUseFixturesWithoutParameters)
{
flake8_pytest_style::rules::marks(self, decorator_list);
}
@ -687,28 +705,40 @@ where
decorator_list,
body,
} => {
if self.settings.rules.enabled(Rule::NullableModelStringField) {
if self
.settings
.rules
.enabled(Rule::DjangoNullableModelStringField)
{
self.diagnostics
.extend(flake8_django::rules::nullable_model_string_field(
self, body,
));
}
if self.settings.rules.enabled(Rule::ExcludeWithModelForm) {
if self
.settings
.rules
.enabled(Rule::DjangoExcludeWithModelForm)
{
if let Some(diagnostic) =
flake8_django::rules::exclude_with_model_form(self, bases, body)
{
self.diagnostics.push(diagnostic);
}
}
if self.settings.rules.enabled(Rule::AllWithModelForm) {
if self.settings.rules.enabled(Rule::DjangoAllWithModelForm) {
if let Some(diagnostic) =
flake8_django::rules::all_with_model_form(self, bases, body)
{
self.diagnostics.push(diagnostic);
}
}
if self.settings.rules.enabled(Rule::ModelWithoutDunderStr) {
if self
.settings
.rules
.enabled(Rule::DjangoModelWithoutDunderStr)
{
if let Some(diagnostic) =
flake8_django::rules::model_without_dunder_str(self, bases, body, stmt)
{
@ -781,17 +811,21 @@ where
if self
.settings
.rules
.enabled(Rule::IncorrectMarkParenthesesStyle)
.enabled(Rule::PytestIncorrectMarkParenthesesStyle)
{
flake8_pytest_style::rules::marks(self, decorator_list);
}
if self.settings.rules.enabled(Rule::DupeClassFieldDefinitions) {
flake8_pie::rules::dupe_class_field_definitions(self, stmt, body);
if self
.settings
.rules
.enabled(Rule::DuplicateClassFieldDefinition)
{
flake8_pie::rules::duplicate_class_field_definition(self, stmt, body);
}
if self.settings.rules.enabled(Rule::PreferUniqueEnums) {
flake8_pie::rules::prefer_unique_enums(self, stmt, body);
if self.settings.rules.enabled(Rule::NonUniqueEnums) {
flake8_pie::rules::non_unique_enums(self, stmt, body);
}
self.check_builtin_shadowing(name, stmt, false);
@ -828,11 +862,11 @@ where
}
}
if self.settings.rules.enabled(Rule::RewriteCElementTree) {
pyupgrade::rules::replace_c_element_tree(self, stmt);
if self.settings.rules.enabled(Rule::DeprecatedCElementTree) {
pyupgrade::rules::deprecated_c_element_tree(self, stmt);
}
if self.settings.rules.enabled(Rule::RewriteMockImport) {
pyupgrade::rules::rewrite_mock_import(self, stmt);
if self.settings.rules.enabled(Rule::DeprecatedMockImport) {
pyupgrade::rules::deprecated_mock_import(self, stmt);
}
// If a module is imported within a `ModuleNotFoundError` body, treat that as a
@ -951,8 +985,8 @@ where
if self.settings.rules.enabled(Rule::UselessImportAlias) {
pylint::rules::useless_import_alias(self, alias);
}
if self.settings.rules.enabled(Rule::ConsiderUsingFromImport) {
pylint::rules::use_from_import(self, stmt, alias, names);
if self.settings.rules.enabled(Rule::ManualFromImport) {
pylint::rules::manual_from_import(self, stmt, alias, names);
}
if let Some(asname) = &alias.node.asname {
@ -1056,7 +1090,11 @@ where
}
}
if self.settings.rules.enabled(Rule::IncorrectPytestImport) {
if self
.settings
.rules
.enabled(Rule::PytestIncorrectPytestImport)
{
if let Some(diagnostic) = flake8_pytest_style::rules::import(
stmt,
&alias.node.name,
@ -1097,11 +1135,11 @@ where
pyupgrade::rules::unnecessary_future_import(self, stmt, names);
}
}
if self.settings.rules.enabled(Rule::RewriteMockImport) {
pyupgrade::rules::rewrite_mock_import(self, stmt);
if self.settings.rules.enabled(Rule::DeprecatedMockImport) {
pyupgrade::rules::deprecated_mock_import(self, stmt);
}
if self.settings.rules.enabled(Rule::RewriteCElementTree) {
pyupgrade::rules::replace_c_element_tree(self, stmt);
if self.settings.rules.enabled(Rule::DeprecatedCElementTree) {
pyupgrade::rules::deprecated_c_element_tree(self, stmt);
}
if self.settings.rules.enabled(Rule::DeprecatedImport) {
pyupgrade::rules::deprecated_import(
@ -1143,7 +1181,11 @@ where
}
}
if self.settings.rules.enabled(Rule::IncorrectPytestImport) {
if self
.settings
.rules
.enabled(Rule::PytestIncorrectPytestImport)
{
if let Some(diagnostic) = flake8_pytest_style::rules::import_from(
stmt,
module.as_deref(),
@ -1212,11 +1254,15 @@ where
},
);
if self.settings.rules.enabled(Rule::ImportStarNotPermitted) {
if self
.settings
.rules
.enabled(Rule::UndefinedLocalWithNestedImportStarUsage)
{
let scope = self.ctx.scope();
if !matches!(scope.kind, ScopeKind::Module) {
self.diagnostics.push(Diagnostic::new(
pyflakes::rules::ImportStarNotPermitted {
pyflakes::rules::UndefinedLocalWithNestedImportStarUsage {
name: helpers::format_import_from(
level.as_ref(),
module.as_deref(),
@ -1227,9 +1273,13 @@ where
}
}
if self.settings.rules.enabled(Rule::ImportStar) {
if self
.settings
.rules
.enabled(Rule::UndefinedLocalWithImportStar)
{
self.diagnostics.push(Diagnostic::new(
pyflakes::rules::ImportStar {
pyflakes::rules::UndefinedLocalWithImportStar {
name: helpers::format_import_from(
level.as_ref(),
module.as_deref(),
@ -1496,7 +1546,11 @@ where
if self.settings.rules.enabled(Rule::NeedlessBool) {
flake8_simplify::rules::needless_bool(self, stmt);
}
if self.settings.rules.enabled(Rule::ManualDictLookup) {
if self
.settings
.rules
.enabled(Rule::IfElseBlockInsteadOfDictLookup)
{
flake8_simplify::rules::manual_dict_lookup(
self,
stmt,
@ -1506,14 +1560,18 @@ where
self.ctx.current_stmt_parent().map(Into::into),
);
}
if self.settings.rules.enabled(Rule::UseTernaryOperator) {
if self.settings.rules.enabled(Rule::IfElseBlockInsteadOfIfExp) {
flake8_simplify::rules::use_ternary_operator(
self,
stmt,
self.ctx.current_stmt_parent().map(Into::into),
);
}
if self.settings.rules.enabled(Rule::DictGetWithDefault) {
if self
.settings
.rules
.enabled(Rule::IfElseBlockInsteadOfDictGet)
{
flake8_simplify::rules::use_dict_get_with_default(
self,
stmt,
@ -1523,8 +1581,8 @@ where
self.ctx.current_stmt_parent().map(Into::into),
);
}
if self.settings.rules.enabled(Rule::PreferTypeError) {
tryceratops::rules::prefer_type_error(
if self.settings.rules.enabled(Rule::TypeCheckWithoutTypeError) {
tryceratops::rules::type_check_without_type_error(
self,
body,
test,
@ -1554,12 +1612,12 @@ where
self.diagnostics
.push(flake8_bandit::rules::assert_used(stmt));
}
if self.settings.rules.enabled(Rule::AssertAlwaysFalse) {
if self.settings.rules.enabled(Rule::PytestAssertAlwaysFalse) {
if let Some(diagnostic) = flake8_pytest_style::rules::assert_falsy(stmt, test) {
self.diagnostics.push(diagnostic);
}
}
if self.settings.rules.enabled(Rule::CompositeAssertion) {
if self.settings.rules.enabled(Rule::PytestCompositeAssertion) {
flake8_pytest_style::rules::composite_condition(
self,
stmt,
@ -1575,7 +1633,7 @@ where
if self
.settings
.rules
.enabled(Rule::RaisesWithMultipleStatements)
.enabled(Rule::PytestRaisesWithMultipleStatements)
{
flake8_pytest_style::rules::complex_raises(self, stmt, items, body);
}
@ -1643,7 +1701,7 @@ where
self.ctx.current_sibling_stmt(),
);
}
if self.settings.rules.enabled(Rule::KeyInDict) {
if self.settings.rules.enabled(Rule::InDictKeys) {
flake8_simplify::rules::key_in_dict_for(self, target, iter);
}
}
@ -1687,7 +1745,7 @@ where
if self.settings.rules.enabled(Rule::OSErrorAlias) {
pyupgrade::rules::os_error_alias_handlers(self, handlers);
}
if self.settings.rules.enabled(Rule::AssertInExcept) {
if self.settings.rules.enabled(Rule::PytestAssertInExcept) {
self.diagnostics.extend(
flake8_pytest_style::rules::assert_in_exception_handler(handlers),
);
@ -1738,7 +1796,7 @@ where
}
if self.is_stub {
if self.settings.rules.enabled(Rule::PrefixTypeParams) {
if self.settings.rules.enabled(Rule::UnprefixedTypeParam) {
flake8_pyi::rules::prefix_type_params(self, value, targets);
}
}
@ -1772,11 +1830,11 @@ where
self, stmt, targets, value,
);
}
if self.settings.rules.enabled(Rule::RewriteListComprehension) {
pyupgrade::rules::unpack_list_comprehension(self, targets, value);
if self.settings.rules.enabled(Rule::UnpackedListComprehension) {
pyupgrade::rules::unpacked_list_comprehension(self, targets, value);
}
if self.settings.rules.enabled(Rule::DfIsABadVariableName) {
if self.settings.rules.enabled(Rule::PandasDfVariableName) {
if let Some(diagnostic) = pandas_vet::rules::assignment_to_df(targets) {
self.diagnostics.push(diagnostic);
}
@ -1817,7 +1875,7 @@ where
if self
.settings
.rules
.enabled(Rule::UseCapitalEnvironmentVariables)
.enabled(Rule::UncapitalizedEnvironmentVariables)
{
flake8_simplify::rules::use_capital_environment_variables(self, value);
}
@ -1859,8 +1917,8 @@ where
body,
&Documentable::Function,
);
if self.settings.rules.enabled(Rule::RewriteYieldFrom) {
pyupgrade::rules::rewrite_yield_from(self, stmt);
if self.settings.rules.enabled(Rule::YieldInForLoop) {
pyupgrade::rules::yield_in_for_loop(self, stmt);
}
let scope =
transition_scope(&self.ctx.visible_scope, stmt, &Documentable::Function);
@ -2166,16 +2224,10 @@ where
self.ctx.in_literal = true;
}
if self
.settings
.rules
.enabled(Rule::SysVersionSlice3Referenced)
|| self.settings.rules.enabled(Rule::SysVersion2Referenced)
|| self.settings.rules.enabled(Rule::SysVersion0Referenced)
|| self
.settings
.rules
.enabled(Rule::SysVersionSlice1Referenced)
if self.settings.rules.enabled(Rule::SysVersionSlice3)
|| self.settings.rules.enabled(Rule::SysVersion2)
|| self.settings.rules.enabled(Rule::SysVersion0)
|| self.settings.rules.enabled(Rule::SysVersionSlice1)
{
flake8_2020::rules::subscript(self, value, slice);
}
@ -2186,8 +2238,10 @@ where
.settings
.rules
.enabled(Rule::ExpressionsInStarAssignment);
let check_two_starred_expressions =
self.settings.rules.enabled(Rule::TwoStarredExpressions);
let check_two_starred_expressions = self
.settings
.rules
.enabled(Rule::MultipleStarredExpressions);
if let Some(diagnostic) = pyflakes::rules::starred_expressions(
elts,
check_too_many_expressions,
@ -2241,16 +2295,16 @@ where
ExprContext::Del => self.handle_node_delete(expr),
}
if self.settings.rules.enabled(Rule::SixPY3Referenced) {
if self.settings.rules.enabled(Rule::SixPY3) {
flake8_2020::rules::name_or_attribute(self, expr);
}
if self
.settings
.rules
.enabled(Rule::UsedPriorGlobalDeclaration)
.enabled(Rule::UsePriorToGlobalDeclaration)
{
pylint::rules::used_prior_global_declaration(self, id, expr);
pylint::rules::use_prior_to_global_declaration(self, id, expr);
}
}
ExprKind::Attribute { attr, value, .. } => {
@ -2277,10 +2331,10 @@ where
if self.settings.rules.enabled(Rule::NumpyDeprecatedTypeAlias) {
numpy::rules::deprecated_type_alias(self, expr);
}
if self.settings.rules.enabled(Rule::RewriteMockImport) {
pyupgrade::rules::rewrite_mock_attribute(self, expr);
if self.settings.rules.enabled(Rule::DeprecatedMockImport) {
pyupgrade::rules::deprecated_mock_attribute(self, expr);
}
if self.settings.rules.enabled(Rule::SixPY3Referenced) {
if self.settings.rules.enabled(Rule::SixPY3) {
flake8_2020::rules::name_or_attribute(self, expr);
}
if self.settings.rules.enabled(Rule::BannedApi) {
@ -2424,8 +2478,8 @@ where
}
// flake8-print
if self.settings.rules.enabled(Rule::PrintFound)
|| self.settings.rules.enabled(Rule::PPrintFound)
if self.settings.rules.enabled(Rule::Print)
|| self.settings.rules.enabled(Rule::PPrint)
{
flake8_print::rules::print_call(self, func, keywords);
}
@ -2466,7 +2520,7 @@ where
// flake8-pie
if self.settings.rules.enabled(Rule::UnnecessaryDictKwargs) {
flake8_pie::rules::no_unnecessary_dict_kwargs(self, expr, keywords);
flake8_pie::rules::unnecessary_dict_kwargs(self, expr, keywords);
}
if self
.settings
@ -2680,14 +2734,18 @@ where
}
// pandas-vet
if self.settings.rules.enabled(Rule::UseOfInplaceArgument) {
if self
.settings
.rules
.enabled(Rule::PandasUseOfInplaceArgument)
{
self.diagnostics.extend(
pandas_vet::rules::inplace_argument(self, expr, args, keywords).into_iter(),
);
}
pandas_vet::rules::check_call(self, func);
if self.settings.rules.enabled(Rule::UseOfPdMerge) {
if self.settings.rules.enabled(Rule::PandasUseOfPdMerge) {
if let Some(diagnostic) = pandas_vet::rules::use_of_pd_merge(func) {
self.diagnostics.push(diagnostic);
};
@ -2762,7 +2820,7 @@ where
}
// pygrep-hooks
if self.settings.rules.enabled(Rule::NoEval) {
if self.settings.rules.enabled(Rule::Eval) {
pygrep_hooks::rules::no_eval(self, func);
}
if self.settings.rules.enabled(Rule::DeprecatedLogWarn) {
@ -2777,8 +2835,8 @@ where
{
pylint::rules::unnecessary_direct_lambda_call(self, expr, func);
}
if self.settings.rules.enabled(Rule::ConsiderUsingSysExit) {
pylint::rules::consider_using_sys_exit(self, func);
if self.settings.rules.enabled(Rule::SysExitAlias) {
pylint::rules::sys_exit_alias(self, func);
}
if self.settings.rules.enabled(Rule::BadStrStripCall) {
pylint::rules::bad_str_strip_call(self, func, args);
@ -2791,14 +2849,14 @@ where
}
// flake8-pytest-style
if self.settings.rules.enabled(Rule::PatchWithLambda) {
if self.settings.rules.enabled(Rule::PytestPatchWithLambda) {
if let Some(diagnostic) =
flake8_pytest_style::rules::patch_with_lambda(func, args, keywords)
{
self.diagnostics.push(diagnostic);
}
}
if self.settings.rules.enabled(Rule::UnittestAssertion) {
if self.settings.rules.enabled(Rule::PytestUnittestAssertion) {
if let Some(diagnostic) = flake8_pytest_style::rules::unittest_assertion(
self, expr, func, args, keywords,
) {
@ -2806,13 +2864,16 @@ where
}
}
if self.settings.rules.enabled(Rule::RaisesWithoutException)
|| self.settings.rules.enabled(Rule::RaisesTooBroad)
if self
.settings
.rules
.enabled(Rule::PytestRaisesWithoutException)
|| self.settings.rules.enabled(Rule::PytestRaisesTooBroad)
{
flake8_pytest_style::rules::raises_call(self, func, args, keywords);
}
if self.settings.rules.enabled(Rule::FailWithoutMessage) {
if self.settings.rules.enabled(Rule::PytestFailWithoutMessage) {
flake8_pytest_style::rules::fail_call(self, func, args, keywords);
}
@ -2886,7 +2947,11 @@ where
}
// flake8-django
if self.settings.rules.enabled(Rule::LocalsInRenderFunction) {
if self
.settings
.rules
.enabled(Rule::DjangoLocalsInRenderFunction)
{
flake8_django::rules::locals_in_render_function(self, func, args, keywords);
}
}
@ -2904,7 +2969,7 @@ where
}
if self.settings.rules.enabled(Rule::UnnecessarySpread) {
flake8_pie::rules::no_unnecessary_spread(self, keys, values);
flake8_pie::rules::unnecessary_spread(self, keys, values);
}
}
ExprKind::Yield { .. } => {
@ -3126,9 +3191,9 @@ where
if self
.settings
.rules
.enabled(Rule::UnpackInsteadOfConcatenatingToCollectionLiteral)
.enabled(Rule::CollectionLiteralConcatenation)
{
ruff::rules::unpack_instead_of_concatenating_to_collection_literal(self, expr);
ruff::rules::collection_literal_concatenation(self, expr);
}
if self.settings.rules.enabled(Rule::HardcodedSQLExpression) {
flake8_bandit::rules::hardcoded_sql_expression(self, expr);
@ -3197,10 +3262,7 @@ where
}
if self.settings.rules.enabled(Rule::SysVersionCmpStr3)
|| self
.settings
.rules
.enabled(Rule::SysVersionInfo0Eq3Referenced)
|| self.settings.rules.enabled(Rule::SysVersionInfo0Eq3)
|| self.settings.rules.enabled(Rule::SysVersionInfo1CmpInt)
|| self.settings.rules.enabled(Rule::SysVersionInfoMinorCmpInt)
|| self.settings.rules.enabled(Rule::SysVersionCmpStr10)
@ -3229,7 +3291,7 @@ where
pylint::rules::magic_value_comparison(self, left, comparators);
}
if self.settings.rules.enabled(Rule::KeyInDict) {
if self.settings.rules.enabled(Rule::InDictKeys) {
flake8_simplify::rules::key_in_dict_compare(self, expr, left, ops, comparators);
}
@ -3294,13 +3356,13 @@ where
self.diagnostics.push(diagnostic);
}
}
if self.settings.rules.enabled(Rule::RewriteUnicodeLiteral) {
pyupgrade::rules::rewrite_unicode_literal(self, expr, kind.as_deref());
if self.settings.rules.enabled(Rule::UnicodeKindPrefix) {
pyupgrade::rules::unicode_kind_prefix(self, expr, kind.as_deref());
}
}
ExprKind::Lambda { args, body, .. } => {
if self.settings.rules.enabled(Rule::PreferListBuiltin) {
flake8_pie::rules::prefer_list_builtin(self, expr);
if self.settings.rules.enabled(Rule::ReimplementedListBuiltin) {
flake8_pie::rules::reimplemented_list_builtin(self, expr);
}
// Visit the default arguments, but avoid the body, which will be deferred.
@ -3346,11 +3408,11 @@ where
self.ctx.push_scope(ScopeKind::Generator);
}
ExprKind::BoolOp { op, values } => {
if self.settings.rules.enabled(Rule::ConsiderMergingIsinstance) {
pylint::rules::merge_isinstance(self, expr, op, values);
if self.settings.rules.enabled(Rule::RepeatedIsinstanceCalls) {
pylint::rules::repeated_isinstance_calls(self, expr, op, values);
}
if self.settings.rules.enabled(Rule::SingleStartsEndsWith) {
flake8_pie::rules::single_starts_ends_with(self, expr);
if self.settings.rules.enabled(Rule::MultipleStartsEndsWith) {
flake8_pie::rules::multiple_starts_ends_with(self, expr);
}
if self.settings.rules.enabled(Rule::DuplicateIsinstanceCall) {
flake8_simplify::rules::duplicate_isinstance_call(self, expr);
@ -3623,7 +3685,7 @@ where
}
fn visit_comprehension(&mut self, comprehension: &'b Comprehension) {
if self.settings.rules.enabled(Rule::KeyInDict) {
if self.settings.rules.enabled(Rule::InDictKeys) {
flake8_simplify::rules::key_in_dict_for(
self,
&comprehension.target,
@ -3805,7 +3867,7 @@ where
if self
.settings
.rules
.enabled(Rule::FunctionCallArgumentDefault)
.enabled(Rule::FunctionCallInDefaultArgument)
{
flake8_bugbear::rules::function_call_argument_default(self, arguments);
}
@ -3814,13 +3876,13 @@ where
if self
.settings
.rules
.enabled(Rule::TypedArgumentSimpleDefaults)
.enabled(Rule::TypedArgumentDefaultInStub)
{
flake8_pyi::rules::typed_argument_simple_defaults(self, arguments);
}
}
if self.is_stub {
if self.settings.rules.enabled(Rule::ArgumentSimpleDefaults) {
if self.settings.rules.enabled(Rule::ArgumentDefaultInStub) {
flake8_pyi::rules::argument_simple_defaults(self, arguments);
}
}
@ -4172,7 +4234,11 @@ impl<'a> Checker<'a> {
}
if import_starred {
if self.settings.rules.enabled(Rule::ImportStarUsage) {
if self
.settings
.rules
.enabled(Rule::UndefinedLocalWithImportStarUsage)
{
let mut from_list = vec![];
for scope_index in self.ctx.scope_stack.iter() {
let scope = &self.ctx.scopes[*scope_index];
@ -4188,7 +4254,7 @@ impl<'a> Checker<'a> {
from_list.sort();
self.diagnostics.push(Diagnostic::new(
pyflakes::rules::ImportStarUsage {
pyflakes::rules::UndefinedLocalWithImportStarUsage {
name: id.to_string(),
sources: from_list,
},
@ -4648,7 +4714,10 @@ impl<'a> Checker<'a> {
.enabled(Rule::TypingOnlyStandardLibraryImport));
if !(self.settings.rules.enabled(Rule::UnusedImport)
|| self.settings.rules.enabled(Rule::ImportStarUsage)
|| self
.settings
.rules
.enabled(Rule::UndefinedLocalWithImportStarUsage)
|| self.settings.rules.enabled(Rule::RedefinedWhileUnused)
|| self.settings.rules.enabled(Rule::UndefinedExport)
|| enforce_typing_imports)
@ -4809,7 +4878,11 @@ impl<'a> Checker<'a> {
}
}
if self.settings.rules.enabled(Rule::ImportStarUsage) {
if self
.settings
.rules
.enabled(Rule::UndefinedLocalWithImportStarUsage)
{
if scope.import_starred {
if let Some((names, range)) = &all_names {
let mut from_list = vec![];
@ -4826,7 +4899,7 @@ impl<'a> Checker<'a> {
for &name in names {
if !scope.defines(name) {
diagnostics.push(Diagnostic::new(
pyflakes::rules::ImportStarUsage {
pyflakes::rules::UndefinedLocalWithImportStarUsage {
name: name.to_string(),
sources: from_list.clone(),
},
@ -5026,7 +5099,7 @@ impl<'a> Checker<'a> {
|| self
.settings
.rules
.enabled(Rule::MissingReturnTypePublicFunction)
.enabled(Rule::MissingReturnTypeUndocumentedPublicFunction)
|| self
.settings
.rules
@ -5044,14 +5117,20 @@ impl<'a> Checker<'a> {
.rules
.enabled(Rule::MissingReturnTypeClassMethod)
|| self.settings.rules.enabled(Rule::AnyType);
let enforce_docstrings = self.settings.rules.enabled(Rule::PublicModule)
|| self.settings.rules.enabled(Rule::PublicClass)
|| self.settings.rules.enabled(Rule::PublicMethod)
|| self.settings.rules.enabled(Rule::PublicFunction)
|| self.settings.rules.enabled(Rule::PublicPackage)
|| self.settings.rules.enabled(Rule::MagicMethod)
|| self.settings.rules.enabled(Rule::PublicNestedClass)
|| self.settings.rules.enabled(Rule::PublicInit)
let enforce_docstrings = self.settings.rules.enabled(Rule::UndocumentedPublicModule)
|| self.settings.rules.enabled(Rule::UndocumentedPublicClass)
|| self.settings.rules.enabled(Rule::UndocumentedPublicMethod)
|| self
.settings
.rules
.enabled(Rule::UndocumentedPublicFunction)
|| self.settings.rules.enabled(Rule::UndocumentedPublicPackage)
|| self.settings.rules.enabled(Rule::UndocumentedMagicMethod)
|| self
.settings
.rules
.enabled(Rule::UndocumentedPublicNestedClass)
|| self.settings.rules.enabled(Rule::UndocumentedPublicInit)
|| self.settings.rules.enabled(Rule::FitsOnOneLine)
|| self.settings.rules.enabled(Rule::NoBlankLineBeforeFunction)
|| self.settings.rules.enabled(Rule::NoBlankLineAfterFunction)
@ -5059,11 +5138,11 @@ impl<'a> Checker<'a> {
|| self.settings.rules.enabled(Rule::OneBlankLineAfterClass)
|| self.settings.rules.enabled(Rule::BlankLineAfterSummary)
|| self.settings.rules.enabled(Rule::IndentWithSpaces)
|| self.settings.rules.enabled(Rule::NoUnderIndentation)
|| self.settings.rules.enabled(Rule::NoOverIndentation)
|| self.settings.rules.enabled(Rule::UnderIndentation)
|| self.settings.rules.enabled(Rule::OverIndentation)
|| self.settings.rules.enabled(Rule::NewLineAfterLastParagraph)
|| self.settings.rules.enabled(Rule::NoSurroundingWhitespace)
|| self.settings.rules.enabled(Rule::NoBlankLineBeforeClass)
|| self.settings.rules.enabled(Rule::SurroundingWhitespace)
|| self.settings.rules.enabled(Rule::BlankLineBeforeClass)
|| self.settings.rules.enabled(Rule::MultiLineSummaryFirstLine)
|| self
.settings
@ -5092,12 +5171,12 @@ impl<'a> Checker<'a> {
.settings
.rules
.enabled(Rule::SectionUnderlineMatchesSectionLength)
|| self.settings.rules.enabled(Rule::BlankLineAfterSection)
|| self.settings.rules.enabled(Rule::BlankLineBeforeSection)
|| self.settings.rules.enabled(Rule::NoBlankLineAfterSection)
|| self.settings.rules.enabled(Rule::NoBlankLineBeforeSection)
|| self
.settings
.rules
.enabled(Rule::NoBlankLinesBetweenHeaderAndContent)
.enabled(Rule::BlankLinesBetweenHeaderAndContent)
|| self.settings.rules.enabled(Rule::BlankLineAfterLastSection)
|| self.settings.rules.enabled(Rule::EmptyDocstringSection)
|| self.settings.rules.enabled(Rule::EndsInPunctuation)
@ -5189,7 +5268,7 @@ impl<'a> Checker<'a> {
}
if self.settings.rules.enabled(Rule::OneBlankLineBeforeClass)
|| self.settings.rules.enabled(Rule::OneBlankLineAfterClass)
|| self.settings.rules.enabled(Rule::NoBlankLineBeforeClass)
|| self.settings.rules.enabled(Rule::BlankLineBeforeClass)
{
pydocstyle::rules::blank_before_after_class(self, &docstring);
}
@ -5197,15 +5276,15 @@ impl<'a> Checker<'a> {
pydocstyle::rules::blank_after_summary(self, &docstring);
}
if self.settings.rules.enabled(Rule::IndentWithSpaces)
|| self.settings.rules.enabled(Rule::NoUnderIndentation)
|| self.settings.rules.enabled(Rule::NoOverIndentation)
|| self.settings.rules.enabled(Rule::UnderIndentation)
|| self.settings.rules.enabled(Rule::OverIndentation)
{
pydocstyle::rules::indent(self, &docstring);
}
if self.settings.rules.enabled(Rule::NewLineAfterLastParagraph) {
pydocstyle::rules::newline_after_last_paragraph(self, &docstring);
}
if self.settings.rules.enabled(Rule::NoSurroundingWhitespace) {
if self.settings.rules.enabled(Rule::SurroundingWhitespace) {
pydocstyle::rules::no_surrounding_whitespace(self, &docstring);
}
if self.settings.rules.enabled(Rule::MultiLineSummaryFirstLine)
@ -5264,12 +5343,12 @@ impl<'a> Checker<'a> {
.settings
.rules
.enabled(Rule::SectionUnderlineMatchesSectionLength)
|| self.settings.rules.enabled(Rule::BlankLineAfterSection)
|| self.settings.rules.enabled(Rule::BlankLineBeforeSection)
|| self.settings.rules.enabled(Rule::NoBlankLineAfterSection)
|| self.settings.rules.enabled(Rule::NoBlankLineBeforeSection)
|| self
.settings
.rules
.enabled(Rule::NoBlankLinesBetweenHeaderAndContent)
.enabled(Rule::BlankLinesBetweenHeaderAndContent)
|| self.settings.rules.enabled(Rule::BlankLineAfterLastSection)
|| self.settings.rules.enabled(Rule::EmptyDocstringSection)
|| self.settings.rules.enabled(Rule::SectionNameEndsInColon)

View file

@ -12,8 +12,8 @@ use crate::rules::flake8_executable::rules::{
shebang_missing, shebang_newline, shebang_not_executable, shebang_python, shebang_whitespace,
};
use crate::rules::pycodestyle::rules::{
doc_line_too_long, indentation_contains_tabs, line_too_long, mixed_spaces_and_tabs,
no_newline_at_end_of_file, trailing_whitespace,
doc_line_too_long, line_too_long, mixed_spaces_and_tabs, no_newline_at_end_of_file,
tab_indentation, trailing_whitespace,
};
use crate::rules::pygrep_hooks::rules::{blanket_noqa, blanket_type_ignore};
use crate::rules::pylint;
@ -35,25 +35,25 @@ pub fn check_physical_lines(
let enforce_blanket_noqa = settings.rules.enabled(Rule::BlanketNOQA);
let enforce_shebang_not_executable = settings.rules.enabled(Rule::ShebangNotExecutable);
let enforce_shebang_missing = settings.rules.enabled(Rule::ShebangMissingExecutableFile);
let enforce_shebang_whitespace = settings.rules.enabled(Rule::ShebangWhitespace);
let enforce_shebang_newline = settings.rules.enabled(Rule::ShebangNewline);
let enforce_shebang_python = settings.rules.enabled(Rule::ShebangPython);
let enforce_shebang_whitespace = settings.rules.enabled(Rule::ShebangLeadingWhitespace);
let enforce_shebang_newline = settings.rules.enabled(Rule::ShebangNotFirstLine);
let enforce_shebang_python = settings.rules.enabled(Rule::ShebangMissingPython);
let enforce_blanket_type_ignore = settings.rules.enabled(Rule::BlanketTypeIgnore);
let enforce_doc_line_too_long = settings.rules.enabled(Rule::DocLineTooLong);
let enforce_line_too_long = settings.rules.enabled(Rule::LineTooLong);
let enforce_no_newline_at_end_of_file = settings.rules.enabled(Rule::NoNewLineAtEndOfFile);
let enforce_no_newline_at_end_of_file = settings.rules.enabled(Rule::MissingNewlineAtEndOfFile);
let enforce_unnecessary_coding_comment = settings.rules.enabled(Rule::UTF8EncodingDeclaration);
let enforce_mixed_spaces_and_tabs = settings.rules.enabled(Rule::MixedSpacesAndTabs);
let enforce_bidirectional_unicode = settings.rules.enabled(Rule::BidirectionalUnicode);
let enforce_trailing_whitespace = settings.rules.enabled(Rule::TrailingWhitespace);
let enforce_blank_line_contains_whitespace =
settings.rules.enabled(Rule::BlankLineContainsWhitespace);
let enforce_indentation_contains_tabs = settings.rules.enabled(Rule::IndentationContainsTabs);
settings.rules.enabled(Rule::BlankLineWithWhitespace);
let enforce_tab_indentation = settings.rules.enabled(Rule::TabIndentation);
let fix_unnecessary_coding_comment =
autofix.into() && settings.rules.should_fix(Rule::UTF8EncodingDeclaration);
let fix_shebang_whitespace =
autofix.into() && settings.rules.should_fix(Rule::ShebangWhitespace);
autofix.into() && settings.rules.should_fix(Rule::ShebangLeadingWhitespace);
let mut commented_lines_iter = commented_lines.iter().peekable();
let mut doc_lines_iter = doc_lines.iter().peekable();
@ -154,8 +154,8 @@ pub fn check_physical_lines(
}
}
if enforce_indentation_contains_tabs {
if let Some(diagnostic) = indentation_contains_tabs(index, line) {
if enforce_tab_indentation {
if let Some(diagnostic) = tab_indentation(index, line) {
diagnostics.push(diagnostic);
}
}
@ -165,7 +165,7 @@ pub fn check_physical_lines(
if let Some(diagnostic) = no_newline_at_end_of_file(
locator,
stylist,
autofix.into() && settings.rules.should_fix(Rule::NoNewLineAtEndOfFile),
autofix.into() && settings.rules.should_fix(Rule::MissingNewlineAtEndOfFile),
) {
diagnostics.push(diagnostic);
}

View file

@ -54,9 +54,9 @@ pub fn check_tokens(
]);
let enforce_trailing_comma = settings.rules.any_enabled(&[
Rule::TrailingCommaMissing,
Rule::TrailingCommaOnBareTupleProhibited,
Rule::TrailingCommaProhibited,
Rule::MissingTrailingComma,
Rule::TrailingCommaOnBareTuple,
Rule::ProhibitedTrailingComma,
]);
let enforce_extraneous_parenthesis = settings.rules.enabled(Rule::ExtraneousParentheses);
let enforce_type_comment_in_stub = settings.rules.enabled(Rule::TypeCommentInStub);

View file

@ -108,20 +108,20 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Pycodestyle, "E999") => Rule::SyntaxError,
// pycodestyle warnings
(Pycodestyle, "W191") => Rule::IndentationContainsTabs,
(Pycodestyle, "W191") => Rule::TabIndentation,
(Pycodestyle, "W291") => Rule::TrailingWhitespace,
(Pycodestyle, "W292") => Rule::NoNewLineAtEndOfFile,
(Pycodestyle, "W293") => Rule::BlankLineContainsWhitespace,
(Pycodestyle, "W292") => Rule::MissingNewlineAtEndOfFile,
(Pycodestyle, "W293") => Rule::BlankLineWithWhitespace,
(Pycodestyle, "W505") => Rule::DocLineTooLong,
(Pycodestyle, "W605") => Rule::InvalidEscapeSequence,
// pyflakes
(Pyflakes, "401") => Rule::UnusedImport,
(Pyflakes, "402") => Rule::ImportShadowedByLoopVar,
(Pyflakes, "403") => Rule::ImportStar,
(Pyflakes, "403") => Rule::UndefinedLocalWithImportStar,
(Pyflakes, "404") => Rule::LateFutureImport,
(Pyflakes, "405") => Rule::ImportStarUsage,
(Pyflakes, "406") => Rule::ImportStarNotPermitted,
(Pyflakes, "405") => Rule::UndefinedLocalWithImportStarUsage,
(Pyflakes, "406") => Rule::UndefinedLocalWithNestedImportStarUsage,
(Pyflakes, "407") => Rule::FutureFeatureNotDefined,
(Pyflakes, "501") => Rule::PercentFormatInvalidFormat,
(Pyflakes, "502") => Rule::PercentFormatExpectedMapping,
@ -141,7 +141,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Pyflakes, "601") => Rule::MultiValueRepeatedKeyLiteral,
(Pyflakes, "602") => Rule::MultiValueRepeatedKeyVariable,
(Pyflakes, "621") => Rule::ExpressionsInStarAssignment,
(Pyflakes, "622") => Rule::TwoStarredExpressions,
(Pyflakes, "622") => Rule::MultipleStarredExpressions,
(Pyflakes, "631") => Rule::AssertTuple,
(Pyflakes, "632") => Rule::IsLiteral,
(Pyflakes, "633") => Rule::InvalidPrintSyntax,
@ -168,7 +168,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Pylint, "E0101") => Rule::ReturnInInit,
(Pylint, "E0116") => Rule::ContinueInFinally,
(Pylint, "E0117") => Rule::NonlocalWithoutBinding,
(Pylint, "E0118") => Rule::UsedPriorGlobalDeclaration,
(Pylint, "E0118") => Rule::UsePriorToGlobalDeclaration,
(Pylint, "E0604") => Rule::InvalidAllObject,
(Pylint, "E0605") => Rule::InvalidAllFormat,
(Pylint, "E1142") => Rule::AwaitOutsideAsync,
@ -185,14 +185,14 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Pylint, "E2515") => Rule::InvalidCharacterZeroWidthSpace,
(Pylint, "R0133") => Rule::ComparisonOfConstant,
(Pylint, "R0206") => Rule::PropertyWithParameters,
(Pylint, "R0402") => Rule::ConsiderUsingFromImport,
(Pylint, "R0402") => Rule::ManualFromImport,
(Pylint, "R0911") => Rule::TooManyReturnStatements,
(Pylint, "R0912") => Rule::TooManyBranches,
(Pylint, "R0913") => Rule::TooManyArguments,
(Pylint, "R0915") => Rule::TooManyStatements,
(Pylint, "R1701") => Rule::ConsiderMergingIsinstance,
(Pylint, "R1701") => Rule::RepeatedIsinstanceCalls,
(Pylint, "R1711") => Rule::UselessReturn,
(Pylint, "R1722") => Rule::ConsiderUsingSysExit,
(Pylint, "R1722") => Rule::SysExitAlias,
(Pylint, "R2004") => Rule::MagicValueComparison,
(Pylint, "R5501") => Rule::CollapsibleElseIf,
(Pylint, "W0120") => Rule::UselessElseOnLoop,
@ -213,7 +213,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Flake8Bugbear, "005") => Rule::StripWithMultiCharacters,
(Flake8Bugbear, "006") => Rule::MutableArgumentDefault,
(Flake8Bugbear, "007") => Rule::UnusedLoopControlVariable,
(Flake8Bugbear, "008") => Rule::FunctionCallArgumentDefault,
(Flake8Bugbear, "008") => Rule::FunctionCallInDefaultArgument,
(Flake8Bugbear, "009") => Rule::GetAttrWithConstant,
(Flake8Bugbear, "010") => Rule::SetAttrWithConstant,
(Flake8Bugbear, "011") => Rule::AssertFalse,
@ -287,8 +287,8 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Flake8ImplicitStrConcat, "003") => Rule::ExplicitStringConcatenation,
// flake8-print
(Flake8Print, "1") => Rule::PrintFound,
(Flake8Print, "3") => Rule::PPrintFound,
(Flake8Print, "1") => Rule::Print,
(Flake8Print, "3") => Rule::PPrint,
// flake8-quotes
(Flake8Quotes, "000") => Rule::BadQuotesInlineString,
@ -302,7 +302,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Flake8Annotations, "003") => Rule::MissingTypeKwargs,
(Flake8Annotations, "101") => Rule::MissingTypeSelf,
(Flake8Annotations, "102") => Rule::MissingTypeCls,
(Flake8Annotations, "201") => Rule::MissingReturnTypePublicFunction,
(Flake8Annotations, "201") => Rule::MissingReturnTypeUndocumentedPublicFunction,
(Flake8Annotations, "202") => Rule::MissingReturnTypePrivateFunction,
(Flake8Annotations, "204") => Rule::MissingReturnTypeSpecialMethod,
(Flake8Annotations, "205") => Rule::MissingReturnTypeStaticMethod,
@ -310,16 +310,16 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Flake8Annotations, "401") => Rule::AnyType,
// flake8-2020
(Flake82020, "101") => Rule::SysVersionSlice3Referenced,
(Flake82020, "102") => Rule::SysVersion2Referenced,
(Flake82020, "101") => Rule::SysVersionSlice3,
(Flake82020, "102") => Rule::SysVersion2,
(Flake82020, "103") => Rule::SysVersionCmpStr3,
(Flake82020, "201") => Rule::SysVersionInfo0Eq3Referenced,
(Flake82020, "202") => Rule::SixPY3Referenced,
(Flake82020, "201") => Rule::SysVersionInfo0Eq3,
(Flake82020, "202") => Rule::SixPY3,
(Flake82020, "203") => Rule::SysVersionInfo1CmpInt,
(Flake82020, "204") => Rule::SysVersionInfoMinorCmpInt,
(Flake82020, "301") => Rule::SysVersion0Referenced,
(Flake82020, "301") => Rule::SysVersion0,
(Flake82020, "302") => Rule::SysVersionCmpStr10,
(Flake82020, "303") => Rule::SysVersionSlice1Referenced,
(Flake82020, "303") => Rule::SysVersionSlice1,
// flake8-simplify
(Flake8Simplify, "101") => Rule::DuplicateIsinstanceCall,
@ -327,16 +327,15 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Flake8Simplify, "103") => Rule::NeedlessBool,
(Flake8Simplify, "105") => Rule::UseContextlibSuppress,
(Flake8Simplify, "107") => Rule::ReturnInTryExceptFinally,
(Flake8Simplify, "108") => Rule::UseTernaryOperator,
(Flake8Simplify, "108") => Rule::IfElseBlockInsteadOfIfExp,
(Flake8Simplify, "109") => Rule::CompareWithTuple,
(Flake8Simplify, "110") => Rule::ReimplementedBuiltin,
// (Flake8Simplify, "111") => Rule::ReimplementedBuiltin,
(Flake8Simplify, "112") => Rule::UseCapitalEnvironmentVariables,
(Flake8Simplify, "112") => Rule::UncapitalizedEnvironmentVariables,
(Flake8Simplify, "114") => Rule::IfWithSameArms,
(Flake8Simplify, "115") => Rule::OpenFileWithContextHandler,
(Flake8Simplify, "116") => Rule::ManualDictLookup,
(Flake8Simplify, "116") => Rule::IfElseBlockInsteadOfDictLookup,
(Flake8Simplify, "117") => Rule::MultipleWithStatements,
(Flake8Simplify, "118") => Rule::KeyInDict,
(Flake8Simplify, "118") => Rule::InDictKeys,
(Flake8Simplify, "201") => Rule::NegateEqualOp,
(Flake8Simplify, "202") => Rule::NegateNotEqualOp,
(Flake8Simplify, "208") => Rule::DoubleNegation,
@ -348,7 +347,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Flake8Simplify, "222") => Rule::ExprOrTrue,
(Flake8Simplify, "223") => Rule::ExprAndFalse,
(Flake8Simplify, "300") => Rule::YodaConditions,
(Flake8Simplify, "401") => Rule::DictGetWithDefault,
(Flake8Simplify, "401") => Rule::IfElseBlockInsteadOfDictGet,
// pyupgrade
(Pyupgrade, "001") => Rule::UselessMetaclassType,
@ -371,17 +370,17 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Pyupgrade, "020") => Rule::OpenAlias,
(Pyupgrade, "021") => Rule::ReplaceUniversalNewlines,
(Pyupgrade, "022") => Rule::ReplaceStdoutStderr,
(Pyupgrade, "023") => Rule::RewriteCElementTree,
(Pyupgrade, "023") => Rule::DeprecatedCElementTree,
(Pyupgrade, "024") => Rule::OSErrorAlias,
(Pyupgrade, "025") => Rule::RewriteUnicodeLiteral,
(Pyupgrade, "026") => Rule::RewriteMockImport,
(Pyupgrade, "027") => Rule::RewriteListComprehension,
(Pyupgrade, "028") => Rule::RewriteYieldFrom,
(Pyupgrade, "025") => Rule::UnicodeKindPrefix,
(Pyupgrade, "026") => Rule::DeprecatedMockImport,
(Pyupgrade, "027") => Rule::UnpackedListComprehension,
(Pyupgrade, "028") => Rule::YieldInForLoop,
(Pyupgrade, "029") => Rule::UnnecessaryBuiltinImport,
(Pyupgrade, "030") => Rule::FormatLiterals,
(Pyupgrade, "031") => Rule::PrintfStringFormatting,
(Pyupgrade, "032") => Rule::FString,
(Pyupgrade, "033") => Rule::FunctoolsCache,
(Pyupgrade, "033") => Rule::LRUCacheWithMaxsizeNone,
(Pyupgrade, "034") => Rule::ExtraneousParentheses,
(Pyupgrade, "035") => Rule::DeprecatedImport,
(Pyupgrade, "036") => Rule::OutdatedVersionBlock,
@ -389,14 +388,14 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Pyupgrade, "038") => Rule::IsinstanceWithTuple,
// pydocstyle
(Pydocstyle, "100") => Rule::PublicModule,
(Pydocstyle, "101") => Rule::PublicClass,
(Pydocstyle, "102") => Rule::PublicMethod,
(Pydocstyle, "103") => Rule::PublicFunction,
(Pydocstyle, "104") => Rule::PublicPackage,
(Pydocstyle, "105") => Rule::MagicMethod,
(Pydocstyle, "106") => Rule::PublicNestedClass,
(Pydocstyle, "107") => Rule::PublicInit,
(Pydocstyle, "100") => Rule::UndocumentedPublicModule,
(Pydocstyle, "101") => Rule::UndocumentedPublicClass,
(Pydocstyle, "102") => Rule::UndocumentedPublicMethod,
(Pydocstyle, "103") => Rule::UndocumentedPublicFunction,
(Pydocstyle, "104") => Rule::UndocumentedPublicPackage,
(Pydocstyle, "105") => Rule::UndocumentedMagicMethod,
(Pydocstyle, "106") => Rule::UndocumentedPublicNestedClass,
(Pydocstyle, "107") => Rule::UndocumentedPublicInit,
(Pydocstyle, "200") => Rule::FitsOnOneLine,
(Pydocstyle, "201") => Rule::NoBlankLineBeforeFunction,
(Pydocstyle, "202") => Rule::NoBlankLineAfterFunction,
@ -404,11 +403,11 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Pydocstyle, "204") => Rule::OneBlankLineAfterClass,
(Pydocstyle, "205") => Rule::BlankLineAfterSummary,
(Pydocstyle, "206") => Rule::IndentWithSpaces,
(Pydocstyle, "207") => Rule::NoUnderIndentation,
(Pydocstyle, "208") => Rule::NoOverIndentation,
(Pydocstyle, "207") => Rule::UnderIndentation,
(Pydocstyle, "208") => Rule::OverIndentation,
(Pydocstyle, "209") => Rule::NewLineAfterLastParagraph,
(Pydocstyle, "210") => Rule::NoSurroundingWhitespace,
(Pydocstyle, "211") => Rule::NoBlankLineBeforeClass,
(Pydocstyle, "210") => Rule::SurroundingWhitespace,
(Pydocstyle, "211") => Rule::BlankLineBeforeClass,
(Pydocstyle, "212") => Rule::MultiLineSummaryFirstLine,
(Pydocstyle, "213") => Rule::MultiLineSummarySecondLine,
(Pydocstyle, "214") => Rule::SectionNotOverIndented,
@ -425,9 +424,9 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Pydocstyle, "407") => Rule::DashedUnderlineAfterSection,
(Pydocstyle, "408") => Rule::SectionUnderlineAfterName,
(Pydocstyle, "409") => Rule::SectionUnderlineMatchesSectionLength,
(Pydocstyle, "410") => Rule::BlankLineAfterSection,
(Pydocstyle, "411") => Rule::BlankLineBeforeSection,
(Pydocstyle, "412") => Rule::NoBlankLinesBetweenHeaderAndContent,
(Pydocstyle, "410") => Rule::NoBlankLineAfterSection,
(Pydocstyle, "411") => Rule::NoBlankLineBeforeSection,
(Pydocstyle, "412") => Rule::BlankLinesBetweenHeaderAndContent,
(Pydocstyle, "413") => Rule::BlankLineAfterLastSection,
(Pydocstyle, "414") => Rule::EmptyDocstringSection,
(Pydocstyle, "415") => Rule::EndsInPunctuation,
@ -509,24 +508,24 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Flake8Datetimez, "012") => Rule::CallDateFromtimestamp,
// pygrep-hooks
(PygrepHooks, "001") => Rule::NoEval,
(PygrepHooks, "001") => Rule::Eval,
(PygrepHooks, "002") => Rule::DeprecatedLogWarn,
(PygrepHooks, "003") => Rule::BlanketTypeIgnore,
(PygrepHooks, "004") => Rule::BlanketNOQA,
// pandas-vet
(PandasVet, "002") => Rule::UseOfInplaceArgument,
(PandasVet, "003") => Rule::UseOfDotIsNull,
(PandasVet, "004") => Rule::UseOfDotNotNull,
(PandasVet, "007") => Rule::UseOfDotIx,
(PandasVet, "008") => Rule::UseOfDotAt,
(PandasVet, "009") => Rule::UseOfDotIat,
(PandasVet, "010") => Rule::UseOfDotPivotOrUnstack,
(PandasVet, "011") => Rule::UseOfDotValues,
(PandasVet, "012") => Rule::UseOfDotReadTable,
(PandasVet, "013") => Rule::UseOfDotStack,
(PandasVet, "015") => Rule::UseOfPdMerge,
(PandasVet, "901") => Rule::DfIsABadVariableName,
(PandasVet, "002") => Rule::PandasUseOfInplaceArgument,
(PandasVet, "003") => Rule::PandasUseOfDotIsNull,
(PandasVet, "004") => Rule::PandasUseOfDotNotNull,
(PandasVet, "007") => Rule::PandasUseOfDotIx,
(PandasVet, "008") => Rule::PandasUseOfDotAt,
(PandasVet, "009") => Rule::PandasUseOfDotIat,
(PandasVet, "010") => Rule::PandasUseOfDotPivotOrUnstack,
(PandasVet, "011") => Rule::PandasUseOfDotValues,
(PandasVet, "012") => Rule::PandasUseOfDotReadTable,
(PandasVet, "013") => Rule::PandasUseOfDotStack,
(PandasVet, "015") => Rule::PandasUseOfPdMerge,
(PandasVet, "901") => Rule::PandasDfVariableName,
// flake8-errmsg
(Flake8ErrMsg, "101") => Rule::RawStringInException,
@ -534,58 +533,58 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Flake8ErrMsg, "103") => Rule::DotFormatInException,
// flake8-pyi
(Flake8Pyi, "001") => Rule::PrefixTypeParams,
(Flake8Pyi, "001") => Rule::UnprefixedTypeParam,
(Flake8Pyi, "006") => Rule::BadVersionInfoComparison,
(Flake8Pyi, "007") => Rule::UnrecognizedPlatformCheck,
(Flake8Pyi, "008") => Rule::UnrecognizedPlatformName,
(Flake8Pyi, "009") => Rule::PassStatementStubBody,
(Flake8Pyi, "010") => Rule::NonEmptyStubBody,
(Flake8Pyi, "011") => Rule::TypedArgumentSimpleDefaults,
(Flake8Pyi, "014") => Rule::ArgumentSimpleDefaults,
(Flake8Pyi, "011") => Rule::TypedArgumentDefaultInStub,
(Flake8Pyi, "014") => Rule::ArgumentDefaultInStub,
(Flake8Pyi, "021") => Rule::DocstringInStub,
(Flake8Pyi, "033") => Rule::TypeCommentInStub,
// flake8-pytest-style
(Flake8PytestStyle, "001") => Rule::IncorrectFixtureParenthesesStyle,
(Flake8PytestStyle, "002") => Rule::FixturePositionalArgs,
(Flake8PytestStyle, "003") => Rule::ExtraneousScopeFunction,
(Flake8PytestStyle, "004") => Rule::MissingFixtureNameUnderscore,
(Flake8PytestStyle, "005") => Rule::IncorrectFixtureNameUnderscore,
(Flake8PytestStyle, "006") => Rule::ParametrizeNamesWrongType,
(Flake8PytestStyle, "007") => Rule::ParametrizeValuesWrongType,
(Flake8PytestStyle, "008") => Rule::PatchWithLambda,
(Flake8PytestStyle, "009") => Rule::UnittestAssertion,
(Flake8PytestStyle, "010") => Rule::RaisesWithoutException,
(Flake8PytestStyle, "011") => Rule::RaisesTooBroad,
(Flake8PytestStyle, "012") => Rule::RaisesWithMultipleStatements,
(Flake8PytestStyle, "013") => Rule::IncorrectPytestImport,
(Flake8PytestStyle, "015") => Rule::AssertAlwaysFalse,
(Flake8PytestStyle, "016") => Rule::FailWithoutMessage,
(Flake8PytestStyle, "017") => Rule::AssertInExcept,
(Flake8PytestStyle, "018") => Rule::CompositeAssertion,
(Flake8PytestStyle, "019") => Rule::FixtureParamWithoutValue,
(Flake8PytestStyle, "020") => Rule::DeprecatedYieldFixture,
(Flake8PytestStyle, "021") => Rule::FixtureFinalizerCallback,
(Flake8PytestStyle, "022") => Rule::UselessYieldFixture,
(Flake8PytestStyle, "023") => Rule::IncorrectMarkParenthesesStyle,
(Flake8PytestStyle, "024") => Rule::UnnecessaryAsyncioMarkOnFixture,
(Flake8PytestStyle, "025") => Rule::ErroneousUseFixturesOnFixture,
(Flake8PytestStyle, "026") => Rule::UseFixturesWithoutParameters,
(Flake8PytestStyle, "001") => Rule::PytestFixtureIncorrectParenthesesStyle,
(Flake8PytestStyle, "002") => Rule::PytestFixturePositionalArgs,
(Flake8PytestStyle, "003") => Rule::PytestExtraneousScopeFunction,
(Flake8PytestStyle, "004") => Rule::PytestMissingFixtureNameUnderscore,
(Flake8PytestStyle, "005") => Rule::PytestIncorrectFixtureNameUnderscore,
(Flake8PytestStyle, "006") => Rule::PytestParametrizeNamesWrongType,
(Flake8PytestStyle, "007") => Rule::PytestParametrizeValuesWrongType,
(Flake8PytestStyle, "008") => Rule::PytestPatchWithLambda,
(Flake8PytestStyle, "009") => Rule::PytestUnittestAssertion,
(Flake8PytestStyle, "010") => Rule::PytestRaisesWithoutException,
(Flake8PytestStyle, "011") => Rule::PytestRaisesTooBroad,
(Flake8PytestStyle, "012") => Rule::PytestRaisesWithMultipleStatements,
(Flake8PytestStyle, "013") => Rule::PytestIncorrectPytestImport,
(Flake8PytestStyle, "015") => Rule::PytestAssertAlwaysFalse,
(Flake8PytestStyle, "016") => Rule::PytestFailWithoutMessage,
(Flake8PytestStyle, "017") => Rule::PytestAssertInExcept,
(Flake8PytestStyle, "018") => Rule::PytestCompositeAssertion,
(Flake8PytestStyle, "019") => Rule::PytestFixtureParamWithoutValue,
(Flake8PytestStyle, "020") => Rule::PytestDeprecatedYieldFixture,
(Flake8PytestStyle, "021") => Rule::PytestFixtureFinalizerCallback,
(Flake8PytestStyle, "022") => Rule::PytestUselessYieldFixture,
(Flake8PytestStyle, "023") => Rule::PytestIncorrectMarkParenthesesStyle,
(Flake8PytestStyle, "024") => Rule::PytestUnnecessaryAsyncioMarkOnFixture,
(Flake8PytestStyle, "025") => Rule::PytestErroneousUseFixturesOnFixture,
(Flake8PytestStyle, "026") => Rule::PytestUseFixturesWithoutParameters,
// flake8-pie
(Flake8Pie, "790") => Rule::UnnecessaryPass,
(Flake8Pie, "794") => Rule::DupeClassFieldDefinitions,
(Flake8Pie, "796") => Rule::PreferUniqueEnums,
(Flake8Pie, "794") => Rule::DuplicateClassFieldDefinition,
(Flake8Pie, "796") => Rule::NonUniqueEnums,
(Flake8Pie, "800") => Rule::UnnecessarySpread,
(Flake8Pie, "802") => Rule::UnnecessaryComprehensionAnyAll,
(Flake8Pie, "804") => Rule::UnnecessaryDictKwargs,
(Flake8Pie, "807") => Rule::PreferListBuiltin,
(Flake8Pie, "810") => Rule::SingleStartsEndsWith,
(Flake8Pie, "807") => Rule::ReimplementedListBuiltin,
(Flake8Pie, "810") => Rule::MultipleStartsEndsWith,
// flake8-commas
(Flake8Commas, "812") => Rule::TrailingCommaMissing,
(Flake8Commas, "818") => Rule::TrailingCommaOnBareTupleProhibited,
(Flake8Commas, "819") => Rule::TrailingCommaProhibited,
(Flake8Commas, "812") => Rule::MissingTrailingComma,
(Flake8Commas, "818") => Rule::TrailingCommaOnBareTuple,
(Flake8Commas, "819") => Rule::ProhibitedTrailingComma,
// flake8-no-pep420
(Flake8NoPep420, "001") => Rule::ImplicitNamespacePackage,
@ -593,9 +592,9 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
// flake8-executable
(Flake8Executable, "001") => Rule::ShebangNotExecutable,
(Flake8Executable, "002") => Rule::ShebangMissingExecutableFile,
(Flake8Executable, "003") => Rule::ShebangPython,
(Flake8Executable, "004") => Rule::ShebangWhitespace,
(Flake8Executable, "005") => Rule::ShebangNewline,
(Flake8Executable, "003") => Rule::ShebangMissingPython,
(Flake8Executable, "004") => Rule::ShebangLeadingWhitespace,
(Flake8Executable, "005") => Rule::ShebangNotFirstLine,
// flake8-type-checking
(Flake8TypeChecking, "001") => Rule::TypingOnlyFirstPartyImport,
@ -607,7 +606,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
// tryceratops
(Tryceratops, "002") => Rule::RaiseVanillaClass,
(Tryceratops, "003") => Rule::RaiseVanillaArgs,
(Tryceratops, "004") => Rule::PreferTypeError,
(Tryceratops, "004") => Rule::TypeCheckWithoutTypeError,
(Tryceratops, "200") => Rule::ReraiseNoCause,
(Tryceratops, "201") => Rule::VerboseRaise,
(Tryceratops, "300") => Rule::TryConsiderElse,
@ -666,18 +665,18 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<Rule> {
(Ruff, "001") => Rule::AmbiguousUnicodeCharacterString,
(Ruff, "002") => Rule::AmbiguousUnicodeCharacterDocstring,
(Ruff, "003") => Rule::AmbiguousUnicodeCharacterComment,
(Ruff, "005") => Rule::UnpackInsteadOfConcatenatingToCollectionLiteral,
(Ruff, "005") => Rule::CollectionLiteralConcatenation,
(Ruff, "006") => Rule::AsyncioDanglingTask,
(Ruff, "007") => Rule::PairwiseOverZipped,
(Ruff, "100") => Rule::UnusedNOQA,
// flake8-django
(Flake8Django, "001") => Rule::NullableModelStringField,
(Flake8Django, "003") => Rule::LocalsInRenderFunction,
(Flake8Django, "006") => Rule::ExcludeWithModelForm,
(Flake8Django, "007") => Rule::AllWithModelForm,
(Flake8Django, "008") => Rule::ModelWithoutDunderStr,
(Flake8Django, "013") => Rule::NonLeadingReceiverDecorator,
(Flake8Django, "001") => Rule::DjangoNullableModelStringField,
(Flake8Django, "003") => Rule::DjangoLocalsInRenderFunction,
(Flake8Django, "006") => Rule::DjangoExcludeWithModelForm,
(Flake8Django, "007") => Rule::DjangoAllWithModelForm,
(Flake8Django, "008") => Rule::DjangoModelWithoutDunderStr,
(Flake8Django, "013") => Rule::DjangoNonLeadingReceiverDecorator,
_ => return None,
})

View file

@ -92,19 +92,19 @@ ruff_macros::register_rules!(
rules::pycodestyle::rules::IOError,
rules::pycodestyle::rules::SyntaxError,
// pycodestyle warnings
rules::pycodestyle::rules::IndentationContainsTabs,
rules::pycodestyle::rules::TabIndentation,
rules::pycodestyle::rules::TrailingWhitespace,
rules::pycodestyle::rules::NoNewLineAtEndOfFile,
rules::pycodestyle::rules::BlankLineContainsWhitespace,
rules::pycodestyle::rules::MissingNewlineAtEndOfFile,
rules::pycodestyle::rules::BlankLineWithWhitespace,
rules::pycodestyle::rules::DocLineTooLong,
rules::pycodestyle::rules::InvalidEscapeSequence,
// pyflakes
rules::pyflakes::rules::UnusedImport,
rules::pyflakes::rules::ImportShadowedByLoopVar,
rules::pyflakes::rules::ImportStar,
rules::pyflakes::rules::UndefinedLocalWithImportStar,
rules::pyflakes::rules::LateFutureImport,
rules::pyflakes::rules::ImportStarUsage,
rules::pyflakes::rules::ImportStarNotPermitted,
rules::pyflakes::rules::UndefinedLocalWithImportStarUsage,
rules::pyflakes::rules::UndefinedLocalWithNestedImportStarUsage,
rules::pyflakes::rules::FutureFeatureNotDefined,
rules::pyflakes::rules::PercentFormatInvalidFormat,
rules::pyflakes::rules::PercentFormatExpectedMapping,
@ -124,7 +124,7 @@ ruff_macros::register_rules!(
rules::pyflakes::rules::MultiValueRepeatedKeyLiteral,
rules::pyflakes::rules::MultiValueRepeatedKeyVariable,
rules::pyflakes::rules::ExpressionsInStarAssignment,
rules::pyflakes::rules::TwoStarredExpressions,
rules::pyflakes::rules::MultipleStarredExpressions,
rules::pyflakes::rules::AssertTuple,
rules::pyflakes::rules::IsLiteral,
rules::pyflakes::rules::InvalidPrintSyntax,
@ -162,15 +162,15 @@ ruff_macros::register_rules!(
rules::pylint::rules::UselessImportAlias,
rules::pylint::rules::UnnecessaryDirectLambdaCall,
rules::pylint::rules::NonlocalWithoutBinding,
rules::pylint::rules::UsedPriorGlobalDeclaration,
rules::pylint::rules::UsePriorToGlobalDeclaration,
rules::pylint::rules::AwaitOutsideAsync,
rules::pylint::rules::PropertyWithParameters,
rules::pylint::rules::ReturnInInit,
rules::pylint::rules::ConsiderUsingFromImport,
rules::pylint::rules::ManualFromImport,
rules::pylint::rules::CompareToEmptyString,
rules::pylint::rules::ComparisonOfConstant,
rules::pylint::rules::ConsiderMergingIsinstance,
rules::pylint::rules::ConsiderUsingSysExit,
rules::pylint::rules::RepeatedIsinstanceCalls,
rules::pylint::rules::SysExitAlias,
rules::pylint::rules::MagicValueComparison,
rules::pylint::rules::UselessElseOnLoop,
rules::pylint::rules::GlobalStatement,
@ -194,7 +194,7 @@ ruff_macros::register_rules!(
rules::flake8_bugbear::rules::MutableArgumentDefault,
rules::flake8_bugbear::rules::NoExplicitStacklevel,
rules::flake8_bugbear::rules::UnusedLoopControlVariable,
rules::flake8_bugbear::rules::FunctionCallArgumentDefault,
rules::flake8_bugbear::rules::FunctionCallInDefaultArgument,
rules::flake8_bugbear::rules::GetAttrWithConstant,
rules::flake8_bugbear::rules::SetAttrWithConstant,
rules::flake8_bugbear::rules::AssertFalse,
@ -259,8 +259,8 @@ ruff_macros::register_rules!(
rules::flake8_implicit_str_concat::rules::MultiLineImplicitStringConcatenation,
rules::flake8_implicit_str_concat::rules::ExplicitStringConcatenation,
// flake8-print
rules::flake8_print::rules::PrintFound,
rules::flake8_print::rules::PPrintFound,
rules::flake8_print::rules::Print,
rules::flake8_print::rules::PPrint,
// flake8-quotes
rules::flake8_quotes::rules::BadQuotesInlineString,
rules::flake8_quotes::rules::BadQuotesMultilineString,
@ -272,38 +272,38 @@ ruff_macros::register_rules!(
rules::flake8_annotations::rules::MissingTypeKwargs,
rules::flake8_annotations::rules::MissingTypeSelf,
rules::flake8_annotations::rules::MissingTypeCls,
rules::flake8_annotations::rules::MissingReturnTypePublicFunction,
rules::flake8_annotations::rules::MissingReturnTypeUndocumentedPublicFunction,
rules::flake8_annotations::rules::MissingReturnTypePrivateFunction,
rules::flake8_annotations::rules::MissingReturnTypeSpecialMethod,
rules::flake8_annotations::rules::MissingReturnTypeStaticMethod,
rules::flake8_annotations::rules::MissingReturnTypeClassMethod,
rules::flake8_annotations::rules::AnyType,
// flake8-2020
rules::flake8_2020::rules::SysVersionSlice3Referenced,
rules::flake8_2020::rules::SysVersion2Referenced,
rules::flake8_2020::rules::SysVersionSlice3,
rules::flake8_2020::rules::SysVersion2,
rules::flake8_2020::rules::SysVersionCmpStr3,
rules::flake8_2020::rules::SysVersionInfo0Eq3Referenced,
rules::flake8_2020::rules::SixPY3Referenced,
rules::flake8_2020::rules::SysVersionInfo0Eq3,
rules::flake8_2020::rules::SixPY3,
rules::flake8_2020::rules::SysVersionInfo1CmpInt,
rules::flake8_2020::rules::SysVersionInfoMinorCmpInt,
rules::flake8_2020::rules::SysVersion0Referenced,
rules::flake8_2020::rules::SysVersion0,
rules::flake8_2020::rules::SysVersionCmpStr10,
rules::flake8_2020::rules::SysVersionSlice1Referenced,
rules::flake8_2020::rules::SysVersionSlice1,
// flake8-simplify
rules::flake8_simplify::rules::ManualDictLookup,
rules::flake8_simplify::rules::IfElseBlockInsteadOfDictLookup,
rules::flake8_simplify::rules::DuplicateIsinstanceCall,
rules::flake8_simplify::rules::CollapsibleIf,
rules::flake8_simplify::rules::NeedlessBool,
rules::flake8_simplify::rules::UseContextlibSuppress,
rules::flake8_simplify::rules::ReturnInTryExceptFinally,
rules::flake8_simplify::rules::UseTernaryOperator,
rules::flake8_simplify::rules::IfElseBlockInsteadOfIfExp,
rules::flake8_simplify::rules::CompareWithTuple,
rules::flake8_simplify::rules::ReimplementedBuiltin,
rules::flake8_simplify::rules::UseCapitalEnvironmentVariables,
rules::flake8_simplify::rules::UncapitalizedEnvironmentVariables,
rules::flake8_simplify::rules::IfWithSameArms,
rules::flake8_simplify::rules::OpenFileWithContextHandler,
rules::flake8_simplify::rules::MultipleWithStatements,
rules::flake8_simplify::rules::KeyInDict,
rules::flake8_simplify::rules::InDictKeys,
rules::flake8_simplify::rules::NegateEqualOp,
rules::flake8_simplify::rules::NegateNotEqualOp,
rules::flake8_simplify::rules::DoubleNegation,
@ -315,7 +315,7 @@ ruff_macros::register_rules!(
rules::flake8_simplify::rules::ExprOrTrue,
rules::flake8_simplify::rules::ExprAndFalse,
rules::flake8_simplify::rules::YodaConditions,
rules::flake8_simplify::rules::DictGetWithDefault,
rules::flake8_simplify::rules::IfElseBlockInsteadOfDictGet,
// pyupgrade
rules::pyupgrade::rules::UselessMetaclassType,
rules::pyupgrade::rules::TypeOfPrimitive,
@ -337,31 +337,31 @@ ruff_macros::register_rules!(
rules::pyupgrade::rules::OpenAlias,
rules::pyupgrade::rules::ReplaceUniversalNewlines,
rules::pyupgrade::rules::ReplaceStdoutStderr,
rules::pyupgrade::rules::RewriteCElementTree,
rules::pyupgrade::rules::DeprecatedCElementTree,
rules::pyupgrade::rules::OSErrorAlias,
rules::pyupgrade::rules::RewriteUnicodeLiteral,
rules::pyupgrade::rules::RewriteMockImport,
rules::pyupgrade::rules::RewriteListComprehension,
rules::pyupgrade::rules::RewriteYieldFrom,
rules::pyupgrade::rules::UnicodeKindPrefix,
rules::pyupgrade::rules::DeprecatedMockImport,
rules::pyupgrade::rules::UnpackedListComprehension,
rules::pyupgrade::rules::YieldInForLoop,
rules::pyupgrade::rules::UnnecessaryBuiltinImport,
rules::pyupgrade::rules::FormatLiterals,
rules::pyupgrade::rules::PrintfStringFormatting,
rules::pyupgrade::rules::FString,
rules::pyupgrade::rules::FunctoolsCache,
rules::pyupgrade::rules::LRUCacheWithMaxsizeNone,
rules::pyupgrade::rules::ExtraneousParentheses,
rules::pyupgrade::rules::DeprecatedImport,
rules::pyupgrade::rules::OutdatedVersionBlock,
rules::pyupgrade::rules::QuotedAnnotation,
rules::pyupgrade::rules::IsinstanceWithTuple,
// pydocstyle
rules::pydocstyle::rules::PublicModule,
rules::pydocstyle::rules::PublicClass,
rules::pydocstyle::rules::PublicMethod,
rules::pydocstyle::rules::PublicFunction,
rules::pydocstyle::rules::PublicPackage,
rules::pydocstyle::rules::MagicMethod,
rules::pydocstyle::rules::PublicNestedClass,
rules::pydocstyle::rules::PublicInit,
rules::pydocstyle::rules::UndocumentedPublicModule,
rules::pydocstyle::rules::UndocumentedPublicClass,
rules::pydocstyle::rules::UndocumentedPublicMethod,
rules::pydocstyle::rules::UndocumentedPublicFunction,
rules::pydocstyle::rules::UndocumentedPublicPackage,
rules::pydocstyle::rules::UndocumentedMagicMethod,
rules::pydocstyle::rules::UndocumentedPublicNestedClass,
rules::pydocstyle::rules::UndocumentedPublicInit,
rules::pydocstyle::rules::FitsOnOneLine,
rules::pydocstyle::rules::NoBlankLineBeforeFunction,
rules::pydocstyle::rules::NoBlankLineAfterFunction,
@ -369,11 +369,11 @@ ruff_macros::register_rules!(
rules::pydocstyle::rules::OneBlankLineAfterClass,
rules::pydocstyle::rules::BlankLineAfterSummary,
rules::pydocstyle::rules::IndentWithSpaces,
rules::pydocstyle::rules::NoUnderIndentation,
rules::pydocstyle::rules::NoOverIndentation,
rules::pydocstyle::rules::UnderIndentation,
rules::pydocstyle::rules::OverIndentation,
rules::pydocstyle::rules::NewLineAfterLastParagraph,
rules::pydocstyle::rules::NoSurroundingWhitespace,
rules::pydocstyle::rules::NoBlankLineBeforeClass,
rules::pydocstyle::rules::SurroundingWhitespace,
rules::pydocstyle::rules::BlankLineBeforeClass,
rules::pydocstyle::rules::MultiLineSummaryFirstLine,
rules::pydocstyle::rules::MultiLineSummarySecondLine,
rules::pydocstyle::rules::SectionNotOverIndented,
@ -390,9 +390,9 @@ ruff_macros::register_rules!(
rules::pydocstyle::rules::DashedUnderlineAfterSection,
rules::pydocstyle::rules::SectionUnderlineAfterName,
rules::pydocstyle::rules::SectionUnderlineMatchesSectionLength,
rules::pydocstyle::rules::BlankLineAfterSection,
rules::pydocstyle::rules::BlankLineBeforeSection,
rules::pydocstyle::rules::NoBlankLinesBetweenHeaderAndContent,
rules::pydocstyle::rules::NoBlankLineAfterSection,
rules::pydocstyle::rules::NoBlankLineBeforeSection,
rules::pydocstyle::rules::BlankLinesBetweenHeaderAndContent,
rules::pydocstyle::rules::BlankLineAfterLastSection,
rules::pydocstyle::rules::EmptyDocstringSection,
rules::pydocstyle::rules::EndsInPunctuation,
@ -465,85 +465,85 @@ ruff_macros::register_rules!(
rules::flake8_datetimez::rules::CallDateToday,
rules::flake8_datetimez::rules::CallDateFromtimestamp,
// pygrep-hooks
rules::pygrep_hooks::rules::NoEval,
rules::pygrep_hooks::rules::Eval,
rules::pygrep_hooks::rules::DeprecatedLogWarn,
rules::pygrep_hooks::rules::BlanketTypeIgnore,
rules::pygrep_hooks::rules::BlanketNOQA,
// pandas-vet
rules::pandas_vet::rules::UseOfInplaceArgument,
rules::pandas_vet::rules::UseOfDotIsNull,
rules::pandas_vet::rules::UseOfDotNotNull,
rules::pandas_vet::rules::UseOfDotIx,
rules::pandas_vet::rules::UseOfDotAt,
rules::pandas_vet::rules::UseOfDotIat,
rules::pandas_vet::rules::UseOfDotPivotOrUnstack,
rules::pandas_vet::rules::UseOfDotValues,
rules::pandas_vet::rules::UseOfDotReadTable,
rules::pandas_vet::rules::UseOfDotStack,
rules::pandas_vet::rules::UseOfPdMerge,
rules::pandas_vet::rules::DfIsABadVariableName,
rules::pandas_vet::rules::PandasUseOfInplaceArgument,
rules::pandas_vet::rules::PandasUseOfDotIsNull,
rules::pandas_vet::rules::PandasUseOfDotNotNull,
rules::pandas_vet::rules::PandasUseOfDotIx,
rules::pandas_vet::rules::PandasUseOfDotAt,
rules::pandas_vet::rules::PandasUseOfDotIat,
rules::pandas_vet::rules::PandasUseOfDotPivotOrUnstack,
rules::pandas_vet::rules::PandasUseOfDotValues,
rules::pandas_vet::rules::PandasUseOfDotReadTable,
rules::pandas_vet::rules::PandasUseOfDotStack,
rules::pandas_vet::rules::PandasUseOfPdMerge,
rules::pandas_vet::rules::PandasDfVariableName,
// flake8-errmsg
rules::flake8_errmsg::rules::RawStringInException,
rules::flake8_errmsg::rules::FStringInException,
rules::flake8_errmsg::rules::DotFormatInException,
// flake8-pyi
rules::flake8_pyi::rules::PrefixTypeParams,
rules::flake8_pyi::rules::UnprefixedTypeParam,
rules::flake8_pyi::rules::BadVersionInfoComparison,
rules::flake8_pyi::rules::UnrecognizedPlatformCheck,
rules::flake8_pyi::rules::UnrecognizedPlatformName,
rules::flake8_pyi::rules::PassStatementStubBody,
rules::flake8_pyi::rules::NonEmptyStubBody,
rules::flake8_pyi::rules::DocstringInStub,
rules::flake8_pyi::rules::TypedArgumentSimpleDefaults,
rules::flake8_pyi::rules::ArgumentSimpleDefaults,
rules::flake8_pyi::rules::TypedArgumentDefaultInStub,
rules::flake8_pyi::rules::ArgumentDefaultInStub,
rules::flake8_pyi::rules::TypeCommentInStub,
// flake8-pytest-style
rules::flake8_pytest_style::rules::IncorrectFixtureParenthesesStyle,
rules::flake8_pytest_style::rules::FixturePositionalArgs,
rules::flake8_pytest_style::rules::ExtraneousScopeFunction,
rules::flake8_pytest_style::rules::MissingFixtureNameUnderscore,
rules::flake8_pytest_style::rules::IncorrectFixtureNameUnderscore,
rules::flake8_pytest_style::rules::ParametrizeNamesWrongType,
rules::flake8_pytest_style::rules::ParametrizeValuesWrongType,
rules::flake8_pytest_style::rules::PatchWithLambda,
rules::flake8_pytest_style::rules::UnittestAssertion,
rules::flake8_pytest_style::rules::RaisesWithoutException,
rules::flake8_pytest_style::rules::RaisesTooBroad,
rules::flake8_pytest_style::rules::RaisesWithMultipleStatements,
rules::flake8_pytest_style::rules::IncorrectPytestImport,
rules::flake8_pytest_style::rules::AssertAlwaysFalse,
rules::flake8_pytest_style::rules::FailWithoutMessage,
rules::flake8_pytest_style::rules::AssertInExcept,
rules::flake8_pytest_style::rules::CompositeAssertion,
rules::flake8_pytest_style::rules::FixtureParamWithoutValue,
rules::flake8_pytest_style::rules::DeprecatedYieldFixture,
rules::flake8_pytest_style::rules::FixtureFinalizerCallback,
rules::flake8_pytest_style::rules::UselessYieldFixture,
rules::flake8_pytest_style::rules::IncorrectMarkParenthesesStyle,
rules::flake8_pytest_style::rules::UnnecessaryAsyncioMarkOnFixture,
rules::flake8_pytest_style::rules::ErroneousUseFixturesOnFixture,
rules::flake8_pytest_style::rules::UseFixturesWithoutParameters,
rules::flake8_pytest_style::rules::PytestFixtureIncorrectParenthesesStyle,
rules::flake8_pytest_style::rules::PytestFixturePositionalArgs,
rules::flake8_pytest_style::rules::PytestExtraneousScopeFunction,
rules::flake8_pytest_style::rules::PytestMissingFixtureNameUnderscore,
rules::flake8_pytest_style::rules::PytestIncorrectFixtureNameUnderscore,
rules::flake8_pytest_style::rules::PytestParametrizeNamesWrongType,
rules::flake8_pytest_style::rules::PytestParametrizeValuesWrongType,
rules::flake8_pytest_style::rules::PytestPatchWithLambda,
rules::flake8_pytest_style::rules::PytestUnittestAssertion,
rules::flake8_pytest_style::rules::PytestRaisesWithoutException,
rules::flake8_pytest_style::rules::PytestRaisesTooBroad,
rules::flake8_pytest_style::rules::PytestRaisesWithMultipleStatements,
rules::flake8_pytest_style::rules::PytestIncorrectPytestImport,
rules::flake8_pytest_style::rules::PytestAssertAlwaysFalse,
rules::flake8_pytest_style::rules::PytestFailWithoutMessage,
rules::flake8_pytest_style::rules::PytestAssertInExcept,
rules::flake8_pytest_style::rules::PytestCompositeAssertion,
rules::flake8_pytest_style::rules::PytestFixtureParamWithoutValue,
rules::flake8_pytest_style::rules::PytestDeprecatedYieldFixture,
rules::flake8_pytest_style::rules::PytestFixtureFinalizerCallback,
rules::flake8_pytest_style::rules::PytestUselessYieldFixture,
rules::flake8_pytest_style::rules::PytestIncorrectMarkParenthesesStyle,
rules::flake8_pytest_style::rules::PytestUnnecessaryAsyncioMarkOnFixture,
rules::flake8_pytest_style::rules::PytestErroneousUseFixturesOnFixture,
rules::flake8_pytest_style::rules::PytestUseFixturesWithoutParameters,
// flake8-pie
rules::flake8_pie::rules::UnnecessaryPass,
rules::flake8_pie::rules::DupeClassFieldDefinitions,
rules::flake8_pie::rules::PreferUniqueEnums,
rules::flake8_pie::rules::DuplicateClassFieldDefinition,
rules::flake8_pie::rules::NonUniqueEnums,
rules::flake8_pie::rules::UnnecessarySpread,
rules::flake8_pie::rules::UnnecessaryDictKwargs,
rules::flake8_pie::rules::PreferListBuiltin,
rules::flake8_pie::rules::SingleStartsEndsWith,
rules::flake8_pie::rules::ReimplementedListBuiltin,
rules::flake8_pie::rules::MultipleStartsEndsWith,
rules::flake8_pie::rules::UnnecessaryComprehensionAnyAll,
// flake8-commas
rules::flake8_commas::rules::TrailingCommaMissing,
rules::flake8_commas::rules::TrailingCommaOnBareTupleProhibited,
rules::flake8_commas::rules::TrailingCommaProhibited,
rules::flake8_commas::rules::MissingTrailingComma,
rules::flake8_commas::rules::TrailingCommaOnBareTuple,
rules::flake8_commas::rules::ProhibitedTrailingComma,
// flake8-no-pep420
rules::flake8_no_pep420::rules::ImplicitNamespacePackage,
// flake8-executable
rules::flake8_executable::rules::ShebangNotExecutable,
rules::flake8_executable::rules::ShebangMissingExecutableFile,
rules::flake8_executable::rules::ShebangPython,
rules::flake8_executable::rules::ShebangWhitespace,
rules::flake8_executable::rules::ShebangNewline,
rules::flake8_executable::rules::ShebangMissingPython,
rules::flake8_executable::rules::ShebangLeadingWhitespace,
rules::flake8_executable::rules::ShebangNotFirstLine,
// flake8-type-checking
rules::flake8_type_checking::rules::TypingOnlyFirstPartyImport,
rules::flake8_type_checking::rules::TypingOnlyThirdPartyImport,
@ -553,7 +553,7 @@ ruff_macros::register_rules!(
// tryceratops
rules::tryceratops::rules::RaiseVanillaClass,
rules::tryceratops::rules::RaiseVanillaArgs,
rules::tryceratops::rules::PreferTypeError,
rules::tryceratops::rules::TypeCheckWithoutTypeError,
rules::tryceratops::rules::ReraiseNoCause,
rules::tryceratops::rules::VerboseRaise,
rules::tryceratops::rules::TryConsiderElse,
@ -606,17 +606,17 @@ ruff_macros::register_rules!(
rules::ruff::rules::AmbiguousUnicodeCharacterString,
rules::ruff::rules::AmbiguousUnicodeCharacterDocstring,
rules::ruff::rules::AmbiguousUnicodeCharacterComment,
rules::ruff::rules::UnpackInsteadOfConcatenatingToCollectionLiteral,
rules::ruff::rules::CollectionLiteralConcatenation,
rules::ruff::rules::AsyncioDanglingTask,
rules::ruff::rules::UnusedNOQA,
rules::ruff::rules::PairwiseOverZipped,
// flake8-django
rules::flake8_django::rules::NullableModelStringField,
rules::flake8_django::rules::LocalsInRenderFunction,
rules::flake8_django::rules::ExcludeWithModelForm,
rules::flake8_django::rules::AllWithModelForm,
rules::flake8_django::rules::ModelWithoutDunderStr,
rules::flake8_django::rules::NonLeadingReceiverDecorator,
rules::flake8_django::rules::DjangoNullableModelStringField,
rules::flake8_django::rules::DjangoLocalsInRenderFunction,
rules::flake8_django::rules::DjangoExcludeWithModelForm,
rules::flake8_django::rules::DjangoAllWithModelForm,
rules::flake8_django::rules::DjangoModelWithoutDunderStr,
rules::flake8_django::rules::DjangoNonLeadingReceiverDecorator,
);
pub trait AsRule {
@ -841,17 +841,17 @@ impl Rule {
| Rule::DocLineTooLong
| Rule::LineTooLong
| Rule::MixedSpacesAndTabs
| Rule::NoNewLineAtEndOfFile
| Rule::MissingNewlineAtEndOfFile
| Rule::UTF8EncodingDeclaration
| Rule::ShebangMissingExecutableFile
| Rule::ShebangNotExecutable
| Rule::ShebangNewline
| Rule::ShebangNotFirstLine
| Rule::BidirectionalUnicode
| Rule::ShebangPython
| Rule::ShebangWhitespace
| Rule::ShebangMissingPython
| Rule::ShebangLeadingWhitespace
| Rule::TrailingWhitespace
| Rule::IndentationContainsTabs
| Rule::BlankLineContainsWhitespace => LintSource::PhysicalLines,
| Rule::TabIndentation
| Rule::BlankLineWithWhitespace => LintSource::PhysicalLines,
Rule::AmbiguousUnicodeCharacterComment
| Rule::AmbiguousUnicodeCharacterDocstring
| Rule::AmbiguousUnicodeCharacterString
@ -869,12 +869,12 @@ impl Rule {
| Rule::ExtraneousParentheses
| Rule::InvalidEscapeSequence
| Rule::SingleLineImplicitStringConcatenation
| Rule::TrailingCommaMissing
| Rule::TrailingCommaOnBareTupleProhibited
| Rule::MissingTrailingComma
| Rule::TrailingCommaOnBareTuple
| Rule::MultipleStatementsOnOneLineColon
| Rule::UselessSemicolon
| Rule::MultipleStatementsOnOneLineSemicolon
| Rule::TrailingCommaProhibited
| Rule::ProhibitedTrailingComma
| Rule::TypeCommentInStub => LintSource::Tokens,
Rule::IOError => LintSource::Io,
Rule::UnsortedImports | Rule::MissingRequiredImport => LintSource::Imports,
@ -919,7 +919,7 @@ impl Rule {
/// Pairs of checks that shouldn't be enabled together.
pub const INCOMPATIBLE_CODES: &[(Rule, Rule, &str); 2] = &[
(
Rule::NoBlankLineBeforeClass,
Rule::BlankLineBeforeClass,
Rule::OneBlankLineBeforeClass,
"`one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are \
incompatible. Ignoring `one-blank-line-before-class`.",

View file

@ -13,16 +13,16 @@ mod tests {
use crate::settings;
use crate::test::test_path;
#[test_case(Rule::SysVersionSlice3Referenced, Path::new("YTT101.py"); "YTT101")]
#[test_case(Rule::SysVersion2Referenced, Path::new("YTT102.py"); "YTT102")]
#[test_case(Rule::SysVersionSlice3, Path::new("YTT101.py"); "YTT101")]
#[test_case(Rule::SysVersion2, Path::new("YTT102.py"); "YTT102")]
#[test_case(Rule::SysVersionCmpStr3, Path::new("YTT103.py"); "YTT103")]
#[test_case(Rule::SysVersionInfo0Eq3Referenced, Path::new("YTT201.py"); "YTT201")]
#[test_case(Rule::SixPY3Referenced, Path::new("YTT202.py"); "YTT202")]
#[test_case(Rule::SysVersionInfo0Eq3, Path::new("YTT201.py"); "YTT201")]
#[test_case(Rule::SixPY3, Path::new("YTT202.py"); "YTT202")]
#[test_case(Rule::SysVersionInfo1CmpInt, Path::new("YTT203.py"); "YTT203")]
#[test_case(Rule::SysVersionInfoMinorCmpInt, Path::new("YTT204.py"); "YTT204")]
#[test_case(Rule::SysVersion0Referenced, Path::new("YTT301.py"); "YTT301")]
#[test_case(Rule::SysVersion0, Path::new("YTT301.py"); "YTT301")]
#[test_case(Rule::SysVersionCmpStr10, Path::new("YTT302.py"); "YTT302")]
#[test_case(Rule::SysVersionSlice1Referenced, Path::new("YTT303.py"); "YTT303")]
#[test_case(Rule::SysVersionSlice1, Path::new("YTT303.py"); "YTT303")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(

View file

@ -9,9 +9,9 @@ use crate::checkers::ast::Checker;
use crate::registry::Rule;
#[violation]
pub struct SysVersionSlice3Referenced;
pub struct SysVersionSlice3;
impl Violation for SysVersionSlice3Referenced {
impl Violation for SysVersionSlice3 {
#[derive_message_formats]
fn message(&self) -> String {
format!("`sys.version[:3]` referenced (python3.10), use `sys.version_info`")
@ -19,9 +19,9 @@ impl Violation for SysVersionSlice3Referenced {
}
#[violation]
pub struct SysVersion2Referenced;
pub struct SysVersion2;
impl Violation for SysVersion2Referenced {
impl Violation for SysVersion2 {
#[derive_message_formats]
fn message(&self) -> String {
format!("`sys.version[2]` referenced (python3.10), use `sys.version_info`")
@ -39,9 +39,9 @@ impl Violation for SysVersionCmpStr3 {
}
#[violation]
pub struct SysVersionInfo0Eq3Referenced;
pub struct SysVersionInfo0Eq3;
impl Violation for SysVersionInfo0Eq3Referenced {
impl Violation for SysVersionInfo0Eq3 {
#[derive_message_formats]
fn message(&self) -> String {
format!("`sys.version_info[0] == 3` referenced (python4), use `>=`")
@ -49,9 +49,9 @@ impl Violation for SysVersionInfo0Eq3Referenced {
}
#[violation]
pub struct SixPY3Referenced;
pub struct SixPY3;
impl Violation for SixPY3Referenced {
impl Violation for SixPY3 {
#[derive_message_formats]
fn message(&self) -> String {
format!("`six.PY3` referenced (python4), use `not six.PY2`")
@ -85,9 +85,9 @@ impl Violation for SysVersionInfoMinorCmpInt {
}
#[violation]
pub struct SysVersion0Referenced;
pub struct SysVersion0;
impl Violation for SysVersion0Referenced {
impl Violation for SysVersion0 {
#[derive_message_formats]
fn message(&self) -> String {
format!("`sys.version[0]` referenced (python10), use `sys.version_info`")
@ -105,9 +105,9 @@ impl Violation for SysVersionCmpStr10 {
}
#[violation]
pub struct SysVersionSlice1Referenced;
pub struct SysVersionSlice1;
impl Violation for SysVersionSlice1Referenced {
impl Violation for SysVersionSlice1 {
#[derive_message_formats]
fn message(&self) -> String {
format!("`sys.version[:1]` referenced (python10), use `sys.version_info`")
@ -137,25 +137,17 @@ pub fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) {
} = &upper.node
{
if *i == BigInt::from(1)
&& checker
.settings
.rules
.enabled(Rule::SysVersionSlice1Referenced)
&& checker.settings.rules.enabled(Rule::SysVersionSlice1)
{
checker.diagnostics.push(Diagnostic::new(
SysVersionSlice1Referenced,
Range::from(value),
));
checker
.diagnostics
.push(Diagnostic::new(SysVersionSlice1, Range::from(value)));
} else if *i == BigInt::from(3)
&& checker
.settings
.rules
.enabled(Rule::SysVersionSlice3Referenced)
&& checker.settings.rules.enabled(Rule::SysVersionSlice3)
{
checker.diagnostics.push(Diagnostic::new(
SysVersionSlice3Referenced,
Range::from(value),
));
checker
.diagnostics
.push(Diagnostic::new(SysVersionSlice3, Range::from(value)));
}
}
}
@ -164,18 +156,15 @@ pub fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) {
value: Constant::Int(i),
..
} => {
if *i == BigInt::from(2)
&& checker.settings.rules.enabled(Rule::SysVersion2Referenced)
if *i == BigInt::from(2) && checker.settings.rules.enabled(Rule::SysVersion2) {
checker
.diagnostics
.push(Diagnostic::new(SysVersion2, Range::from(value)));
} else if *i == BigInt::from(0) && checker.settings.rules.enabled(Rule::SysVersion0)
{
checker
.diagnostics
.push(Diagnostic::new(SysVersion2Referenced, Range::from(value)));
} else if *i == BigInt::from(0)
&& checker.settings.rules.enabled(Rule::SysVersion0Referenced)
{
checker
.diagnostics
.push(Diagnostic::new(SysVersion0Referenced, Range::from(value)));
.push(Diagnostic::new(SysVersion0, Range::from(value)));
}
}
@ -207,15 +196,11 @@ pub fn compare(checker: &mut Checker, left: &Expr, ops: &[Cmpop], comparators: &
) = (ops, comparators)
{
if *n == BigInt::from(3)
&& checker
.settings
.rules
.enabled(Rule::SysVersionInfo0Eq3Referenced)
&& checker.settings.rules.enabled(Rule::SysVersionInfo0Eq3)
{
checker.diagnostics.push(Diagnostic::new(
SysVersionInfo0Eq3Referenced,
Range::from(left),
));
checker
.diagnostics
.push(Diagnostic::new(SysVersionInfo0Eq3, Range::from(left)));
}
}
} else if *i == BigInt::from(1) {
@ -309,6 +294,6 @@ pub fn name_or_attribute(checker: &mut Checker, expr: &Expr) {
{
checker
.diagnostics
.push(Diagnostic::new(SixPY3Referenced, Range::from(expr)));
.push(Diagnostic::new(SixPY3, Range::from(expr)));
}
}

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
---
- kind:
name: SysVersionSlice3Referenced
name: SysVersionSlice3
body: "`sys.version[:3]` referenced (python3.10), use `sys.version_info`"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: SysVersionSlice3Referenced
name: SysVersionSlice3
body: "`sys.version[:3]` referenced (python3.10), use `sys.version_info`"
suggestion: ~
fixable: false
@ -29,7 +29,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: SysVersionSlice3Referenced
name: SysVersionSlice3
body: "`sys.version[:3]` referenced (python3.10), use `sys.version_info`"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
---
- kind:
name: SysVersion2Referenced
name: SysVersion2
body: "`sys.version[2]` referenced (python3.10), use `sys.version_info`"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: SysVersion2Referenced
name: SysVersion2
body: "`sys.version[2]` referenced (python3.10), use `sys.version_info`"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
---
- kind:
name: SysVersionInfo0Eq3Referenced
name: SysVersionInfo0Eq3
body: "`sys.version_info[0] == 3` referenced (python4), use `>=`"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: SysVersionInfo0Eq3Referenced
name: SysVersionInfo0Eq3
body: "`sys.version_info[0] == 3` referenced (python4), use `>=`"
suggestion: ~
fixable: false
@ -29,7 +29,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: SysVersionInfo0Eq3Referenced
name: SysVersionInfo0Eq3
body: "`sys.version_info[0] == 3` referenced (python4), use `>=`"
suggestion: ~
fixable: false
@ -42,7 +42,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: SysVersionInfo0Eq3Referenced
name: SysVersionInfo0Eq3
body: "`sys.version_info[0] == 3` referenced (python4), use `>=`"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
---
- kind:
name: SixPY3Referenced
name: SixPY3
body: "`six.PY3` referenced (python4), use `not six.PY2`"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: SixPY3Referenced
name: SixPY3
body: "`six.PY3` referenced (python4), use `not six.PY2`"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
---
- kind:
name: SysVersion0Referenced
name: SysVersion0
body: "`sys.version[0]` referenced (python10), use `sys.version_info`"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: SysVersion0Referenced
name: SysVersion0
body: "`sys.version[0]` referenced (python10), use `sys.version_info`"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_2020/mod.rs
expression: diagnostics
---
- kind:
name: SysVersionSlice1Referenced
name: SysVersionSlice1
body: "`sys.version[:1]` referenced (python10), use `sys.version_info`"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: SysVersionSlice1Referenced
name: SysVersionSlice1
body: "`sys.version[:1]` referenced (python10), use `sys.version_info`"
suggestion: ~
fixable: false

View file

@ -26,7 +26,7 @@ mod tests {
Rule::MissingTypeKwargs,
Rule::MissingTypeSelf,
Rule::MissingTypeCls,
Rule::MissingReturnTypePublicFunction,
Rule::MissingReturnTypeUndocumentedPublicFunction,
Rule::MissingReturnTypePrivateFunction,
Rule::MissingReturnTypeSpecialMethod,
Rule::MissingReturnTypeStaticMethod,
@ -54,7 +54,7 @@ mod tests {
Rule::MissingTypeKwargs,
Rule::MissingTypeSelf,
Rule::MissingTypeCls,
Rule::MissingReturnTypePublicFunction,
Rule::MissingReturnTypeUndocumentedPublicFunction,
Rule::MissingReturnTypePrivateFunction,
Rule::MissingReturnTypeSpecialMethod,
Rule::MissingReturnTypeStaticMethod,
@ -99,7 +99,7 @@ mod tests {
..Default::default()
},
..Settings::for_rules(vec![
Rule::MissingReturnTypePublicFunction,
Rule::MissingReturnTypeUndocumentedPublicFunction,
Rule::MissingReturnTypePrivateFunction,
Rule::MissingReturnTypeSpecialMethod,
Rule::MissingReturnTypeStaticMethod,
@ -126,7 +126,7 @@ mod tests {
Rule::MissingTypeKwargs,
Rule::MissingTypeSelf,
Rule::MissingTypeCls,
Rule::MissingReturnTypePublicFunction,
Rule::MissingReturnTypeUndocumentedPublicFunction,
Rule::MissingReturnTypePrivateFunction,
Rule::MissingReturnTypeSpecialMethod,
Rule::MissingReturnTypeStaticMethod,
@ -161,7 +161,7 @@ mod tests {
Path::new("flake8_annotations/allow_overload.py"),
&Settings {
..Settings::for_rules(vec![
Rule::MissingReturnTypePublicFunction,
Rule::MissingReturnTypeUndocumentedPublicFunction,
Rule::MissingReturnTypePrivateFunction,
Rule::MissingReturnTypeSpecialMethod,
Rule::MissingReturnTypeStaticMethod,
@ -179,7 +179,7 @@ mod tests {
Path::new("flake8_annotations/allow_nested_overload.py"),
&Settings {
..Settings::for_rules(vec![
Rule::MissingReturnTypePublicFunction,
Rule::MissingReturnTypeUndocumentedPublicFunction,
Rule::MissingReturnTypePrivateFunction,
Rule::MissingReturnTypeSpecialMethod,
Rule::MissingReturnTypeStaticMethod,

View file

@ -209,14 +209,14 @@ impl Violation for MissingTypeCls {
/// return a + b
/// ```
#[violation]
pub struct MissingReturnTypePublicFunction {
pub struct MissingReturnTypeUndocumentedPublicFunction {
pub name: String,
}
impl Violation for MissingReturnTypePublicFunction {
impl Violation for MissingReturnTypeUndocumentedPublicFunction {
#[derive_message_formats]
fn message(&self) -> String {
let MissingReturnTypePublicFunction { name } = self;
let MissingReturnTypeUndocumentedPublicFunction { name } = self;
format!("Missing return type annotation for public function `{name}`")
}
}
@ -696,10 +696,10 @@ pub fn definition(
if checker
.settings
.rules
.enabled(Rule::MissingReturnTypePublicFunction)
.enabled(Rule::MissingReturnTypeUndocumentedPublicFunction)
{
diagnostics.push(Diagnostic::new(
MissingReturnTypePublicFunction {
MissingReturnTypeUndocumentedPublicFunction {
name: name.to_string(),
},
helpers::identifier_range(stmt, checker.locator),

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_annotations/mod.rs
expression: diagnostics
---
- kind:
name: MissingReturnTypePublicFunction
name: MissingReturnTypeUndocumentedPublicFunction
body: "Missing return type annotation for public function `bar`"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_annotations/mod.rs
expression: diagnostics
---
- kind:
name: MissingReturnTypePublicFunction
name: MissingReturnTypeUndocumentedPublicFunction
body: "Missing return type annotation for public function `foo`"
suggestion: ~
fixable: false
@ -42,7 +42,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: MissingReturnTypePublicFunction
name: MissingReturnTypeUndocumentedPublicFunction
body: "Missing return type annotation for public function `foo`"
suggestion: ~
fixable: false
@ -81,7 +81,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: MissingReturnTypePublicFunction
name: MissingReturnTypeUndocumentedPublicFunction
body: "Missing return type annotation for public function `foo`"
suggestion: ~
fixable: false
@ -94,7 +94,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: MissingReturnTypePublicFunction
name: MissingReturnTypeUndocumentedPublicFunction
body: "Missing return type annotation for public function `foo`"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_annotations/mod.rs
expression: diagnostics
---
- kind:
name: MissingReturnTypePublicFunction
name: MissingReturnTypeUndocumentedPublicFunction
body: "Missing return type annotation for public function `error_partially_typed_1`"
suggestion: ~
fixable: false
@ -42,7 +42,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: MissingReturnTypePublicFunction
name: MissingReturnTypeUndocumentedPublicFunction
body: "Missing return type annotation for public function `error_partially_typed_3`"
suggestion: ~
fixable: false
@ -55,7 +55,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: MissingReturnTypePublicFunction
name: MissingReturnTypeUndocumentedPublicFunction
body: "Missing return type annotation for public function `error_typed_self`"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_annotations/mod.rs
expression: diagnostics
---
- kind:
name: MissingReturnTypePublicFunction
name: MissingReturnTypeUndocumentedPublicFunction
body: "Missing return type annotation for public function `foo`"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: MissingReturnTypePublicFunction
name: MissingReturnTypeUndocumentedPublicFunction
body: "Missing return type annotation for public function `foo`"
suggestion: ~
fixable: false

View file

@ -20,7 +20,7 @@ mod tests {
#[test_case(Rule::StripWithMultiCharacters, Path::new("B005.py"); "B005")]
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_B008.py"); "B006")]
#[test_case(Rule::UnusedLoopControlVariable, Path::new("B007.py"); "B007")]
#[test_case(Rule::FunctionCallArgumentDefault, Path::new("B006_B008.py"); "B008")]
#[test_case(Rule::FunctionCallInDefaultArgument, Path::new("B006_B008.py"); "B008")]
#[test_case(Rule::GetAttrWithConstant, Path::new("B009_B010.py"); "B009")]
#[test_case(Rule::SetAttrWithConstant, Path::new("B009_B010.py"); "B010")]
#[test_case(Rule::AssertFalse, Path::new("B011.py"); "B011")]
@ -69,7 +69,7 @@ mod tests {
"fastapi.Query".to_string(),
],
},
..Settings::for_rules(vec![Rule::FunctionCallArgumentDefault])
..Settings::for_rules(vec![Rule::FunctionCallInDefaultArgument])
},
)?;
assert_yaml_snapshot!(snapshot, diagnostics);

View file

@ -13,14 +13,14 @@ use crate::checkers::ast::Checker;
use super::mutable_argument_default::is_mutable_func;
#[violation]
pub struct FunctionCallArgumentDefault {
pub struct FunctionCallInDefaultArgument {
pub name: Option<String>,
}
impl Violation for FunctionCallArgumentDefault {
impl Violation for FunctionCallInDefaultArgument {
#[derive_message_formats]
fn message(&self) -> String {
let FunctionCallArgumentDefault { name } = self;
let FunctionCallInDefaultArgument { name } = self;
if let Some(name) = name {
format!("Do not perform function call `{name}` in argument defaults")
} else {
@ -71,7 +71,7 @@ where
&& !is_nan_or_infinity(func, args)
{
self.diagnostics.push((
FunctionCallArgumentDefault {
FunctionCallInDefaultArgument {
name: compose_call_path(func),
}
.into(),

View file

@ -16,7 +16,7 @@ pub use except_with_non_exception_classes::{
};
pub use f_string_docstring::{f_string_docstring, FStringDocstring};
pub use function_call_argument_default::{
function_call_argument_default, FunctionCallArgumentDefault,
function_call_argument_default, FunctionCallInDefaultArgument,
};
pub use function_uses_loop_variable::{function_uses_loop_variable, FunctionUsesLoopVariable};
pub use getattr_with_constant::{getattr_with_constant, GetAttrWithConstant};

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
---
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `range` in argument defaults"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `range` in argument defaults"
suggestion: ~
fixable: false
@ -29,7 +29,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `range` in argument defaults"
suggestion: ~
fixable: false
@ -42,7 +42,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `time.time` in argument defaults"
suggestion: ~
fixable: false
@ -55,7 +55,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `dt.datetime.now` in argument defaults"
suggestion: ~
fixable: false
@ -68,7 +68,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `dt.timedelta` in argument defaults"
suggestion: ~
fixable: false
@ -81,7 +81,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: Do not perform function call in argument defaults
suggestion: ~
fixable: false
@ -94,7 +94,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `float` in argument defaults"
suggestion: ~
fixable: false
@ -107,7 +107,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `float` in argument defaults"
suggestion: ~
fixable: false
@ -120,7 +120,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `float` in argument defaults"
suggestion: ~
fixable: false
@ -133,7 +133,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `float` in argument defaults"
suggestion: ~
fixable: false
@ -146,7 +146,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `dt.datetime.now` in argument defaults"
suggestion: ~
fixable: false
@ -159,7 +159,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `map` in argument defaults"
suggestion: ~
fixable: false
@ -172,7 +172,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `random.randint` in argument defaults"
suggestion: ~
fixable: false
@ -185,7 +185,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `dt.datetime.now` in argument defaults"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_bugbear/mod.rs
expression: diagnostics
---
- kind:
name: FunctionCallArgumentDefault
name: FunctionCallInDefaultArgument
body: "Do not perform function call `Depends` in argument defaults"
suggestion: ~
fixable: false

View file

@ -19,9 +19,9 @@ mod tests {
let diagnostics = test_path(
Path::new("flake8_commas").join(path).as_path(),
&settings::Settings::for_rules(vec![
Rule::TrailingCommaMissing,
Rule::TrailingCommaOnBareTupleProhibited,
Rule::TrailingCommaProhibited,
Rule::MissingTrailingComma,
Rule::TrailingCommaOnBareTuple,
Rule::ProhibitedTrailingComma,
]),
)?;
assert_yaml_snapshot!(snapshot, diagnostics);

View file

@ -111,9 +111,9 @@ impl Context {
}
#[violation]
pub struct TrailingCommaMissing;
pub struct MissingTrailingComma;
impl AlwaysAutofixableViolation for TrailingCommaMissing {
impl AlwaysAutofixableViolation for MissingTrailingComma {
#[derive_message_formats]
fn message(&self) -> String {
format!("Trailing comma missing")
@ -125,9 +125,9 @@ impl AlwaysAutofixableViolation for TrailingCommaMissing {
}
#[violation]
pub struct TrailingCommaOnBareTupleProhibited;
pub struct TrailingCommaOnBareTuple;
impl Violation for TrailingCommaOnBareTupleProhibited {
impl Violation for TrailingCommaOnBareTuple {
#[derive_message_formats]
fn message(&self) -> String {
format!("Trailing comma on bare tuple prohibited")
@ -135,9 +135,9 @@ impl Violation for TrailingCommaOnBareTupleProhibited {
}
#[violation]
pub struct TrailingCommaProhibited;
pub struct ProhibitedTrailingComma;
impl AlwaysAutofixableViolation for TrailingCommaProhibited {
impl AlwaysAutofixableViolation for ProhibitedTrailingComma {
#[derive_message_formats]
fn message(&self) -> String {
format!("Trailing comma prohibited")
@ -254,13 +254,13 @@ pub fn trailing_commas(
if comma_prohibited {
let comma = prev.spanned.unwrap();
let mut diagnostic = Diagnostic::new(
TrailingCommaProhibited,
ProhibitedTrailingComma,
Range {
location: comma.0,
end_location: comma.2,
},
);
if autofix.into() && settings.rules.should_fix(Rule::TrailingCommaProhibited) {
if autofix.into() && settings.rules.should_fix(Rule::ProhibitedTrailingComma) {
diagnostic.amend(Fix::deletion(comma.0, comma.2));
}
diagnostics.push(diagnostic);
@ -273,7 +273,7 @@ pub fn trailing_commas(
if bare_comma_prohibited {
let comma = prev.spanned.unwrap();
diagnostics.push(Diagnostic::new(
TrailingCommaOnBareTupleProhibited,
TrailingCommaOnBareTuple,
Range {
location: comma.0,
end_location: comma.2,
@ -298,13 +298,13 @@ pub fn trailing_commas(
if comma_required {
let missing_comma = prev_prev.spanned.unwrap();
let mut diagnostic = Diagnostic::new(
TrailingCommaMissing,
MissingTrailingComma,
Range {
location: missing_comma.2,
end_location: missing_comma.2,
},
);
if autofix.into() && settings.rules.should_fix(Rule::TrailingCommaMissing) {
if autofix.into() && settings.rules.should_fix(Rule::MissingTrailingComma) {
// Create a replacement that includes the final bracket (or other token),
// rather than just inserting a comma at the end. This prevents the UP034 autofix
// removing any brackets in the same linter pass - doing both at the same time could

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_commas/mod.rs
expression: diagnostics
---
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -23,7 +23,7 @@ expression: diagnostics
column: 17
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -43,7 +43,7 @@ expression: diagnostics
column: 5
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -63,7 +63,7 @@ expression: diagnostics
column: 5
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -83,7 +83,7 @@ expression: diagnostics
column: 5
parent: ~
- kind:
name: TrailingCommaOnBareTupleProhibited
name: TrailingCommaOnBareTuple
body: Trailing comma on bare tuple prohibited
suggestion: ~
fixable: false
@ -96,7 +96,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: TrailingCommaOnBareTupleProhibited
name: TrailingCommaOnBareTuple
body: Trailing comma on bare tuple prohibited
suggestion: ~
fixable: false
@ -109,7 +109,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: TrailingCommaOnBareTupleProhibited
name: TrailingCommaOnBareTuple
body: Trailing comma on bare tuple prohibited
suggestion: ~
fixable: false
@ -122,7 +122,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: TrailingCommaOnBareTupleProhibited
name: TrailingCommaOnBareTuple
body: Trailing comma on bare tuple prohibited
suggestion: ~
fixable: false
@ -135,7 +135,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: TrailingCommaOnBareTupleProhibited
name: TrailingCommaOnBareTuple
body: Trailing comma on bare tuple prohibited
suggestion: ~
fixable: false
@ -148,7 +148,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: TrailingCommaOnBareTupleProhibited
name: TrailingCommaOnBareTuple
body: Trailing comma on bare tuple prohibited
suggestion: ~
fixable: false
@ -161,7 +161,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: TrailingCommaOnBareTupleProhibited
name: TrailingCommaOnBareTuple
body: Trailing comma on bare tuple prohibited
suggestion: ~
fixable: false
@ -174,7 +174,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -194,7 +194,7 @@ expression: diagnostics
column: 7
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -214,7 +214,7 @@ expression: diagnostics
column: 7
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -234,7 +234,7 @@ expression: diagnostics
column: 7
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -254,7 +254,7 @@ expression: diagnostics
column: 5
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -274,7 +274,7 @@ expression: diagnostics
column: 10
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -294,7 +294,7 @@ expression: diagnostics
column: 14
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -314,7 +314,7 @@ expression: diagnostics
column: 13
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -334,7 +334,7 @@ expression: diagnostics
column: 13
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -354,7 +354,7 @@ expression: diagnostics
column: 9
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -374,7 +374,7 @@ expression: diagnostics
column: 14
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -394,7 +394,7 @@ expression: diagnostics
column: 14
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -414,7 +414,7 @@ expression: diagnostics
column: 14
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -434,7 +434,7 @@ expression: diagnostics
column: 14
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -454,7 +454,7 @@ expression: diagnostics
column: 14
parent: ~
- kind:
name: TrailingCommaProhibited
name: ProhibitedTrailingComma
body: Trailing comma prohibited
suggestion: Remove trailing comma
fixable: true
@ -474,7 +474,7 @@ expression: diagnostics
column: 21
parent: ~
- kind:
name: TrailingCommaProhibited
name: ProhibitedTrailingComma
body: Trailing comma prohibited
suggestion: Remove trailing comma
fixable: true
@ -494,7 +494,7 @@ expression: diagnostics
column: 13
parent: ~
- kind:
name: TrailingCommaProhibited
name: ProhibitedTrailingComma
body: Trailing comma prohibited
suggestion: Remove trailing comma
fixable: true
@ -514,7 +514,7 @@ expression: diagnostics
column: 18
parent: ~
- kind:
name: TrailingCommaProhibited
name: ProhibitedTrailingComma
body: Trailing comma prohibited
suggestion: Remove trailing comma
fixable: true
@ -534,7 +534,7 @@ expression: diagnostics
column: 6
parent: ~
- kind:
name: TrailingCommaProhibited
name: ProhibitedTrailingComma
body: Trailing comma prohibited
suggestion: Remove trailing comma
fixable: true
@ -554,7 +554,7 @@ expression: diagnostics
column: 21
parent: ~
- kind:
name: TrailingCommaProhibited
name: ProhibitedTrailingComma
body: Trailing comma prohibited
suggestion: Remove trailing comma
fixable: true
@ -574,7 +574,7 @@ expression: diagnostics
column: 13
parent: ~
- kind:
name: TrailingCommaProhibited
name: ProhibitedTrailingComma
body: Trailing comma prohibited
suggestion: Remove trailing comma
fixable: true
@ -594,7 +594,7 @@ expression: diagnostics
column: 18
parent: ~
- kind:
name: TrailingCommaProhibited
name: ProhibitedTrailingComma
body: Trailing comma prohibited
suggestion: Remove trailing comma
fixable: true
@ -614,7 +614,7 @@ expression: diagnostics
column: 6
parent: ~
- kind:
name: TrailingCommaProhibited
name: ProhibitedTrailingComma
body: Trailing comma prohibited
suggestion: Remove trailing comma
fixable: true
@ -634,7 +634,7 @@ expression: diagnostics
column: 10
parent: ~
- kind:
name: TrailingCommaProhibited
name: ProhibitedTrailingComma
body: Trailing comma prohibited
suggestion: Remove trailing comma
fixable: true
@ -654,7 +654,7 @@ expression: diagnostics
column: 9
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -674,7 +674,7 @@ expression: diagnostics
column: 12
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -694,7 +694,7 @@ expression: diagnostics
column: 9
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -714,7 +714,7 @@ expression: diagnostics
column: 15
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -734,7 +734,7 @@ expression: diagnostics
column: 12
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -754,7 +754,7 @@ expression: diagnostics
column: 23
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -774,7 +774,7 @@ expression: diagnostics
column: 14
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -794,7 +794,7 @@ expression: diagnostics
column: 12
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -814,7 +814,7 @@ expression: diagnostics
column: 12
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -834,7 +834,7 @@ expression: diagnostics
column: 9
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -854,7 +854,7 @@ expression: diagnostics
column: 9
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -874,7 +874,7 @@ expression: diagnostics
column: 9
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -894,7 +894,7 @@ expression: diagnostics
column: 12
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -914,7 +914,7 @@ expression: diagnostics
column: 14
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true
@ -934,7 +934,7 @@ expression: diagnostics
column: 19
parent: ~
- kind:
name: TrailingCommaMissing
name: MissingTrailingComma
body: Trailing comma missing
suggestion: Add trailing comma
fixable: true

View file

@ -13,12 +13,12 @@ mod tests {
use crate::settings;
use crate::test::test_path;
#[test_case(Rule::NullableModelStringField, Path::new("DJ001.py"); "DJ001")]
#[test_case(Rule::LocalsInRenderFunction, Path::new("DJ003.py"); "DJ003")]
#[test_case(Rule::ExcludeWithModelForm, Path::new("DJ006.py"); "DJ006")]
#[test_case(Rule::AllWithModelForm, Path::new("DJ007.py"); "DJ007")]
#[test_case(Rule::ModelWithoutDunderStr, Path::new("DJ008.py"); "DJ008")]
#[test_case(Rule::NonLeadingReceiverDecorator, Path::new("DJ013.py"); "DJ013")]
#[test_case(Rule::DjangoNullableModelStringField, Path::new("DJ001.py"); "DJ001")]
#[test_case(Rule::DjangoLocalsInRenderFunction, Path::new("DJ003.py"); "DJ003")]
#[test_case(Rule::DjangoExcludeWithModelForm, Path::new("DJ006.py"); "DJ006")]
#[test_case(Rule::DjangoAllWithModelForm, Path::new("DJ007.py"); "DJ007")]
#[test_case(Rule::DjangoModelWithoutDunderStr, Path::new("DJ008.py"); "DJ008")]
#[test_case(Rule::DjangoNonLeadingReceiverDecorator, Path::new("DJ013.py"); "DJ013")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(

View file

@ -38,9 +38,9 @@ use crate::rules::flake8_django::rules::helpers::is_model_form;
/// fields = ["title", "content"]
/// ```
#[violation]
pub struct AllWithModelForm;
pub struct DjangoAllWithModelForm;
impl Violation for AllWithModelForm {
impl Violation for DjangoAllWithModelForm {
#[derive_message_formats]
fn message(&self) -> String {
format!("Do not use `__all__` with `ModelForm`, use `fields` instead")
@ -76,12 +76,18 @@ pub fn all_with_model_form(checker: &Checker, bases: &[Expr], body: &[Stmt]) ->
match &value {
Constant::Str(s) => {
if s == "__all__" {
return Some(Diagnostic::new(AllWithModelForm, Range::from(element)));
return Some(Diagnostic::new(
DjangoAllWithModelForm,
Range::from(element),
));
}
}
Constant::Bytes(b) => {
if b == "__all__".as_bytes() {
return Some(Diagnostic::new(AllWithModelForm, Range::from(element)));
return Some(Diagnostic::new(
DjangoAllWithModelForm,
Range::from(element),
));
}
}
_ => (),

View file

@ -34,9 +34,9 @@ use crate::rules::flake8_django::rules::helpers::is_model_form;
/// fields = ["title", "content"]
/// ```
#[violation]
pub struct ExcludeWithModelForm;
pub struct DjangoExcludeWithModelForm;
impl Violation for ExcludeWithModelForm {
impl Violation for DjangoExcludeWithModelForm {
#[derive_message_formats]
fn message(&self) -> String {
format!("Do not use `exclude` with `ModelForm`, use `fields` instead")
@ -68,7 +68,10 @@ pub fn exclude_with_model_form(
continue;
};
if id == "exclude" {
return Some(Diagnostic::new(ExcludeWithModelForm, Range::from(target)));
return Some(Diagnostic::new(
DjangoExcludeWithModelForm,
Range::from(target),
));
}
}
}

View file

@ -32,9 +32,9 @@ use crate::checkers::ast::Checker;
/// return render(request, "app/index.html", context)
/// ```
#[violation]
pub struct LocalsInRenderFunction;
pub struct DjangoLocalsInRenderFunction;
impl Violation for LocalsInRenderFunction {
impl Violation for DjangoLocalsInRenderFunction {
#[derive_message_formats]
fn message(&self) -> String {
format!("Avoid passing `locals()` as context to a `render` function")
@ -78,9 +78,10 @@ pub fn locals_in_render_function(
return;
};
checker
.diagnostics
.push(Diagnostic::new(LocalsInRenderFunction, Range::from(locals)));
checker.diagnostics.push(Diagnostic::new(
DjangoLocalsInRenderFunction,
Range::from(locals),
));
}
fn is_locals_call(checker: &Checker, expr: &Expr) -> bool {

View file

@ -1,11 +1,13 @@
pub use all_with_model_form::{all_with_model_form, AllWithModelForm};
pub use exclude_with_model_form::{exclude_with_model_form, ExcludeWithModelForm};
pub use locals_in_render_function::{locals_in_render_function, LocalsInRenderFunction};
pub use model_without_dunder_str::{model_without_dunder_str, ModelWithoutDunderStr};
pub use all_with_model_form::{all_with_model_form, DjangoAllWithModelForm};
pub use exclude_with_model_form::{exclude_with_model_form, DjangoExcludeWithModelForm};
pub use locals_in_render_function::{locals_in_render_function, DjangoLocalsInRenderFunction};
pub use model_without_dunder_str::{model_without_dunder_str, DjangoModelWithoutDunderStr};
pub use non_leading_receiver_decorator::{
non_leading_receiver_decorator, NonLeadingReceiverDecorator,
non_leading_receiver_decorator, DjangoNonLeadingReceiverDecorator,
};
pub use nullable_model_string_field::{
nullable_model_string_field, DjangoNullableModelStringField,
};
pub use nullable_model_string_field::{nullable_model_string_field, NullableModelStringField};
mod all_with_model_form;
mod exclude_with_model_form;

View file

@ -41,9 +41,9 @@ use super::helpers;
/// return f"{self.field}"
/// ```
#[violation]
pub struct ModelWithoutDunderStr;
pub struct DjangoModelWithoutDunderStr;
impl Violation for ModelWithoutDunderStr {
impl Violation for DjangoModelWithoutDunderStr {
#[derive_message_formats]
fn message(&self) -> String {
format!("Model does not define `__str__` method")
@ -62,7 +62,7 @@ pub fn model_without_dunder_str(
}
if !has_dunder_method(body) {
return Some(Diagnostic::new(
ModelWithoutDunderStr,
DjangoModelWithoutDunderStr,
Range::from(class_location),
));
}

View file

@ -38,9 +38,9 @@ use ruff_python_ast::types::{CallPath, Range};
/// pass
/// ```
#[violation]
pub struct NonLeadingReceiverDecorator;
pub struct DjangoNonLeadingReceiverDecorator;
impl Violation for NonLeadingReceiverDecorator {
impl Violation for DjangoNonLeadingReceiverDecorator {
#[derive_message_formats]
fn message(&self) -> String {
format!("`@receiver` decorator must be on top of all the other decorators")
@ -66,7 +66,7 @@ where
};
if i > 0 && is_receiver && !seen_receiver {
diagnostics.push(Diagnostic::new(
NonLeadingReceiverDecorator,
DjangoNonLeadingReceiverDecorator,
Range::from(decorator),
));
}

View file

@ -40,14 +40,14 @@ use super::helpers;
/// field = models.CharField(max_length=255, default="")
/// ```
#[violation]
pub struct NullableModelStringField {
pub struct DjangoNullableModelStringField {
pub field_name: String,
}
impl Violation for NullableModelStringField {
impl Violation for DjangoNullableModelStringField {
#[derive_message_formats]
fn message(&self) -> String {
let NullableModelStringField { field_name } = self;
let DjangoNullableModelStringField { field_name } = self;
format!("Avoid using `null=True` on string-based fields such as {field_name}")
}
}
@ -70,7 +70,7 @@ pub fn nullable_model_string_field(checker: &Checker, body: &[Stmt]) -> Vec<Diag
};
if let Some(field_name) = is_nullable_field(checker, value) {
errors.push(Diagnostic::new(
NullableModelStringField {
DjangoNullableModelStringField {
field_name: field_name.to_string(),
},
Range::from(value),

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_django/mod.rs
expression: diagnostics
---
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as CharField"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as TextField"
suggestion: ~
fixable: false
@ -29,7 +29,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as SlugField"
suggestion: ~
fixable: false
@ -42,7 +42,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as EmailField"
suggestion: ~
fixable: false
@ -55,7 +55,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as FilePathField"
suggestion: ~
fixable: false
@ -68,7 +68,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as URLField"
suggestion: ~
fixable: false
@ -81,7 +81,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as CharField"
suggestion: ~
fixable: false
@ -94,7 +94,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as CharField"
suggestion: ~
fixable: false
@ -107,7 +107,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as SlugField"
suggestion: ~
fixable: false
@ -120,7 +120,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as EmailField"
suggestion: ~
fixable: false
@ -133,7 +133,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as FilePathField"
suggestion: ~
fixable: false
@ -146,7 +146,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as URLField"
suggestion: ~
fixable: false
@ -159,7 +159,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as CharField"
suggestion: ~
fixable: false
@ -172,7 +172,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as CharField"
suggestion: ~
fixable: false
@ -185,7 +185,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as SlugField"
suggestion: ~
fixable: false
@ -198,7 +198,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as EmailField"
suggestion: ~
fixable: false
@ -211,7 +211,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as FilePathField"
suggestion: ~
fixable: false
@ -224,7 +224,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NullableModelStringField
name: DjangoNullableModelStringField
body: "Avoid using `null=True` on string-based fields such as URLField"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_django/mod.rs
expression: diagnostics
---
- kind:
name: LocalsInRenderFunction
name: DjangoLocalsInRenderFunction
body: "Avoid passing `locals()` as context to a `render` function"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: LocalsInRenderFunction
name: DjangoLocalsInRenderFunction
body: "Avoid passing `locals()` as context to a `render` function"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_django/mod.rs
expression: diagnostics
---
- kind:
name: ExcludeWithModelForm
name: DjangoExcludeWithModelForm
body: "Do not use `exclude` with `ModelForm`, use `fields` instead"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_django/mod.rs
expression: diagnostics
---
- kind:
name: AllWithModelForm
name: DjangoAllWithModelForm
body: "Do not use `__all__` with `ModelForm`, use `fields` instead"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: AllWithModelForm
name: DjangoAllWithModelForm
body: "Do not use `__all__` with `ModelForm`, use `fields` instead"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_django/mod.rs
expression: diagnostics
---
- kind:
name: ModelWithoutDunderStr
name: DjangoModelWithoutDunderStr
body: "Model does not define `__str__` method"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ModelWithoutDunderStr
name: DjangoModelWithoutDunderStr
body: "Model does not define `__str__` method"
suggestion: ~
fixable: false
@ -29,7 +29,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ModelWithoutDunderStr
name: DjangoModelWithoutDunderStr
body: "Model does not define `__str__` method"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_django/mod.rs
expression: diagnostics
---
- kind:
name: NonLeadingReceiverDecorator
name: DjangoNonLeadingReceiverDecorator
body: "`@receiver` decorator must be on top of all the other decorators"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: NonLeadingReceiverDecorator
name: DjangoNonLeadingReceiverDecorator
body: "`@receiver` decorator must be on top of all the other decorators"
suggestion: ~
fixable: false

View file

@ -35,9 +35,9 @@ mod tests {
&settings::Settings::for_rules(vec![
Rule::ShebangNotExecutable,
Rule::ShebangMissingExecutableFile,
Rule::ShebangWhitespace,
Rule::ShebangNewline,
Rule::ShebangPython,
Rule::ShebangLeadingWhitespace,
Rule::ShebangNotFirstLine,
Rule::ShebangMissingPython,
]),
)?;
assert_yaml_snapshot!(snapshot, diagnostics);

View file

@ -1,8 +1,8 @@
pub use shebang_missing::{shebang_missing, ShebangMissingExecutableFile};
pub use shebang_newline::{shebang_newline, ShebangNewline};
pub use shebang_newline::{shebang_newline, ShebangNotFirstLine};
pub use shebang_not_executable::{shebang_not_executable, ShebangNotExecutable};
pub use shebang_python::{shebang_python, ShebangPython};
pub use shebang_whitespace::{shebang_whitespace, ShebangWhitespace};
pub use shebang_python::{shebang_python, ShebangMissingPython};
pub use shebang_whitespace::{shebang_whitespace, ShebangLeadingWhitespace};
mod shebang_missing;
mod shebang_newline;

View file

@ -7,9 +7,9 @@ use ruff_python_ast::types::Range;
use crate::rules::flake8_executable::helpers::ShebangDirective;
#[violation]
pub struct ShebangNewline;
pub struct ShebangNotFirstLine;
impl Violation for ShebangNewline {
impl Violation for ShebangNotFirstLine {
#[derive_message_formats]
fn message(&self) -> String {
format!("Shebang should be at the beginning of the file")
@ -21,7 +21,7 @@ pub fn shebang_newline(lineno: usize, shebang: &ShebangDirective) -> Option<Diag
if let ShebangDirective::Match(_, start, end, _) = shebang {
if lineno > 1 {
let diagnostic = Diagnostic::new(
ShebangNewline,
ShebangNotFirstLine,
Range::new(
Location::new(lineno + 1, *start),
Location::new(lineno + 1, *end),

View file

@ -7,9 +7,9 @@ use ruff_python_ast::types::Range;
use crate::rules::flake8_executable::helpers::ShebangDirective;
#[violation]
pub struct ShebangPython;
pub struct ShebangMissingPython;
impl Violation for ShebangPython {
impl Violation for ShebangMissingPython {
#[derive_message_formats]
fn message(&self) -> String {
format!("Shebang should contain `python`")
@ -23,7 +23,7 @@ pub fn shebang_python(lineno: usize, shebang: &ShebangDirective) -> Option<Diagn
None
} else {
let diagnostic = Diagnostic::new(
ShebangPython,
ShebangMissingPython,
Range::new(
Location::new(lineno + 1, start - 2),
Location::new(lineno + 1, *end),

View file

@ -7,9 +7,9 @@ use ruff_python_ast::types::Range;
use crate::rules::flake8_executable::helpers::ShebangDirective;
#[violation]
pub struct ShebangWhitespace;
pub struct ShebangLeadingWhitespace;
impl AlwaysAutofixableViolation for ShebangWhitespace {
impl AlwaysAutofixableViolation for ShebangLeadingWhitespace {
#[derive_message_formats]
fn message(&self) -> String {
format!("Avoid whitespace before shebang")
@ -29,7 +29,7 @@ pub fn shebang_whitespace(
if let ShebangDirective::Match(n_spaces, start, ..) = shebang {
if *n_spaces > 0 && *start == n_spaces + 2 {
let mut diagnostic = Diagnostic::new(
ShebangWhitespace,
ShebangLeadingWhitespace,
Range::new(
Location::new(lineno + 1, 0),
Location::new(lineno + 1, *n_spaces),

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_executable/mod.rs
expression: diagnostics
---
- kind:
name: ShebangPython
name: ShebangMissingPython
body: "Shebang should contain `python`"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_executable/mod.rs
expression: diagnostics
---
- kind:
name: ShebangWhitespace
name: ShebangLeadingWhitespace
body: Avoid whitespace before shebang
suggestion: Remove whitespace before shebang
fixable: true

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_executable/mod.rs
expression: diagnostics
---
- kind:
name: ShebangNewline
name: ShebangNotFirstLine
body: Shebang should be at the beginning of the file
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_executable/mod.rs
expression: diagnostics
---
- kind:
name: ShebangNewline
name: ShebangNotFirstLine
body: Shebang should be at the beginning of the file
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_executable/mod.rs
expression: diagnostics
---
- kind:
name: ShebangNewline
name: ShebangNotFirstLine
body: Shebang should be at the beginning of the file
suggestion: ~
fixable: false

View file

@ -14,13 +14,13 @@ mod tests {
use crate::settings;
use crate::test::test_path;
#[test_case(Rule::DupeClassFieldDefinitions, Path::new("PIE794.py"); "PIE794")]
#[test_case(Rule::DuplicateClassFieldDefinition, Path::new("PIE794.py"); "PIE794")]
#[test_case(Rule::UnnecessaryDictKwargs, Path::new("PIE804.py"); "PIE804")]
#[test_case(Rule::SingleStartsEndsWith, Path::new("PIE810.py"); "PIE810")]
#[test_case(Rule::MultipleStartsEndsWith, Path::new("PIE810.py"); "PIE810")]
#[test_case(Rule::UnnecessaryPass, Path::new("PIE790.py"); "PIE790")]
#[test_case(Rule::UnnecessarySpread, Path::new("PIE800.py"); "PIE800")]
#[test_case(Rule::PreferListBuiltin, Path::new("PIE807.py"); "PIE807")]
#[test_case(Rule::PreferUniqueEnums, Path::new("PIE796.py"); "PIE796")]
#[test_case(Rule::ReimplementedListBuiltin, Path::new("PIE807.py"); "PIE807")]
#[test_case(Rule::NonUniqueEnums, Path::new("PIE796.py"); "PIE796")]
#[test_case(Rule::UnnecessaryComprehensionAnyAll, Path::new("PIE802.py"); "PIE802")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());

View file

@ -39,30 +39,30 @@ impl AlwaysAutofixableViolation for UnnecessaryPass {
}
#[violation]
pub struct DupeClassFieldDefinitions(pub String);
pub struct DuplicateClassFieldDefinition(pub String);
impl AlwaysAutofixableViolation for DupeClassFieldDefinitions {
impl AlwaysAutofixableViolation for DuplicateClassFieldDefinition {
#[derive_message_formats]
fn message(&self) -> String {
let DupeClassFieldDefinitions(name) = self;
let DuplicateClassFieldDefinition(name) = self;
format!("Class field `{name}` is defined multiple times")
}
fn autofix_title(&self) -> String {
let DupeClassFieldDefinitions(name) = self;
let DuplicateClassFieldDefinition(name) = self;
format!("Remove duplicate field definition for `{name}`")
}
}
#[violation]
pub struct PreferUniqueEnums {
pub struct NonUniqueEnums {
pub value: String,
}
impl Violation for PreferUniqueEnums {
impl Violation for NonUniqueEnums {
#[derive_message_formats]
fn message(&self) -> String {
let PreferUniqueEnums { value } = self;
let NonUniqueEnums { value } = self;
format!("Enum contains duplicate value: `{value}`")
}
}
@ -122,19 +122,19 @@ impl Violation for UnnecessarySpread {
}
#[violation]
pub struct SingleStartsEndsWith {
pub struct MultipleStartsEndsWith {
pub attr: String,
}
impl AlwaysAutofixableViolation for SingleStartsEndsWith {
impl AlwaysAutofixableViolation for MultipleStartsEndsWith {
#[derive_message_formats]
fn message(&self) -> String {
let SingleStartsEndsWith { attr } = self;
let MultipleStartsEndsWith { attr } = self;
format!("Call `{attr}` once with a `tuple`")
}
fn autofix_title(&self) -> String {
let SingleStartsEndsWith { attr } = self;
let MultipleStartsEndsWith { attr } = self;
format!("Merge into a single `{attr}` call")
}
}
@ -150,9 +150,9 @@ impl Violation for UnnecessaryDictKwargs {
}
#[violation]
pub struct PreferListBuiltin;
pub struct ReimplementedListBuiltin;
impl AlwaysAutofixableViolation for PreferListBuiltin {
impl AlwaysAutofixableViolation for ReimplementedListBuiltin {
#[derive_message_formats]
fn message(&self) -> String {
format!("Prefer `list` over useless lambda")
@ -216,7 +216,7 @@ pub fn no_unnecessary_pass(checker: &mut Checker, body: &[Stmt]) {
}
/// PIE794
pub fn dupe_class_field_definitions<'a, 'b>(
pub fn duplicate_class_field_definition<'a, 'b>(
checker: &mut Checker<'a>,
parent: &'b Stmt,
body: &'b [Stmt],
@ -249,7 +249,7 @@ pub fn dupe_class_field_definitions<'a, 'b>(
if !seen_targets.insert(target) {
let mut diagnostic = Diagnostic::new(
DupeClassFieldDefinitions(target.to_string()),
DuplicateClassFieldDefinition(target.to_string()),
Range::from(stmt),
);
if checker.patch(diagnostic.kind.rule()) {
@ -278,7 +278,7 @@ pub fn dupe_class_field_definitions<'a, 'b>(
}
/// PIE796
pub fn prefer_unique_enums<'a, 'b>(checker: &mut Checker<'a>, parent: &'b Stmt, body: &'b [Stmt])
pub fn non_unique_enums<'a, 'b>(checker: &mut Checker<'a>, parent: &'b Stmt, body: &'b [Stmt])
where
'b: 'a,
{
@ -313,7 +313,7 @@ where
if !seen_targets.insert(ComparableExpr::from(value)) {
let diagnostic = Diagnostic::new(
PreferUniqueEnums {
NonUniqueEnums {
value: unparse_expr(value, checker.stylist),
},
Range::from(stmt),
@ -324,7 +324,7 @@ where
}
/// PIE800
pub fn no_unnecessary_spread(checker: &mut Checker, keys: &[Option<Expr>], values: &[Expr]) {
pub fn unnecessary_spread(checker: &mut Checker, keys: &[Option<Expr>], values: &[Expr]) {
for item in keys.iter().zip(values.iter()) {
if let (None, value) = item {
// We only care about when the key is None which indicates a spread `**`
@ -384,7 +384,7 @@ fn is_valid_kwarg_name(key: &Expr) -> bool {
}
/// PIE804
pub fn no_unnecessary_dict_kwargs(checker: &mut Checker, expr: &Expr, kwargs: &[Keyword]) {
pub fn unnecessary_dict_kwargs(checker: &mut Checker, expr: &Expr, kwargs: &[Keyword]) {
for kw in kwargs {
// keyword is a spread operator (indicated by None)
if kw.node.arg.is_none() {
@ -403,7 +403,7 @@ pub fn no_unnecessary_dict_kwargs(checker: &mut Checker, expr: &Expr, kwargs: &[
}
/// PIE810
pub fn single_starts_ends_with(checker: &mut Checker, expr: &Expr) {
pub fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) {
let ExprKind::BoolOp { op: Boolop::Or, values } = &expr.node else {
return;
};
@ -445,7 +445,7 @@ pub fn single_starts_ends_with(checker: &mut Checker, expr: &Expr) {
for ((attr_name, arg_name), indices) in duplicates {
if indices.len() > 1 {
let mut diagnostic = Diagnostic::new(
SingleStartsEndsWith {
MultipleStartsEndsWith {
attr: attr_name.to_string(),
},
Range::from(expr),
@ -518,7 +518,7 @@ pub fn single_starts_ends_with(checker: &mut Checker, expr: &Expr) {
}
/// PIE807
pub fn prefer_list_builtin(checker: &mut Checker, expr: &Expr) {
pub fn reimplemented_list_builtin(checker: &mut Checker, expr: &Expr) {
let ExprKind::Lambda { args, body } = &expr.node else {
unreachable!("Expected ExprKind::Lambda");
};
@ -530,7 +530,7 @@ pub fn prefer_list_builtin(checker: &mut Checker, expr: &Expr) {
{
if let ExprKind::List { elts, .. } = &body.node {
if elts.is_empty() {
let mut diagnostic = Diagnostic::new(PreferListBuiltin, Range::from(expr));
let mut diagnostic = Diagnostic::new(ReimplementedListBuiltin, Range::from(expr));
if checker.patch(diagnostic.kind.rule()) {
diagnostic.amend(Fix::replacement(
"list".to_string(),

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pie/mod.rs
expression: diagnostics
---
- kind:
name: DupeClassFieldDefinitions
name: DuplicateClassFieldDefinition
body: "Class field `name` is defined multiple times"
suggestion: "Remove duplicate field definition for `name`"
fixable: true
@ -23,7 +23,7 @@ expression: diagnostics
column: 0
parent: ~
- kind:
name: DupeClassFieldDefinitions
name: DuplicateClassFieldDefinition
body: "Class field `name` is defined multiple times"
suggestion: "Remove duplicate field definition for `name`"
fixable: true
@ -43,7 +43,7 @@ expression: diagnostics
column: 0
parent: ~
- kind:
name: DupeClassFieldDefinitions
name: DuplicateClassFieldDefinition
body: "Class field `bar` is defined multiple times"
suggestion: "Remove duplicate field definition for `bar`"
fixable: true
@ -63,7 +63,7 @@ expression: diagnostics
column: 0
parent: ~
- kind:
name: DupeClassFieldDefinitions
name: DuplicateClassFieldDefinition
body: "Class field `bar` is defined multiple times"
suggestion: "Remove duplicate field definition for `bar`"
fixable: true

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pie/mod.rs
expression: diagnostics
---
- kind:
name: PreferUniqueEnums
name: NonUniqueEnums
body: "Enum contains duplicate value: `\"B\"`"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: PreferUniqueEnums
name: NonUniqueEnums
body: "Enum contains duplicate value: `2`"
suggestion: ~
fixable: false
@ -29,7 +29,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: PreferUniqueEnums
name: NonUniqueEnums
body: "Enum contains duplicate value: `\"2\"`"
suggestion: ~
fixable: false
@ -42,7 +42,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: PreferUniqueEnums
name: NonUniqueEnums
body: "Enum contains duplicate value: `2.5`"
suggestion: ~
fixable: false
@ -55,7 +55,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: PreferUniqueEnums
name: NonUniqueEnums
body: "Enum contains duplicate value: `False`"
suggestion: ~
fixable: false
@ -68,7 +68,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: PreferUniqueEnums
name: NonUniqueEnums
body: "Enum contains duplicate value: `None`"
suggestion: ~
fixable: false
@ -81,7 +81,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: PreferUniqueEnums
name: NonUniqueEnums
body: "Enum contains duplicate value: `2`"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pie/mod.rs
expression: diagnostics
---
- kind:
name: PreferListBuiltin
name: ReimplementedListBuiltin
body: "Prefer `list` over useless lambda"
suggestion: "Replace with `list`"
fixable: true
@ -23,7 +23,7 @@ expression: diagnostics
column: 53
parent: ~
- kind:
name: PreferListBuiltin
name: ReimplementedListBuiltin
body: "Prefer `list` over useless lambda"
suggestion: "Replace with `list`"
fixable: true
@ -43,7 +43,7 @@ expression: diagnostics
column: 45
parent: ~
- kind:
name: PreferListBuiltin
name: ReimplementedListBuiltin
body: "Prefer `list` over useless lambda"
suggestion: "Replace with `list`"
fixable: true

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pie/mod.rs
expression: diagnostics
---
- kind:
name: SingleStartsEndsWith
name: MultipleStartsEndsWith
body: "Call `startswith` once with a `tuple`"
suggestion: "Merge into a single `startswith` call"
fixable: true
@ -23,7 +23,7 @@ expression: diagnostics
column: 46
parent: ~
- kind:
name: SingleStartsEndsWith
name: MultipleStartsEndsWith
body: "Call `endswith` once with a `tuple`"
suggestion: "Merge into a single `endswith` call"
fixable: true
@ -43,7 +43,7 @@ expression: diagnostics
column: 42
parent: ~
- kind:
name: SingleStartsEndsWith
name: MultipleStartsEndsWith
body: "Call `startswith` once with a `tuple`"
suggestion: "Merge into a single `startswith` call"
fixable: true
@ -63,7 +63,7 @@ expression: diagnostics
column: 42
parent: ~
- kind:
name: SingleStartsEndsWith
name: MultipleStartsEndsWith
body: "Call `startswith` once with a `tuple`"
suggestion: "Merge into a single `startswith` call"
fixable: true
@ -83,7 +83,7 @@ expression: diagnostics
column: 44
parent: ~
- kind:
name: SingleStartsEndsWith
name: MultipleStartsEndsWith
body: "Call `startswith` once with a `tuple`"
suggestion: "Merge into a single `startswith` call"
fixable: true

View file

@ -13,8 +13,8 @@ mod tests {
use crate::settings;
use crate::test::test_path;
#[test_case(Rule::PrintFound, Path::new("T201.py"); "T201")]
#[test_case(Rule::PPrintFound, Path::new("T203.py"); "T203")]
#[test_case(Rule::Print, Path::new("T201.py"); "T201")]
#[test_case(Rule::PPrint, Path::new("T203.py"); "T203")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(

View file

@ -1,3 +1,3 @@
pub use print_call::{print_call, PPrintFound, PrintFound};
pub use print_call::{print_call, PPrint, Print};
mod print_call;

View file

@ -9,9 +9,9 @@ use crate::checkers::ast::Checker;
use crate::registry::AsRule;
#[violation]
pub struct PrintFound;
pub struct Print;
impl Violation for PrintFound {
impl Violation for Print {
#[derive_message_formats]
fn message(&self) -> String {
format!("`print` found")
@ -19,9 +19,9 @@ impl Violation for PrintFound {
}
#[violation]
pub struct PPrintFound;
pub struct PPrint;
impl Violation for PPrintFound {
impl Violation for PPrint {
#[derive_message_formats]
fn message(&self) -> String {
format!("`pprint` found")
@ -54,11 +54,11 @@ pub fn print_call(checker: &mut Checker, func: &Expr, keywords: &[Keyword]) {
}
}
}
Diagnostic::new(PrintFound, Range::from(func))
Diagnostic::new(Print, Range::from(func))
} else if call_path.as_ref().map_or(false, |call_path| {
*call_path.as_slice() == ["pprint", "pprint"]
}) {
Diagnostic::new(PPrintFound, Range::from(func))
Diagnostic::new(PPrint, Range::from(func))
} else {
return;
}

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_print/mod.rs
expression: diagnostics
---
- kind:
name: PrintFound
name: Print
body: "`print` found"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: PrintFound
name: Print
body: "`print` found"
suggestion: ~
fixable: false
@ -29,7 +29,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: PrintFound
name: Print
body: "`print` found"
suggestion: ~
fixable: false
@ -42,7 +42,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: PrintFound
name: Print
body: "`print` found"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_print/mod.rs
expression: diagnostics
---
- kind:
name: PPrintFound
name: PPrint
body: "`pprint` found"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: PPrintFound
name: PPrint
body: "`pprint` found"
suggestion: ~
fixable: false

View file

@ -13,8 +13,8 @@ mod tests {
use crate::settings;
use crate::test::test_path;
#[test_case(Rule::PrefixTypeParams, Path::new("PYI001.pyi"))]
#[test_case(Rule::PrefixTypeParams, Path::new("PYI001.py"))]
#[test_case(Rule::UnprefixedTypeParam, Path::new("PYI001.pyi"))]
#[test_case(Rule::UnprefixedTypeParam, Path::new("PYI001.py"))]
#[test_case(Rule::BadVersionInfoComparison, Path::new("PYI006.pyi"))]
#[test_case(Rule::BadVersionInfoComparison, Path::new("PYI006.py"))]
#[test_case(Rule::UnrecognizedPlatformCheck, Path::new("PYI007.pyi"))]
@ -25,10 +25,10 @@ mod tests {
#[test_case(Rule::NonEmptyStubBody, Path::new("PYI010.pyi"))]
#[test_case(Rule::PassStatementStubBody, Path::new("PYI009.py"))]
#[test_case(Rule::PassStatementStubBody, Path::new("PYI009.pyi"))]
#[test_case(Rule::TypedArgumentSimpleDefaults, Path::new("PYI011.py"))]
#[test_case(Rule::TypedArgumentSimpleDefaults, Path::new("PYI011.pyi"))]
#[test_case(Rule::ArgumentSimpleDefaults, Path::new("PYI014.py"))]
#[test_case(Rule::ArgumentSimpleDefaults, Path::new("PYI014.pyi"))]
#[test_case(Rule::TypedArgumentDefaultInStub, Path::new("PYI011.py"))]
#[test_case(Rule::TypedArgumentDefaultInStub, Path::new("PYI011.pyi"))]
#[test_case(Rule::ArgumentDefaultInStub, Path::new("PYI014.py"))]
#[test_case(Rule::ArgumentDefaultInStub, Path::new("PYI014.pyi"))]
#[test_case(Rule::DocstringInStub, Path::new("PYI021.py"))]
#[test_case(Rule::DocstringInStub, Path::new("PYI021.pyi"))]
#[test_case(Rule::TypeCommentInStub, Path::new("PYI033.py"))]

View file

@ -2,10 +2,10 @@ pub use bad_version_info_comparison::{bad_version_info_comparison, BadVersionInf
pub use docstring_in_stubs::{docstring_in_stubs, DocstringInStub};
pub use non_empty_stub_body::{non_empty_stub_body, NonEmptyStubBody};
pub use pass_statement_stub_body::{pass_statement_stub_body, PassStatementStubBody};
pub use prefix_type_params::{prefix_type_params, PrefixTypeParams};
pub use prefix_type_params::{prefix_type_params, UnprefixedTypeParam};
pub use simple_defaults::{
argument_simple_defaults, typed_argument_simple_defaults, ArgumentSimpleDefaults,
TypedArgumentSimpleDefaults,
argument_simple_defaults, typed_argument_simple_defaults, ArgumentDefaultInStub,
TypedArgumentDefaultInStub,
};
pub use type_comment_in_stub::{type_comment_in_stub, TypeCommentInStub};
pub use unrecognized_platform::{

View file

@ -47,14 +47,14 @@ impl fmt::Display for VarKind {
/// _T = TypeVar("_T")
/// ```
#[violation]
pub struct PrefixTypeParams {
pub struct UnprefixedTypeParam {
pub kind: VarKind,
}
impl Violation for PrefixTypeParams {
impl Violation for UnprefixedTypeParam {
#[derive_message_formats]
fn message(&self) -> String {
let PrefixTypeParams { kind } = self;
let UnprefixedTypeParam { kind } = self;
format!("Name of private `{kind}` must start with `_`")
}
}
@ -85,7 +85,7 @@ pub fn prefix_type_params(checker: &mut Checker, value: &Expr, targets: &[Expr])
return;
};
checker.diagnostics.push(Diagnostic::new(
PrefixTypeParams { kind },
UnprefixedTypeParam { kind },
Range::from(value),
));
}

View file

@ -8,10 +8,10 @@ use crate::checkers::ast::Checker;
use crate::registry::AsRule;
#[violation]
pub struct TypedArgumentSimpleDefaults;
pub struct TypedArgumentDefaultInStub;
/// PYI011
impl AlwaysAutofixableViolation for TypedArgumentSimpleDefaults {
impl AlwaysAutofixableViolation for TypedArgumentDefaultInStub {
#[derive_message_formats]
fn message(&self) -> String {
format!("Only simple default values allowed for typed arguments")
@ -23,10 +23,10 @@ impl AlwaysAutofixableViolation for TypedArgumentSimpleDefaults {
}
#[violation]
pub struct ArgumentSimpleDefaults;
pub struct ArgumentDefaultInStub;
/// PYI014
impl Violation for ArgumentSimpleDefaults {
impl Violation for ArgumentDefaultInStub {
#[derive_message_formats]
fn message(&self) -> String {
format!("Only simple default values allowed for arguments")
@ -194,7 +194,7 @@ pub fn typed_argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
if arg.node.annotation.is_some() {
if !is_valid_default_value_with_annotation(default, checker) {
let mut diagnostic =
Diagnostic::new(TypedArgumentSimpleDefaults, Range::from(default));
Diagnostic::new(TypedArgumentDefaultInStub, Range::from(default));
if checker.patch(diagnostic.kind.rule()) {
diagnostic.amend(Fix::replacement(
@ -221,7 +221,7 @@ pub fn typed_argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
if kwarg.node.annotation.is_some() {
if !is_valid_default_value_with_annotation(default, checker) {
let mut diagnostic =
Diagnostic::new(TypedArgumentSimpleDefaults, Range::from(default));
Diagnostic::new(TypedArgumentDefaultInStub, Range::from(default));
if checker.patch(diagnostic.kind.rule()) {
diagnostic.amend(Fix::replacement(
@ -250,10 +250,9 @@ pub fn argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
{
if arg.node.annotation.is_none() {
if !is_valid_default_value_with_annotation(default, checker) {
checker.diagnostics.push(Diagnostic::new(
ArgumentSimpleDefaults,
Range::from(default),
));
checker
.diagnostics
.push(Diagnostic::new(ArgumentDefaultInStub, Range::from(default)));
}
}
}
@ -269,10 +268,9 @@ pub fn argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
{
if kwarg.node.annotation.is_none() {
if !is_valid_default_value_with_annotation(default, checker) {
checker.diagnostics.push(Diagnostic::new(
ArgumentSimpleDefaults,
Range::from(default),
));
checker
.diagnostics
.push(Diagnostic::new(ArgumentDefaultInStub, Range::from(default)));
}
}
}

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pyi/mod.rs
expression: diagnostics
---
- kind:
name: PrefixTypeParams
name: UnprefixedTypeParam
body: "Name of private `TypeVar` must start with `_`"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: PrefixTypeParams
name: UnprefixedTypeParam
body: "Name of private `TypeVarTuple` must start with `_`"
suggestion: ~
fixable: false
@ -29,7 +29,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: PrefixTypeParams
name: UnprefixedTypeParam
body: "Name of private `ParamSpec` must start with `_`"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pyi/mod.rs
expression: diagnostics
---
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -23,7 +23,7 @@ expression: diagnostics
column: 23
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -43,7 +43,7 @@ expression: diagnostics
column: 5
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -63,7 +63,7 @@ expression: diagnostics
column: 5
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -83,7 +83,7 @@ expression: diagnostics
column: 5
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -103,7 +103,7 @@ expression: diagnostics
column: 5
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -123,7 +123,7 @@ expression: diagnostics
column: 11
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -143,7 +143,7 @@ expression: diagnostics
column: 12
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -163,7 +163,7 @@ expression: diagnostics
column: 7
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -183,7 +183,7 @@ expression: diagnostics
column: 7
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -203,7 +203,7 @@ expression: diagnostics
column: 8
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -223,7 +223,7 @@ expression: diagnostics
column: 10
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -243,7 +243,7 @@ expression: diagnostics
column: 18
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -263,7 +263,7 @@ expression: diagnostics
column: 21
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -283,7 +283,7 @@ expression: diagnostics
column: 24
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true
@ -303,7 +303,7 @@ expression: diagnostics
column: 8
parent: ~
- kind:
name: TypedArgumentSimpleDefaults
name: TypedArgumentDefaultInStub
body: Only simple default values allowed for typed arguments
suggestion: "Replace default value by `...`"
fixable: true

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pyi/mod.rs
expression: diagnostics
---
- kind:
name: ArgumentSimpleDefaults
name: ArgumentDefaultInStub
body: Only simple default values allowed for arguments
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ArgumentSimpleDefaults
name: ArgumentDefaultInStub
body: Only simple default values allowed for arguments
suggestion: ~
fixable: false
@ -29,7 +29,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ArgumentSimpleDefaults
name: ArgumentDefaultInStub
body: Only simple default values allowed for arguments
suggestion: ~
fixable: false
@ -42,7 +42,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ArgumentSimpleDefaults
name: ArgumentDefaultInStub
body: Only simple default values allowed for arguments
suggestion: ~
fixable: false
@ -55,7 +55,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ArgumentSimpleDefaults
name: ArgumentDefaultInStub
body: Only simple default values allowed for arguments
suggestion: ~
fixable: false
@ -68,7 +68,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ArgumentSimpleDefaults
name: ArgumentDefaultInStub
body: Only simple default values allowed for arguments
suggestion: ~
fixable: false
@ -81,7 +81,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ArgumentSimpleDefaults
name: ArgumentDefaultInStub
body: Only simple default values allowed for arguments
suggestion: ~
fixable: false
@ -94,7 +94,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ArgumentSimpleDefaults
name: ArgumentDefaultInStub
body: Only simple default values allowed for arguments
suggestion: ~
fixable: false
@ -107,7 +107,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ArgumentSimpleDefaults
name: ArgumentDefaultInStub
body: Only simple default values allowed for arguments
suggestion: ~
fixable: false
@ -120,7 +120,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ArgumentSimpleDefaults
name: ArgumentDefaultInStub
body: Only simple default values allowed for arguments
suggestion: ~
fixable: false
@ -133,7 +133,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ArgumentSimpleDefaults
name: ArgumentDefaultInStub
body: Only simple default values allowed for arguments
suggestion: ~
fixable: false

View file

@ -18,9 +18,9 @@ mod tests {
use super::settings::Settings;
use super::types;
#[test_case(Rule::IncorrectFixtureParenthesesStyle, Path::new("PT001.py"), Settings::default(), "PT001_default"; "PT001_0")]
#[test_case(Rule::PytestFixtureIncorrectParenthesesStyle, Path::new("PT001.py"), Settings::default(), "PT001_default"; "PT001_0")]
#[test_case(
Rule::IncorrectFixtureParenthesesStyle,
Rule::PytestFixtureIncorrectParenthesesStyle,
Path::new("PT001.py"),
Settings {
fixture_parentheses: false,
@ -29,13 +29,13 @@ mod tests {
"PT001_no_parentheses";
"PT001_1"
)]
#[test_case(Rule::FixturePositionalArgs, Path::new("PT002.py"), Settings::default(), "PT002"; "PT002")]
#[test_case(Rule::ExtraneousScopeFunction, Path::new("PT003.py"), Settings::default(), "PT003"; "PT003")]
#[test_case(Rule::MissingFixtureNameUnderscore, Path::new("PT004.py"), Settings::default(), "PT004"; "PT004")]
#[test_case(Rule::IncorrectFixtureNameUnderscore, Path::new("PT005.py"), Settings::default(), "PT005"; "PT005")]
#[test_case(Rule::ParametrizeNamesWrongType, Path::new("PT006.py"), Settings::default(), "PT006_default"; "PT006_0")]
#[test_case(Rule::PytestFixturePositionalArgs, Path::new("PT002.py"), Settings::default(), "PT002"; "PT002")]
#[test_case(Rule::PytestExtraneousScopeFunction, Path::new("PT003.py"), Settings::default(), "PT003"; "PT003")]
#[test_case(Rule::PytestMissingFixtureNameUnderscore, Path::new("PT004.py"), Settings::default(), "PT004"; "PT004")]
#[test_case(Rule::PytestIncorrectFixtureNameUnderscore, Path::new("PT005.py"), Settings::default(), "PT005"; "PT005")]
#[test_case(Rule::PytestParametrizeNamesWrongType, Path::new("PT006.py"), Settings::default(), "PT006_default"; "PT006_0")]
#[test_case(
Rule::ParametrizeNamesWrongType,
Rule::PytestParametrizeNamesWrongType,
Path::new("PT006.py"),
Settings {
parametrize_names_type: types::ParametrizeNameType::Csv,
@ -45,7 +45,7 @@ mod tests {
"PT006_1"
)]
#[test_case(
Rule::ParametrizeNamesWrongType,
Rule::PytestParametrizeNamesWrongType,
Path::new("PT006.py"),
Settings {
parametrize_names_type: types::ParametrizeNameType::List,
@ -55,14 +55,14 @@ mod tests {
"PT006_2"
)]
#[test_case(
Rule::ParametrizeValuesWrongType,
Rule::PytestParametrizeValuesWrongType,
Path::new("PT007.py"),
Settings::default(),
"PT007_list_of_tuples";
"PT007_0"
)]
#[test_case(
Rule::ParametrizeValuesWrongType,
Rule::PytestParametrizeValuesWrongType,
Path::new("PT007.py"),
Settings {
parametrize_values_type: types::ParametrizeValuesType::Tuple,
@ -72,7 +72,7 @@ mod tests {
"PT007_1"
)]
#[test_case(
Rule::ParametrizeValuesWrongType,
Rule::PytestParametrizeValuesWrongType,
Path::new("PT007.py"),
Settings {
parametrize_values_type: types::ParametrizeValuesType::Tuple,
@ -83,7 +83,7 @@ mod tests {
"PT007_2"
)]
#[test_case(
Rule::ParametrizeValuesWrongType,
Rule::PytestParametrizeValuesWrongType,
Path::new("PT007.py"),
Settings {
parametrize_values_row_type: types::ParametrizeValuesRowType::List,
@ -93,29 +93,29 @@ mod tests {
"PT007_3"
)]
#[test_case(
Rule::PatchWithLambda,
Rule::PytestPatchWithLambda,
Path::new("PT008.py"),
Settings::default(),
"PT008";
"PT008"
)]
#[test_case(
Rule::UnittestAssertion,
Rule::PytestUnittestAssertion,
Path::new("PT009.py"),
Settings::default(),
"PT009";
"PT009"
)]
#[test_case(Rule::RaisesWithoutException, Path::new("PT010.py"), Settings::default(), "PT010"; "PT0010")]
#[test_case(Rule::PytestRaisesWithoutException, Path::new("PT010.py"), Settings::default(), "PT010"; "PT0010")]
#[test_case(
Rule::RaisesTooBroad,
Rule::PytestRaisesTooBroad,
Path::new("PT011.py"),
Settings::default(),
"PT011_default";
"PT011_0"
)]
#[test_case(
Rule::RaisesTooBroad,
Rule::PytestRaisesTooBroad,
Path::new("PT011.py"),
Settings {
raises_extend_require_match_for: vec!["ZeroDivisionError".to_string()],
@ -125,7 +125,7 @@ mod tests {
"PT011_1"
)]
#[test_case(
Rule::RaisesTooBroad,
Rule::PytestRaisesTooBroad,
Path::new("PT011.py"),
Settings {
raises_require_match_for: vec!["ZeroDivisionError".to_string()],
@ -135,84 +135,84 @@ mod tests {
"PT011_2"
)]
#[test_case(
Rule::RaisesWithMultipleStatements,
Rule::PytestRaisesWithMultipleStatements,
Path::new("PT012.py"),
Settings::default(),
"PT012";
"PT012"
)]
#[test_case(
Rule::IncorrectPytestImport,
Rule::PytestIncorrectPytestImport,
Path::new("PT013.py"),
Settings::default(),
"PT013";
"PT013"
)]
#[test_case(
Rule::AssertAlwaysFalse,
Rule::PytestAssertAlwaysFalse,
Path::new("PT015.py"),
Settings::default(),
"PT015";
"PT015"
)]
#[test_case(
Rule::FailWithoutMessage,
Rule::PytestFailWithoutMessage,
Path::new("PT016.py"),
Settings::default(),
"PT016";
"PT016"
)]
#[test_case(
Rule::AssertInExcept,
Rule::PytestAssertInExcept,
Path::new("PT017.py"),
Settings::default(),
"PT017";
"PT017"
)]
#[test_case(
Rule::CompositeAssertion,
Rule::PytestCompositeAssertion,
Path::new("PT018.py"),
Settings::default(),
"PT018";
"PT018"
)]
#[test_case(
Rule::FixtureParamWithoutValue,
Rule::PytestFixtureParamWithoutValue,
Path::new("PT019.py"),
Settings::default(),
"PT019";
"PT019"
)]
#[test_case(
Rule::DeprecatedYieldFixture,
Rule::PytestDeprecatedYieldFixture,
Path::new("PT020.py"),
Settings::default(),
"PT020";
"PT020"
)]
#[test_case(
Rule::FixtureFinalizerCallback,
Rule::PytestFixtureFinalizerCallback,
Path::new("PT021.py"),
Settings::default(),
"PT021";
"PT021"
)]
#[test_case(
Rule::UselessYieldFixture,
Rule::PytestUselessYieldFixture,
Path::new("PT022.py"),
Settings::default(),
"PT022";
"PT022"
)]
#[test_case(
Rule::IncorrectMarkParenthesesStyle,
Rule::PytestIncorrectMarkParenthesesStyle,
Path::new("PT023.py"),
Settings::default(),
"PT023_default";
"PT023_0"
)]
#[test_case(
Rule::IncorrectMarkParenthesesStyle,
Rule::PytestIncorrectMarkParenthesesStyle,
Path::new("PT023.py"),
Settings {
mark_parentheses: false,
@ -222,21 +222,21 @@ mod tests {
"PT023_1"
)]
#[test_case(
Rule::UnnecessaryAsyncioMarkOnFixture,
Rule::PytestUnnecessaryAsyncioMarkOnFixture,
Path::new("PT024.py"),
Settings::default(),
"PT024";
"PT024"
)]
#[test_case(
Rule::ErroneousUseFixturesOnFixture,
Rule::PytestErroneousUseFixturesOnFixture,
Path::new("PT025.py"),
Settings::default(),
"PT025";
"PT025"
)]
#[test_case(
Rule::UseFixturesWithoutParameters,
Rule::PytestUseFixturesWithoutParameters,
Path::new("PT026.py"),
Settings::default(),
"PT026";

View file

@ -54,11 +54,11 @@ use super::unittest_assert::UnittestAssert;
/// assert not something_else
/// ```
#[violation]
pub struct CompositeAssertion {
pub struct PytestCompositeAssertion {
pub fixable: bool,
}
impl Violation for CompositeAssertion {
impl Violation for PytestCompositeAssertion {
const AUTOFIX: Option<AutofixKind> = Some(AutofixKind::new(Availability::Sometimes));
#[derive_message_formats]
@ -73,14 +73,14 @@ impl Violation for CompositeAssertion {
}
#[violation]
pub struct AssertInExcept {
pub struct PytestAssertInExcept {
pub name: String,
}
impl Violation for AssertInExcept {
impl Violation for PytestAssertInExcept {
#[derive_message_formats]
fn message(&self) -> String {
let AssertInExcept { name } = self;
let PytestAssertInExcept { name } = self;
format!(
"Found assertion on exception `{name}` in `except` block, use `pytest.raises()` instead"
)
@ -88,9 +88,9 @@ impl Violation for AssertInExcept {
}
#[violation]
pub struct AssertAlwaysFalse;
pub struct PytestAssertAlwaysFalse;
impl Violation for AssertAlwaysFalse {
impl Violation for PytestAssertAlwaysFalse {
#[derive_message_formats]
fn message(&self) -> String {
format!("Assertion always fails, replace with `pytest.fail()`")
@ -98,23 +98,23 @@ impl Violation for AssertAlwaysFalse {
}
#[violation]
pub struct UnittestAssertion {
pub struct PytestUnittestAssertion {
pub assertion: String,
pub fixable: bool,
}
impl Violation for UnittestAssertion {
impl Violation for PytestUnittestAssertion {
const AUTOFIX: Option<AutofixKind> = Some(AutofixKind::new(Availability::Sometimes));
#[derive_message_formats]
fn message(&self) -> String {
let UnittestAssertion { assertion, .. } = self;
let PytestUnittestAssertion { assertion, .. } = self;
format!("Use a regular `assert` instead of unittest-style `{assertion}`")
}
fn autofix_title_formatter(&self) -> Option<fn(&Self) -> String> {
self.fixable
.then_some(|UnittestAssertion { assertion, .. }| {
.then_some(|PytestUnittestAssertion { assertion, .. }| {
format!("Replace `{assertion}(...)` with `assert ...`")
})
}
@ -159,7 +159,7 @@ where
if let Some(current_assert) = self.current_assert {
if id.as_str() == self.exception_name {
self.errors.push(Diagnostic::new(
AssertInExcept {
PytestAssertInExcept {
name: id.to_string(),
},
Range::from(current_assert),
@ -198,7 +198,7 @@ pub fn unittest_assertion(
&& matches!(checker.ctx.current_stmt().node, StmtKind::Expr { .. })
&& !has_comments_in(Range::from(expr), checker.locator);
let mut diagnostic = Diagnostic::new(
UnittestAssertion {
PytestUnittestAssertion {
assertion: unittest_assert.to_string(),
fixable,
},
@ -225,7 +225,7 @@ pub fn unittest_assertion(
/// PT015
pub fn assert_falsy(stmt: &Stmt, test: &Expr) -> Option<Diagnostic> {
if is_falsy_constant(test) {
Some(Diagnostic::new(AssertAlwaysFalse, Range::from(stmt)))
Some(Diagnostic::new(PytestAssertAlwaysFalse, Range::from(stmt)))
} else {
None
}
@ -432,7 +432,8 @@ pub fn composite_condition(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg:
let fixable = matches!(composite, CompositionKind::Simple)
&& msg.is_none()
&& !has_comments_in(Range::from(stmt), checker.locator);
let mut diagnostic = Diagnostic::new(CompositeAssertion { fixable }, Range::from(stmt));
let mut diagnostic =
Diagnostic::new(PytestCompositeAssertion { fixable }, Range::from(stmt));
if fixable && checker.patch(diagnostic.kind.rule()) {
if let Ok(fix) = fix_composite_condition(stmt, checker.locator, checker.stylist) {
diagnostic.amend(fix);

View file

@ -10,9 +10,9 @@ use crate::checkers::ast::Checker;
use super::helpers::{is_empty_or_null_string, is_pytest_fail};
#[violation]
pub struct FailWithoutMessage;
pub struct PytestFailWithoutMessage;
impl Violation for FailWithoutMessage {
impl Violation for PytestFailWithoutMessage {
#[derive_message_formats]
fn message(&self) -> String {
format!("No message passed to `pytest.fail()`")
@ -28,12 +28,12 @@ pub fn fail_call(checker: &mut Checker, func: &Expr, args: &[Expr], keywords: &[
if is_empty_or_null_string(msg) {
checker
.diagnostics
.push(Diagnostic::new(FailWithoutMessage, Range::from(func)));
.push(Diagnostic::new(PytestFailWithoutMessage, Range::from(func)));
}
} else {
checker
.diagnostics
.push(Diagnostic::new(FailWithoutMessage, Range::from(func)));
.push(Diagnostic::new(PytestFailWithoutMessage, Range::from(func)));
}
}
}

View file

@ -21,15 +21,15 @@ use super::helpers::{
};
#[violation]
pub struct IncorrectFixtureParenthesesStyle {
pub struct PytestFixtureIncorrectParenthesesStyle {
pub expected_parens: String,
pub actual_parens: String,
}
impl AlwaysAutofixableViolation for IncorrectFixtureParenthesesStyle {
impl AlwaysAutofixableViolation for PytestFixtureIncorrectParenthesesStyle {
#[derive_message_formats]
fn message(&self) -> String {
let IncorrectFixtureParenthesesStyle {
let PytestFixtureIncorrectParenthesesStyle {
expected_parens,
actual_parens,
} = self;
@ -42,22 +42,22 @@ impl AlwaysAutofixableViolation for IncorrectFixtureParenthesesStyle {
}
#[violation]
pub struct FixturePositionalArgs {
pub struct PytestFixturePositionalArgs {
pub function: String,
}
impl Violation for FixturePositionalArgs {
impl Violation for PytestFixturePositionalArgs {
#[derive_message_formats]
fn message(&self) -> String {
let FixturePositionalArgs { function } = self;
let PytestFixturePositionalArgs { function } = self;
format!("Configuration for fixture `{function}` specified via positional args, use kwargs")
}
}
#[violation]
pub struct ExtraneousScopeFunction;
pub struct PytestExtraneousScopeFunction;
impl AlwaysAutofixableViolation for ExtraneousScopeFunction {
impl AlwaysAutofixableViolation for PytestExtraneousScopeFunction {
#[derive_message_formats]
fn message(&self) -> String {
format!("`scope='function'` is implied in `@pytest.fixture()`")
@ -69,40 +69,40 @@ impl AlwaysAutofixableViolation for ExtraneousScopeFunction {
}
#[violation]
pub struct MissingFixtureNameUnderscore {
pub struct PytestMissingFixtureNameUnderscore {
pub function: String,
}
impl Violation for MissingFixtureNameUnderscore {
impl Violation for PytestMissingFixtureNameUnderscore {
#[derive_message_formats]
fn message(&self) -> String {
let MissingFixtureNameUnderscore { function } = self;
let PytestMissingFixtureNameUnderscore { function } = self;
format!("Fixture `{function}` does not return anything, add leading underscore")
}
}
#[violation]
pub struct IncorrectFixtureNameUnderscore {
pub struct PytestIncorrectFixtureNameUnderscore {
pub function: String,
}
impl Violation for IncorrectFixtureNameUnderscore {
impl Violation for PytestIncorrectFixtureNameUnderscore {
#[derive_message_formats]
fn message(&self) -> String {
let IncorrectFixtureNameUnderscore { function } = self;
let PytestIncorrectFixtureNameUnderscore { function } = self;
format!("Fixture `{function}` returns a value, remove leading underscore")
}
}
#[violation]
pub struct FixtureParamWithoutValue {
pub struct PytestFixtureParamWithoutValue {
pub name: String,
}
impl Violation for FixtureParamWithoutValue {
impl Violation for PytestFixtureParamWithoutValue {
#[derive_message_formats]
fn message(&self) -> String {
let FixtureParamWithoutValue { name } = self;
let PytestFixtureParamWithoutValue { name } = self;
format!(
"Fixture `{name}` without value is injected as parameter, use \
`@pytest.mark.usefixtures` instead"
@ -111,9 +111,9 @@ impl Violation for FixtureParamWithoutValue {
}
#[violation]
pub struct DeprecatedYieldFixture;
pub struct PytestDeprecatedYieldFixture;
impl Violation for DeprecatedYieldFixture {
impl Violation for PytestDeprecatedYieldFixture {
#[derive_message_formats]
fn message(&self) -> String {
format!("`@pytest.yield_fixture` is deprecated, use `@pytest.fixture`")
@ -121,9 +121,9 @@ impl Violation for DeprecatedYieldFixture {
}
#[violation]
pub struct FixtureFinalizerCallback;
pub struct PytestFixtureFinalizerCallback;
impl Violation for FixtureFinalizerCallback {
impl Violation for PytestFixtureFinalizerCallback {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use `yield` instead of `request.addfinalizer`")
@ -131,14 +131,14 @@ impl Violation for FixtureFinalizerCallback {
}
#[violation]
pub struct UselessYieldFixture {
pub struct PytestUselessYieldFixture {
pub name: String,
}
impl AlwaysAutofixableViolation for UselessYieldFixture {
impl AlwaysAutofixableViolation for PytestUselessYieldFixture {
#[derive_message_formats]
fn message(&self) -> String {
let UselessYieldFixture { name } = self;
let PytestUselessYieldFixture { name } = self;
format!("No teardown in fixture `{name}`, use `return` instead of `yield`")
}
@ -148,9 +148,9 @@ impl AlwaysAutofixableViolation for UselessYieldFixture {
}
#[violation]
pub struct ErroneousUseFixturesOnFixture;
pub struct PytestErroneousUseFixturesOnFixture;
impl AlwaysAutofixableViolation for ErroneousUseFixturesOnFixture {
impl AlwaysAutofixableViolation for PytestErroneousUseFixturesOnFixture {
#[derive_message_formats]
fn message(&self) -> String {
format!("`pytest.mark.usefixtures` has no effect on fixtures")
@ -162,9 +162,9 @@ impl AlwaysAutofixableViolation for ErroneousUseFixturesOnFixture {
}
#[violation]
pub struct UnnecessaryAsyncioMarkOnFixture;
pub struct PytestUnnecessaryAsyncioMarkOnFixture;
impl AlwaysAutofixableViolation for UnnecessaryAsyncioMarkOnFixture {
impl AlwaysAutofixableViolation for PytestUnnecessaryAsyncioMarkOnFixture {
#[derive_message_formats]
fn message(&self) -> String {
format!("`pytest.mark.asyncio` is unnecessary for fixtures")
@ -242,7 +242,7 @@ fn pytest_fixture_parentheses(
actual: &str,
) {
let mut diagnostic = Diagnostic::new(
IncorrectFixtureParenthesesStyle {
PytestFixtureIncorrectParenthesesStyle {
expected_parens: preferred.to_string(),
actual_parens: actual.to_string(),
},
@ -277,7 +277,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E
if checker
.settings
.rules
.enabled(Rule::IncorrectFixtureParenthesesStyle)
.enabled(Rule::PytestFixtureIncorrectParenthesesStyle)
&& !checker.settings.flake8_pytest_style.fixture_parentheses
&& args.is_empty()
&& keywords.is_empty()
@ -287,9 +287,14 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E
pytest_fixture_parentheses(checker, decorator, fix, "", "()");
}
if checker.settings.rules.enabled(Rule::FixturePositionalArgs) && !args.is_empty() {
if checker
.settings
.rules
.enabled(Rule::PytestFixturePositionalArgs)
&& !args.is_empty()
{
checker.diagnostics.push(Diagnostic::new(
FixturePositionalArgs {
PytestFixturePositionalArgs {
function: func_name.to_string(),
},
Range::from(decorator),
@ -299,7 +304,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E
if checker
.settings
.rules
.enabled(Rule::ExtraneousScopeFunction)
.enabled(Rule::PytestExtraneousScopeFunction)
{
let scope_keyword = keywords
.iter()
@ -307,8 +312,10 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E
if let Some(scope_keyword) = scope_keyword {
if keyword_is_literal(scope_keyword, "function") {
let mut diagnostic =
Diagnostic::new(ExtraneousScopeFunction, Range::from(scope_keyword));
let mut diagnostic = Diagnostic::new(
PytestExtraneousScopeFunction,
Range::from(scope_keyword),
);
if checker.patch(diagnostic.kind.rule()) {
match fix_extraneous_scope_function(
checker.locator,
@ -333,7 +340,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E
if checker
.settings
.rules
.enabled(Rule::IncorrectFixtureParenthesesStyle)
.enabled(Rule::PytestFixtureIncorrectParenthesesStyle)
&& checker.settings.flake8_pytest_style.fixture_parentheses
{
let fix = Fix::insertion("()".to_string(), decorator.end_location.unwrap());
@ -354,12 +361,12 @@ fn check_fixture_returns(checker: &mut Checker, func: &Stmt, func_name: &str, bo
if checker
.settings
.rules
.enabled(Rule::IncorrectFixtureNameUnderscore)
.enabled(Rule::PytestIncorrectFixtureNameUnderscore)
&& visitor.has_return_with_value
&& func_name.starts_with('_')
{
checker.diagnostics.push(Diagnostic::new(
IncorrectFixtureNameUnderscore {
PytestIncorrectFixtureNameUnderscore {
function: func_name.to_string(),
},
Range::from(func),
@ -367,26 +374,30 @@ fn check_fixture_returns(checker: &mut Checker, func: &Stmt, func_name: &str, bo
} else if checker
.settings
.rules
.enabled(Rule::MissingFixtureNameUnderscore)
.enabled(Rule::PytestMissingFixtureNameUnderscore)
&& !visitor.has_return_with_value
&& !visitor.has_yield_from
&& !func_name.starts_with('_')
{
checker.diagnostics.push(Diagnostic::new(
MissingFixtureNameUnderscore {
PytestMissingFixtureNameUnderscore {
function: func_name.to_string(),
},
Range::from(func),
));
}
if checker.settings.rules.enabled(Rule::UselessYieldFixture) {
if checker
.settings
.rules
.enabled(Rule::PytestUselessYieldFixture)
{
if let Some(stmt) = body.last() {
if let StmtKind::Expr { value, .. } = &stmt.node {
if let ExprKind::Yield { .. } = value.node {
if visitor.yield_statements.len() == 1 {
let mut diagnostic = Diagnostic::new(
UselessYieldFixture {
PytestUselessYieldFixture {
name: func_name.to_string(),
},
Range::from(stmt),
@ -415,7 +426,7 @@ fn check_test_function_args(checker: &mut Checker, args: &Arguments) {
let name = &arg.node.arg;
if name.starts_with('_') {
checker.diagnostics.push(Diagnostic::new(
FixtureParamWithoutValue {
PytestFixtureParamWithoutValue {
name: name.to_string(),
},
Range::from(arg),
@ -428,7 +439,7 @@ fn check_test_function_args(checker: &mut Checker, args: &Arguments) {
fn check_fixture_decorator_name(checker: &mut Checker, decorator: &Expr) {
if is_pytest_yield_fixture(decorator, checker) {
checker.diagnostics.push(Diagnostic::new(
DeprecatedYieldFixture,
PytestDeprecatedYieldFixture,
Range::from(decorator),
));
}
@ -448,7 +459,7 @@ fn check_fixture_addfinalizer(checker: &mut Checker, args: &Arguments, body: &[S
if let Some(addfinalizer) = visitor.addfinalizer_call {
checker.diagnostics.push(Diagnostic::new(
FixtureFinalizerCallback,
PytestFixtureFinalizerCallback,
Range::from(addfinalizer),
));
}
@ -462,11 +473,11 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Expr]) {
if checker
.settings
.rules
.enabled(Rule::UnnecessaryAsyncioMarkOnFixture)
.enabled(Rule::PytestUnnecessaryAsyncioMarkOnFixture)
{
if name == "asyncio" {
let mut diagnostic =
Diagnostic::new(UnnecessaryAsyncioMarkOnFixture, Range::from(mark));
Diagnostic::new(PytestUnnecessaryAsyncioMarkOnFixture, Range::from(mark));
if checker.patch(diagnostic.kind.rule()) {
let start = Location::new(mark.location.row(), 0);
let end = Location::new(mark.end_location.unwrap().row() + 1, 0);
@ -479,11 +490,11 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Expr]) {
if checker
.settings
.rules
.enabled(Rule::ErroneousUseFixturesOnFixture)
.enabled(Rule::PytestErroneousUseFixturesOnFixture)
{
if name == "usefixtures" {
let mut diagnostic =
Diagnostic::new(ErroneousUseFixturesOnFixture, Range::from(mark));
Diagnostic::new(PytestErroneousUseFixturesOnFixture, Range::from(mark));
if checker.patch(diagnostic.kind.rule()) {
let start = Location::new(mark.location.row(), 0);
let end = Location::new(mark.end_location.unwrap().row() + 1, 0);
@ -508,17 +519,23 @@ pub fn fixture(
if checker
.settings
.rules
.enabled(Rule::IncorrectFixtureParenthesesStyle)
|| checker.settings.rules.enabled(Rule::FixturePositionalArgs)
.enabled(Rule::PytestFixtureIncorrectParenthesesStyle)
|| checker
.settings
.rules
.enabled(Rule::ExtraneousScopeFunction)
.enabled(Rule::PytestFixturePositionalArgs)
|| checker
.settings
.rules
.enabled(Rule::PytestExtraneousScopeFunction)
{
check_fixture_decorator(checker, func_name, decorator);
}
if checker.settings.rules.enabled(Rule::DeprecatedYieldFixture)
if checker
.settings
.rules
.enabled(Rule::PytestDeprecatedYieldFixture)
&& checker.settings.flake8_pytest_style.fixture_parentheses
{
check_fixture_decorator_name(checker, decorator);
@ -527,12 +544,15 @@ pub fn fixture(
if (checker
.settings
.rules
.enabled(Rule::MissingFixtureNameUnderscore)
.enabled(Rule::PytestMissingFixtureNameUnderscore)
|| checker
.settings
.rules
.enabled(Rule::IncorrectFixtureNameUnderscore)
|| checker.settings.rules.enabled(Rule::UselessYieldFixture))
.enabled(Rule::PytestIncorrectFixtureNameUnderscore)
|| checker
.settings
.rules
.enabled(Rule::PytestUselessYieldFixture))
&& !has_abstractmethod_decorator(decorators, checker)
{
check_fixture_returns(checker, func, func_name, body);
@ -541,7 +561,7 @@ pub fn fixture(
if checker
.settings
.rules
.enabled(Rule::FixtureFinalizerCallback)
.enabled(Rule::PytestFixtureFinalizerCallback)
{
check_fixture_addfinalizer(checker, args, body);
}
@ -549,11 +569,11 @@ pub fn fixture(
if checker
.settings
.rules
.enabled(Rule::UnnecessaryAsyncioMarkOnFixture)
.enabled(Rule::PytestUnnecessaryAsyncioMarkOnFixture)
|| checker
.settings
.rules
.enabled(Rule::ErroneousUseFixturesOnFixture)
.enabled(Rule::PytestErroneousUseFixturesOnFixture)
{
check_fixture_marks(checker, decorators);
}
@ -562,7 +582,7 @@ pub fn fixture(
if checker
.settings
.rules
.enabled(Rule::FixtureParamWithoutValue)
.enabled(Rule::PytestFixtureParamWithoutValue)
&& func_name.starts_with("test_")
{
check_test_function_args(checker, args);

View file

@ -5,9 +5,9 @@ use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::types::Range;
#[violation]
pub struct IncorrectPytestImport;
pub struct PytestIncorrectPytestImport;
impl Violation for IncorrectPytestImport {
impl Violation for PytestIncorrectPytestImport {
#[derive_message_formats]
fn message(&self) -> String {
format!("Found incorrect import of pytest, use simple `import pytest` instead")
@ -24,7 +24,7 @@ pub fn import(import_from: &Stmt, name: &str, asname: Option<&str>) -> Option<Di
if let Some(alias) = asname {
if alias != name {
return Some(Diagnostic::new(
IncorrectPytestImport,
PytestIncorrectPytestImport,
Range::from(import_from),
));
}
@ -49,7 +49,7 @@ pub fn import_from(
if let Some(module) = module {
if is_pytest_or_subpackage(module) {
return Some(Diagnostic::new(
IncorrectPytestImport,
PytestIncorrectPytestImport,
Range::from(import_from),
));
}

View file

@ -10,16 +10,16 @@ use crate::registry::{AsRule, Rule};
use super::helpers::{get_mark_decorators, get_mark_name};
#[violation]
pub struct IncorrectMarkParenthesesStyle {
pub struct PytestIncorrectMarkParenthesesStyle {
pub mark_name: String,
pub expected_parens: String,
pub actual_parens: String,
}
impl AlwaysAutofixableViolation for IncorrectMarkParenthesesStyle {
impl AlwaysAutofixableViolation for PytestIncorrectMarkParenthesesStyle {
#[derive_message_formats]
fn message(&self) -> String {
let IncorrectMarkParenthesesStyle {
let PytestIncorrectMarkParenthesesStyle {
mark_name,
expected_parens,
actual_parens,
@ -36,9 +36,9 @@ impl AlwaysAutofixableViolation for IncorrectMarkParenthesesStyle {
}
#[violation]
pub struct UseFixturesWithoutParameters;
pub struct PytestUseFixturesWithoutParameters;
impl AlwaysAutofixableViolation for UseFixturesWithoutParameters {
impl AlwaysAutofixableViolation for PytestUseFixturesWithoutParameters {
#[derive_message_formats]
fn message(&self) -> String {
format!("Useless `pytest.mark.usefixtures` without parameters")
@ -57,7 +57,7 @@ fn pytest_mark_parentheses(
actual: &str,
) {
let mut diagnostic = Diagnostic::new(
IncorrectMarkParenthesesStyle {
PytestIncorrectMarkParenthesesStyle {
mark_name: get_mark_name(decorator).to_string(),
expected_parens: preferred.to_string(),
actual_parens: actual.to_string(),
@ -110,7 +110,8 @@ fn check_useless_usefixtures(checker: &mut Checker, decorator: &Expr) {
}
if !has_parameters {
let mut diagnostic = Diagnostic::new(UseFixturesWithoutParameters, Range::from(decorator));
let mut diagnostic =
Diagnostic::new(PytestUseFixturesWithoutParameters, Range::from(decorator));
if checker.patch(diagnostic.kind.rule()) {
let at_start = Location::new(decorator.location.row(), decorator.location.column() - 1);
diagnostic.amend(Fix::deletion(at_start, decorator.end_location.unwrap()));
@ -123,11 +124,11 @@ pub fn marks(checker: &mut Checker, decorators: &[Expr]) {
let enforce_parentheses = checker
.settings
.rules
.enabled(Rule::IncorrectMarkParenthesesStyle);
.enabled(Rule::PytestIncorrectMarkParenthesesStyle);
let enforce_useless_usefixtures = checker
.settings
.rules
.enabled(Rule::UseFixturesWithoutParameters);
.enabled(Rule::PytestUseFixturesWithoutParameters);
for mark in get_mark_decorators(decorators) {
if enforce_parentheses {

View file

@ -1,21 +1,26 @@
pub use assertion::{
assert_falsy, assert_in_exception_handler, composite_condition, unittest_assertion,
AssertAlwaysFalse, AssertInExcept, CompositeAssertion, UnittestAssertion,
PytestAssertAlwaysFalse, PytestAssertInExcept, PytestCompositeAssertion,
PytestUnittestAssertion,
};
pub use fail::{fail_call, FailWithoutMessage};
pub use fail::{fail_call, PytestFailWithoutMessage};
pub use fixture::{
fixture, DeprecatedYieldFixture, ErroneousUseFixturesOnFixture, ExtraneousScopeFunction,
FixtureFinalizerCallback, FixtureParamWithoutValue, FixturePositionalArgs,
IncorrectFixtureNameUnderscore, IncorrectFixtureParenthesesStyle, MissingFixtureNameUnderscore,
UnnecessaryAsyncioMarkOnFixture, UselessYieldFixture,
fixture, PytestDeprecatedYieldFixture, PytestErroneousUseFixturesOnFixture,
PytestExtraneousScopeFunction, PytestFixtureFinalizerCallback,
PytestFixtureIncorrectParenthesesStyle, PytestFixtureParamWithoutValue,
PytestFixturePositionalArgs, PytestIncorrectFixtureNameUnderscore,
PytestMissingFixtureNameUnderscore, PytestUnnecessaryAsyncioMarkOnFixture,
PytestUselessYieldFixture,
};
pub use imports::{import, import_from, IncorrectPytestImport};
pub use marks::{marks, IncorrectMarkParenthesesStyle, UseFixturesWithoutParameters};
pub use parametrize::{parametrize, ParametrizeNamesWrongType, ParametrizeValuesWrongType};
pub use patch::{patch_with_lambda, PatchWithLambda};
pub use imports::{import, import_from, PytestIncorrectPytestImport};
pub use marks::{marks, PytestIncorrectMarkParenthesesStyle, PytestUseFixturesWithoutParameters};
pub use parametrize::{
parametrize, PytestParametrizeNamesWrongType, PytestParametrizeValuesWrongType,
};
pub use patch::{patch_with_lambda, PytestPatchWithLambda};
pub use raises::{
complex_raises, raises_call, RaisesTooBroad, RaisesWithMultipleStatements,
RaisesWithoutException,
complex_raises, raises_call, PytestRaisesTooBroad, PytestRaisesWithMultipleStatements,
PytestRaisesWithoutException,
};
mod assertion;

View file

@ -13,33 +13,33 @@ use super::super::types;
use super::helpers::{is_pytest_parametrize, split_names};
#[violation]
pub struct ParametrizeNamesWrongType {
pub struct PytestParametrizeNamesWrongType {
pub expected: types::ParametrizeNameType,
}
impl AlwaysAutofixableViolation for ParametrizeNamesWrongType {
impl AlwaysAutofixableViolation for PytestParametrizeNamesWrongType {
#[derive_message_formats]
fn message(&self) -> String {
let ParametrizeNamesWrongType { expected } = self;
let PytestParametrizeNamesWrongType { expected } = self;
format!("Wrong name(s) type in `@pytest.mark.parametrize`, expected `{expected}`")
}
fn autofix_title(&self) -> String {
let ParametrizeNamesWrongType { expected } = self;
let PytestParametrizeNamesWrongType { expected } = self;
format!("Use a `{expected}` for parameter names")
}
}
#[violation]
pub struct ParametrizeValuesWrongType {
pub struct PytestParametrizeValuesWrongType {
pub values: types::ParametrizeValuesType,
pub row: types::ParametrizeValuesRowType,
}
impl Violation for ParametrizeValuesWrongType {
impl Violation for PytestParametrizeValuesWrongType {
#[derive_message_formats]
fn message(&self) -> String {
let ParametrizeValuesWrongType { values, row } = self;
let PytestParametrizeValuesWrongType { values, row } = self;
format!("Wrong values type in `@pytest.mark.parametrize` expected `{values}` of `{row}`")
}
}
@ -94,7 +94,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
match names_type {
types::ParametrizeNameType::Tuple => {
let mut diagnostic = Diagnostic::new(
ParametrizeNamesWrongType {
PytestParametrizeNamesWrongType {
expected: names_type,
},
Range::from(expr),
@ -127,7 +127,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
}
types::ParametrizeNameType::List => {
let mut diagnostic = Diagnostic::new(
ParametrizeNamesWrongType {
PytestParametrizeNamesWrongType {
expected: names_type,
},
Range::from(expr),
@ -169,7 +169,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
types::ParametrizeNameType::Tuple => {}
types::ParametrizeNameType::List => {
let mut diagnostic = Diagnostic::new(
ParametrizeNamesWrongType {
PytestParametrizeNamesWrongType {
expected: names_type,
},
Range::from(expr),
@ -191,7 +191,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
}
types::ParametrizeNameType::Csv => {
let mut diagnostic = Diagnostic::new(
ParametrizeNamesWrongType {
PytestParametrizeNamesWrongType {
expected: names_type,
},
Range::from(expr),
@ -220,7 +220,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
types::ParametrizeNameType::List => {}
types::ParametrizeNameType::Tuple => {
let mut diagnostic = Diagnostic::new(
ParametrizeNamesWrongType {
PytestParametrizeNamesWrongType {
expected: names_type,
},
Range::from(expr),
@ -245,7 +245,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
}
types::ParametrizeNameType::Csv => {
let mut diagnostic = Diagnostic::new(
ParametrizeNamesWrongType {
PytestParametrizeNamesWrongType {
expected: names_type,
},
Range::from(expr),
@ -291,7 +291,7 @@ fn check_values(checker: &mut Checker, names: &Expr, values: &Expr) {
ExprKind::List { elts, .. } => {
if values_type != types::ParametrizeValuesType::List {
checker.diagnostics.push(Diagnostic::new(
ParametrizeValuesWrongType {
PytestParametrizeValuesWrongType {
values: values_type,
row: values_row_type,
},
@ -305,7 +305,7 @@ fn check_values(checker: &mut Checker, names: &Expr, values: &Expr) {
ExprKind::Tuple { elts, .. } => {
if values_type != types::ParametrizeValuesType::Tuple {
checker.diagnostics.push(Diagnostic::new(
ParametrizeValuesWrongType {
PytestParametrizeValuesWrongType {
values: values_type,
row: values_row_type,
},
@ -322,7 +322,7 @@ fn check_values(checker: &mut Checker, names: &Expr, values: &Expr) {
fn handle_single_name(checker: &mut Checker, expr: &Expr, value: &Expr) {
let mut diagnostic = Diagnostic::new(
ParametrizeNamesWrongType {
PytestParametrizeNamesWrongType {
expected: types::ParametrizeNameType::Csv,
},
Range::from(expr),
@ -349,7 +349,7 @@ fn handle_value_rows(
ExprKind::Tuple { .. } => {
if values_row_type != types::ParametrizeValuesRowType::Tuple {
checker.diagnostics.push(Diagnostic::new(
ParametrizeValuesWrongType {
PytestParametrizeValuesWrongType {
values: values_type,
row: values_row_type,
},
@ -360,7 +360,7 @@ fn handle_value_rows(
ExprKind::List { .. } => {
if values_row_type != types::ParametrizeValuesRowType::List {
checker.diagnostics.push(Diagnostic::new(
ParametrizeValuesWrongType {
PytestParametrizeValuesWrongType {
values: values_type,
row: values_row_type,
},
@ -380,7 +380,7 @@ pub fn parametrize(checker: &mut Checker, decorators: &[Expr]) {
if checker
.settings
.rules
.enabled(Rule::ParametrizeNamesWrongType)
.enabled(Rule::PytestParametrizeNamesWrongType)
{
if let Some(names) = args.get(0) {
check_names(checker, names);
@ -389,7 +389,7 @@ pub fn parametrize(checker: &mut Checker, decorators: &[Expr]) {
if checker
.settings
.rules
.enabled(Rule::ParametrizeValuesWrongType)
.enabled(Rule::PytestParametrizeValuesWrongType)
{
if let Some(names) = args.get(0) {
if let Some(values) = args.get(1) {

View file

@ -9,9 +9,9 @@ use ruff_python_ast::visitor;
use ruff_python_ast::visitor::Visitor;
#[violation]
pub struct PatchWithLambda;
pub struct PytestPatchWithLambda;
impl Violation for PatchWithLambda {
impl Violation for PytestPatchWithLambda {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use `return_value=` instead of patching with `lambda`")
@ -82,7 +82,7 @@ fn check_patch_call(
visitor.visit_expr(body);
if !visitor.uses_args {
return Some(Diagnostic::new(PatchWithLambda, Range::from(call)));
return Some(Diagnostic::new(PytestPatchWithLambda, Range::from(call)));
}
}
}

View file

@ -11,9 +11,9 @@ use crate::registry::Rule;
use super::helpers::is_empty_or_null_string;
#[violation]
pub struct RaisesWithMultipleStatements;
pub struct PytestRaisesWithMultipleStatements;
impl Violation for RaisesWithMultipleStatements {
impl Violation for PytestRaisesWithMultipleStatements {
#[derive_message_formats]
fn message(&self) -> String {
format!("`pytest.raises()` block should contain a single simple statement")
@ -21,14 +21,14 @@ impl Violation for RaisesWithMultipleStatements {
}
#[violation]
pub struct RaisesTooBroad {
pub struct PytestRaisesTooBroad {
pub exception: String,
}
impl Violation for RaisesTooBroad {
impl Violation for PytestRaisesTooBroad {
#[derive_message_formats]
fn message(&self) -> String {
let RaisesTooBroad { exception } = self;
let PytestRaisesTooBroad { exception } = self;
format!(
"`pytest.raises({exception})` is too broad, set the `match` parameter or use a more \
specific exception"
@ -37,9 +37,9 @@ impl Violation for RaisesTooBroad {
}
#[violation]
pub struct RaisesWithoutException;
pub struct PytestRaisesWithoutException;
impl Violation for RaisesWithoutException {
impl Violation for PytestRaisesWithoutException {
#[derive_message_formats]
fn message(&self) -> String {
format!("set the expected exception in `pytest.raises()`")
@ -67,15 +67,20 @@ const fn is_non_trivial_with_body(body: &[Stmt]) -> bool {
pub fn raises_call(checker: &mut Checker, func: &Expr, args: &[Expr], keywords: &[Keyword]) {
if is_pytest_raises(checker, func) {
if checker.settings.rules.enabled(Rule::RaisesWithoutException) {
if checker
.settings
.rules
.enabled(Rule::PytestRaisesWithoutException)
{
if args.is_empty() && keywords.is_empty() {
checker
.diagnostics
.push(Diagnostic::new(RaisesWithoutException, Range::from(func)));
checker.diagnostics.push(Diagnostic::new(
PytestRaisesWithoutException,
Range::from(func),
));
}
}
if checker.settings.rules.enabled(Rule::RaisesTooBroad) {
if checker.settings.rules.enabled(Rule::PytestRaisesTooBroad) {
let match_keyword = keywords
.iter()
.find(|kw| kw.node.arg == Some("match".to_string()));
@ -127,7 +132,7 @@ pub fn complex_raises(checker: &mut Checker, stmt: &Stmt, items: &[Withitem], bo
if is_too_complex {
checker.diagnostics.push(Diagnostic::new(
RaisesWithMultipleStatements,
PytestRaisesWithMultipleStatements,
Range::from(stmt),
));
}
@ -160,7 +165,7 @@ fn exception_needs_match(checker: &mut Checker, exception: &Expr) {
})
{
checker.diagnostics.push(Diagnostic::new(
RaisesTooBroad {
PytestRaisesTooBroad {
exception: call_path,
},
Range::from(exception),

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
expression: diagnostics
---
- kind:
name: IncorrectFixtureParenthesesStyle
name: PytestFixtureIncorrectParenthesesStyle
body: "Use `@pytest.fixture()` over `@pytest.fixture`"
suggestion: Add/remove parentheses
fixable: true
@ -23,7 +23,7 @@ expression: diagnostics
column: 15
parent: ~
- kind:
name: IncorrectFixtureParenthesesStyle
name: PytestFixtureIncorrectParenthesesStyle
body: "Use `@pytest.fixture()` over `@pytest.fixture`"
suggestion: Add/remove parentheses
fixable: true
@ -43,7 +43,7 @@ expression: diagnostics
column: 8
parent: ~
- kind:
name: IncorrectFixtureParenthesesStyle
name: PytestFixtureIncorrectParenthesesStyle
body: "Use `@pytest.fixture()` over `@pytest.fixture`"
suggestion: Add/remove parentheses
fixable: true

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
expression: diagnostics
---
- kind:
name: IncorrectFixtureParenthesesStyle
name: PytestFixtureIncorrectParenthesesStyle
body: "Use `@pytest.fixture` over `@pytest.fixture()`"
suggestion: Add/remove parentheses
fixable: true
@ -23,7 +23,7 @@ expression: diagnostics
column: 17
parent: ~
- kind:
name: IncorrectFixtureParenthesesStyle
name: PytestFixtureIncorrectParenthesesStyle
body: "Use `@pytest.fixture` over `@pytest.fixture()`"
suggestion: Add/remove parentheses
fixable: true
@ -43,7 +43,7 @@ expression: diagnostics
column: 1
parent: ~
- kind:
name: IncorrectFixtureParenthesesStyle
name: PytestFixtureIncorrectParenthesesStyle
body: "Use `@pytest.fixture` over `@pytest.fixture()`"
suggestion: Add/remove parentheses
fixable: true
@ -63,7 +63,7 @@ expression: diagnostics
column: 10
parent: ~
- kind:
name: IncorrectFixtureParenthesesStyle
name: PytestFixtureIncorrectParenthesesStyle
body: "Use `@pytest.fixture` over `@pytest.fixture()`"
suggestion: Add/remove parentheses
fixable: true
@ -83,7 +83,7 @@ expression: diagnostics
column: 1
parent: ~
- kind:
name: IncorrectFixtureParenthesesStyle
name: PytestFixtureIncorrectParenthesesStyle
body: "Use `@pytest.fixture` over `@pytest.fixture()`"
suggestion: Add/remove parentheses
fixable: true
@ -103,7 +103,7 @@ expression: diagnostics
column: 10
parent: ~
- kind:
name: IncorrectFixtureParenthesesStyle
name: PytestFixtureIncorrectParenthesesStyle
body: "Use `@pytest.fixture` over `@pytest.fixture()`"
suggestion: Add/remove parentheses
fixable: true

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
expression: diagnostics
---
- kind:
name: FixturePositionalArgs
name: PytestFixturePositionalArgs
body: "Configuration for fixture `my_fixture` specified via positional args, use kwargs"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: FixturePositionalArgs
name: PytestFixturePositionalArgs
body: "Configuration for fixture `my_fixture` specified via positional args, use kwargs"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
expression: diagnostics
---
- kind:
name: ExtraneousScopeFunction
name: PytestExtraneousScopeFunction
body: "`scope='function'` is implied in `@pytest.fixture()`"
suggestion: "Remove implied `scope` argument"
fixable: true
@ -23,7 +23,7 @@ expression: diagnostics
column: 32
parent: ~
- kind:
name: ExtraneousScopeFunction
name: PytestExtraneousScopeFunction
body: "`scope='function'` is implied in `@pytest.fixture()`"
suggestion: "Remove implied `scope` argument"
fixable: true
@ -43,7 +43,7 @@ expression: diagnostics
column: 34
parent: ~
- kind:
name: ExtraneousScopeFunction
name: PytestExtraneousScopeFunction
body: "`scope='function'` is implied in `@pytest.fixture()`"
suggestion: "Remove implied `scope` argument"
fixable: true
@ -63,7 +63,7 @@ expression: diagnostics
column: 51
parent: ~
- kind:
name: ExtraneousScopeFunction
name: PytestExtraneousScopeFunction
body: "`scope='function'` is implied in `@pytest.fixture()`"
suggestion: "Remove implied `scope` argument"
fixable: true
@ -83,7 +83,7 @@ expression: diagnostics
column: 53
parent: ~
- kind:
name: ExtraneousScopeFunction
name: PytestExtraneousScopeFunction
body: "`scope='function'` is implied in `@pytest.fixture()`"
suggestion: "Remove implied `scope` argument"
fixable: true
@ -103,7 +103,7 @@ expression: diagnostics
column: 46
parent: ~
- kind:
name: ExtraneousScopeFunction
name: PytestExtraneousScopeFunction
body: "`scope='function'` is implied in `@pytest.fixture()`"
suggestion: "Remove implied `scope` argument"
fixable: true
@ -123,7 +123,7 @@ expression: diagnostics
column: 4
parent: ~
- kind:
name: ExtraneousScopeFunction
name: PytestExtraneousScopeFunction
body: "`scope='function'` is implied in `@pytest.fixture()`"
suggestion: "Remove implied `scope` argument"
fixable: true
@ -143,7 +143,7 @@ expression: diagnostics
column: 20
parent: ~
- kind:
name: ExtraneousScopeFunction
name: PytestExtraneousScopeFunction
body: "`scope='function'` is implied in `@pytest.fixture()`"
suggestion: "Remove implied `scope` argument"
fixable: true

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
expression: diagnostics
---
- kind:
name: MissingFixtureNameUnderscore
name: PytestMissingFixtureNameUnderscore
body: "Fixture `patch_something` does not return anything, add leading underscore"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: MissingFixtureNameUnderscore
name: PytestMissingFixtureNameUnderscore
body: "Fixture `activate_context` does not return anything, add leading underscore"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
expression: diagnostics
---
- kind:
name: IncorrectFixtureNameUnderscore
name: PytestIncorrectFixtureNameUnderscore
body: "Fixture `_my_fixture` returns a value, remove leading underscore"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: IncorrectFixtureNameUnderscore
name: PytestIncorrectFixtureNameUnderscore
body: "Fixture `_activate_context` returns a value, remove leading underscore"
suggestion: ~
fixable: false
@ -29,7 +29,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: IncorrectFixtureNameUnderscore
name: PytestIncorrectFixtureNameUnderscore
body: "Fixture `_activate_context` returns a value, remove leading underscore"
suggestion: ~
fixable: false

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
expression: diagnostics
---
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`"
suggestion: "Use a `csv` for parameter names"
fixable: true
@ -23,7 +23,7 @@ expression: diagnostics
column: 45
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`"
suggestion: "Use a `csv` for parameter names"
fixable: true
@ -43,7 +43,7 @@ expression: diagnostics
column: 36
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`"
suggestion: "Use a `csv` for parameter names"
fixable: true
@ -63,7 +63,7 @@ expression: diagnostics
column: 45
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`"
suggestion: "Use a `csv` for parameter names"
fixable: true
@ -83,7 +83,7 @@ expression: diagnostics
column: 35
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`"
suggestion: "Use a `csv` for parameter names"
fixable: true
@ -96,7 +96,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`"
suggestion: "Use a `csv` for parameter names"
fixable: true

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
expression: diagnostics
---
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple`"
suggestion: "Use a `tuple` for parameter names"
fixable: true
@ -23,7 +23,7 @@ expression: diagnostics
column: 40
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple`"
suggestion: "Use a `tuple` for parameter names"
fixable: true
@ -43,7 +43,7 @@ expression: diagnostics
column: 56
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple`"
suggestion: "Use a `tuple` for parameter names"
fixable: true
@ -63,7 +63,7 @@ expression: diagnostics
column: 40
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`"
suggestion: "Use a `csv` for parameter names"
fixable: true
@ -83,7 +83,7 @@ expression: diagnostics
column: 36
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple`"
suggestion: "Use a `tuple` for parameter names"
fixable: true
@ -103,7 +103,7 @@ expression: diagnostics
column: 45
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`"
suggestion: "Use a `csv` for parameter names"
fixable: true
@ -123,7 +123,7 @@ expression: diagnostics
column: 35
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple`"
suggestion: "Use a `tuple` for parameter names"
fixable: true
@ -143,7 +143,7 @@ expression: diagnostics
column: 50
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple`"
suggestion: "Use a `tuple` for parameter names"
fixable: true

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
expression: diagnostics
---
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `list`"
suggestion: "Use a `list` for parameter names"
fixable: true
@ -23,7 +23,7 @@ expression: diagnostics
column: 40
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `list`"
suggestion: "Use a `list` for parameter names"
fixable: true
@ -43,7 +43,7 @@ expression: diagnostics
column: 56
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `list`"
suggestion: "Use a `list` for parameter names"
fixable: true
@ -63,7 +63,7 @@ expression: diagnostics
column: 40
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `list`"
suggestion: "Use a `list` for parameter names"
fixable: true
@ -83,7 +83,7 @@ expression: diagnostics
column: 45
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`"
suggestion: "Use a `csv` for parameter names"
fixable: true
@ -103,7 +103,7 @@ expression: diagnostics
column: 36
parent: ~
- kind:
name: ParametrizeNamesWrongType
name: PytestParametrizeNamesWrongType
body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`"
suggestion: "Use a `csv` for parameter names"
fixable: true

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
expression: diagnostics
---
- kind:
name: ParametrizeValuesWrongType
name: PytestParametrizeValuesWrongType
body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`"
suggestion: ~
fixable: false
@ -16,7 +16,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ParametrizeValuesWrongType
name: PytestParametrizeValuesWrongType
body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`"
suggestion: ~
fixable: false
@ -29,7 +29,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ParametrizeValuesWrongType
name: PytestParametrizeValuesWrongType
body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`"
suggestion: ~
fixable: false
@ -42,7 +42,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ParametrizeValuesWrongType
name: PytestParametrizeValuesWrongType
body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`"
suggestion: ~
fixable: false
@ -55,7 +55,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ParametrizeValuesWrongType
name: PytestParametrizeValuesWrongType
body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`"
suggestion: ~
fixable: false
@ -68,7 +68,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ParametrizeValuesWrongType
name: PytestParametrizeValuesWrongType
body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`"
suggestion: ~
fixable: false
@ -81,7 +81,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ParametrizeValuesWrongType
name: PytestParametrizeValuesWrongType
body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`"
suggestion: ~
fixable: false
@ -94,7 +94,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ParametrizeValuesWrongType
name: PytestParametrizeValuesWrongType
body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`"
suggestion: ~
fixable: false
@ -107,7 +107,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ParametrizeValuesWrongType
name: PytestParametrizeValuesWrongType
body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`"
suggestion: ~
fixable: false
@ -120,7 +120,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
name: ParametrizeValuesWrongType
name: PytestParametrizeValuesWrongType
body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`"
suggestion: ~
fixable: false

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