From 14ba469fc099e0678859bba3ae6f67477d8934ec Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Wed, 27 Nov 2024 10:41:40 +0100 Subject: [PATCH] Use a derive macro for Violations (#14557) Co-authored-by: Alex Waygood --- CONTRIBUTING.md | 2 +- clippy.toml | 36 ++++--- crates/ruff_diagnostics/src/lib.rs | 2 +- crates/ruff_diagnostics/src/violation.rs | 27 ++++- .../airflow/rules/dag_schedule_argument.rs | 6 +- .../rules/airflow/rules/task_variable_name.rs | 6 +- .../eradicate/rules/commented_out_code.rs | 6 +- .../rules/fastapi_non_annotated_dependency.rs | 6 +- .../rules/fastapi_redundant_response_model.rs | 6 +- .../rules/fastapi_unused_path_parameter.rs | 6 +- .../src/rules/flake8_2020/rules/compare.rs | 22 ++-- .../flake8_2020/rules/name_or_attribute.rs | 6 +- .../src/rules/flake8_2020/rules/subscript.rs | 18 ++-- .../flake8_annotations/rules/definition.rs | 46 ++++---- .../flake8_async/rules/async_busy_wait.rs | 6 +- .../rules/async_function_with_timeout.rs | 7 +- .../flake8_async/rules/async_zero_sleep.rs | 6 +- .../flake8_async/rules/blocking_http_call.rs | 6 +- .../flake8_async/rules/blocking_open_call.rs | 6 +- .../rules/blocking_process_invocation.rs | 14 +-- .../flake8_async/rules/blocking_sleep.rs | 6 +- .../rules/cancel_scope_no_checkpoint.rs | 6 +- .../rules/long_sleep_not_forever.rs | 6 +- .../src/rules/flake8_async/rules/sync_call.rs | 6 +- .../rules/flake8_bandit/rules/assert_used.rs | 6 +- .../rules/bad_file_permissions.rs | 6 +- .../rules/flake8_bandit/rules/django_extra.rs | 6 +- .../flake8_bandit/rules/django_raw_sql.rs | 6 +- .../rules/flake8_bandit/rules/exec_used.rs | 6 +- .../flake8_bandit/rules/flask_debug_true.rs | 6 +- .../rules/hardcoded_bind_all_interfaces.rs | 6 +- .../rules/hardcoded_password_default.rs | 6 +- .../rules/hardcoded_password_func_arg.rs | 6 +- .../rules/hardcoded_password_string.rs | 6 +- .../rules/hardcoded_sql_expression.rs | 6 +- .../rules/hardcoded_tmp_directory.rs | 6 +- .../rules/hashlib_insecure_hash_functions.rs | 6 +- .../rules/jinja2_autoescape_false.rs | 6 +- .../rules/logging_config_insecure_listen.rs | 6 +- .../flake8_bandit/rules/mako_templates.rs | 6 +- .../flake8_bandit/rules/paramiko_calls.rs | 6 +- .../rules/request_with_no_cert_validation.rs | 6 +- .../rules/request_without_timeout.rs | 6 +- .../flake8_bandit/rules/shell_injection.rs | 30 +++--- .../rules/snmp_insecure_version.rs | 6 +- .../rules/snmp_weak_cryptography.rs | 6 +- .../rules/ssh_no_host_key_verification.rs | 6 +- .../rules/ssl_insecure_version.rs | 6 +- .../rules/ssl_with_bad_defaults.rs | 6 +- .../rules/ssl_with_no_version.rs | 6 +- .../rules/suspicious_function_call.rs | 86 +++++++-------- .../flake8_bandit/rules/suspicious_imports.rs | 58 +++++----- .../rules/tarfile_unsafe_members.rs | 6 +- .../rules/try_except_continue.rs | 6 +- .../flake8_bandit/rules/try_except_pass.rs | 6 +- .../flake8_bandit/rules/unsafe_yaml_load.rs | 6 +- .../rules/weak_cryptographic_key.rs | 6 +- .../flake8_blind_except/rules/blind_except.rs | 6 +- ...olean_default_value_positional_argument.rs | 6 +- .../rules/boolean_positional_value_in_call.rs | 6 +- .../boolean_type_hint_positional_argument.rs | 6 +- .../rules/abstract_base_class.rs | 10 +- .../flake8_bugbear/rules/assert_false.rs | 6 +- .../rules/assert_raises_exception.rs | 6 +- .../rules/assignment_to_os_environ.rs | 6 +- .../rules/cached_instance_method.rs | 6 +- .../rules/duplicate_exceptions.rs | 10 +- .../flake8_bugbear/rules/duplicate_value.rs | 6 +- .../rules/except_with_empty_tuple.rs | 6 +- .../except_with_non_exception_classes.rs | 6 +- .../rules/f_string_docstring.rs | 6 +- .../function_call_in_argument_default.rs | 6 +- .../rules/function_uses_loop_variable.rs | 6 +- .../rules/getattr_with_constant.rs | 6 +- .../rules/jump_statement_in_finally.rs | 6 +- .../rules/loop_iterator_mutation.rs | 6 +- .../rules/loop_variable_overrides_iterator.rs | 6 +- .../rules/mutable_argument_default.rs | 6 +- .../rules/mutable_contextvar_default.rs | 6 +- .../rules/no_explicit_stacklevel.rs | 6 +- .../flake8_bugbear/rules/raise_literal.rs | 6 +- .../rules/raise_without_from_inside_except.rs | 6 +- .../rules/re_sub_positional_args.rs | 6 +- .../redundant_tuple_in_exception_handler.rs | 6 +- .../rules/return_in_generator.rs | 6 +- .../rules/reuse_of_groupby_generator.rs | 6 +- .../rules/setattr_with_constant.rs | 6 +- .../star_arg_unpacking_after_keyword_arg.rs | 6 +- .../rules/static_key_dict_comprehension.rs | 6 +- .../rules/strip_with_multi_characters.rs | 6 +- .../rules/unary_prefix_increment_decrement.rs | 6 +- .../rules/unintentional_type_annotation.rs | 6 +- .../rules/unreliable_callable_check.rs | 6 +- .../rules/unused_loop_control_variable.rs | 6 +- .../rules/useless_comparison.rs | 6 +- .../rules/useless_contextlib_suppress.rs | 6 +- .../rules/useless_expression.rs | 6 +- .../rules/zip_without_explicit_strict.rs | 6 +- .../rules/builtin_argument_shadowing.rs | 6 +- .../rules/builtin_attribute_shadowing.rs | 6 +- .../rules/builtin_import_shadowing.rs | 6 +- .../builtin_lambda_argument_shadowing.rs | 6 +- .../rules/builtin_module_shadowing.rs | 6 +- .../rules/builtin_variable_shadowing.rs | 6 +- .../flake8_commas/rules/trailing_commas.rs | 14 +-- .../rules/unnecessary_call_around_sorted.rs | 6 +- .../rules/unnecessary_collection_call.rs | 6 +- .../rules/unnecessary_comprehension.rs | 6 +- .../unnecessary_comprehension_in_call.rs | 6 +- ...cessary_dict_comprehension_for_iterable.rs | 6 +- .../unnecessary_double_cast_or_process.rs | 6 +- .../rules/unnecessary_generator_dict.rs | 6 +- .../rules/unnecessary_generator_list.rs | 6 +- .../rules/unnecessary_generator_set.rs | 6 +- .../rules/unnecessary_list_call.rs | 6 +- .../unnecessary_list_comprehension_dict.rs | 6 +- .../unnecessary_list_comprehension_set.rs | 6 +- .../rules/unnecessary_literal_dict.rs | 6 +- .../rules/unnecessary_literal_set.rs | 6 +- .../unnecessary_literal_within_dict_call.rs | 6 +- .../unnecessary_literal_within_list_call.rs | 6 +- .../unnecessary_literal_within_tuple_call.rs | 6 +- .../rules/unnecessary_map.rs | 6 +- .../rules/unnecessary_subscript_reversal.rs | 6 +- .../rules/missing_copyright_notice.rs | 6 +- .../rules/call_date_fromtimestamp.rs | 6 +- .../flake8_datetimez/rules/call_date_today.rs | 6 +- .../rules/call_datetime_fromtimestamp.rs | 6 +- .../rules/call_datetime_now_without_tzinfo.rs | 6 +- .../call_datetime_strptime_without_zone.rs | 6 +- .../rules/call_datetime_today.rs | 6 +- .../rules/call_datetime_utcfromtimestamp.rs | 6 +- .../rules/call_datetime_utcnow.rs | 6 +- .../rules/call_datetime_without_tzinfo.rs | 6 +- .../rules/datetime_min_max.rs | 6 +- .../rules/flake8_debugger/rules/debugger.rs | 6 +- .../rules/all_with_model_form.rs | 6 +- .../rules/exclude_with_model_form.rs | 6 +- .../rules/locals_in_render_function.rs | 6 +- .../rules/model_without_dunder_str.rs | 6 +- .../rules/non_leading_receiver_decorator.rs | 6 +- .../rules/nullable_model_string_field.rs | 6 +- .../rules/unordered_body_content_in_model.rs | 6 +- .../rules/string_in_exception.rs | 14 +-- .../rules/shebang_leading_whitespace.rs | 6 +- .../rules/shebang_missing_executable_file.rs | 6 +- .../rules/shebang_missing_python.rs | 6 +- .../rules/shebang_not_executable.rs | 6 +- .../rules/shebang_not_first_line.rs | 6 +- .../src/rules/flake8_fixme/rules/todos.rs | 18 ++-- .../rules/future_required_type_annotation.rs | 6 +- .../future_rewritable_type_annotation.rs | 6 +- .../rules/f_string_in_gettext_func_call.rs | 6 +- .../rules/format_in_gettext_func_call.rs | 6 +- .../rules/printf_in_gettext_func_call.rs | 6 +- .../rules/explicit.rs | 6 +- .../rules/implicit.rs | 13 ++- .../rules/banned_import_alias.rs | 6 +- .../rules/banned_import_from.rs | 6 +- .../rules/unconventional_import_alias.rs | 6 +- .../rules/direct_logger_instantiation.rs | 6 +- .../rules/exception_without_exc_info.rs | 6 +- .../rules/invalid_get_logger_argument.rs | 6 +- .../flake8_logging/rules/root_logger_call.rs | 6 +- .../flake8_logging/rules/undocumented_warn.rs | 6 +- .../rules/flake8_logging_format/violations.rs | 34 +++--- .../rules/implicit_namespace_package.rs | 6 +- .../rules/duplicate_class_field_definition.rs | 6 +- .../rules/multiple_starts_ends_with.rs | 6 +- .../flake8_pie/rules/non_unique_enums.rs | 6 +- .../rules/reimplemented_container_builtin.rs | 6 +- .../rules/unnecessary_dict_kwargs.rs | 6 +- .../rules/unnecessary_placeholder.rs | 6 +- .../rules/unnecessary_range_start.rs | 6 +- .../flake8_pie/rules/unnecessary_spread.rs | 6 +- .../rules/flake8_print/rules/print_call.rs | 10 +- .../flake8_pyi/rules/any_eq_ne_annotation.rs | 6 +- .../rules/bad_generator_return_type.rs | 6 +- .../rules/bad_version_info_comparison.rs | 10 +- .../flake8_pyi/rules/bytestring_usage.rs | 6 +- .../rules/collections_named_tuple.rs | 6 +- .../rules/complex_assignment_in_stub.rs | 6 +- .../rules/complex_if_statement_in_stub.rs | 6 +- .../rules/custom_type_var_return_type.rs | 6 +- .../flake8_pyi/rules/docstring_in_stubs.rs | 6 +- .../rules/duplicate_literal_member.rs | 6 +- .../rules/duplicate_union_member.rs | 6 +- .../rules/ellipsis_in_non_empty_class_body.rs | 6 +- .../flake8_pyi/rules/exit_annotations.rs | 6 +- .../rules/future_annotations_in_stub.rs | 6 +- .../rules/generic_not_last_base_class.rs | 6 +- .../rules/iter_method_return_iterable.rs | 6 +- .../rules/no_return_argument_annotation.rs | 6 +- .../flake8_pyi/rules/non_empty_stub_body.rs | 6 +- .../flake8_pyi/rules/non_self_return_type.rs | 6 +- .../rules/numeric_literal_too_long.rs | 6 +- .../flake8_pyi/rules/pass_in_class_body.rs | 6 +- .../rules/pass_statement_stub_body.rs | 6 +- .../rules/pre_pep570_positional_argument.rs | 6 +- .../flake8_pyi/rules/prefix_type_params.rs | 6 +- .../rules/quoted_annotation_in_stub.rs | 6 +- .../rules/redundant_final_literal.rs | 6 +- .../rules/redundant_literal_union.rs | 6 +- .../rules/redundant_none_literal.rs | 6 +- .../rules/redundant_numeric_union.rs | 6 +- .../rules/flake8_pyi/rules/simple_defaults.rs | 26 ++--- .../rules/str_or_repr_defined_in_stub.rs | 6 +- .../rules/string_or_bytes_too_long.rs | 6 +- .../rules/stub_body_multiple_statements.rs | 6 +- .../flake8_pyi/rules/type_alias_naming.rs | 10 +- .../flake8_pyi/rules/type_comment_in_stub.rs | 6 +- .../unaliased_collections_abc_set_import.rs | 6 +- .../rules/unnecessary_literal_union.rs | 6 +- .../rules/unnecessary_type_union.rs | 6 +- .../flake8_pyi/rules/unrecognized_platform.rs | 10 +- .../rules/unrecognized_version_info.rs | 14 +-- .../rules/unsupported_method_call_on_all.rs | 6 +- .../rules/unused_private_type_definition.rs | 18 ++-- .../flake8_pytest_style/rules/assertion.rs | 22 ++-- .../rules/flake8_pytest_style/rules/fail.rs | 6 +- .../flake8_pytest_style/rules/fixture.rs | 46 ++++---- .../flake8_pytest_style/rules/imports.rs | 6 +- .../rules/flake8_pytest_style/rules/marks.rs | 10 +- .../flake8_pytest_style/rules/parametrize.rs | 14 +-- .../rules/flake8_pytest_style/rules/patch.rs | 6 +- .../rules/flake8_pytest_style/rules/raises.rs | 14 +-- .../rules/avoidable_escaped_quote.rs | 6 +- .../rules/check_string_quotes.rs | 14 +-- .../rules/unnecessary_escaped_quote.rs | 6 +- .../unnecessary_paren_on_raise_exception.rs | 6 +- .../src/rules/flake8_return/rules/function.rs | 34 +++--- .../rules/private_member_access.rs | 6 +- .../flake8_simplify/rules/ast_bool_op.rs | 26 ++--- .../rules/flake8_simplify/rules/ast_expr.rs | 10 +- .../rules/flake8_simplify/rules/ast_ifexp.rs | 14 +-- .../flake8_simplify/rules/ast_unary_op.rs | 14 +-- .../rules/flake8_simplify/rules/ast_with.rs | 6 +- .../flake8_simplify/rules/collapsible_if.rs | 6 +- .../rules/enumerate_for_loop.rs | 6 +- .../if_else_block_instead_of_dict_get.rs | 6 +- .../if_else_block_instead_of_dict_lookup.rs | 6 +- .../rules/if_else_block_instead_of_if_exp.rs | 6 +- .../rules/if_with_same_arms.rs | 6 +- .../flake8_simplify/rules/key_in_dict.rs | 6 +- .../flake8_simplify/rules/needless_bool.rs | 6 +- .../rules/open_file_with_context_handler.rs | 6 +- .../rules/reimplemented_builtin.rs | 6 +- .../rules/return_in_try_except_finally.rs | 6 +- .../rules/split_static_string.rs | 6 +- .../rules/suppressible_exception.rs | 6 +- .../flake8_simplify/rules/yoda_conditions.rs | 6 +- .../rules/zip_dict_keys_and_values.rs | 6 +- .../rules/no_slots_in_namedtuple_subclass.rs | 6 +- .../rules/no_slots_in_str_subclass.rs | 6 +- .../rules/no_slots_in_tuple_subclass.rs | 6 +- .../flake8_tidy_imports/rules/banned_api.rs | 6 +- .../rules/banned_module_level_imports.rs | 6 +- .../rules/relative_imports.rs | 6 +- .../src/rules/flake8_todos/rules/todos.rs | 30 +++--- .../rules/empty_type_checking_block.rs | 6 +- .../rules/runtime_cast_value.rs | 6 +- .../runtime_import_in_type_checking_block.rs | 6 +- .../rules/runtime_string_union.rs | 6 +- .../rules/type_alias_quotes.rs | 10 +- .../rules/typing_only_runtime_import.rs | 14 +-- .../rules/unused_arguments.rs | 22 ++-- .../flake8_use_pathlib/rules/glob_rule.rs | 6 +- .../rules/os_path_getatime.rs | 6 +- .../rules/os_path_getctime.rs | 6 +- .../rules/os_path_getmtime.rs | 6 +- .../rules/os_path_getsize.rs | 6 +- .../flake8_use_pathlib/rules/os_sep_split.rs | 6 +- .../path_constructor_current_directory.rs | 6 +- .../rules/flake8_use_pathlib/violations.rs | 102 +++++++++--------- .../flynt/rules/static_join_to_fstring.rs | 6 +- .../rules/isort/rules/add_required_imports.rs | 6 +- .../src/rules/isort/rules/organize_imports.rs | 6 +- .../mccabe/rules/function_is_too_complex.rs | 6 +- .../rules/numpy/rules/deprecated_function.rs | 6 +- .../numpy/rules/deprecated_type_alias.rs | 6 +- .../src/rules/numpy/rules/legacy_random.rs | 6 +- .../numpy/rules/numpy_2_0_deprecation.rs | 6 +- .../pandas_vet/rules/assignment_to_df.rs | 8 +- .../src/rules/pandas_vet/rules/attr.rs | 6 +- .../src/rules/pandas_vet/rules/call.rs | 18 ++-- .../pandas_vet/rules/inplace_argument.rs | 6 +- .../rules/nunique_constant_series_check.rs | 6 +- .../src/rules/pandas_vet/rules/pd_merge.rs | 8 +- .../src/rules/pandas_vet/rules/read_table.rs | 6 +- .../src/rules/pandas_vet/rules/subscript.rs | 18 ++-- .../rules/camelcase_imported_as_acronym.rs | 6 +- .../rules/camelcase_imported_as_constant.rs | 6 +- .../rules/camelcase_imported_as_lowercase.rs | 6 +- .../constant_imported_as_non_constant.rs | 6 +- .../pep8_naming/rules/dunder_function_name.rs | 6 +- .../rules/error_suffix_on_exception_name.rs | 6 +- .../rules/invalid_argument_name.rs | 10 +- .../pep8_naming/rules/invalid_class_name.rs | 6 +- .../rules/invalid_first_argument_name.rs | 10 +- .../rules/invalid_function_name.rs | 6 +- .../pep8_naming/rules/invalid_module_name.rs | 6 +- .../lowercase_imported_as_non_lowercase.rs | 6 +- .../mixed_case_variable_in_class_scope.rs | 10 +- .../mixed_case_variable_in_global_scope.rs | 18 ++-- .../non_lowercase_variable_in_function.rs | 6 +- .../perflint/rules/incorrect_dict_iterator.rs | 6 +- .../rules/manual_dict_comprehension.rs | 6 +- .../rules/manual_list_comprehension.rs | 6 +- .../rules/perflint/rules/manual_list_copy.rs | 6 +- .../perflint/rules/try_except_in_loop.rs | 6 +- .../perflint/rules/unnecessary_list_cast.rs | 6 +- .../pycodestyle/rules/ambiguous_class_name.rs | 6 +- .../rules/ambiguous_function_name.rs | 6 +- .../rules/ambiguous_variable_name.rs | 6 +- .../rules/pycodestyle/rules/bare_except.rs | 6 +- .../rules/pycodestyle/rules/blank_lines.rs | 26 ++--- .../pycodestyle/rules/compound_statements.rs | 14 +-- .../pycodestyle/rules/doc_line_too_long.rs | 6 +- .../src/rules/pycodestyle/rules/errors.rs | 8 +- .../rules/invalid_escape_sequence.rs | 6 +- .../pycodestyle/rules/lambda_assignment.rs | 6 +- .../rules/pycodestyle/rules/line_too_long.rs | 6 +- .../pycodestyle/rules/literal_comparisons.rs | 10 +- .../logical_lines/extraneous_whitespace.rs | 14 +-- .../rules/logical_lines/indentation.rs | 30 +++--- .../rules/logical_lines/missing_whitespace.rs | 6 +- .../missing_whitespace_after_keyword.rs | 6 +- .../missing_whitespace_around_operator.rs | 18 ++-- .../logical_lines/redundant_backslash.rs | 6 +- .../logical_lines/space_around_operator.rs | 26 ++--- .../whitespace_around_keywords.rs | 18 ++-- ...hitespace_around_named_parameter_equals.rs | 10 +- .../whitespace_before_comment.rs | 18 ++-- .../whitespace_before_parameters.rs | 6 +- .../rules/missing_newline_at_end_of_file.rs | 6 +- .../rules/mixed_spaces_and_tabs.rs | 6 +- .../rules/module_import_not_at_top_of_file.rs | 6 +- .../rules/multiple_imports_on_one_line.rs | 6 +- .../src/rules/pycodestyle/rules/not_tests.rs | 10 +- .../pycodestyle/rules/tab_indentation.rs | 6 +- .../rules/too_many_newlines_at_end_of_file.rs | 6 +- .../pycodestyle/rules/trailing_whitespace.rs | 10 +- .../pycodestyle/rules/type_comparison.rs | 6 +- .../rules/whitespace_after_decorator.rs | 6 +- .../rules/pydoclint/rules/check_docstring.rs | 26 ++--- .../src/rules/pydocstyle/rules/backslashes.rs | 6 +- .../pydocstyle/rules/blank_after_summary.rs | 6 +- .../rules/blank_before_after_class.rs | 14 +-- .../rules/blank_before_after_function.rs | 10 +- .../src/rules/pydocstyle/rules/capitalized.rs | 6 +- .../pydocstyle/rules/ends_with_period.rs | 6 +- .../pydocstyle/rules/ends_with_punctuation.rs | 6 +- .../src/rules/pydocstyle/rules/if_needed.rs | 6 +- .../src/rules/pydocstyle/rules/indent.rs | 15 +-- .../rules/multi_line_summary_start.rs | 10 +- .../rules/newline_after_last_paragraph.rs | 6 +- .../rules/pydocstyle/rules/no_signature.rs | 6 +- .../rules/no_surrounding_whitespace.rs | 6 +- .../pydocstyle/rules/non_imperative_mood.rs | 6 +- .../src/rules/pydocstyle/rules/not_empty.rs | 6 +- .../src/rules/pydocstyle/rules/not_missing.rs | 34 +++--- .../src/rules/pydocstyle/rules/one_liner.rs | 6 +- .../src/rules/pydocstyle/rules/sections.rs | 58 +++++----- .../pydocstyle/rules/starts_with_this.rs | 6 +- .../rules/pydocstyle/rules/triple_quotes.rs | 6 +- .../src/rules/pyflakes/rules/assert_tuple.rs | 6 +- .../pyflakes/rules/break_outside_loop.rs | 6 +- .../pyflakes/rules/continue_outside_loop.rs | 6 +- .../pyflakes/rules/default_except_not_last.rs | 6 +- .../rules/f_string_missing_placeholders.rs | 6 +- .../rules/forward_annotation_syntax_error.rs | 6 +- .../rules/future_feature_not_defined.rs | 6 +- .../src/rules/pyflakes/rules/if_tuple.rs | 6 +- .../src/rules/pyflakes/rules/imports.rs | 22 ++-- .../rules/invalid_literal_comparisons.rs | 6 +- .../pyflakes/rules/invalid_print_syntax.rs | 6 +- .../pyflakes/rules/raise_not_implemented.rs | 6 +- .../pyflakes/rules/redefined_while_unused.rs | 6 +- .../src/rules/pyflakes/rules/repeated_keys.rs | 10 +- .../pyflakes/rules/return_outside_function.rs | 6 +- .../pyflakes/rules/starred_expressions.rs | 10 +- .../src/rules/pyflakes/rules/strings.rs | 58 +++++----- .../rules/pyflakes/rules/undefined_export.rs | 6 +- .../rules/pyflakes/rules/undefined_local.rs | 6 +- .../rules/pyflakes/rules/undefined_name.rs | 6 +- .../rules/pyflakes/rules/unused_annotation.rs | 6 +- .../src/rules/pyflakes/rules/unused_import.rs | 6 +- .../rules/pyflakes/rules/unused_variable.rs | 6 +- .../pyflakes/rules/yield_outside_function.rs | 6 +- .../rules/pygrep_hooks/rules/blanket_noqa.rs | 6 +- .../pygrep_hooks/rules/blanket_type_ignore.rs | 6 +- .../pygrep_hooks/rules/deprecated_log_warn.rs | 6 +- .../pygrep_hooks/rules/invalid_mock_access.rs | 6 +- .../src/rules/pygrep_hooks/rules/no_eval.rs | 6 +- .../src/rules/pylint/rules/and_or_ternary.rs | 6 +- .../pylint/rules/assert_on_string_literal.rs | 6 +- .../rules/pylint/rules/await_outside_async.rs | 6 +- .../pylint/rules/bad_dunder_method_name.rs | 6 +- .../src/rules/pylint/rules/bad_open_mode.rs | 6 +- .../pylint/rules/bad_staticmethod_argument.rs | 6 +- .../rules/pylint/rules/bad_str_strip_call.rs | 6 +- .../rules/bad_string_format_character.rs | 6 +- .../pylint/rules/bad_string_format_type.rs | 6 +- .../pylint/rules/bidirectional_unicode.rs | 6 +- .../rules/pylint/rules/binary_op_exception.rs | 6 +- .../rules/boolean_chained_comparison.rs | 14 +-- .../rules/pylint/rules/collapsible_else_if.rs | 6 +- .../pylint/rules/compare_to_empty_string.rs | 6 +- .../pylint/rules/comparison_of_constant.rs | 6 +- .../pylint/rules/comparison_with_itself.rs | 6 +- .../rules/pylint/rules/continue_in_finally.rs | 6 +- .../pylint/rules/dict_index_missing_items.rs | 6 +- .../pylint/rules/dict_iter_missing_items.rs | 6 +- .../src/rules/pylint/rules/duplicate_bases.rs | 6 +- .../src/rules/pylint/rules/empty_comment.rs | 6 +- .../src/rules/pylint/rules/eq_without_hash.rs | 6 +- .../pylint/rules/global_at_module_level.rs | 6 +- .../rules/pylint/rules/global_statement.rs | 6 +- .../rules/global_variable_not_assigned.rs | 6 +- .../src/rules/pylint/rules/if_stmt_min_max.rs | 6 +- .../pylint/rules/import_outside_top_level.rs | 6 +- .../rules/pylint/rules/import_private_name.rs | 6 +- .../src/rules/pylint/rules/import_self.rs | 6 +- .../rules/pylint/rules/invalid_all_format.rs | 6 +- .../rules/pylint/rules/invalid_all_object.rs | 6 +- .../rules/pylint/rules/invalid_bool_return.rs | 6 +- .../pylint/rules/invalid_bytes_return.rs | 6 +- .../pylint/rules/invalid_envvar_default.rs | 6 +- .../pylint/rules/invalid_envvar_value.rs | 6 +- .../rules/pylint/rules/invalid_hash_return.rs | 6 +- .../pylint/rules/invalid_index_return.rs | 8 +- .../pylint/rules/invalid_length_return.rs | 6 +- .../rules/pylint/rules/invalid_str_return.rs | 6 +- .../pylint/rules/invalid_string_characters.rs | 22 ++-- .../rules/pylint/rules/iteration_over_set.rs | 6 +- .../src/rules/pylint/rules/len_test.rs | 6 +- .../rules/pylint/rules/literal_membership.rs | 6 +- .../rules/load_before_global_declaration.rs | 6 +- .../src/rules/pylint/rules/logging.rs | 10 +- .../pylint/rules/magic_value_comparison.rs | 6 +- .../rules/pylint/rules/manual_import_from.rs | 6 +- .../pylint/rules/misplaced_bare_raise.rs | 6 +- .../pylint/rules/modified_iterating_set.rs | 6 +- .../rules/named_expr_without_context.rs | 6 +- .../src/rules/pylint/rules/nan_comparison.rs | 6 +- .../src/rules/pylint/rules/nested_min_max.rs | 6 +- .../rules/pylint/rules/no_method_decorator.rs | 10 +- .../src/rules/pylint/rules/no_self_use.rs | 6 +- .../pylint/rules/non_ascii_module_import.rs | 6 +- .../src/rules/pylint/rules/non_ascii_name.rs | 6 +- .../pylint/rules/non_augmented_assignment.rs | 8 +- .../rules/pylint/rules/non_slot_assignment.rs | 6 +- .../rules/pylint/rules/nonlocal_and_global.rs | 6 +- .../pylint/rules/nonlocal_without_binding.rs | 6 +- .../pylint/rules/potential_index_error.rs | 6 +- .../pylint/rules/property_with_parameters.rs | 6 +- .../pylint/rules/redeclared_assigned_name.rs | 6 +- .../rules/redefined_argument_from_local.rs | 6 +- .../rules/pylint/rules/redefined_loop_name.rs | 6 +- .../rules/repeated_equality_comparison.rs | 6 +- .../pylint/rules/repeated_isinstance_calls.rs | 6 +- .../pylint/rules/repeated_keyword_argument.rs | 6 +- .../src/rules/pylint/rules/return_in_init.rs | 6 +- .../pylint/rules/self_assigning_variable.rs | 6 +- .../pylint/rules/self_or_cls_assignment.rs | 6 +- .../pylint/rules/shallow_copy_environ.rs | 6 +- .../rules/pylint/rules/single_string_slots.rs | 6 +- .../pylint/rules/singledispatch_method.rs | 6 +- .../rules/singledispatchmethod_function.rs | 6 +- .../rules/subprocess_popen_preexec_fn.rs | 6 +- .../rules/subprocess_run_without_check.rs | 6 +- .../pylint/rules/super_without_brackets.rs | 6 +- .../src/rules/pylint/rules/sys_exit_alias.rs | 6 +- .../rules/pylint/rules/too_many_arguments.rs | 6 +- .../rules/too_many_boolean_expressions.rs | 6 +- .../rules/pylint/rules/too_many_branches.rs | 6 +- .../src/rules/pylint/rules/too_many_locals.rs | 6 +- .../pylint/rules/too_many_nested_blocks.rs | 6 +- .../rules/too_many_positional_arguments.rs | 6 +- .../pylint/rules/too_many_public_methods.rs | 6 +- .../rules/too_many_return_statements.rs | 6 +- .../rules/pylint/rules/too_many_statements.rs | 6 +- .../src/rules/pylint/rules/type_bivariance.rs | 6 +- .../rules/type_name_incorrect_variance.rs | 6 +- .../pylint/rules/type_param_name_mismatch.rs | 6 +- .../unexpected_special_method_signature.rs | 6 +- .../rules/unnecessary_dict_index_lookup.rs | 6 +- .../rules/unnecessary_direct_lambda_call.rs | 6 +- .../pylint/rules/unnecessary_dunder_call.rs | 6 +- .../rules/pylint/rules/unnecessary_lambda.rs | 6 +- .../rules/unnecessary_list_index_lookup.rs | 6 +- .../pylint/rules/unspecified_encoding.rs | 6 +- .../pylint/rules/useless_else_on_loop.rs | 6 +- .../rules/useless_exception_statement.rs | 6 +- .../pylint/rules/useless_import_alias.rs | 6 +- .../src/rules/pylint/rules/useless_return.rs | 6 +- .../rules/pylint/rules/useless_with_lock.rs | 6 +- .../rules/yield_from_in_async_function.rs | 6 +- .../src/rules/pylint/rules/yield_in_init.rs | 6 +- ...convert_named_tuple_functional_to_class.rs | 6 +- .../convert_typed_dict_functional_to_class.rs | 6 +- .../pyupgrade/rules/datetime_utc_alias.rs | 6 +- .../rules/deprecated_c_element_tree.rs | 6 +- .../pyupgrade/rules/deprecated_import.rs | 6 +- .../pyupgrade/rules/deprecated_mock_import.rs | 6 +- .../rules/deprecated_unittest_alias.rs | 6 +- .../pyupgrade/rules/extraneous_parentheses.rs | 6 +- .../src/rules/pyupgrade/rules/f_strings.rs | 6 +- .../rules/pyupgrade/rules/format_literals.rs | 6 +- .../rules/lru_cache_with_maxsize_none.rs | 6 +- .../rules/lru_cache_without_parameters.rs | 6 +- .../rules/pyupgrade/rules/native_literals.rs | 6 +- .../src/rules/pyupgrade/rules/open_alias.rs | 6 +- .../rules/pyupgrade/rules/os_error_alias.rs | 6 +- .../pyupgrade/rules/outdated_version_block.rs | 6 +- .../rules/printf_string_formatting.rs | 6 +- .../pyupgrade/rules/quoted_annotation.rs | 6 +- .../pyupgrade/rules/redundant_open_modes.rs | 6 +- .../pyupgrade/rules/replace_stdout_stderr.rs | 6 +- .../rules/pyupgrade/rules/replace_str_enum.rs | 6 +- .../rules/replace_universal_newlines.rs | 6 +- .../rules/super_call_with_parameters.rs | 6 +- .../pyupgrade/rules/timeout_error_alias.rs | 6 +- .../pyupgrade/rules/type_of_primitive.rs | 6 +- .../pyupgrade/rules/typing_text_str_alias.rs | 6 +- .../pyupgrade/rules/unicode_kind_prefix.rs | 6 +- .../rules/unnecessary_builtin_import.rs | 6 +- .../rules/unnecessary_class_parentheses.rs | 6 +- .../rules/unnecessary_coding_comment.rs | 6 +- .../rules/unnecessary_default_type_args.rs | 6 +- .../rules/unnecessary_encode_utf8.rs | 6 +- .../rules/unnecessary_future_import.rs | 6 +- .../rules/unpacked_list_comprehension.rs | 6 +- .../pyupgrade/rules/use_pep585_annotation.rs | 6 +- .../pyupgrade/rules/use_pep604_annotation.rs | 6 +- .../pyupgrade/rules/use_pep604_isinstance.rs | 6 +- .../pyupgrade/rules/use_pep646_unpack.rs | 6 +- .../pyupgrade/rules/use_pep695_type_alias.rs | 6 +- .../pyupgrade/rules/useless_metaclass_type.rs | 6 +- .../rules/useless_object_inheritance.rs | 6 +- .../pyupgrade/rules/yield_in_for_loop.rs | 6 +- .../src/rules/refurb/rules/bit_count.rs | 6 +- .../refurb/rules/check_and_remove_from_set.rs | 6 +- .../rules/refurb/rules/delete_full_slice.rs | 6 +- .../refurb/rules/for_loop_set_mutations.rs | 6 +- .../refurb/rules/fstring_number_format.rs | 6 +- .../refurb/rules/hardcoded_string_charset.rs | 6 +- .../rules/refurb/rules/hashlib_digest_hex.rs | 6 +- .../rules/if_exp_instead_of_or_operator.rs | 6 +- .../src/rules/refurb/rules/if_expr_min_max.rs | 6 +- .../src/rules/refurb/rules/implicit_cwd.rs | 6 +- .../rules/refurb/rules/int_on_sliced_str.rs | 6 +- .../refurb/rules/isinstance_type_none.rs | 6 +- .../rules/refurb/rules/list_reverse_copy.rs | 6 +- .../src/rules/refurb/rules/math_constant.rs | 6 +- .../rules/refurb/rules/metaclass_abcmeta.rs | 6 +- .../rules/refurb/rules/print_empty_string.rs | 6 +- .../src/rules/refurb/rules/read_whole_file.rs | 6 +- .../rules/refurb/rules/readlines_in_for.rs | 4 +- .../rules/refurb/rules/redundant_log_base.rs | 6 +- .../rules/refurb/rules/regex_flag_alias.rs | 6 +- .../refurb/rules/reimplemented_operator.rs | 6 +- .../refurb/rules/reimplemented_starmap.rs | 6 +- .../src/rules/refurb/rules/repeated_append.rs | 6 +- .../src/rules/refurb/rules/repeated_global.rs | 6 +- .../rules/single_item_membership_test.rs | 6 +- .../src/rules/refurb/rules/slice_copy.rs | 6 +- .../rules/slice_to_remove_prefix_or_suffix.rs | 9 +- .../src/rules/refurb/rules/sorted_min_max.rs | 6 +- .../rules/refurb/rules/subclass_builtin.rs | 6 +- .../refurb/rules/type_none_comparison.rs | 6 +- .../refurb/rules/unnecessary_enumerate.rs | 6 +- .../refurb/rules/unnecessary_from_float.rs | 6 +- .../rules/verbose_decimal_constructor.rs | 6 +- .../rules/refurb/rules/write_whole_file.rs | 6 +- .../ruff/rules/ambiguous_unicode_character.rs | 14 +-- .../ruff/rules/assert_with_print_message.rs | 6 +- .../rules/ruff/rules/assignment_in_assert.rs | 6 +- .../rules/ruff/rules/asyncio_dangling_task.rs | 6 +- .../rules/collection_literal_concatenation.rs | 6 +- .../ruff/rules/decimal_from_float_literal.rs | 6 +- .../rules/ruff/rules/default_factory_kwarg.rs | 6 +- .../explicit_f_string_type_conversion.rs | 6 +- .../function_call_in_dataclass_default.rs | 6 +- .../src/rules/ruff/rules/implicit_optional.rs | 6 +- ...rectly_parenthesized_tuple_in_subscript.rs | 6 +- ...invalid_assert_message_literal_argument.rs | 6 +- .../invalid_formatter_suppression_comment.rs | 6 +- .../rules/ruff/rules/invalid_index_type.rs | 6 +- .../ruff/rules/invalid_pyproject_toml.rs | 6 +- .../ruff/rules/map_int_version_parsing.rs | 6 +- .../ruff/rules/missing_fstring_syntax.rs | 6 +- .../rules/ruff/rules/mutable_class_default.rs | 6 +- .../ruff/rules/mutable_dataclass_default.rs | 6 +- .../ruff/rules/mutable_fromkeys_value.rs | 6 +- .../src/rules/ruff/rules/never_union.rs | 6 +- .../ruff/rules/none_not_at_end_of_union.rs | 6 +- .../rules/parenthesize_chained_operators.rs | 6 +- .../src/rules/ruff/rules/post_init_default.rs | 6 +- .../ruff/rules/quadratic_list_summation.rs | 6 +- .../src/rules/ruff/rules/redirected_noqa.rs | 6 +- .../ruff/rules/redundant_bool_literal.rs | 6 +- .../src/rules/ruff/rules/sort_dunder_all.rs | 6 +- .../src/rules/ruff/rules/sort_dunder_slots.rs | 6 +- .../rules/static_key_dict_comprehension.rs | 6 +- .../src/rules/ruff/rules/test_rules.rs | 50 ++++----- ...y_iterable_allocation_for_first_element.rs | 4 +- .../rules/ruff/rules/unnecessary_key_check.rs | 6 +- .../src/rules/ruff/rules/unraw_re_pattern.rs | 6 +- .../src/rules/ruff/rules/unsafe_markup_use.rs | 6 +- .../src/rules/ruff/rules/unused_async.rs | 6 +- .../src/rules/ruff/rules/unused_noqa.rs | 8 +- .../src/rules/ruff/rules/useless_if_else.rs | 6 +- .../ruff/rules/zip_instead_of_pairwise.rs | 6 +- .../rules/error_instead_of_exception.rs | 6 +- .../tryceratops/rules/raise_vanilla_args.rs | 6 +- .../tryceratops/rules/raise_vanilla_class.rs | 6 +- .../tryceratops/rules/raise_within_try.rs | 6 +- .../tryceratops/rules/reraise_no_cause.rs | 6 +- .../tryceratops/rules/try_consider_else.rs | 6 +- .../rules/type_check_without_type_error.rs | 6 +- .../tryceratops/rules/useless_try_except.rs | 6 +- .../tryceratops/rules/verbose_log_message.rs | 6 +- .../rules/tryceratops/rules/verbose_raise.rs | 6 +- crates/ruff_macros/src/lib.rs | 17 +-- crates/ruff_macros/src/map_codes.rs | 5 +- crates/ruff_macros/src/violation.rs | 100 ----------------- crates/ruff_macros/src/violation_metadata.rs | 66 ++++++++++++ scripts/add_rule.py | 6 +- 629 files changed, 2555 insertions(+), 2562 deletions(-) delete mode 100644 crates/ruff_macros/src/violation.rs create mode 100644 crates/ruff_macros/src/violation_metadata.rs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8e0f6295d247e..43b2d68e1ec02 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -139,7 +139,7 @@ At a high level, the steps involved in adding a new lint rule are as follows: 1. Create a file for your rule (e.g., `crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs`). 1. In that file, define a violation struct (e.g., `pub struct AssertFalse`). You can grep for - `#[violation]` to see examples. + `#[derive(ViolationMetadata)]` to see examples. 1. In that file, define a function that adds the violation to the diagnostic list as appropriate (e.g., `pub(crate) fn assert_false`) based on whatever inputs are required for the rule (e.g., diff --git a/clippy.toml b/clippy.toml index 12052f24fd26e..4ea6eccde06e5 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,21 +1,25 @@ doc-valid-idents = [ - "..", - "CodeQL", - "FastAPI", - "IPython", - "LangChain", - "LibCST", - "McCabe", - "NumPy", - "SCREAMING_SNAKE_CASE", - "SQLAlchemy", - "StackOverflow", - "PyCharm", + "..", + "CodeQL", + "FastAPI", + "IPython", + "LangChain", + "LibCST", + "McCabe", + "NumPy", + "SCREAMING_SNAKE_CASE", + "SQLAlchemy", + "StackOverflow", + "PyCharm", + "SNMPv1", + "SNMPv2", + "SNMPv3", + "PyFlakes" ] ignore-interior-mutability = [ - # Interned is read-only. The wrapped `Rc` never gets updated. - "ruff_formatter::format_element::Interned", - # The expression is read-only. - "ruff_python_ast::hashable::HashableExpr", + # Interned is read-only. The wrapped `Rc` never gets updated. + "ruff_formatter::format_element::Interned", + # The expression is read-only. + "ruff_python_ast::hashable::HashableExpr", ] diff --git a/crates/ruff_diagnostics/src/lib.rs b/crates/ruff_diagnostics/src/lib.rs index f21419abe9cd4..75a9bec240c3b 100644 --- a/crates/ruff_diagnostics/src/lib.rs +++ b/crates/ruff_diagnostics/src/lib.rs @@ -2,7 +2,7 @@ pub use diagnostic::{Diagnostic, DiagnosticKind}; pub use edit::Edit; pub use fix::{Applicability, Fix, IsolationLevel}; pub use source_map::{SourceMap, SourceMarker}; -pub use violation::{AlwaysFixableViolation, FixAvailability, Violation}; +pub use violation::{AlwaysFixableViolation, FixAvailability, Violation, ViolationMetadata}; mod diagnostic; mod edit; diff --git a/crates/ruff_diagnostics/src/violation.rs b/crates/ruff_diagnostics/src/violation.rs index 70fcdd6c94bb2..bf6690c5b28e4 100644 --- a/crates/ruff_diagnostics/src/violation.rs +++ b/crates/ruff_diagnostics/src/violation.rs @@ -1,3 +1,4 @@ +use crate::DiagnosticKind; use std::fmt::{Debug, Display}; #[derive(Debug, Copy, Clone)] @@ -17,7 +18,16 @@ impl Display for FixAvailability { } } -pub trait Violation: Debug + PartialEq + Eq { +pub trait ViolationMetadata { + /// Returns the rule name of this violation + fn rule_name() -> &'static str; + + /// Returns an explanation of what this violation catches, + /// why it's bad, and what users should do instead. + fn explain() -> Option<&'static str>; +} + +pub trait Violation: ViolationMetadata { /// `None` in the case a fix is never available or otherwise Some /// [`FixAvailability`] describing the available fix. const FIX_AVAILABILITY: FixAvailability = FixAvailability::None; @@ -41,7 +51,7 @@ pub trait Violation: Debug + PartialEq + Eq { /// This trait exists just to make implementing the [`Violation`] trait more /// convenient for violations that can always be fixed. -pub trait AlwaysFixableViolation: Debug + PartialEq + Eq { +pub trait AlwaysFixableViolation: ViolationMetadata { /// The message used to describe the violation. fn message(&self) -> String; @@ -69,3 +79,16 @@ impl Violation for V { ::message_formats() } } + +impl From for DiagnosticKind +where + T: Violation, +{ + fn from(value: T) -> Self { + Self { + body: Violation::message(&value), + suggestion: Violation::fix_title(&value), + name: T::rule_name().to_string(), + } + } +} diff --git a/crates/ruff_linter/src/rules/airflow/rules/dag_schedule_argument.rs b/crates/ruff_linter/src/rules/airflow/rules/dag_schedule_argument.rs index 50abf69304cda..b3ae01e527744 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/dag_schedule_argument.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/dag_schedule_argument.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Expr; use ruff_python_ast::{self as ast}; use ruff_python_semantic::Modules; @@ -39,8 +39,8 @@ use crate::checkers::ast::Checker; /// /// dag = DAG(dag_id="my_dag", schedule=timedelta(days=1)) /// ``` -#[violation] -pub struct AirflowDagNoScheduleArgument; +#[derive(ViolationMetadata)] +pub(crate) struct AirflowDagNoScheduleArgument; impl Violation for AirflowDagNoScheduleArgument { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/airflow/rules/task_variable_name.rs b/crates/ruff_linter/src/rules/airflow/rules/task_variable_name.rs index 097a8da2c8946..a9d7a537d1073 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/task_variable_name.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/task_variable_name.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::Expr; use ruff_python_semantic::Modules; @@ -31,8 +31,8 @@ use crate::checkers::ast::Checker; /// /// my_task = PythonOperator(task_id="my_task") /// ``` -#[violation] -pub struct AirflowVariableNameTaskIdMismatch { +#[derive(ViolationMetadata)] +pub(crate) struct AirflowVariableNameTaskIdMismatch { task_id: String, } diff --git a/crates/ruff_linter/src/rules/eradicate/rules/commented_out_code.rs b/crates/ruff_linter/src/rules/eradicate/rules/commented_out_code.rs index e444e679cf2b4..ff59462eb8a5d 100644 --- a/crates/ruff_linter/src/rules/eradicate/rules/commented_out_code.rs +++ b/crates/ruff_linter/src/rules/eradicate/rules/commented_out_code.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_trivia::CommentRanges; use ruff_source_file::{LineRanges, UniversalNewlineIterator}; use ruff_text_size::TextRange; @@ -29,8 +29,8 @@ use super::super::detection::comment_contains_code; /// - `lint.task-tags` /// /// [#4845]: https://github.com/astral-sh/ruff/issues/4845 -#[violation] -pub struct CommentedOutCode; +#[derive(ViolationMetadata)] +pub(crate) struct CommentedOutCode; impl Violation for CommentedOutCode { const FIX_AVAILABILITY: FixAvailability = FixAvailability::None; diff --git a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs index 8475d3977ab22..14148c56ac0a3 100644 --- a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs +++ b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::helpers::map_callable; use ruff_python_semantic::Modules; @@ -63,8 +63,8 @@ use crate::settings::types::PythonVersion; /// [fastAPI documentation]: https://fastapi.tiangolo.com/tutorial/query-params-str-validations/?h=annotated#advantages-of-annotated /// [typing.Annotated]: https://docs.python.org/3/library/typing.html#typing.Annotated /// [typing_extensions]: https://typing-extensions.readthedocs.io/en/stable/ -#[violation] -pub struct FastApiNonAnnotatedDependency { +#[derive(ViolationMetadata)] +pub(crate) struct FastApiNonAnnotatedDependency { py_version: PythonVersion, } diff --git a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_redundant_response_model.rs b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_redundant_response_model.rs index a18749d05b5dd..e1b38bbb37995 100644 --- a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_redundant_response_model.rs +++ b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_redundant_response_model.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Decorator, Expr, ExprCall, Keyword, StmtFunctionDef}; use ruff_python_semantic::{Modules, SemanticModel}; use ruff_text_size::Ranged; @@ -59,8 +59,8 @@ use crate::rules::fastapi::rules::is_fastapi_route_decorator; /// return item /// ``` -#[violation] -pub struct FastApiRedundantResponseModel; +#[derive(ViolationMetadata)] +pub(crate) struct FastApiRedundantResponseModel; impl AlwaysFixableViolation for FastApiRedundantResponseModel { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs index ec6acffebd29d..2c0535d762bf2 100644 --- a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs +++ b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs @@ -4,7 +4,7 @@ use std::str::CharIndices; use ruff_diagnostics::Fix; use ruff_diagnostics::{Diagnostic, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::{Expr, Parameter, ParameterWithDefault}; use ruff_python_semantic::{Modules, SemanticModel}; @@ -62,8 +62,8 @@ use crate::rules::fastapi::rules::is_fastapi_route_decorator; /// ## Fix safety /// This rule's fix is marked as unsafe, as modifying a function signature can /// change the behavior of the code. -#[violation] -pub struct FastApiUnusedPathParameter { +#[derive(ViolationMetadata)] +pub(crate) struct FastApiUnusedPathParameter { arg_name: String, function_name: String, is_positional: bool, diff --git a/crates/ruff_linter/src/rules/flake8_2020/rules/compare.rs b/crates/ruff_linter/src/rules/flake8_2020/rules/compare.rs index ecf009d5754fd..ec2ca7fd936ce 100644 --- a/crates/ruff_linter/src/rules/flake8_2020/rules/compare.rs +++ b/crates/ruff_linter/src/rules/flake8_2020/rules/compare.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, CmpOp, Expr}; use ruff_text_size::Ranged; @@ -40,8 +40,8 @@ use super::super::helpers::is_sys; /// ## References /// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version) /// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info) -#[violation] -pub struct SysVersionCmpStr3; +#[derive(ViolationMetadata)] +pub(crate) struct SysVersionCmpStr3; impl Violation for SysVersionCmpStr3 { #[derive_message_formats] @@ -87,8 +87,8 @@ impl Violation for SysVersionCmpStr3 { /// ## References /// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version) /// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info) -#[violation] -pub struct SysVersionInfo0Eq3; +#[derive(ViolationMetadata)] +pub(crate) struct SysVersionInfo0Eq3; impl Violation for SysVersionInfo0Eq3 { #[derive_message_formats] @@ -127,8 +127,8 @@ impl Violation for SysVersionInfo0Eq3 { /// ## References /// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version) /// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info) -#[violation] -pub struct SysVersionInfo1CmpInt; +#[derive(ViolationMetadata)] +pub(crate) struct SysVersionInfo1CmpInt; impl Violation for SysVersionInfo1CmpInt { #[derive_message_formats] @@ -169,8 +169,8 @@ impl Violation for SysVersionInfo1CmpInt { /// ## References /// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version) /// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info) -#[violation] -pub struct SysVersionInfoMinorCmpInt; +#[derive(ViolationMetadata)] +pub(crate) struct SysVersionInfoMinorCmpInt; impl Violation for SysVersionInfoMinorCmpInt { #[derive_message_formats] @@ -212,8 +212,8 @@ impl Violation for SysVersionInfoMinorCmpInt { /// ## References /// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version) /// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info) -#[violation] -pub struct SysVersionCmpStr10; +#[derive(ViolationMetadata)] +pub(crate) struct SysVersionCmpStr10; impl Violation for SysVersionCmpStr10 { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_2020/rules/name_or_attribute.rs b/crates/ruff_linter/src/rules/flake8_2020/rules/name_or_attribute.rs index eb3178bfce697..e92b619a2a208 100644 --- a/crates/ruff_linter/src/rules/flake8_2020/rules/name_or_attribute.rs +++ b/crates/ruff_linter/src/rules/flake8_2020/rules/name_or_attribute.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Expr; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -35,8 +35,8 @@ use crate::checkers::ast::Checker; /// - [PyPI: `six`](https://pypi.org/project/six/) /// - [Six documentation: `six.PY2`](https://six.readthedocs.io/#six.PY2) /// - [Six documentation: `six.PY3`](https://six.readthedocs.io/#six.PY3) -#[violation] -pub struct SixPY3; +#[derive(ViolationMetadata)] +pub(crate) struct SixPY3; impl Violation for SixPY3 { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_2020/rules/subscript.rs b/crates/ruff_linter/src/rules/flake8_2020/rules/subscript.rs index f2ea8cd115e11..e853aba6144e6 100644 --- a/crates/ruff_linter/src/rules/flake8_2020/rules/subscript.rs +++ b/crates/ruff_linter/src/rules/flake8_2020/rules/subscript.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -37,8 +37,8 @@ use crate::rules::flake8_2020::helpers::is_sys; /// ## References /// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version) /// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info) -#[violation] -pub struct SysVersionSlice3; +#[derive(ViolationMetadata)] +pub(crate) struct SysVersionSlice3; impl Violation for SysVersionSlice3 { #[derive_message_formats] @@ -77,8 +77,8 @@ impl Violation for SysVersionSlice3 { /// ## References /// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version) /// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info) -#[violation] -pub struct SysVersion2; +#[derive(ViolationMetadata)] +pub(crate) struct SysVersion2; impl Violation for SysVersion2 { #[derive_message_formats] @@ -117,8 +117,8 @@ impl Violation for SysVersion2 { /// ## References /// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version) /// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info) -#[violation] -pub struct SysVersion0; +#[derive(ViolationMetadata)] +pub(crate) struct SysVersion0; impl Violation for SysVersion0 { #[derive_message_formats] @@ -157,8 +157,8 @@ impl Violation for SysVersion0 { /// ## References /// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version) /// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info) -#[violation] -pub struct SysVersionSlice1; +#[derive(ViolationMetadata)] +pub(crate) struct SysVersionSlice1; impl Violation for SysVersionSlice1 { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs b/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs index aed85eb102832..ee7ad9b1aecbc 100644 --- a/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs +++ b/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::ReturnStatementVisitor; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::visitor::Visitor; @@ -33,8 +33,8 @@ use crate::rules::ruff::typing::type_hint_resolves_to_any; /// ```python /// def foo(x: int): ... /// ``` -#[violation] -pub struct MissingTypeFunctionArgument { +#[derive(ViolationMetadata)] +pub(crate) struct MissingTypeFunctionArgument { name: String, } @@ -65,8 +65,8 @@ impl Violation for MissingTypeFunctionArgument { /// ```python /// def foo(*args: int): ... /// ``` -#[violation] -pub struct MissingTypeArgs { +#[derive(ViolationMetadata)] +pub(crate) struct MissingTypeArgs { name: String, } @@ -97,8 +97,8 @@ impl Violation for MissingTypeArgs { /// ```python /// def foo(**kwargs: int): ... /// ``` -#[violation] -pub struct MissingTypeKwargs { +#[derive(ViolationMetadata)] +pub(crate) struct MissingTypeKwargs { name: String, } @@ -137,9 +137,9 @@ impl Violation for MissingTypeKwargs { /// class Foo: /// def bar(self: "Foo"): ... /// ``` -#[violation] +#[derive(ViolationMetadata)] #[deprecated(note = "ANN101 has been removed")] -pub struct MissingTypeSelf; +pub(crate) struct MissingTypeSelf; #[allow(deprecated)] impl Violation for MissingTypeSelf { @@ -181,9 +181,9 @@ impl Violation for MissingTypeSelf { /// @classmethod /// def bar(cls: Type["Foo"]): ... /// ``` -#[violation] +#[derive(ViolationMetadata)] #[deprecated(note = "ANN102 has been removed")] -pub struct MissingTypeCls; +pub(crate) struct MissingTypeCls; #[allow(deprecated)] impl Violation for MissingTypeCls { @@ -215,8 +215,8 @@ impl Violation for MissingTypeCls { /// def add(a: int, b: int) -> int: /// return a + b /// ``` -#[violation] -pub struct MissingReturnTypeUndocumentedPublicFunction { +#[derive(ViolationMetadata)] +pub(crate) struct MissingReturnTypeUndocumentedPublicFunction { name: String, annotation: Option, } @@ -258,8 +258,8 @@ impl Violation for MissingReturnTypeUndocumentedPublicFunction { /// def _add(a: int, b: int) -> int: /// return a + b /// ``` -#[violation] -pub struct MissingReturnTypePrivateFunction { +#[derive(ViolationMetadata)] +pub(crate) struct MissingReturnTypePrivateFunction { name: String, annotation: Option, } @@ -314,8 +314,8 @@ impl Violation for MissingReturnTypePrivateFunction { /// def __init__(self, x: int) -> None: /// self.x = x /// ``` -#[violation] -pub struct MissingReturnTypeSpecialMethod { +#[derive(ViolationMetadata)] +pub(crate) struct MissingReturnTypeSpecialMethod { name: String, annotation: Option, } @@ -361,8 +361,8 @@ impl Violation for MissingReturnTypeSpecialMethod { /// def bar() -> int: /// return 1 /// ``` -#[violation] -pub struct MissingReturnTypeStaticMethod { +#[derive(ViolationMetadata)] +pub(crate) struct MissingReturnTypeStaticMethod { name: String, annotation: Option, } @@ -408,8 +408,8 @@ impl Violation for MissingReturnTypeStaticMethod { /// def bar(cls) -> int: /// return 1 /// ``` -#[violation] -pub struct MissingReturnTypeClassMethod { +#[derive(ViolationMetadata)] +pub(crate) struct MissingReturnTypeClassMethod { name: String, annotation: Option, } @@ -474,8 +474,8 @@ impl Violation for MissingReturnTypeClassMethod { /// - [Typing spec: `Any`](https://typing.readthedocs.io/en/latest/spec/special-types.html#any) /// - [Python documentation: `typing.Any`](https://docs.python.org/3/library/typing.html#typing.Any) /// - [Mypy documentation: The Any type](https://mypy.readthedocs.io/en/stable/kinds_of_types.html#the-any-type) -#[violation] -pub struct AnyType { +#[derive(ViolationMetadata)] +pub(crate) struct AnyType { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/async_busy_wait.rs b/crates/ruff_linter/src/rules/flake8_async/rules/async_busy_wait.rs index 9ee406c75b826..c5da23555a5fa 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/async_busy_wait.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/async_busy_wait.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_text_size::Ranged; @@ -37,8 +37,8 @@ use crate::rules::flake8_async::helpers::AsyncModule; /// - [`asyncio` events](https://docs.python.org/3/library/asyncio-sync.html#asyncio.Event) /// - [`anyio` events](https://trio.readthedocs.io/en/latest/reference-core.html#trio.Event) /// - [`trio` events](https://anyio.readthedocs.io/en/latest/api.html#anyio.Event) -#[violation] -pub struct AsyncBusyWait { +#[derive(ViolationMetadata)] +pub(crate) struct AsyncBusyWait { module: AsyncModule, } diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/async_function_with_timeout.rs b/crates/ruff_linter/src/rules/flake8_async/rules/async_function_with_timeout.rs index e13888e57bb6a..172b219dc349f 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/async_function_with_timeout.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/async_function_with_timeout.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -8,6 +8,7 @@ use crate::checkers::ast::Checker; use crate::rules::flake8_async::helpers::AsyncModule; use crate::settings::types::PythonVersion; +#[allow(clippy::doc_link_with_quotes)] /// ## What it does /// Checks for `async` function definitions with `timeout` parameters. /// @@ -63,8 +64,8 @@ use crate::settings::types::PythonVersion; /// - [`trio` timeouts](https://trio.readthedocs.io/en/stable/reference-core.html#cancellation-and-timeouts) /// /// ["structured concurrency"]: https://vorpus.org/blog/some-thoughts-on-asynchronous-api-design-in-a-post-asyncawait-world/#timeouts-and-cancellation -#[violation] -pub struct AsyncFunctionWithTimeout { +#[derive(ViolationMetadata)] +pub(crate) struct AsyncFunctionWithTimeout { module: AsyncModule, } diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/async_zero_sleep.rs b/crates/ruff_linter/src/rules/flake8_async/rules/async_zero_sleep.rs index 3b09122e52e30..31e1126e69c5d 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/async_zero_sleep.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/async_zero_sleep.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, ExprCall, Int, Number}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -32,8 +32,8 @@ use crate::rules::flake8_async::helpers::AsyncModule; /// async def func(): /// await trio.lowlevel.checkpoint() /// ``` -#[violation] -pub struct AsyncZeroSleep { +#[derive(ViolationMetadata)] +pub(crate) struct AsyncZeroSleep { module: AsyncModule, } diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_http_call.rs b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_http_call.rs index 7b8de7a8a73f3..2ca475961985c 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_http_call.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_http_call.rs @@ -1,7 +1,7 @@ use ruff_python_ast::ExprCall; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::QualifiedName; use ruff_text_size::Ranged; @@ -31,8 +31,8 @@ use crate::checkers::ast::Checker; /// async with session.get("https://example.com/foo/bar") as resp: /// ... /// ``` -#[violation] -pub struct BlockingHttpCallInAsyncFunction; +#[derive(ViolationMetadata)] +pub(crate) struct BlockingHttpCallInAsyncFunction; impl Violation for BlockingHttpCallInAsyncFunction { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_open_call.rs b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_open_call.rs index 97c21fffedda1..3f8ac8ba7b7b6 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_open_call.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_open_call.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::{analyze, SemanticModel}; use ruff_text_size::Ranged; @@ -33,8 +33,8 @@ use crate::checkers::ast::Checker; /// async with await anyio.open_file("bar.txt") as f: /// contents = await f.read() /// ``` -#[violation] -pub struct BlockingOpenCallInAsyncFunction; +#[derive(ViolationMetadata)] +pub(crate) struct BlockingOpenCallInAsyncFunction; impl Violation for BlockingOpenCallInAsyncFunction { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_process_invocation.rs b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_process_invocation.rs index 1e41d8233e861..2e7843c64324a 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_process_invocation.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_process_invocation.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, DiagnosticKind, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::analyze::typing::find_assigned_value; use ruff_python_semantic::SemanticModel; @@ -30,8 +30,8 @@ use crate::registry::AsRule; /// async def foo(): /// asyncio.create_subprocess_shell(cmd) /// ``` -#[violation] -pub struct CreateSubprocessInAsyncFunction; +#[derive(ViolationMetadata)] +pub(crate) struct CreateSubprocessInAsyncFunction; impl Violation for CreateSubprocessInAsyncFunction { #[derive_message_formats] @@ -62,8 +62,8 @@ impl Violation for CreateSubprocessInAsyncFunction { /// async def foo(): /// asyncio.create_subprocess_shell(cmd) /// ``` -#[violation] -pub struct RunProcessInAsyncFunction; +#[derive(ViolationMetadata)] +pub(crate) struct RunProcessInAsyncFunction; impl Violation for RunProcessInAsyncFunction { #[derive_message_formats] @@ -98,8 +98,8 @@ impl Violation for RunProcessInAsyncFunction { /// async def foo(): /// await asyncio.loop.run_in_executor(None, wait_for_process) /// ``` -#[violation] -pub struct WaitForProcessInAsyncFunction; +#[derive(ViolationMetadata)] +pub(crate) struct WaitForProcessInAsyncFunction; impl Violation for WaitForProcessInAsyncFunction { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_sleep.rs b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_sleep.rs index 61de6318db399..36583e385ab85 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_sleep.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_sleep.rs @@ -1,7 +1,7 @@ use ruff_python_ast::ExprCall; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::QualifiedName; use ruff_text_size::Ranged; @@ -28,8 +28,8 @@ use crate::checkers::ast::Checker; /// async def fetch(): /// await asyncio.sleep(1) /// ``` -#[violation] -pub struct BlockingSleepInAsyncFunction; +#[derive(ViolationMetadata)] +pub(crate) struct BlockingSleepInAsyncFunction; impl Violation for BlockingSleepInAsyncFunction { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/cancel_scope_no_checkpoint.rs b/crates/ruff_linter/src/rules/flake8_async/rules/cancel_scope_no_checkpoint.rs index 408aefca50bc3..9c9b94a103db1 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/cancel_scope_no_checkpoint.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/cancel_scope_no_checkpoint.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::{any_over_body, AwaitVisitor}; use ruff_python_ast::visitor::Visitor; use ruff_python_ast::{Expr, StmtWith, WithItem}; @@ -38,8 +38,8 @@ use crate::rules::flake8_async::helpers::MethodName; /// - [`asyncio` timeouts](https://docs.python.org/3/library/asyncio-task.html#timeouts) /// - [`anyio` timeouts](https://anyio.readthedocs.io/en/stable/cancellation.html) /// - [`trio` timeouts](https://trio.readthedocs.io/en/stable/reference-core.html#cancellation-and-timeouts) -#[violation] -pub struct CancelScopeNoCheckpoint { +#[derive(ViolationMetadata)] +pub(crate) struct CancelScopeNoCheckpoint { method_name: MethodName, } diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/long_sleep_not_forever.rs b/crates/ruff_linter/src/rules/flake8_async/rules/long_sleep_not_forever.rs index 4ab4460113adc..6d37fe24596ee 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/long_sleep_not_forever.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/long_sleep_not_forever.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Expr, ExprCall, ExprNumberLiteral, Number}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -34,8 +34,8 @@ use crate::rules::flake8_async::helpers::AsyncModule; /// async def func(): /// await trio.sleep_forever() /// ``` -#[violation] -pub struct LongSleepNotForever { +#[derive(ViolationMetadata)] +pub(crate) struct LongSleepNotForever { module: AsyncModule, } diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/sync_call.rs b/crates/ruff_linter/src/rules/flake8_async/rules/sync_call.rs index 99a6cf326563a..8315a71b5215b 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/sync_call.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/sync_call.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Expr, ExprCall}; use ruff_python_semantic::Modules; use ruff_text_size::{Ranged, TextRange}; @@ -31,8 +31,8 @@ use crate::rules::flake8_async::helpers::MethodName; /// ## Fix safety /// This rule's fix is marked as unsafe, as adding an `await` to a function /// call changes its semantics and runtime behavior. -#[violation] -pub struct TrioSyncCall { +#[derive(ViolationMetadata)] +pub(crate) struct TrioSyncCall { method_name: MethodName, } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/assert_used.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/assert_used.rs index 6d840559d9681..458a8335b30d0 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/assert_used.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/assert_used.rs @@ -2,7 +2,7 @@ use ruff_python_ast::Stmt; use ruff_text_size::{TextLen, TextRange}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; /// ## What it does @@ -30,8 +30,8 @@ use ruff_text_size::Ranged; /// if x <= 0: /// raise ValueError("Expected positive value.") /// ``` -#[violation] -pub struct Assert; +#[derive(ViolationMetadata)] +pub(crate) struct Assert; impl Violation for Assert { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/bad_file_permissions.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/bad_file_permissions.rs index 12f9cce71fc8a..2fe7e159e4846 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/bad_file_permissions.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/bad_file_permissions.rs @@ -1,7 +1,7 @@ use anyhow::Result; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::QualifiedName; use ruff_python_ast::{self as ast, Expr, Operator}; use ruff_python_semantic::{Modules, SemanticModel}; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// - [Python documentation: `os.chmod`](https://docs.python.org/3/library/os.html#os.chmod) /// - [Python documentation: `stat`](https://docs.python.org/3/library/stat.html) /// - [Common Weakness Enumeration: CWE-732](https://cwe.mitre.org/data/definitions/732.html) -#[violation] -pub struct BadFilePermissions { +#[derive(ViolationMetadata)] +pub(crate) struct BadFilePermissions { reason: Reason, } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/django_extra.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/django_extra.rs index b8362cf055a2e..2473f69155277 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/django_extra.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/django_extra.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, ExprAttribute}; use ruff_text_size::Ranged; @@ -33,8 +33,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Django documentation: SQL injection protection](https://docs.djangoproject.com/en/dev/topics/security/#sql-injection-protection) /// - [Common Weakness Enumeration: CWE-89](https://cwe.mitre.org/data/definitions/89.html) -#[violation] -pub struct DjangoExtra; +#[derive(ViolationMetadata)] +pub(crate) struct DjangoExtra; impl Violation for DjangoExtra { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/django_raw_sql.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/django_raw_sql.rs index e23aec64c5b19..ed75a1b05b52b 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/django_raw_sql.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/django_raw_sql.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -24,8 +24,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Django documentation: SQL injection protection](https://docs.djangoproject.com/en/dev/topics/security/#sql-injection-protection) /// - [Common Weakness Enumeration: CWE-89](https://cwe.mitre.org/data/definitions/89.html) -#[violation] -pub struct DjangoRawSql; +#[derive(ViolationMetadata)] +pub(crate) struct DjangoRawSql; impl Violation for DjangoRawSql { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/exec_used.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/exec_used.rs index 23d9b18c1d9a9..b09429dda5afb 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/exec_used.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/exec_used.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -21,8 +21,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: `exec`](https://docs.python.org/3/library/functions.html#exec) /// - [Common Weakness Enumeration: CWE-78](https://cwe.mitre.org/data/definitions/78.html) -#[violation] -pub struct ExecBuiltin; +#[derive(ViolationMetadata)] +pub(crate) struct ExecBuiltin; impl Violation for ExecBuiltin { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/flask_debug_true.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/flask_debug_true.rs index 7d0f03be594c5..960e742a94d5b 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/flask_debug_true.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/flask_debug_true.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_const_true; use ruff_python_ast::{Expr, ExprAttribute, ExprCall}; use ruff_python_semantic::analyze::typing; @@ -36,8 +36,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Flask documentation: Debug Mode](https://flask.palletsprojects.com/en/latest/quickstart/#debug-mode) -#[violation] -pub struct FlaskDebugTrue; +#[derive(ViolationMetadata)] +pub(crate) struct FlaskDebugTrue; impl Violation for FlaskDebugTrue { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs index e3bd68b829787..a1e4739d84dce 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, StringLike}; use ruff_text_size::Ranged; @@ -26,8 +26,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Common Weakness Enumeration: CWE-200](https://cwe.mitre.org/data/definitions/200.html) -#[violation] -pub struct HardcodedBindAllInterfaces; +#[derive(ViolationMetadata)] +pub(crate) struct HardcodedBindAllInterfaces; impl Violation for HardcodedBindAllInterfaces { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_default.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_default.rs index ade608a1d5829..925002e0669cd 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_default.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_default.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{Expr, Parameter, ParameterWithDefault, Parameters}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -38,8 +38,8 @@ use super::super::helpers::{matches_password_name, string_literal}; /// /// ## References /// - [Common Weakness Enumeration: CWE-259](https://cwe.mitre.org/data/definitions/259.html) -#[violation] -pub struct HardcodedPasswordDefault { +#[derive(ViolationMetadata)] +pub(crate) struct HardcodedPasswordDefault { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_func_arg.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_func_arg.rs index 3c5d48ac19a9f..378be84695b3f 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_func_arg.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_func_arg.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Keyword; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -34,8 +34,8 @@ use super::super::helpers::{matches_password_name, string_literal}; /// /// ## References /// - [Common Weakness Enumeration: CWE-259](https://cwe.mitre.org/data/definitions/259.html) -#[violation] -pub struct HardcodedPasswordFuncArg { +#[derive(ViolationMetadata)] +pub(crate) struct HardcodedPasswordFuncArg { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_string.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_string.rs index 13e74cabeafb0..cb7ce5c297b97 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_string.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_password_string.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -33,8 +33,8 @@ use super::super::helpers::{matches_password_name, string_literal}; /// /// ## References /// - [Common Weakness Enumeration: CWE-259](https://cwe.mitre.org/data/definitions/259.html) -#[violation] -pub struct HardcodedPasswordString { +#[derive(ViolationMetadata)] +pub(crate) struct HardcodedPasswordString { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs index 45e9c6229c003..607db1eb569f8 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs @@ -3,7 +3,7 @@ use std::sync::LazyLock; use regex::Regex; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::str::raw_contents; use ruff_python_ast::{self as ast, Expr, Operator}; use ruff_text_size::Ranged; @@ -35,8 +35,8 @@ static SQL_REGEX: LazyLock = LazyLock::new(|| { /// ## References /// - [B608: Test for SQL injection](https://bandit.readthedocs.io/en/latest/plugins/b608_hardcoded_sql_expressions.html) /// - [psycopg3: Server-side binding](https://www.psycopg.org/psycopg3/docs/basic/from_pg2.html#server-side-binding) -#[violation] -pub struct HardcodedSQLExpression; +#[derive(ViolationMetadata)] +pub(crate) struct HardcodedSQLExpression; impl Violation for HardcodedSQLExpression { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs index b57ad8d395431..911bfc5b922de 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Expr, StringLike}; use ruff_text_size::{Ranged, TextRange}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::checkers::ast::Checker; @@ -39,8 +39,8 @@ use crate::checkers::ast::Checker; /// - [Common Weakness Enumeration: CWE-377](https://cwe.mitre.org/data/definitions/377.html) /// - [Common Weakness Enumeration: CWE-379](https://cwe.mitre.org/data/definitions/379.html) /// - [Python documentation: `tempfile`](https://docs.python.org/3/library/tempfile.html) -#[violation] -pub struct HardcodedTempFile { +#[derive(ViolationMetadata)] +pub(crate) struct HardcodedTempFile { string: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs index e19d6eb848db1..a02e922310cdd 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_const_false; use ruff_python_ast::{self as ast, Arguments}; use ruff_text_size::Ranged; @@ -48,8 +48,8 @@ use super::super::helpers::string_literal; /// - [Common Weakness Enumeration: CWE-327](https://cwe.mitre.org/data/definitions/327.html) /// - [Common Weakness Enumeration: CWE-328](https://cwe.mitre.org/data/definitions/328.html) /// - [Common Weakness Enumeration: CWE-916](https://cwe.mitre.org/data/definitions/916.html) -#[violation] -pub struct HashlibInsecureHashFunction { +#[derive(ViolationMetadata)] +pub(crate) struct HashlibInsecureHashFunction { library: String, string: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs index ba7737183f520..478aecb423a5e 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/jinja2_autoescape_false.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Jinja documentation: API](https://jinja.palletsprojects.com/en/latest/api/#autoescaping) /// - [Common Weakness Enumeration: CWE-94](https://cwe.mitre.org/data/definitions/94.html) -#[violation] -pub struct Jinja2AutoescapeFalse { +#[derive(ViolationMetadata)] +pub(crate) struct Jinja2AutoescapeFalse { value: bool, } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/logging_config_insecure_listen.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/logging_config_insecure_listen.rs index a685944cf058c..b10b2aa26b2f2 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/logging_config_insecure_listen.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/logging_config_insecure_listen.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -24,8 +24,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `logging.config.listen()`](https://docs.python.org/3/library/logging.config.html#logging.config.listen) -#[violation] -pub struct LoggingConfigInsecureListen; +#[derive(ViolationMetadata)] +pub(crate) struct LoggingConfigInsecureListen; impl Violation for LoggingConfigInsecureListen { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/mako_templates.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/mako_templates.rs index 867d51d548166..a0b1ff20d4883 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/mako_templates.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/mako_templates.rs @@ -1,6 +1,6 @@ use crate::checkers::ast::Checker; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast}; use ruff_text_size::Ranged; @@ -31,8 +31,8 @@ use ruff_text_size::Ranged; /// - [Mako documentation](https://www.makotemplates.org/) /// - [OpenStack security: Cross site scripting XSS](https://security.openstack.org/guidelines/dg_cross-site-scripting-xss.html) /// - [Common Weakness Enumeration: CWE-80](https://cwe.mitre.org/data/definitions/80.html) -#[violation] -pub struct MakoTemplates; +#[derive(ViolationMetadata)] +pub(crate) struct MakoTemplates; impl Violation for MakoTemplates { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/paramiko_calls.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/paramiko_calls.rs index 098825e327bfa..f4f5f55ffe576 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/paramiko_calls.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/paramiko_calls.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -25,8 +25,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Common Weakness Enumeration: CWE-78](https://cwe.mitre.org/data/definitions/78.html) /// - [Paramiko documentation: `SSHClient.exec_command()`](https://docs.paramiko.org/en/stable/api/client.html#paramiko.client.SSHClient.exec_command) -#[violation] -pub struct ParamikoCall; +#[derive(ViolationMetadata)] +pub(crate) struct ParamikoCall; impl Violation for ParamikoCall { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/request_with_no_cert_validation.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/request_with_no_cert_validation.rs index 463a73376be7f..a2b7358999e6a 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/request_with_no_cert_validation.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/request_with_no_cert_validation.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::helpers::is_const_false; use ruff_text_size::Ranged; @@ -30,8 +30,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Common Weakness Enumeration: CWE-295](https://cwe.mitre.org/data/definitions/295.html) -#[violation] -pub struct RequestWithNoCertValidation { +#[derive(ViolationMetadata)] +pub(crate) struct RequestWithNoCertValidation { string: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/request_without_timeout.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/request_without_timeout.rs index a5c08b1f123e1..641e5b267946a 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/request_without_timeout.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/request_without_timeout.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_text_size::Ranged; @@ -32,8 +32,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Requests documentation: Timeouts](https://requests.readthedocs.io/en/latest/user/advanced/#timeouts) /// - [httpx documentation: Timeouts](https://www.python-httpx.org/advanced/timeouts/) -#[violation] -pub struct RequestWithoutTimeout { +#[derive(ViolationMetadata)] +pub(crate) struct RequestWithoutTimeout { implicit: bool, module: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs index 584ae5f801e5d..b8854a91e1b59 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs @@ -1,7 +1,7 @@ //! Checks relating to shell injection. use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::Truthiness; use ruff_python_ast::{self as ast, Arguments, Expr}; use ruff_python_semantic::SemanticModel; @@ -36,8 +36,8 @@ use crate::{ /// ## References /// - [Python documentation: `subprocess` — Subprocess management](https://docs.python.org/3/library/subprocess.html) /// - [Common Weakness Enumeration: CWE-78](https://cwe.mitre.org/data/definitions/78.html) -#[violation] -pub struct SubprocessPopenWithShellEqualsTrue { +#[derive(ViolationMetadata)] +pub(crate) struct SubprocessPopenWithShellEqualsTrue { safety: Safety, is_exact: bool, } @@ -78,8 +78,8 @@ impl Violation for SubprocessPopenWithShellEqualsTrue { /// - [Python documentation: `subprocess` — Subprocess management](https://docs.python.org/3/library/subprocess.html) /// /// [#4045]: https://github.com/astral-sh/ruff/issues/4045 -#[violation] -pub struct SubprocessWithoutShellEqualsTrue; +#[derive(ViolationMetadata)] +pub(crate) struct SubprocessWithoutShellEqualsTrue; impl Violation for SubprocessWithoutShellEqualsTrue { #[derive_message_formats] @@ -116,8 +116,8 @@ impl Violation for SubprocessWithoutShellEqualsTrue { /// /// ## References /// - [Python documentation: Security Considerations](https://docs.python.org/3/library/subprocess.html#security-considerations) -#[violation] -pub struct CallWithShellEqualsTrue { +#[derive(ViolationMetadata)] +pub(crate) struct CallWithShellEqualsTrue { is_exact: bool, } @@ -168,8 +168,8 @@ impl Violation for CallWithShellEqualsTrue { /// /// ## References /// - [Python documentation: `subprocess`](https://docs.python.org/3/library/subprocess.html) -#[violation] -pub struct StartProcessWithAShell { +#[derive(ViolationMetadata)] +pub(crate) struct StartProcessWithAShell { safety: Safety, } @@ -209,8 +209,8 @@ impl Violation for StartProcessWithAShell { /// ``` /// /// [start-process-with-a-shell]: https://docs.astral.sh/ruff/rules/start-process-with-a-shell/#start-process-with-a-shell-s605 -#[violation] -pub struct StartProcessWithNoShell; +#[derive(ViolationMetadata)] +pub(crate) struct StartProcessWithNoShell; impl Violation for StartProcessWithNoShell { #[derive_message_formats] @@ -244,8 +244,8 @@ impl Violation for StartProcessWithNoShell { /// ## References /// - [Python documentation: `subprocess.Popen()`](https://docs.python.org/3/library/subprocess.html#subprocess.Popen) /// - [Common Weakness Enumeration: CWE-426](https://cwe.mitre.org/data/definitions/426.html) -#[violation] -pub struct StartProcessWithPartialPath; +#[derive(ViolationMetadata)] +pub(crate) struct StartProcessWithPartialPath; impl Violation for StartProcessWithPartialPath { #[derive_message_formats] @@ -277,8 +277,8 @@ impl Violation for StartProcessWithPartialPath { /// /// ## References /// - [Common Weakness Enumeration: CWE-78](https://cwe.mitre.org/data/definitions/78.html) -#[violation] -pub struct UnixCommandWildcardInjection; +#[derive(ViolationMetadata)] +pub(crate) struct UnixCommandWildcardInjection; impl Violation for UnixCommandWildcardInjection { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_insecure_version.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_insecure_version.rs index c82d54651ee4c..21c3638ae84c8 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_insecure_version.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_insecure_version.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Int}; use ruff_text_size::Ranged; @@ -30,8 +30,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Cybersecurity and Infrastructure Security Agency (CISA): Alert TA17-156A](https://www.cisa.gov/news-events/alerts/2017/06/05/reducing-risk-snmp-abuse) /// - [Common Weakness Enumeration: CWE-319](https://cwe.mitre.org/data/definitions/319.html) -#[violation] -pub struct SnmpInsecureVersion; +#[derive(ViolationMetadata)] +pub(crate) struct SnmpInsecureVersion; impl Violation for SnmpInsecureVersion { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_weak_cryptography.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_weak_cryptography.rs index e8bfee7714c7e..23231f1b7c700 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_weak_cryptography.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/snmp_weak_cryptography.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast}; use ruff_text_size::Ranged; @@ -28,8 +28,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Common Weakness Enumeration: CWE-319](https://cwe.mitre.org/data/definitions/319.html) -#[violation] -pub struct SnmpWeakCryptography; +#[derive(ViolationMetadata)] +pub(crate) struct SnmpWeakCryptography; impl Violation for SnmpWeakCryptography { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssh_no_host_key_verification.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssh_no_host_key_verification.rs index 1a9abd519a076..996167379b29b 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssh_no_host_key_verification.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssh_no_host_key_verification.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::map_callable; use ruff_python_ast::{Expr, ExprAttribute, ExprCall}; use ruff_python_semantic::analyze::typing; @@ -33,8 +33,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Paramiko documentation: set_missing_host_key_policy](https://docs.paramiko.org/en/latest/api/client.html#paramiko.client.SSHClient.set_missing_host_key_policy) -#[violation] -pub struct SSHNoHostKeyVerification; +#[derive(ViolationMetadata)] +pub(crate) struct SSHNoHostKeyVerification; impl Violation for SSHNoHostKeyVerification { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_insecure_version.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_insecure_version.rs index 796c7979a3e29..ca565b2e5df63 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_insecure_version.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_insecure_version.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, ExprCall}; use ruff_text_size::Ranged; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// /// ssl.wrap_socket(ssl_version=ssl.PROTOCOL_TLSv1_2) /// ``` -#[violation] -pub struct SslInsecureVersion { +#[derive(ViolationMetadata)] +pub(crate) struct SslInsecureVersion { protocol: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_bad_defaults.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_bad_defaults.rs index bfff9cbf343d0..710cda5c116eb 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_bad_defaults.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_bad_defaults.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, StmtFunctionDef}; use crate::checkers::ast::Checker; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// /// def func(version=ssl.PROTOCOL_TLSv1_2): ... /// ``` -#[violation] -pub struct SslWithBadDefaults { +#[derive(ViolationMetadata)] +pub(crate) struct SslWithBadDefaults { protocol: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_no_version.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_no_version.rs index 69f1cd1df27a3..7623270692f10 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_no_version.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/ssl_with_no_version.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::ExprCall; use ruff_text_size::Ranged; @@ -25,8 +25,8 @@ use crate::checkers::ast::Checker; /// /// ssl.wrap_socket(ssl_version=ssl.PROTOCOL_TLSv1_2) /// ``` -#[violation] -pub struct SslWithNoVersion; +#[derive(ViolationMetadata)] +pub(crate) struct SslWithNoVersion; impl Violation for SslWithNoVersion { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_function_call.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_function_call.rs index 1cfb38b1cdbee..a5af59e8dff9d 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_function_call.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_function_call.rs @@ -3,7 +3,7 @@ //! See: use itertools::Either; use ruff_diagnostics::{Diagnostic, DiagnosticKind, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Decorator, Expr, ExprCall, Operator}; use ruff_text_size::Ranged; @@ -46,8 +46,8 @@ use crate::registry::AsRule; /// ## References /// - [Python documentation: `pickle` — Python object serialization](https://docs.python.org/3/library/pickle.html) /// - [Common Weakness Enumeration: CWE-502](https://cwe.mitre.org/data/definitions/502.html) -#[violation] -pub struct SuspiciousPickleUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousPickleUsage; impl Violation for SuspiciousPickleUsage { #[derive_message_formats] @@ -91,8 +91,8 @@ impl Violation for SuspiciousPickleUsage { /// ## References /// - [Python documentation: `marshal` — Internal Python object serialization](https://docs.python.org/3/library/marshal.html) /// - [Common Weakness Enumeration: CWE-502](https://cwe.mitre.org/data/definitions/502.html) -#[violation] -pub struct SuspiciousMarshalUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousMarshalUsage; impl Violation for SuspiciousMarshalUsage { #[derive_message_formats] @@ -137,8 +137,8 @@ impl Violation for SuspiciousMarshalUsage { /// - [Common Weakness Enumeration: CWE-327](https://cwe.mitre.org/data/definitions/327.html) /// - [Common Weakness Enumeration: CWE-328](https://cwe.mitre.org/data/definitions/328.html) /// - [Common Weakness Enumeration: CWE-916](https://cwe.mitre.org/data/definitions/916.html) -#[violation] -pub struct SuspiciousInsecureHashUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousInsecureHashUsage; impl Violation for SuspiciousInsecureHashUsage { #[derive_message_formats] @@ -175,8 +175,8 @@ impl Violation for SuspiciousInsecureHashUsage { /// /// ## References /// - [Common Weakness Enumeration: CWE-327](https://cwe.mitre.org/data/definitions/327.html) -#[violation] -pub struct SuspiciousInsecureCipherUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousInsecureCipherUsage; impl Violation for SuspiciousInsecureCipherUsage { #[derive_message_formats] @@ -215,8 +215,8 @@ impl Violation for SuspiciousInsecureCipherUsage { /// /// ## References /// - [Common Weakness Enumeration: CWE-327](https://cwe.mitre.org/data/definitions/327.html) -#[violation] -pub struct SuspiciousInsecureCipherModeUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousInsecureCipherModeUsage; impl Violation for SuspiciousInsecureCipherModeUsage { #[derive_message_formats] @@ -260,8 +260,8 @@ impl Violation for SuspiciousInsecureCipherModeUsage { /// /// ## References /// - [Python documentation:`mktemp`](https://docs.python.org/3/library/tempfile.html#tempfile.mktemp) -#[violation] -pub struct SuspiciousMktempUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousMktempUsage; impl Violation for SuspiciousMktempUsage { #[derive_message_formats] @@ -296,8 +296,8 @@ impl Violation for SuspiciousMktempUsage { /// - [Python documentation: `eval`](https://docs.python.org/3/library/functions.html#eval) /// - [Python documentation: `literal_eval`](https://docs.python.org/3/library/ast.html#ast.literal_eval) /// - [_Eval really is dangerous_ by Ned Batchelder](https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html) -#[violation] -pub struct SuspiciousEvalUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousEvalUsage; impl Violation for SuspiciousEvalUsage { #[derive_message_formats] @@ -335,8 +335,8 @@ impl Violation for SuspiciousEvalUsage { /// - [Django documentation: `mark_safe`](https://docs.djangoproject.com/en/dev/ref/utils/#django.utils.safestring.mark_safe) /// - [Django documentation: Cross Site Scripting (XSS) protection](https://docs.djangoproject.com/en/dev/topics/security/#cross-site-scripting-xss-protection) /// - [Common Weakness Enumeration: CWE-80](https://cwe.mitre.org/data/definitions/80.html) -#[violation] -pub struct SuspiciousMarkSafeUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousMarkSafeUsage; impl Violation for SuspiciousMarkSafeUsage { #[derive_message_formats] @@ -383,8 +383,8 @@ impl Violation for SuspiciousMarkSafeUsage { /// /// ## References /// - [Python documentation: `urlopen`](https://docs.python.org/3/library/urllib.request.html#urllib.request.urlopen) -#[violation] -pub struct SuspiciousURLOpenUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousURLOpenUsage; impl Violation for SuspiciousURLOpenUsage { #[derive_message_formats] @@ -421,8 +421,8 @@ impl Violation for SuspiciousURLOpenUsage { /// /// ## References /// - [Python documentation: `random` — Generate pseudo-random numbers](https://docs.python.org/3/library/random.html) -#[violation] -pub struct SuspiciousNonCryptographicRandomUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousNonCryptographicRandomUsage; impl Violation for SuspiciousNonCryptographicRandomUsage { #[derive_message_formats] @@ -461,8 +461,8 @@ impl Violation for SuspiciousNonCryptographicRandomUsage { /// - [PyPI: `defusedxml`](https://pypi.org/project/defusedxml/) /// - [Common Weakness Enumeration: CWE-400](https://cwe.mitre.org/data/definitions/400.html) /// - [Common Weakness Enumeration: CWE-776](https://cwe.mitre.org/data/definitions/776.html) -#[violation] -pub struct SuspiciousXMLCElementTreeUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousXMLCElementTreeUsage; impl Violation for SuspiciousXMLCElementTreeUsage { #[derive_message_formats] @@ -501,8 +501,8 @@ impl Violation for SuspiciousXMLCElementTreeUsage { /// - [PyPI: `defusedxml`](https://pypi.org/project/defusedxml/) /// - [Common Weakness Enumeration: CWE-400](https://cwe.mitre.org/data/definitions/400.html) /// - [Common Weakness Enumeration: CWE-776](https://cwe.mitre.org/data/definitions/776.html) -#[violation] -pub struct SuspiciousXMLElementTreeUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousXMLElementTreeUsage; impl Violation for SuspiciousXMLElementTreeUsage { #[derive_message_formats] @@ -541,8 +541,8 @@ impl Violation for SuspiciousXMLElementTreeUsage { /// - [PyPI: `defusedxml`](https://pypi.org/project/defusedxml/) /// - [Common Weakness Enumeration: CWE-400](https://cwe.mitre.org/data/definitions/400.html) /// - [Common Weakness Enumeration: CWE-776](https://cwe.mitre.org/data/definitions/776.html) -#[violation] -pub struct SuspiciousXMLExpatReaderUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousXMLExpatReaderUsage; impl Violation for SuspiciousXMLExpatReaderUsage { #[derive_message_formats] @@ -581,8 +581,8 @@ impl Violation for SuspiciousXMLExpatReaderUsage { /// - [PyPI: `defusedxml`](https://pypi.org/project/defusedxml/) /// - [Common Weakness Enumeration: CWE-400](https://cwe.mitre.org/data/definitions/400.html) /// - [Common Weakness Enumeration: CWE-776](https://cwe.mitre.org/data/definitions/776.html) -#[violation] -pub struct SuspiciousXMLExpatBuilderUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousXMLExpatBuilderUsage; impl Violation for SuspiciousXMLExpatBuilderUsage { #[derive_message_formats] @@ -621,8 +621,8 @@ impl Violation for SuspiciousXMLExpatBuilderUsage { /// - [PyPI: `defusedxml`](https://pypi.org/project/defusedxml/) /// - [Common Weakness Enumeration: CWE-400](https://cwe.mitre.org/data/definitions/400.html) /// - [Common Weakness Enumeration: CWE-776](https://cwe.mitre.org/data/definitions/776.html) -#[violation] -pub struct SuspiciousXMLSaxUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousXMLSaxUsage; impl Violation for SuspiciousXMLSaxUsage { #[derive_message_formats] @@ -661,8 +661,8 @@ impl Violation for SuspiciousXMLSaxUsage { /// - [PyPI: `defusedxml`](https://pypi.org/project/defusedxml/) /// - [Common Weakness Enumeration: CWE-400](https://cwe.mitre.org/data/definitions/400.html) /// - [Common Weakness Enumeration: CWE-776](https://cwe.mitre.org/data/definitions/776.html) -#[violation] -pub struct SuspiciousXMLMiniDOMUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousXMLMiniDOMUsage; impl Violation for SuspiciousXMLMiniDOMUsage { #[derive_message_formats] @@ -701,8 +701,8 @@ impl Violation for SuspiciousXMLMiniDOMUsage { /// - [PyPI: `defusedxml`](https://pypi.org/project/defusedxml/) /// - [Common Weakness Enumeration: CWE-400](https://cwe.mitre.org/data/definitions/400.html) /// - [Common Weakness Enumeration: CWE-776](https://cwe.mitre.org/data/definitions/776.html) -#[violation] -pub struct SuspiciousXMLPullDOMUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousXMLPullDOMUsage; impl Violation for SuspiciousXMLPullDOMUsage { #[derive_message_formats] @@ -730,8 +730,8 @@ impl Violation for SuspiciousXMLPullDOMUsage { /// - [PyPI: `lxml`](https://pypi.org/project/lxml/) /// - [Common Weakness Enumeration: CWE-400](https://cwe.mitre.org/data/definitions/400.html) /// - [Common Weakness Enumeration: CWE-776](https://cwe.mitre.org/data/definitions/776.html) -#[violation] -pub struct SuspiciousXMLETreeUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousXMLETreeUsage; impl Violation for SuspiciousXMLETreeUsage { #[derive_message_formats] @@ -773,8 +773,8 @@ impl Violation for SuspiciousXMLETreeUsage { /// - [Python documentation: `ssl` — TLS/SSL wrapper for socket objects](https://docs.python.org/3/library/ssl.html) /// /// [PEP 476]: https://peps.python.org/pep-0476/ -#[violation] -pub struct SuspiciousUnverifiedContextUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousUnverifiedContextUsage; impl Violation for SuspiciousUnverifiedContextUsage { #[derive_message_formats] @@ -794,8 +794,8 @@ impl Violation for SuspiciousUnverifiedContextUsage { /// /// ## References /// - [Python documentation: `telnetlib` — Telnet client](https://docs.python.org/3/library/telnetlib.html) -#[violation] -pub struct SuspiciousTelnetUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousTelnetUsage; impl Violation for SuspiciousTelnetUsage { #[derive_message_formats] @@ -815,8 +815,8 @@ impl Violation for SuspiciousTelnetUsage { /// /// ## References /// - [Python documentation: `ftplib` — FTP protocol client](https://docs.python.org/3/library/ftplib.html) -#[violation] -pub struct SuspiciousFTPLibUsage; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousFTPLibUsage; impl Violation for SuspiciousFTPLibUsage { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_imports.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_imports.rs index fb40986448824..9599abf657031 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_imports.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/suspicious_imports.rs @@ -2,7 +2,7 @@ //! //! See: use ruff_diagnostics::{Diagnostic, DiagnosticKind, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Stmt}; use ruff_text_size::{Ranged, TextRange}; @@ -25,8 +25,8 @@ use crate::registry::AsRule; /// ## References /// - [Python documentation: `telnetlib` - Telnet client](https://docs.python.org/3.12/library/telnetlib.html#module-telnetlib) /// - [PEP 594: `telnetlib`](https://peps.python.org/pep-0594/#telnetlib) -#[violation] -pub struct SuspiciousTelnetlibImport; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousTelnetlibImport; impl Violation for SuspiciousTelnetlibImport { #[derive_message_formats] @@ -49,8 +49,8 @@ impl Violation for SuspiciousTelnetlibImport { /// /// ## References /// - [Python documentation: `ftplib` - FTP protocol client](https://docs.python.org/3/library/ftplib.html) -#[violation] -pub struct SuspiciousFtplibImport; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousFtplibImport; impl Violation for SuspiciousFtplibImport { #[derive_message_formats] @@ -74,8 +74,8 @@ impl Violation for SuspiciousFtplibImport { /// /// ## References /// - [Python documentation: `pickle` — Python object serialization](https://docs.python.org/3/library/pickle.html) -#[violation] -pub struct SuspiciousPickleImport; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousPickleImport; impl Violation for SuspiciousPickleImport { #[derive_message_formats] @@ -95,8 +95,8 @@ impl Violation for SuspiciousPickleImport { /// ```python /// import subprocess /// ``` -#[violation] -pub struct SuspiciousSubprocessImport; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousSubprocessImport; impl Violation for SuspiciousSubprocessImport { #[derive_message_formats] @@ -118,8 +118,8 @@ impl Violation for SuspiciousSubprocessImport { /// ```python /// import xml.etree.cElementTree /// ``` -#[violation] -pub struct SuspiciousXmlEtreeImport; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousXmlEtreeImport; impl Violation for SuspiciousXmlEtreeImport { #[derive_message_formats] @@ -141,8 +141,8 @@ impl Violation for SuspiciousXmlEtreeImport { /// ```python /// import xml.sax /// ``` -#[violation] -pub struct SuspiciousXmlSaxImport; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousXmlSaxImport; impl Violation for SuspiciousXmlSaxImport { #[derive_message_formats] @@ -164,8 +164,8 @@ impl Violation for SuspiciousXmlSaxImport { /// ```python /// import xml.dom.expatbuilder /// ``` -#[violation] -pub struct SuspiciousXmlExpatImport; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousXmlExpatImport; impl Violation for SuspiciousXmlExpatImport { #[derive_message_formats] @@ -187,8 +187,8 @@ impl Violation for SuspiciousXmlExpatImport { /// ```python /// import xml.dom.minidom /// ``` -#[violation] -pub struct SuspiciousXmlMinidomImport; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousXmlMinidomImport; impl Violation for SuspiciousXmlMinidomImport { #[derive_message_formats] @@ -210,8 +210,8 @@ impl Violation for SuspiciousXmlMinidomImport { /// ```python /// import xml.dom.pulldom /// ``` -#[violation] -pub struct SuspiciousXmlPulldomImport; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousXmlPulldomImport; impl Violation for SuspiciousXmlPulldomImport { #[derive_message_formats] @@ -240,8 +240,8 @@ impl Violation for SuspiciousXmlPulldomImport { /// ``` /// /// [deprecated]: https://github.com/tiran/defusedxml/blob/c7445887f5e1bcea470a16f61369d29870cfcfe1/README.md#defusedxmllxml -#[violation] -pub struct SuspiciousLxmlImport; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousLxmlImport; impl Violation for SuspiciousLxmlImport { #[derive_message_formats] @@ -263,8 +263,8 @@ impl Violation for SuspiciousLxmlImport { /// ```python /// import xmlrpc /// ``` -#[violation] -pub struct SuspiciousXmlrpcImport; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousXmlrpcImport; impl Violation for SuspiciousXmlrpcImport { #[derive_message_formats] @@ -289,8 +289,8 @@ impl Violation for SuspiciousXmlrpcImport { /// /// ## References /// - [httpoxy website](https://httpoxy.org/) -#[violation] -pub struct SuspiciousHttpoxyImport; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousHttpoxyImport; impl Violation for SuspiciousHttpoxyImport { #[derive_message_formats] @@ -314,8 +314,8 @@ impl Violation for SuspiciousHttpoxyImport { /// /// ## References /// - [Buffer Overflow Issue](https://github.com/pycrypto/pycrypto/issues/176) -#[violation] -pub struct SuspiciousPycryptoImport; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousPycryptoImport; impl Violation for SuspiciousPycryptoImport { #[derive_message_formats] @@ -339,8 +339,8 @@ impl Violation for SuspiciousPycryptoImport { /// /// ## References /// - [Buffer Overflow Issue](https://github.com/pycrypto/pycrypto/issues/176) -#[violation] -pub struct SuspiciousPyghmiImport; +#[derive(ViolationMetadata)] +pub(crate) struct SuspiciousPyghmiImport; impl Violation for SuspiciousPyghmiImport { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/tarfile_unsafe_members.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/tarfile_unsafe_members.rs index fbf30606fed86..7f1f72817d106 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/tarfile_unsafe_members.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/tarfile_unsafe_members.rs @@ -1,7 +1,7 @@ use crate::checkers::ast::Checker; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -37,8 +37,8 @@ use ruff_text_size::Ranged; /// - [Python documentation: Extraction filters](https://docs.python.org/3/library/tarfile.html#tarfile-extraction-filter) /// /// [PEP 706]: https://peps.python.org/pep-0706/#backporting-forward-compatibility -#[violation] -pub struct TarfileUnsafeMembers; +#[derive(ViolationMetadata)] +pub(crate) struct TarfileUnsafeMembers; impl Violation for TarfileUnsafeMembers { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_continue.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_continue.rs index cdc5b53f1374e..87f1692f76d90 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_continue.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_continue.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{ExceptHandler, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -41,8 +41,8 @@ use crate::rules::flake8_bandit::helpers::is_untyped_exception; /// ## References /// - [Common Weakness Enumeration: CWE-703](https://cwe.mitre.org/data/definitions/703.html) /// - [Python documentation: `logging`](https://docs.python.org/3/library/logging.html) -#[violation] -pub struct TryExceptContinue; +#[derive(ViolationMetadata)] +pub(crate) struct TryExceptContinue; impl Violation for TryExceptContinue { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_pass.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_pass.rs index a90b1c8718792..0b4dcbaabd812 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_pass.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/try_except_pass.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{ExceptHandler, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -37,8 +37,8 @@ use crate::rules::flake8_bandit::helpers::is_untyped_exception; /// ## References /// - [Common Weakness Enumeration: CWE-703](https://cwe.mitre.org/data/definitions/703.html) /// - [Python documentation: `logging`](https://docs.python.org/3/library/logging.html) -#[violation] -pub struct TryExceptPass; +#[derive(ViolationMetadata)] +pub(crate) struct TryExceptPass; impl Violation for TryExceptPass { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs index e2e2e64f76b51..2bf7878d9cd39 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [PyYAML documentation: Loading YAML](https://pyyaml.org/wiki/PyYAMLDocumentation) /// - [Common Weakness Enumeration: CWE-20](https://cwe.mitre.org/data/definitions/20.html) -#[violation] -pub struct UnsafeYAMLLoad { +#[derive(ViolationMetadata)] +pub(crate) struct UnsafeYAMLLoad { pub loader: Option, } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/weak_cryptographic_key.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/weak_cryptographic_key.rs index 48137db7fb4d0..4f1e738b5c22d 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/weak_cryptographic_key.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/weak_cryptographic_key.rs @@ -1,7 +1,7 @@ use std::fmt::{Display, Formatter}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, ExprAttribute, ExprCall}; use ruff_text_size::{Ranged, TextRange}; @@ -32,8 +32,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [CSRC: Transitioning the Use of Cryptographic Algorithms and Key Lengths](https://csrc.nist.gov/pubs/sp/800/131/a/r2/final) -#[violation] -pub struct WeakCryptographicKey { +#[derive(ViolationMetadata)] +pub(crate) struct WeakCryptographicKey { cryptographic_key: CryptographicKey, } diff --git a/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs b/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs index 4d9c1a85f215f..88fa267ec28cf 100644 --- a/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs +++ b/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_const_true; use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor}; use ruff_python_ast::{self as ast, Expr, Stmt}; @@ -61,8 +61,8 @@ use crate::checkers::ast::Checker; /// - [Python documentation: The `try` statement](https://docs.python.org/3/reference/compound_stmts.html#the-try-statement) /// - [Python documentation: Exception hierarchy](https://docs.python.org/3/library/exceptions.html#exception-hierarchy) /// - [PEP 8: Programming Recommendations on bare `except`](https://peps.python.org/pep-0008/#programming-recommendations) -#[violation] -pub struct BlindExcept { +#[derive(ViolationMetadata)] +pub(crate) struct BlindExcept { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_default_value_positional_argument.rs b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_default_value_positional_argument.rs index 5c838330409a7..c46eb1fbca00b 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_default_value_positional_argument.rs +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_default_value_positional_argument.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::UnqualifiedName; use ruff_python_ast::{Decorator, ParameterWithDefault, Parameters}; use ruff_python_semantic::analyze::visibility; @@ -89,8 +89,8 @@ use crate::rules::flake8_boolean_trap::helpers::is_allowed_func_def; /// ## References /// - [Python documentation: Calls](https://docs.python.org/3/reference/expressions.html#calls) /// - [_How to Avoid “The Boolean Trap”_ by Adam Johnson](https://adamj.eu/tech/2021/07/10/python-type-hints-how-to-avoid-the-boolean-trap/) -#[violation] -pub struct BooleanDefaultValuePositionalArgument; +#[derive(ViolationMetadata)] +pub(crate) struct BooleanDefaultValuePositionalArgument; impl Violation for BooleanDefaultValuePositionalArgument { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_positional_value_in_call.rs b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_positional_value_in_call.rs index 87eb740c2cd14..76c6d39fefc49 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_positional_value_in_call.rs +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_positional_value_in_call.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_text_size::Ranged; @@ -41,8 +41,8 @@ use crate::rules::flake8_boolean_trap::helpers::allow_boolean_trap; /// ## References /// - [Python documentation: Calls](https://docs.python.org/3/reference/expressions.html#calls) /// - [_How to Avoid “The Boolean Trap”_ by Adam Johnson](https://adamj.eu/tech/2021/07/10/python-type-hints-how-to-avoid-the-boolean-trap/) -#[violation] -pub struct BooleanPositionalValueInCall; +#[derive(ViolationMetadata)] +pub(crate) struct BooleanPositionalValueInCall; impl Violation for BooleanPositionalValueInCall { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_type_hint_positional_argument.rs b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_type_hint_positional_argument.rs index 6d756ec37b184..0a2a70d39716e 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_type_hint_positional_argument.rs +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/rules/boolean_type_hint_positional_argument.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::UnqualifiedName; use ruff_python_ast::{self as ast, Decorator, Expr, ParameterWithDefault, Parameters}; use ruff_python_semantic::analyze::visibility; @@ -98,8 +98,8 @@ use crate::rules::flake8_boolean_trap::helpers::is_allowed_func_def; /// - [_How to Avoid “The Boolean Trap”_ by Adam Johnson](https://adamj.eu/tech/2021/07/10/python-type-hints-how-to-avoid-the-boolean-trap/) /// /// [preview]: https://docs.astral.sh/ruff/preview/ -#[violation] -pub struct BooleanTypeHintPositionalArgument; +#[derive(ViolationMetadata)] +pub(crate) struct BooleanTypeHintPositionalArgument; impl Violation for BooleanTypeHintPositionalArgument { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/abstract_base_class.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/abstract_base_class.rs index 97d29159eea03..158edc082bbd6 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/abstract_base_class.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/abstract_base_class.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Arguments, Expr, Keyword, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use ruff_python_semantic::analyze::visibility::{is_abstract, is_overload}; use ruff_python_semantic::SemanticModel; @@ -53,8 +53,8 @@ use crate::registry::Rule; /// ## References /// - [Python documentation: `abc`](https://docs.python.org/3/library/abc.html) /// - [Python documentation: `typing.ClassVar`](https://docs.python.org/3/library/typing.html#typing.ClassVar) -#[violation] -pub struct AbstractBaseClassWithoutAbstractMethod { +#[derive(ViolationMetadata)] +pub(crate) struct AbstractBaseClassWithoutAbstractMethod { name: String, } @@ -98,8 +98,8 @@ impl Violation for AbstractBaseClassWithoutAbstractMethod { /// /// ## References /// - [Python documentation: `abc`](https://docs.python.org/3/library/abc.html) -#[violation] -pub struct EmptyMethodWithoutAbstractDecorator { +#[derive(ViolationMetadata)] +pub(crate) struct EmptyMethodWithoutAbstractDecorator { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs index f52583d579caf..dcddda06f5743 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Arguments, Expr, ExprContext, Stmt}; use ruff_text_size::{Ranged, TextRange}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_const_false; use crate::checkers::ast::Checker; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `assert`](https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement) -#[violation] -pub struct AssertFalse; +#[derive(ViolationMetadata)] +pub(crate) struct AssertFalse; impl AlwaysFixableViolation for AssertFalse { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs index a3da3f9dc69ad..cf11734a8e8dc 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_raises_exception.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, WithItem}; use ruff_text_size::Ranged; @@ -28,8 +28,8 @@ use crate::checkers::ast::Checker; /// ```python /// self.assertRaises(SomeSpecificException, foo) /// ``` -#[violation] -pub struct AssertRaisesException { +#[derive(ViolationMetadata)] +pub(crate) struct AssertRaisesException { assertion: AssertionKind, exception: ExceptionKind, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs index 7260f42569d91..1cebc3bff7019 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assignment_to_os_environ.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -39,8 +39,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: `os.environ`](https://docs.python.org/3/library/os.html#os.environ) /// - [Python documentation: `subprocess.Popen`](https://docs.python.org/3/library/subprocess.html#subprocess.Popen) -#[violation] -pub struct AssignmentToOsEnviron; +#[derive(ViolationMetadata)] +pub(crate) struct AssignmentToOsEnviron; impl Violation for AssignmentToOsEnviron { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/cached_instance_method.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/cached_instance_method.rs index 1eb5895c7d205..c10405a2357bf 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/cached_instance_method.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/cached_instance_method.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::map_callable; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::analyze::{class, function_type}; @@ -62,8 +62,8 @@ use crate::checkers::ast::Checker; /// - [Python documentation: `functools.lru_cache`](https://docs.python.org/3/library/functools.html#functools.lru_cache) /// - [Python documentation: `functools.cache`](https://docs.python.org/3/library/functools.html#functools.cache) /// - [don't lru_cache methods!](https://www.youtube.com/watch?v=sVjtp6tGo0g) -#[violation] -pub struct CachedInstanceMethod; +#[derive(ViolationMetadata)] +pub(crate) struct CachedInstanceMethod; impl Violation for CachedInstanceMethod { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs index 450253b18defc..bff4c8ea88832 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs @@ -3,7 +3,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; use ruff_diagnostics::{AlwaysFixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::UnqualifiedName; use ruff_python_ast::{self as ast, ExceptHandler, Expr, ExprContext}; use ruff_text_size::{Ranged, TextRange}; @@ -39,8 +39,8 @@ use crate::registry::Rule; /// /// ## References /// - [Python documentation: `except` clause](https://docs.python.org/3/reference/compound_stmts.html#except-clause) -#[violation] -pub struct DuplicateTryBlockException { +#[derive(ViolationMetadata)] +pub(crate) struct DuplicateTryBlockException { name: String, } @@ -81,8 +81,8 @@ impl Violation for DuplicateTryBlockException { /// ## References /// - [Python documentation: `except` clause](https://docs.python.org/3/reference/compound_stmts.html#except-clause) /// - [Python documentation: Exception hierarchy](https://docs.python.org/3/library/exceptions.html#exception-hierarchy) -#[violation] -pub struct DuplicateHandlerException { +#[derive(ViolationMetadata)] +pub(crate) struct DuplicateHandlerException { pub names: Vec, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs index 0ef4427306e01..a48603a6cc370 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_value.rs @@ -2,7 +2,7 @@ use anyhow::{Context, Result}; use rustc_hash::FxHashMap; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::comparable::HashableExpr; use ruff_python_ast::Expr; @@ -28,8 +28,8 @@ use crate::checkers::ast::Checker; /// ```python /// {1, 2, 3} /// ``` -#[violation] -pub struct DuplicateValue { +#[derive(ViolationMetadata)] +pub(crate) struct DuplicateValue { value: String, existing: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_empty_tuple.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_empty_tuple.rs index 4135c21c56e24..1e55a6abde3b8 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_empty_tuple.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_empty_tuple.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast}; use ruff_python_ast::{ExceptHandler, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -33,8 +33,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `except` clause](https://docs.python.org/3/reference/compound_stmts.html#except-clause) -#[violation] -pub struct ExceptWithEmptyTuple; +#[derive(ViolationMetadata)] +pub(crate) struct ExceptWithEmptyTuple; impl Violation for ExceptWithEmptyTuple { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_non_exception_classes.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_non_exception_classes.rs index 88c721ee31773..180596395846c 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_non_exception_classes.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/except_with_non_exception_classes.rs @@ -3,7 +3,7 @@ use std::collections::VecDeque; use ruff_python_ast::{self as ast, ExceptHandler, Expr, Operator}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: `except` clause](https://docs.python.org/3/reference/compound_stmts.html#except-clause) /// - [Python documentation: Built-in Exceptions](https://docs.python.org/3/library/exceptions.html#built-in-exceptions) -#[violation] -pub struct ExceptWithNonExceptionClasses; +#[derive(ViolationMetadata)] +pub(crate) struct ExceptWithNonExceptionClasses; impl Violation for ExceptWithNonExceptionClasses { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/f_string_docstring.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/f_string_docstring.rs index d89adf5188843..4a2cb94fbb60f 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/f_string_docstring.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/f_string_docstring.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use crate::checkers::ast::Checker; @@ -30,8 +30,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [Python documentation: Formatted string literals](https://docs.python.org/3/reference/lexical_analysis.html#f-strings) -#[violation] -pub struct FStringDocstring; +#[derive(ViolationMetadata)] +pub(crate) struct FStringDocstring; impl Violation for FStringDocstring { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_call_in_argument_default.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_call_in_argument_default.rs index 16e6aaaeac07b..ab20364ac943b 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_call_in_argument_default.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_call_in_argument_default.rs @@ -3,7 +3,7 @@ use ruff_text_size::{Ranged, TextRange}; use ruff_diagnostics::Violation; use ruff_diagnostics::{Diagnostic, DiagnosticKind}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::{QualifiedName, UnqualifiedName}; use ruff_python_ast::visitor; use ruff_python_ast::visitor::Visitor; @@ -64,8 +64,8 @@ use crate::checkers::ast::Checker; /// /// ## Options /// - `lint.flake8-bugbear.extend-immutable-calls` -#[violation] -pub struct FunctionCallInDefaultArgument { +#[derive(ViolationMetadata)] +pub(crate) struct FunctionCallInDefaultArgument { name: Option, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs index ae4e7323cbf0a..e795be0466cf6 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_uses_loop_variable.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::types::Node; use ruff_python_ast::visitor; use ruff_python_ast::visitor::Visitor; @@ -41,8 +41,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [The Hitchhiker's Guide to Python: Late Binding Closures](https://docs.python-guide.org/writing/gotchas/#late-binding-closures) /// - [Python documentation: `functools.partial`](https://docs.python.org/3/library/functools.html#functools.partial) -#[violation] -pub struct FunctionUsesLoopVariable { +#[derive(ViolationMetadata)] +pub(crate) struct FunctionUsesLoopVariable { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs index 6d938eeec12a4..b0b4b728a2dcd 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_stdlib::identifiers::{is_identifier, is_mangled_private}; use ruff_source_file::LineRanges; @@ -31,8 +31,8 @@ use crate::fix::edits::pad; /// /// ## References /// - [Python documentation: `getattr`](https://docs.python.org/3/library/functions.html#getattr) -#[violation] -pub struct GetAttrWithConstant; +#[derive(ViolationMetadata)] +pub(crate) struct GetAttrWithConstant; impl AlwaysFixableViolation for GetAttrWithConstant { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/jump_statement_in_finally.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/jump_statement_in_finally.rs index 23c23d2f11d73..afabc56a208e4 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/jump_statement_in_finally.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/jump_statement_in_finally.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -40,8 +40,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: The `try` statement](https://docs.python.org/3/reference/compound_stmts.html#the-try-statement) -#[violation] -pub struct JumpStatementInFinally { +#[derive(ViolationMetadata)] +pub(crate) struct JumpStatementInFinally { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs index 62f60acb5e793..f4f806abfc3c2 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_iterator_mutation.rs @@ -3,7 +3,7 @@ use std::fmt::Debug; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::name::UnqualifiedName; use ruff_python_ast::{ @@ -36,8 +36,8 @@ use crate::fix::snippet::SourceCodeSnippet; /// /// ## References /// - [Python documentation: Mutable Sequence Types](https://docs.python.org/3/library/stdtypes.html#typesseq-mutable) -#[violation] -pub struct LoopIteratorMutation { +#[derive(ViolationMetadata)] +pub(crate) struct LoopIteratorMutation { name: Option, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_variable_overrides_iterator.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_variable_overrides_iterator.rs index 24c2004453c73..4e3b49df2ca5a 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_variable_overrides_iterator.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/loop_variable_overrides_iterator.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Expr, ParameterWithDefault}; use rustc_hash::FxHashMap; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::visitor; use ruff_python_ast::visitor::Visitor; use ruff_text_size::Ranged; @@ -36,8 +36,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: The `for` statement](https://docs.python.org/3/reference/compound_stmts.html#the-for-statement) -#[violation] -pub struct LoopVariableOverridesIterator { +#[derive(ViolationMetadata)] +pub(crate) struct LoopVariableOverridesIterator { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs index 34a4d0ab48d31..d43fddbe613bd 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_docstring_stmt; use ruff_python_ast::name::QualifiedName; use ruff_python_ast::{self as ast, Expr, Parameter, ParameterWithDefault}; @@ -68,8 +68,8 @@ use crate::Locator; /// /// ## References /// - [Python documentation: Default Argument Values](https://docs.python.org/3/tutorial/controlflow.html#default-argument-values) -#[violation] -pub struct MutableArgumentDefault; +#[derive(ViolationMetadata)] +pub(crate) struct MutableArgumentDefault; impl Violation for MutableArgumentDefault { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_contextvar_default.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_contextvar_default.rs index dba296aa08d91..1c2087cd342f1 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_contextvar_default.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_contextvar_default.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::map_subscript; use ruff_python_ast::name::QualifiedName; use ruff_python_ast::{self as ast, Expr}; @@ -53,8 +53,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `contextvars` — Context Variables](https://docs.python.org/3/library/contextvars.html) -#[violation] -pub struct MutableContextvarDefault; +#[derive(ViolationMetadata)] +pub(crate) struct MutableContextvarDefault; impl Violation for MutableContextvarDefault { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs index 45d0b7b8becab..65e88e1d35465 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/no_explicit_stacklevel.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast}; use ruff_text_size::Ranged; @@ -30,8 +30,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `warnings.warn`](https://docs.python.org/3/library/warnings.html#warnings.warn) -#[violation] -pub struct NoExplicitStacklevel; +#[derive(ViolationMetadata)] +pub(crate) struct NoExplicitStacklevel; impl Violation for NoExplicitStacklevel { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_literal.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_literal.rs index dd39ea9b00c8a..221da07133ee6 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_literal.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_literal.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -26,8 +26,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `raise` statement](https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement) -#[violation] -pub struct RaiseLiteral; +#[derive(ViolationMetadata)] +pub(crate) struct RaiseLiteral; impl Violation for RaiseLiteral { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs index 7ea4fe4e82200..493cd06f72c3e 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/raise_without_from_inside_except.rs @@ -2,7 +2,7 @@ use ruff_python_ast as ast; use ruff_python_ast::Stmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::RaiseStatementVisitor; use ruff_python_ast::statement_visitor::StatementVisitor; @@ -46,8 +46,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `raise` statement](https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement) -#[violation] -pub struct RaiseWithoutFromInsideExcept; +#[derive(ViolationMetadata)] +pub(crate) struct RaiseWithoutFromInsideExcept; impl Violation for RaiseWithoutFromInsideExcept { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs index 06bbc8cdd8237..285b23b7d8ba5 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/re_sub_positional_args.rs @@ -3,7 +3,7 @@ use std::fmt; use ruff_python_ast::{self as ast}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -39,8 +39,8 @@ use crate::checkers::ast::Checker; /// - [Python documentation: `re.sub`](https://docs.python.org/3/library/re.html#re.sub) /// - [Python documentation: `re.subn`](https://docs.python.org/3/library/re.html#re.subn) /// - [Python documentation: `re.split`](https://docs.python.org/3/library/re.html#re.split) -#[violation] -pub struct ReSubPositionalArgs { +#[derive(ViolationMetadata)] +pub(crate) struct ReSubPositionalArgs { method: Method, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs index fddd8493ac614..c2a5d091d28c0 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, ExceptHandler, Expr}; use ruff_text_size::Ranged; @@ -35,8 +35,8 @@ use crate::fix::edits::pad; /// /// ## References /// - [Python documentation: `except` clause](https://docs.python.org/3/reference/compound_stmts.html#except-clause) -#[violation] -pub struct RedundantTupleInExceptionHandler { +#[derive(ViolationMetadata)] +pub(crate) struct RedundantTupleInExceptionHandler { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/return_in_generator.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/return_in_generator.rs index 95d38e0407209..e04ce11eef252 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/return_in_generator.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/return_in_generator.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::statement_visitor; use ruff_python_ast::statement_visitor::StatementVisitor; use ruff_python_ast::{self as ast, Expr, Stmt, StmtFunctionDef}; @@ -79,8 +79,8 @@ use crate::checkers::ast::Checker; /// for file_type in file_types: /// yield from dir_path.glob(f"*.{file_type}") /// ``` -#[violation] -pub struct ReturnInGenerator; +#[derive(ViolationMetadata)] +pub(crate) struct ReturnInGenerator; impl Violation for ReturnInGenerator { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs index d617f995c48a1..58121f42b06bb 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Comprehension, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::visitor::{self, Visitor}; use ruff_text_size::Ranged; @@ -33,8 +33,8 @@ use crate::checkers::ast::Checker; /// for _ in range(5): /// do_something_with_the_group(values) /// ``` -#[violation] -pub struct ReuseOfGroupbyGenerator; +#[derive(ViolationMetadata)] +pub(crate) struct ReuseOfGroupbyGenerator; impl Violation for ReuseOfGroupbyGenerator { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs index 69a65c7c2e7fa..bd4a6aad12524 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Expr, ExprContext, Identifier, Stmt}; use ruff_text_size::{Ranged, TextRange}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_codegen::Generator; use ruff_python_stdlib::identifiers::{is_identifier, is_mangled_private}; @@ -30,8 +30,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `setattr`](https://docs.python.org/3/library/functions.html#setattr) -#[violation] -pub struct SetAttrWithConstant; +#[derive(ViolationMetadata)] +pub(crate) struct SetAttrWithConstant; impl AlwaysFixableViolation for SetAttrWithConstant { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs index c8233468c5bfb..dc453fb480cd3 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{Expr, Keyword}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -45,8 +45,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: Calls](https://docs.python.org/3/reference/expressions.html#calls) /// - [Disallow iterable argument unpacking after a keyword argument?](https://github.com/python/cpython/issues/82741) -#[violation] -pub struct StarArgUnpackingAfterKeywordArg; +#[derive(ViolationMetadata)] +pub(crate) struct StarArgUnpackingAfterKeywordArg; impl Violation for StarArgUnpackingAfterKeywordArg { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/static_key_dict_comprehension.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/static_key_dict_comprehension.rs index af2bac4e64b74..5f9653708600d 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/static_key_dict_comprehension.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/static_key_dict_comprehension.rs @@ -1,7 +1,7 @@ use rustc_hash::FxHashMap; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::StoredNameFinder; use ruff_python_ast::visitor::Visitor; use ruff_python_ast::{self as ast, Expr}; @@ -30,8 +30,8 @@ use crate::fix::snippet::SourceCodeSnippet; /// data = ["some", "Data"] /// {value: value.upper() for value in data} /// ``` -#[violation] -pub struct StaticKeyDictComprehension { +#[derive(ViolationMetadata)] +pub(crate) struct StaticKeyDictComprehension { key: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs index 9ef7ecedba23e..d102c6605a1b5 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/strip_with_multi_characters.rs @@ -2,7 +2,7 @@ use itertools::Itertools; use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -44,8 +44,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `str.strip`](https://docs.python.org/3/library/stdtypes.html#str.strip) -#[violation] -pub struct StripWithMultiCharacters; +#[derive(ViolationMetadata)] +pub(crate) struct StripWithMultiCharacters; impl Violation for StripWithMultiCharacters { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unary_prefix_increment_decrement.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unary_prefix_increment_decrement.rs index e2a7c844a79b2..6781125fe1799 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unary_prefix_increment_decrement.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unary_prefix_increment_decrement.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr, UnaryOp}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -30,8 +30,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: Unary arithmetic and bitwise operations](https://docs.python.org/3/reference/expressions.html#unary-arithmetic-and-bitwise-operations) /// - [Python documentation: Augmented assignment statements](https://docs.python.org/3/reference/simple_stmts.html#augmented-assignment-statements) -#[violation] -pub struct UnaryPrefixIncrementDecrement { +#[derive(ViolationMetadata)] +pub(crate) struct UnaryPrefixIncrementDecrement { operator: UnaryPrefixOperatorType, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs index 5ed04e6227b56..fd390154b0e0b 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unintentional_type_annotation.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -22,8 +22,8 @@ use crate::checkers::ast::Checker; /// ```python /// a["b"] = 1 /// ``` -#[violation] -pub struct UnintentionalTypeAnnotation; +#[derive(ViolationMetadata)] +pub(crate) struct UnintentionalTypeAnnotation; impl Violation for UnintentionalTypeAnnotation { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs index 8eedf348e682c..23186b2a37fd4 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -31,8 +31,8 @@ use crate::checkers::ast::Checker; /// - [Python documentation: `hasattr`](https://docs.python.org/3/library/functions.html#hasattr) /// - [Python documentation: `__getattr__`](https://docs.python.org/3/reference/datamodel.html#object.__getattr__) /// - [Python documentation: `__call__`](https://docs.python.org/3/reference/datamodel.html#object.__call__) -#[violation] -pub struct UnreliableCallableCheck; +#[derive(ViolationMetadata)] +pub(crate) struct UnreliableCallableCheck; impl Violation for UnreliableCallableCheck { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs index bf8f7318a3b45..363dd128a0942 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::helpers; use ruff_python_ast::helpers::{NameFinder, StoredNameFinder}; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [PEP 8: Naming Conventions](https://peps.python.org/pep-0008/#naming-conventions) -#[violation] -pub struct UnusedLoopControlVariable { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedLoopControlVariable { /// The name of the loop control variable. name: String, /// The name to which the variable should be renamed, if it can be diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_comparison.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_comparison.rs index 0b327f88bb17d..a51cd1ca49414 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_comparison.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_comparison.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Expr, Stmt}; use ruff_python_semantic::ScopeKind; use ruff_text_size::Ranged; @@ -33,8 +33,8 @@ use super::super::helpers::at_last_top_level_expression_in_cell; /// /// ## References /// - [Python documentation: `assert` statement](https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement) -#[violation] -pub struct UselessComparison { +#[derive(ViolationMetadata)] +pub(crate) struct UselessComparison { at: ComparisonLocationAt, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs index 61e01738e2317..b507acfdf1b54 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_contextlib_suppress.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -36,8 +36,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `contextlib.suppress`](https://docs.python.org/3/library/contextlib.html#contextlib.suppress) -#[violation] -pub struct UselessContextlibSuppress; +#[derive(ViolationMetadata)] +pub(crate) struct UselessContextlibSuppress; impl Violation for UselessContextlibSuppress { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_expression.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_expression.rs index 02b54082bba87..bc6e7b293a4ea 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_expression.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/useless_expression.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::contains_effect; use ruff_python_ast::Expr; use ruff_text_size::Ranged; @@ -50,8 +50,8 @@ use super::super::helpers::at_last_top_level_expression_in_cell; /// with errors.ExceptionRaisedContext(): /// _ = obj.attribute /// ``` -#[violation] -pub struct UselessExpression { +#[derive(ViolationMetadata)] +pub(crate) struct UselessExpression { kind: Kind, } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs index c7a5b2f3daac6..272ea7a596ac6 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Applicability, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Arguments, Expr}; use ruff_python_semantic::SemanticModel; @@ -37,8 +37,8 @@ use crate::fix::edits::add_argument; /// /// ## References /// - [Python documentation: `zip`](https://docs.python.org/3/library/functions.html#zip) -#[violation] -pub struct ZipWithoutExplicitStrict; +#[derive(ViolationMetadata)] +pub(crate) struct ZipWithoutExplicitStrict; impl AlwaysFixableViolation for ZipWithoutExplicitStrict { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_argument_shadowing.rs b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_argument_shadowing.rs index 2b46b8112720d..a406a179ae031 100644 --- a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_argument_shadowing.rs +++ b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_argument_shadowing.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Expr, Parameter}; use ruff_python_semantic::analyze::visibility::{is_overload, is_override}; use ruff_text_size::Ranged; @@ -49,8 +49,8 @@ use super::super::helpers::shadows_builtin; /// ## References /// - [_Is it bad practice to use a built-in function name as an attribute or method identifier?_](https://stackoverflow.com/questions/9109333/is-it-bad-practice-to-use-a-built-in-function-name-as-an-attribute-or-method-ide) /// - [_Why is it a bad idea to name a variable `id` in Python?_](https://stackoverflow.com/questions/77552/id-is-a-bad-variable-name-in-python) -#[violation] -pub struct BuiltinArgumentShadowing { +#[derive(ViolationMetadata)] +pub(crate) struct BuiltinArgumentShadowing { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_attribute_shadowing.rs b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_attribute_shadowing.rs index 179471ab650a7..a4cb7a04a24d6 100644 --- a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_attribute_shadowing.rs +++ b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_attribute_shadowing.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::{BindingKind, Scope, ScopeId}; use ruff_source_file::SourceRow; @@ -56,8 +56,8 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin; /// /// ## Options /// - `lint.flake8-builtins.builtins-ignorelist` -#[violation] -pub struct BuiltinAttributeShadowing { +#[derive(ViolationMetadata)] +pub(crate) struct BuiltinAttributeShadowing { kind: Kind, name: String, row: SourceRow, diff --git a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_import_shadowing.rs b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_import_shadowing.rs index 9c546b55461d0..2bcde2c90da9c 100644 --- a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_import_shadowing.rs +++ b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_import_shadowing.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Alias; use crate::checkers::ast::Checker; @@ -41,8 +41,8 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin; /// - `lint.flake8-builtins.builtins-ignorelist` /// - `target-version` /// -#[violation] -pub struct BuiltinImportShadowing { +#[derive(ViolationMetadata)] +pub(crate) struct BuiltinImportShadowing { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_lambda_argument_shadowing.rs b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_lambda_argument_shadowing.rs index f8f8756df1c9d..b5c9b01c11d1a 100644 --- a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_lambda_argument_shadowing.rs +++ b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_lambda_argument_shadowing.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::ExprLambda; use ruff_text_size::Ranged; @@ -20,8 +20,8 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin; /// /// ## Options /// - `lint.flake8-builtins.builtins-ignorelist` -#[violation] -pub struct BuiltinLambdaArgumentShadowing { +#[derive(ViolationMetadata)] +pub(crate) struct BuiltinLambdaArgumentShadowing { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_module_shadowing.rs b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_module_shadowing.rs index 292cfc952074c..385cf2cf1ed7b 100644 --- a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_module_shadowing.rs +++ b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_module_shadowing.rs @@ -1,7 +1,7 @@ use std::path::Path; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::PySourceType; use ruff_python_stdlib::path::is_module_file; use ruff_python_stdlib::sys::is_known_standard_library; @@ -24,8 +24,8 @@ use crate::settings::types::PythonVersion; /// /// ## Options /// - `lint.flake8-builtins.builtins-allowed-modules` -#[violation] -pub struct BuiltinModuleShadowing { +#[derive(ViolationMetadata)] +pub(crate) struct BuiltinModuleShadowing { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_variable_shadowing.rs b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_variable_shadowing.rs index 5dc661dc409cc..120f7616c3493 100644 --- a/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_variable_shadowing.rs +++ b/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_variable_shadowing.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::TextRange; use crate::checkers::ast::Checker; @@ -44,8 +44,8 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin; /// /// ## References /// - [_Why is it a bad idea to name a variable `id` in Python?_](https://stackoverflow.com/questions/77552/id-is-a-bad-variable-name-in-python) -#[violation] -pub struct BuiltinVariableShadowing { +#[derive(ViolationMetadata)] +pub(crate) struct BuiltinVariableShadowing { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_commas/rules/trailing_commas.rs b/crates/ruff_linter/src/rules/flake8_commas/rules/trailing_commas.rs index be73f48ede6f7..ddc4d076a59c8 100644 --- a/crates/ruff_linter/src/rules/flake8_commas/rules/trailing_commas.rs +++ b/crates/ruff_linter/src/rules/flake8_commas/rules/trailing_commas.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::{AlwaysFixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_index::Indexer; use ruff_python_parser::{TokenKind, Tokens}; use ruff_text_size::{Ranged, TextRange}; @@ -145,8 +145,8 @@ impl Context { /// formatter enforces consistent use of trailing commas, making the rule redundant. /// /// [formatter]:https://docs.astral.sh/ruff/formatter/ -#[violation] -pub struct MissingTrailingComma; +#[derive(ViolationMetadata)] +pub(crate) struct MissingTrailingComma; impl AlwaysFixableViolation for MissingTrailingComma { #[derive_message_formats] @@ -190,8 +190,8 @@ impl AlwaysFixableViolation for MissingTrailingComma { /// /// foo = (json.dumps({"bar": 1})) /// ``` -#[violation] -pub struct TrailingCommaOnBareTuple; +#[derive(ViolationMetadata)] +pub(crate) struct TrailingCommaOnBareTuple; impl Violation for TrailingCommaOnBareTuple { #[derive_message_formats] @@ -222,8 +222,8 @@ impl Violation for TrailingCommaOnBareTuple { /// formatter enforces consistent use of trailing commas, making the rule redundant. /// /// [formatter]:https://docs.astral.sh/ruff/formatter/ -#[violation] -pub struct ProhibitedTrailingComma; +#[derive(ViolationMetadata)] +pub(crate) struct ProhibitedTrailingComma; impl AlwaysFixableViolation for ProhibitedTrailingComma { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs index 2ce7713b1fe9d..d713b2bb366c5 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Applicability, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -38,8 +38,8 @@ use crate::rules::flake8_comprehensions::fixes; /// collection, while `sorted` with `reverse=True` will perform a stable /// reverse sort, which will preserve the order of elements that compare as /// equal. -#[violation] -pub struct UnnecessaryCallAroundSorted { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryCallAroundSorted { func: String, } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs index 089892b07eabb..ef0da178c4b17 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_text_size::{Ranged, TextSize}; @@ -39,8 +39,8 @@ use crate::rules::flake8_comprehensions::settings::Settings; /// /// ## Options /// - `lint.flake8-comprehensions.allow-dict-calls-with-keyword-arguments` -#[violation] -pub struct UnnecessaryCollectionCall { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryCollectionCall { obj_type: String, } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs index 409e73c2f0396..13fdc25d5c871 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::{self as ast, Comprehension, Expr}; use ruff_text_size::Ranged; @@ -56,8 +56,8 @@ use crate::rules::flake8_comprehensions::fixes; /// Due to the known problem with dictionary comprehensions, this fix is marked as unsafe. /// /// Additionally, this fix may drop comments when rewriting the comprehension. -#[violation] -pub struct UnnecessaryComprehension { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryComprehension { obj_type: String, } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_in_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_in_call.rs index c1a06041d1bdc..2bfb81acf8e67 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_in_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_in_call.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::{Diagnostic, FixAvailability}; use ruff_diagnostics::{Edit, Fix, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::any_over_expr; use ruff_python_ast::{self as ast, Expr, Keyword}; use ruff_text_size::{Ranged, TextSize}; @@ -65,8 +65,8 @@ use crate::rules::flake8_comprehensions::fixes; /// rewriting some comprehensions. /// /// [preview]: https://docs.astral.sh/ruff/preview/ -#[violation] -pub struct UnnecessaryComprehensionInCall { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryComprehensionInCall { comprehension_kind: ComprehensionKind, } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs index d5fbfd7a4f69c..a723ba4e59351 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs @@ -1,6 +1,6 @@ use ast::ExprName; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::helpers::any_over_expr; use ruff_python_ast::{self as ast, Arguments, Comprehension, Expr, ExprCall, ExprContext}; @@ -33,8 +33,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `dict.fromkeys`](https://docs.python.org/3/library/stdtypes.html#dict.fromkeys) -#[violation] -pub struct UnnecessaryDictComprehensionForIterable { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryDictComprehensionForIterable { is_value_none_literal: bool, } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs index 2be956db390ad..b9f836ce5a0b1 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableKeyword; use ruff_python_ast::{self as ast, Arguments, Expr, Keyword}; use ruff_text_size::Ranged; @@ -47,8 +47,8 @@ use crate::rules::flake8_comprehensions::fixes; /// ## Fix safety /// This rule's fix is marked as unsafe, as it may occasionally drop comments /// when rewriting the call. In most cases, though, comments will be preserved. -#[violation] -pub struct UnnecessaryDoubleCastOrProcess { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryDoubleCastOrProcess { inner: String, outer: String, } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs index 306f7f19cfba8..e4ffc432bc497 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Keyword}; use ruff_text_size::Ranged; @@ -31,8 +31,8 @@ use super::helpers; /// ## Fix safety /// This rule's fix is marked as unsafe, as it may occasionally drop comments /// when rewriting the call. In most cases, though, comments will be preserved. -#[violation] -pub struct UnnecessaryGeneratorDict; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryGeneratorDict; impl AlwaysFixableViolation for UnnecessaryGeneratorDict { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs index 0ba85613ab3ea..e83db15f60d59 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::parenthesize::parenthesized_range; @@ -40,8 +40,8 @@ use super::helpers; /// ## Fix safety /// This rule's fix is marked as unsafe, as it may occasionally drop comments /// when rewriting the call. In most cases, though, comments will be preserved. -#[violation] -pub struct UnnecessaryGeneratorList { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryGeneratorList { short_circuit: bool, } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs index f382ee5af859d..9a60ca0072b4b 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::ExprGenerator; @@ -38,8 +38,8 @@ use super::helpers; /// ## Fix safety /// This rule's fix is marked as unsafe, as it may occasionally drop comments /// when rewriting the call. In most cases, though, comments will be preserved. -#[violation] -pub struct UnnecessaryGeneratorSet { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryGeneratorSet { short_circuit: bool, } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs index dd20de2fa0a39..912912d1bdb4e 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -29,8 +29,8 @@ use super::helpers; /// ## Fix safety /// This rule's fix is marked as unsafe, as it may occasionally drop comments /// when rewriting the call. In most cases, though, comments will be preserved. -#[violation] -pub struct UnnecessaryListCall; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryListCall; impl AlwaysFixableViolation for UnnecessaryListCall { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs index d16d195af8185..7aee84e3c5238 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Keyword}; use ruff_text_size::Ranged; @@ -29,8 +29,8 @@ use super::helpers; /// ## Fix safety /// This rule's fix is marked as unsafe, as it may occasionally drop comments /// when rewriting the call. In most cases, though, comments will be preserved. -#[violation] -pub struct UnnecessaryListComprehensionDict; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryListComprehensionDict; impl AlwaysFixableViolation for UnnecessaryListComprehensionDict { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs index 019a19bc9dd5f..383c90a89605c 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_text_size::{Ranged, TextSize}; @@ -28,8 +28,8 @@ use super::helpers; /// ## Fix safety /// This rule's fix is marked as unsafe, as it may occasionally drop comments /// when rewriting the call. In most cases, though, comments will be preserved. -#[violation] -pub struct UnnecessaryListComprehensionSet; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryListComprehensionSet; impl AlwaysFixableViolation for UnnecessaryListComprehensionSet { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs index d7a6032b58a61..571d915f3f2da 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Keyword}; use ruff_text_size::Ranged; @@ -33,8 +33,8 @@ use super::helpers; /// ## Fix safety /// This rule's fix is marked as unsafe, as it may occasionally drop comments /// when rewriting the call. In most cases, though, comments will be preserved. -#[violation] -pub struct UnnecessaryLiteralDict { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryLiteralDict { obj_type: String, } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs index 445de6658f82d..e1de6e7001626 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::{Ranged, TextSize}; @@ -33,8 +33,8 @@ use super::helpers; /// ## Fix safety /// This rule's fix is marked as unsafe, as it may occasionally drop comments /// when rewriting the call. In most cases, though, comments will be preserved. -#[violation] -pub struct UnnecessaryLiteralSet { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryLiteralSet { obj_type: String, } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs index 2b18ee8833664..4e4399da91b2b 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs @@ -3,7 +3,7 @@ use std::fmt; use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -48,8 +48,8 @@ impl fmt::Display for DictKind { /// ## Fix safety /// This rule's fix is marked as unsafe, as it may occasionally drop comments /// when rewriting the call. In most cases, though, comments will be preserved. -#[violation] -pub struct UnnecessaryLiteralWithinDictCall { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryLiteralWithinDictCall { kind: DictKind, } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs index f71e11db41b57..317b197ca3850 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::{Ranged, TextSize}; @@ -34,8 +34,8 @@ use super::helpers; /// ## Fix safety /// This rule's fix is marked as unsafe, as it may occasionally drop comments /// when rewriting the call. In most cases, though, comments will be preserved. -#[violation] -pub struct UnnecessaryLiteralWithinListCall { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryLiteralWithinListCall { literal: String, } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs index ae7e18e28ae71..d5f5744c68d44 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::any_over_expr; use ruff_python_ast::{self as ast, Expr}; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; @@ -46,8 +46,8 @@ use super::helpers; /// when rewriting the call. In most cases, though, comments will be preserved. /// /// [preview]: https://docs.astral.sh/ruff/preview/ -#[violation] -pub struct UnnecessaryLiteralWithinTupleCall { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryLiteralWithinTupleCall { literal_kind: TupleLiteralKind, } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs index a1dd7fe08d143..ce7703b8dfc47 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs @@ -2,7 +2,7 @@ use std::fmt; use ruff_diagnostics::{Diagnostic, Fix}; use ruff_diagnostics::{FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::visitor; use ruff_python_ast::visitor::Visitor; use ruff_python_ast::{self as ast, Arguments, Expr, ExprContext, Parameters, Stmt}; @@ -45,8 +45,8 @@ use super::helpers; /// ## Fix safety /// This rule's fix is marked as unsafe, as it may occasionally drop comments /// when rewriting the call. In most cases, though, comments will be preserved. -#[violation] -pub struct UnnecessaryMap { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryMap { object_type: ObjectType, } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs index 54aca2a6302af..7662b16bc047a 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, UnaryOp}; use ruff_text_size::Ranged; @@ -26,8 +26,8 @@ use crate::checkers::ast::Checker; /// set(iterable) /// iterable /// ``` -#[violation] -pub struct UnnecessarySubscriptReversal { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessarySubscriptReversal { func: String, } diff --git a/crates/ruff_linter/src/rules/flake8_copyright/rules/missing_copyright_notice.rs b/crates/ruff_linter/src/rules/flake8_copyright/rules/missing_copyright_notice.rs index f9cfa23162123..51628a469546d 100644 --- a/crates/ruff_linter/src/rules/flake8_copyright/rules/missing_copyright_notice.rs +++ b/crates/ruff_linter/src/rules/flake8_copyright/rules/missing_copyright_notice.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::{TextRange, TextSize}; use crate::settings::LinterSettings; @@ -13,8 +13,8 @@ use crate::Locator; /// ## Why is this bad? /// In some codebases, it's common to have a license header at the top of every /// file. This rule ensures that the license header is present. -#[violation] -pub struct MissingCopyrightNotice; +#[derive(ViolationMetadata)] +pub(crate) struct MissingCopyrightNotice; impl Violation for MissingCopyrightNotice { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_fromtimestamp.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_fromtimestamp.rs index 13c60d099823f..fde4eecde3c1f 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_fromtimestamp.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_fromtimestamp.rs @@ -2,7 +2,7 @@ use ruff_python_ast::Expr; use ruff_text_size::TextRange; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Modules; use crate::checkers::ast::Checker; @@ -44,8 +44,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: Aware and Naive Objects](https://docs.python.org/3/library/datetime.html#aware-and-naive-objects) -#[violation] -pub struct CallDateFromtimestamp; +#[derive(ViolationMetadata)] +pub(crate) struct CallDateFromtimestamp; impl Violation for CallDateFromtimestamp { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_today.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_today.rs index 1e1920075bf06..ad1d6702f51d7 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_today.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_date_today.rs @@ -2,7 +2,7 @@ use ruff_python_ast::Expr; use ruff_text_size::TextRange; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Modules; use crate::checkers::ast::Checker; @@ -43,8 +43,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: Aware and Naive Objects](https://docs.python.org/3/library/datetime.html#aware-and-naive-objects) -#[violation] -pub struct CallDateToday; +#[derive(ViolationMetadata)] +pub(crate) struct CallDateToday; impl Violation for CallDateToday { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_fromtimestamp.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_fromtimestamp.rs index 32fb1a77da124..7cf70c933ce17 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_fromtimestamp.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_fromtimestamp.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast}; use ruff_python_semantic::Modules; @@ -47,8 +47,8 @@ use super::helpers::{self, DatetimeModuleAntipattern}; /// /// ## References /// - [Python documentation: Aware and Naive Objects](https://docs.python.org/3/library/datetime.html#aware-and-naive-objects) -#[violation] -pub struct CallDatetimeFromtimestamp(DatetimeModuleAntipattern); +#[derive(ViolationMetadata)] +pub(crate) struct CallDatetimeFromtimestamp(DatetimeModuleAntipattern); impl Violation for CallDatetimeFromtimestamp { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_now_without_tzinfo.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_now_without_tzinfo.rs index 42c34a9a90b2f..8ca0b3ca972cd 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_now_without_tzinfo.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_now_without_tzinfo.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::Modules; @@ -45,8 +45,8 @@ use super::helpers::{self, DatetimeModuleAntipattern}; /// /// ## References /// - [Python documentation: Aware and Naive Objects](https://docs.python.org/3/library/datetime.html#aware-and-naive-objects) -#[violation] -pub struct CallDatetimeNowWithoutTzinfo(DatetimeModuleAntipattern); +#[derive(ViolationMetadata)] +pub(crate) struct CallDatetimeNowWithoutTzinfo(DatetimeModuleAntipattern); impl Violation for CallDatetimeNowWithoutTzinfo { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs index 32941f3a239a5..30eeb8359d36a 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_strptime_without_zone.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::Modules; @@ -50,8 +50,8 @@ use super::helpers::DatetimeModuleAntipattern; /// ## References /// - [Python documentation: Aware and Naive Objects](https://docs.python.org/3/library/datetime.html#aware-and-naive-objects) /// - [Python documentation: `strftime()` and `strptime()` Behavior](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior) -#[violation] -pub struct CallDatetimeStrptimeWithoutZone(DatetimeModuleAntipattern); +#[derive(ViolationMetadata)] +pub(crate) struct CallDatetimeStrptimeWithoutZone(DatetimeModuleAntipattern); impl Violation for CallDatetimeStrptimeWithoutZone { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_today.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_today.rs index e44219ebc53cb..7bdcd9f74476b 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_today.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_today.rs @@ -2,7 +2,7 @@ use ruff_python_ast::Expr; use ruff_text_size::TextRange; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Modules; use crate::checkers::ast::Checker; @@ -42,8 +42,8 @@ use super::helpers; /// /// datetime.datetime.now(tz=datetime.UTC) /// ``` -#[violation] -pub struct CallDatetimeToday; +#[derive(ViolationMetadata)] +pub(crate) struct CallDatetimeToday; impl Violation for CallDatetimeToday { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcfromtimestamp.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcfromtimestamp.rs index 83df4f1eab809..4514302bc2870 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcfromtimestamp.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcfromtimestamp.rs @@ -2,7 +2,7 @@ use ruff_python_ast::Expr; use ruff_text_size::TextRange; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Modules; use crate::checkers::ast::Checker; @@ -46,8 +46,8 @@ use super::helpers; /// /// ## References /// - [Python documentation: Aware and Naive Objects](https://docs.python.org/3/library/datetime.html#aware-and-naive-objects) -#[violation] -pub struct CallDatetimeUtcfromtimestamp; +#[derive(ViolationMetadata)] +pub(crate) struct CallDatetimeUtcfromtimestamp; impl Violation for CallDatetimeUtcfromtimestamp { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcnow.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcnow.rs index 32906e02c650c..1e474ff159909 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcnow.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_utcnow.rs @@ -2,7 +2,7 @@ use ruff_python_ast::Expr; use ruff_text_size::TextRange; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Modules; use crate::checkers::ast::Checker; @@ -45,8 +45,8 @@ use super::helpers; /// /// ## References /// - [Python documentation: Aware and Naive Objects](https://docs.python.org/3/library/datetime.html#aware-and-naive-objects) -#[violation] -pub struct CallDatetimeUtcnow; +#[derive(ViolationMetadata)] +pub(crate) struct CallDatetimeUtcnow; impl Violation for CallDatetimeUtcnow { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs index b5d8f67d898f3..5dac0ee87dd63 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::Modules; @@ -41,8 +41,8 @@ use super::helpers::{self, DatetimeModuleAntipattern}; /// /// datetime.datetime(2000, 1, 1, 0, 0, 0, tzinfo=datetime.UTC) /// ``` -#[violation] -pub struct CallDatetimeWithoutTzinfo(DatetimeModuleAntipattern); +#[derive(ViolationMetadata)] +pub(crate) struct CallDatetimeWithoutTzinfo(DatetimeModuleAntipattern); impl Violation for CallDatetimeWithoutTzinfo { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/rules/datetime_min_max.rs b/crates/ruff_linter/src/rules/flake8_datetimez/rules/datetime_min_max.rs index be39435d55586..56ade9ced28c1 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/rules/datetime_min_max.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/rules/datetime_min_max.rs @@ -1,7 +1,7 @@ use std::fmt::{Display, Formatter}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Expr, ExprAttribute, ExprCall}; use ruff_python_semantic::{Modules, SemanticModel}; use ruff_text_size::Ranged; @@ -32,8 +32,8 @@ use crate::checkers::ast::Checker; /// ```python /// datetime.max.replace(tzinfo=datetime.UTC) /// ``` -#[violation] -pub struct DatetimeMinMax { +#[derive(ViolationMetadata)] +pub(crate) struct DatetimeMinMax { min_max: MinMax, } diff --git a/crates/ruff_linter/src/rules/flake8_debugger/rules/debugger.rs b/crates/ruff_linter/src/rules/flake8_debugger/rules/debugger.rs index fa3ace456be77..cee0fbe9b8d86 100644 --- a/crates/ruff_linter/src/rules/flake8_debugger/rules/debugger.rs +++ b/crates/ruff_linter/src/rules/flake8_debugger/rules/debugger.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::QualifiedName; use ruff_text_size::Ranged; @@ -30,8 +30,8 @@ use crate::rules::flake8_debugger::types::DebuggerUsingType; /// ## References /// - [Python documentation: `pdb` — The Python Debugger](https://docs.python.org/3/library/pdb.html) /// - [Python documentation: `logging` — Logging facility for Python](https://docs.python.org/3/library/logging.html) -#[violation] -pub struct Debugger { +#[derive(ViolationMetadata)] +pub(crate) struct Debugger { using_type: DebuggerUsingType, } diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs b/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs index 51fe2ba4934aa..a2c2962b32ff8 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/all_with_model_form.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -37,8 +37,8 @@ use crate::rules::flake8_django::rules::helpers::is_model_form; /// model = Post /// fields = ["title", "content"] /// ``` -#[violation] -pub struct DjangoAllWithModelForm; +#[derive(ViolationMetadata)] +pub(crate) struct DjangoAllWithModelForm; impl Violation for DjangoAllWithModelForm { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/exclude_with_model_form.rs b/crates/ruff_linter/src/rules/flake8_django/rules/exclude_with_model_form.rs index 73736225b46e6..0441edb209bd3 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/exclude_with_model_form.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/exclude_with_model_form.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -35,8 +35,8 @@ use crate::rules::flake8_django::rules::helpers::is_model_form; /// model = Post /// fields = ["title", "content"] /// ``` -#[violation] -pub struct DjangoExcludeWithModelForm; +#[derive(ViolationMetadata)] +pub(crate) struct DjangoExcludeWithModelForm; impl Violation for DjangoExcludeWithModelForm { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/locals_in_render_function.rs b/crates/ruff_linter/src/rules/flake8_django/rules/locals_in_render_function.rs index b004b8ded730b..b08adc2be1f7b 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/locals_in_render_function.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/locals_in_render_function.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::{Modules, SemanticModel}; use ruff_text_size::Ranged; @@ -33,8 +33,8 @@ use crate::checkers::ast::Checker; /// context = {"posts": posts} /// return render(request, "app/index.html", context) /// ``` -#[violation] -pub struct DjangoLocalsInRenderFunction; +#[derive(ViolationMetadata)] +pub(crate) struct DjangoLocalsInRenderFunction; impl Violation for DjangoLocalsInRenderFunction { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs b/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs index bf0bd77b21134..294d79e94d4d2 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/model_without_dunder_str.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_const_true; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::{self as ast, Expr, Stmt}; @@ -40,8 +40,8 @@ use super::helpers; /// def __str__(self): /// return f"{self.field}" /// ``` -#[violation] -pub struct DjangoModelWithoutDunderStr; +#[derive(ViolationMetadata)] +pub(crate) struct DjangoModelWithoutDunderStr; impl Violation for DjangoModelWithoutDunderStr { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/non_leading_receiver_decorator.rs b/crates/ruff_linter/src/rules/flake8_django/rules/non_leading_receiver_decorator.rs index 12d573920e39b..72801f22025a9 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/non_leading_receiver_decorator.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/non_leading_receiver_decorator.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Decorator; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -40,8 +40,8 @@ use crate::checkers::ast::Checker; /// def my_handler(sender, instance, created, **kwargs): /// pass /// ``` -#[violation] -pub struct DjangoNonLeadingReceiverDecorator; +#[derive(ViolationMetadata)] +pub(crate) struct DjangoNonLeadingReceiverDecorator; impl Violation for DjangoNonLeadingReceiverDecorator { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/nullable_model_string_field.rs b/crates/ruff_linter/src/rules/flake8_django/rules/nullable_model_string_field.rs index 2fe2b6aaba9d2..9d103c6c1de99 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/nullable_model_string_field.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/nullable_model_string_field.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_const_true; use ruff_python_semantic::{Modules, SemanticModel}; use ruff_text_size::Ranged; @@ -40,8 +40,8 @@ use super::helpers; /// class MyModel(models.Model): /// field = models.CharField(max_length=255, default="") /// ``` -#[violation] -pub struct DjangoNullableModelStringField { +#[derive(ViolationMetadata)] +pub(crate) struct DjangoNullableModelStringField { field_name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_django/rules/unordered_body_content_in_model.rs b/crates/ruff_linter/src/rules/flake8_django/rules/unordered_body_content_in_model.rs index 7b5596d55269b..14adaf6277fb0 100644 --- a/crates/ruff_linter/src/rules/flake8_django/rules/unordered_body_content_in_model.rs +++ b/crates/ruff_linter/src/rules/flake8_django/rules/unordered_body_content_in_model.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_python_semantic::{Modules, SemanticModel}; use ruff_text_size::Ranged; @@ -61,8 +61,8 @@ use super::helpers; /// ``` /// /// [Django Style Guide]: https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/coding-style/#model-style -#[violation] -pub struct DjangoUnorderedBodyContentInModel { +#[derive(ViolationMetadata)] +pub(crate) struct DjangoUnorderedBodyContentInModel { element_type: ContentType, prev_element_type: ContentType, } diff --git a/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs b/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs index 4f461b07a394d..42bbf9067fbf8 100644 --- a/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::whitespace; use ruff_python_ast::{self as ast, Arguments, Expr, Stmt}; use ruff_python_codegen::Stylist; @@ -47,8 +47,8 @@ use crate::Locator; /// raise RuntimeError(msg) /// RuntimeError: 'Some value' is incorrect /// ``` -#[violation] -pub struct RawStringInException; +#[derive(ViolationMetadata)] +pub(crate) struct RawStringInException; impl Violation for RawStringInException { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; @@ -102,8 +102,8 @@ impl Violation for RawStringInException { /// raise RuntimeError(msg) /// RuntimeError: 'Some value' is incorrect /// ``` -#[violation] -pub struct FStringInException; +#[derive(ViolationMetadata)] +pub(crate) struct FStringInException; impl Violation for FStringInException { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; @@ -158,8 +158,8 @@ impl Violation for FStringInException { /// raise RuntimeError(msg) /// RuntimeError: 'Some value' is incorrect /// ``` -#[violation] -pub struct DotFormatInException; +#[derive(ViolationMetadata)] +pub(crate) struct DotFormatInException; impl Violation for DotFormatInException { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs b/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs index fcc6d299ccbc9..a0d3bb8a64763 100644 --- a/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs +++ b/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs @@ -2,7 +2,7 @@ use ruff_text_size::{TextRange, TextSize}; use crate::Locator; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_trivia::is_python_whitespace; /// ## What it does @@ -29,8 +29,8 @@ use ruff_python_trivia::is_python_whitespace; /// /// ## References /// - [Python documentation: Executable Python Scripts](https://docs.python.org/3/tutorial/appendix.html#executable-python-scripts) -#[violation] -pub struct ShebangLeadingWhitespace; +#[derive(ViolationMetadata)] +pub(crate) struct ShebangLeadingWhitespace; impl AlwaysFixableViolation for ShebangLeadingWhitespace { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_missing_executable_file.rs b/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_missing_executable_file.rs index 84d2a8faccd8c..ef539e53ce831 100644 --- a/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_missing_executable_file.rs +++ b/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_missing_executable_file.rs @@ -5,7 +5,7 @@ use std::path::Path; use ruff_text_size::{Ranged, TextRange}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::registry::AsRule; #[cfg(target_family = "unix")] @@ -35,8 +35,8 @@ use crate::rules::flake8_executable::helpers::is_executable; /// /// ## References /// - [Python documentation: Executable Python Scripts](https://docs.python.org/3/tutorial/appendix.html#executable-python-scripts) -#[violation] -pub struct ShebangMissingExecutableFile; +#[derive(ViolationMetadata)] +pub(crate) struct ShebangMissingExecutableFile; impl Violation for ShebangMissingExecutableFile { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_missing_python.rs b/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_missing_python.rs index 2ce920116e01a..d5aaf9ddd65d5 100644 --- a/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_missing_python.rs +++ b/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_missing_python.rs @@ -1,7 +1,7 @@ use ruff_text_size::TextRange; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::comments::shebang::ShebangDirective; @@ -30,8 +30,8 @@ use crate::comments::shebang::ShebangDirective; /// /// ## References /// - [Python documentation: Executable Python Scripts](https://docs.python.org/3/tutorial/appendix.html#executable-python-scripts) -#[violation] -pub struct ShebangMissingPython; +#[derive(ViolationMetadata)] +pub(crate) struct ShebangMissingPython; impl Violation for ShebangMissingPython { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_not_executable.rs b/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_not_executable.rs index 5a5939f5ac271..c885d2f93faa5 100644 --- a/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_not_executable.rs +++ b/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_not_executable.rs @@ -5,7 +5,7 @@ use std::path::Path; use ruff_text_size::{Ranged, TextRange}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; #[cfg(target_family = "unix")] use crate::rules::flake8_executable::helpers::is_executable; @@ -40,8 +40,8 @@ use crate::rules::flake8_executable::helpers::is_executable; /// /// ## References /// - [Python documentation: Executable Python Scripts](https://docs.python.org/3/tutorial/appendix.html#executable-python-scripts) -#[violation] -pub struct ShebangNotExecutable; +#[derive(ViolationMetadata)] +pub(crate) struct ShebangNotExecutable; impl Violation for ShebangNotExecutable { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_not_first_line.rs b/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_not_first_line.rs index 687e253bd7ddd..6c1bb58bba566 100644 --- a/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_not_first_line.rs +++ b/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_not_first_line.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_trivia::is_python_whitespace; use ruff_text_size::{TextRange, TextSize}; @@ -31,8 +31,8 @@ use crate::Locator; /// /// ## References /// - [Python documentation: Executable Python Scripts](https://docs.python.org/3/tutorial/appendix.html#executable-python-scripts) -#[violation] -pub struct ShebangNotFirstLine; +#[derive(ViolationMetadata)] +pub(crate) struct ShebangNotFirstLine; impl Violation for ShebangNotFirstLine { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_fixme/rules/todos.rs b/crates/ruff_linter/src/rules/flake8_fixme/rules/todos.rs index 3a4af612f6343..722ca1543e451 100644 --- a/crates/ruff_linter/src/rules/flake8_fixme/rules/todos.rs +++ b/crates/ruff_linter/src/rules/flake8_fixme/rules/todos.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::directives::{TodoComment, TodoDirectiveKind}; @@ -21,8 +21,8 @@ use crate::directives::{TodoComment, TodoDirectiveKind}; /// def greet(name): /// return f"Hello, {name}!" # TODO: Add support for custom greetings. /// ``` -#[violation] -pub struct LineContainsTodo; +#[derive(ViolationMetadata)] +pub(crate) struct LineContainsTodo; impl Violation for LineContainsTodo { #[derive_message_formats] fn message(&self) -> String { @@ -47,8 +47,8 @@ impl Violation for LineContainsTodo { /// def speed(distance, time): /// return distance / time # FIXME: Raises ZeroDivisionError for time = 0. /// ``` -#[violation] -pub struct LineContainsFixme; +#[derive(ViolationMetadata)] +pub(crate) struct LineContainsFixme; impl Violation for LineContainsFixme { #[derive_message_formats] fn message(&self) -> String { @@ -70,8 +70,8 @@ impl Violation for LineContainsFixme { /// def speed(distance, time): /// return distance / time # XXX: Raises ZeroDivisionError for time = 0. /// ``` -#[violation] -pub struct LineContainsXxx; +#[derive(ViolationMetadata)] +pub(crate) struct LineContainsXxx; impl Violation for LineContainsXxx { #[derive_message_formats] fn message(&self) -> String { @@ -105,8 +105,8 @@ impl Violation for LineContainsXxx { /// os.rmdir("C:\\Windows\\System32\\") /// return False /// ``` -#[violation] -pub struct LineContainsHack; +#[derive(ViolationMetadata)] +pub(crate) struct LineContainsHack; impl Violation for LineContainsHack { #[derive_message_formats] fn message(&self) -> String { diff --git a/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_required_type_annotation.rs b/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_required_type_annotation.rs index 48f0ab7484c8e..e4c721417e0c3 100644 --- a/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_required_type_annotation.rs +++ b/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_required_type_annotation.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Expr; use ruff_python_semantic::{MemberNameImport, NameImport}; use ruff_text_size::{Ranged, TextSize}; @@ -49,8 +49,8 @@ use crate::checkers::ast::Checker; /// /// ## Options /// - `target-version` -#[violation] -pub struct FutureRequiredTypeAnnotation { +#[derive(ViolationMetadata)] +pub(crate) struct FutureRequiredTypeAnnotation { reason: Reason, } diff --git a/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_rewritable_type_annotation.rs b/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_rewritable_type_annotation.rs index c6e4b2bf96ac8..8a6b1f00636ba 100644 --- a/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_rewritable_type_annotation.rs +++ b/crates/ruff_linter/src/rules/flake8_future_annotations/rules/future_rewritable_type_annotation.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -63,8 +63,8 @@ use crate::checkers::ast::Checker; /// /// ## Options /// - `target-version` -#[violation] -pub struct FutureRewritableTypeAnnotation { +#[derive(ViolationMetadata)] +pub(crate) struct FutureRewritableTypeAnnotation { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs b/crates/ruff_linter/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs index b46e523d11bc7..c6fe3312695b1 100644 --- a/crates/ruff_linter/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs +++ b/crates/ruff_linter/src/rules/flake8_gettext/rules/f_string_in_gettext_func_call.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -40,8 +40,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `gettext` — Multilingual internationalization services](https://docs.python.org/3/library/gettext.html) -#[violation] -pub struct FStringInGetTextFuncCall; +#[derive(ViolationMetadata)] +pub(crate) struct FStringInGetTextFuncCall; impl Violation for FStringInGetTextFuncCall { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs b/crates/ruff_linter/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs index 712c6e6df36e6..eb8534a2fa0ec 100644 --- a/crates/ruff_linter/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs +++ b/crates/ruff_linter/src/rules/flake8_gettext/rules/format_in_gettext_func_call.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -40,8 +40,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `gettext` — Multilingual internationalization services](https://docs.python.org/3/library/gettext.html) -#[violation] -pub struct FormatInGetTextFuncCall; +#[derive(ViolationMetadata)] +pub(crate) struct FormatInGetTextFuncCall; impl Violation for FormatInGetTextFuncCall { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs b/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs index 7d68d75f77c4e..8e243618916e4 100644 --- a/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs +++ b/crates/ruff_linter/src/rules/flake8_gettext/rules/printf_in_gettext_func_call.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Expr, Operator}; use crate::checkers::ast::Checker; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; /// ## What it does @@ -39,8 +39,8 @@ use ruff_text_size::Ranged; /// /// ## References /// - [Python documentation: `gettext` — Multilingual internationalization services](https://docs.python.org/3/library/gettext.html) -#[violation] -pub struct PrintfInGetTextFuncCall; +#[derive(ViolationMetadata)] +pub(crate) struct PrintfInGetTextFuncCall; impl Violation for PrintfInGetTextFuncCall { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/explicit.rs b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/explicit.rs index 730e04c5e946f..16429da3e793f 100644 --- a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/explicit.rs +++ b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/explicit.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Operator}; use ruff_source_file::LineRanges; use ruff_text_size::Ranged; @@ -31,8 +31,8 @@ use crate::Locator; /// "dog" /// ) /// ``` -#[violation] -pub struct ExplicitStringConcatenation; +#[derive(ViolationMetadata)] +pub(crate) struct ExplicitStringConcatenation; impl Violation for ExplicitStringConcatenation { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/implicit.rs b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/implicit.rs index c2b34f66c20ad..86c90bbd7c883 100644 --- a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/implicit.rs +++ b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/implicit.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use itertools::Itertools; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::str::{leading_quote, trailing_quote}; use ruff_python_index::Indexer; use ruff_python_parser::{TokenKind, Tokens}; @@ -43,13 +43,14 @@ use crate::Locator; /// 1. Run the linter with this rule (`ISC001`) disabled /// 2. Run the [formatter] /// 3. Rerun the linter with this rule (`ISC001`) enabled +/// /// This is one of very few cases where the [formatter] can produce code that /// contains lint violations. It is a known issue that should be resolved by the /// new 2025 style guide. /// /// [formatter]:https://docs.astral.sh/ruff/formatter/ -#[violation] -pub struct SingleLineImplicitStringConcatenation; +#[derive(ViolationMetadata)] +pub(crate) struct SingleLineImplicitStringConcatenation; impl Violation for SingleLineImplicitStringConcatenation { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; @@ -100,17 +101,19 @@ impl Violation for SingleLineImplicitStringConcatenation { /// Currently, the [formatter] can introduce new multi-line implicitly /// concatenated strings, therefore we suggest rerunning the linter and /// [formatter] in the following order: +/// /// 1. Run the linter with this rule (`ISC002`) disabled /// 2. Run the [formatter] /// 3. Rerun the linter with this rule (`ISC002`) enabled +/// /// This is one of very few cases where the [formatter] can produce code that /// contains lint violations. It is a known issue that should be resolved by the /// new 2025 style guide. /// /// [PEP 8]: https://peps.python.org/pep-0008/#maximum-line-length /// [formatter]:https://docs.astral.sh/ruff/formatter/ -#[violation] -pub struct MultiLineImplicitStringConcatenation; +#[derive(ViolationMetadata)] +pub(crate) struct MultiLineImplicitStringConcatenation; impl Violation for MultiLineImplicitStringConcatenation { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_import_conventions/rules/banned_import_alias.rs b/crates/ruff_linter/src/rules/flake8_import_conventions/rules/banned_import_alias.rs index 071736ac3cbae..7f6788fa25db7 100644 --- a/crates/ruff_linter/src/rules/flake8_import_conventions/rules/banned_import_alias.rs +++ b/crates/ruff_linter/src/rules/flake8_import_conventions/rules/banned_import_alias.rs @@ -1,7 +1,7 @@ use rustc_hash::FxHashMap; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Stmt; use ruff_text_size::Ranged; @@ -32,8 +32,8 @@ use crate::rules::flake8_import_conventions::settings::BannedAliases; /// /// ## Options /// - `lint.flake8-import-conventions.banned-aliases` -#[violation] -pub struct BannedImportAlias { +#[derive(ViolationMetadata)] +pub(crate) struct BannedImportAlias { name: String, asname: String, } diff --git a/crates/ruff_linter/src/rules/flake8_import_conventions/rules/banned_import_from.rs b/crates/ruff_linter/src/rules/flake8_import_conventions/rules/banned_import_from.rs index 7cbeae6f831f8..2fa407d54e678 100644 --- a/crates/ruff_linter/src/rules/flake8_import_conventions/rules/banned_import_from.rs +++ b/crates/ruff_linter/src/rules/flake8_import_conventions/rules/banned_import_from.rs @@ -2,7 +2,7 @@ use ruff_python_ast::Stmt; use rustc_hash::FxHashSet; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; /// ## What it does @@ -31,8 +31,8 @@ use ruff_text_size::Ranged; /// /// ## Options /// - `lint.flake8-import-conventions.banned-from` -#[violation] -pub struct BannedImportFrom { +#[derive(ViolationMetadata)] +pub(crate) struct BannedImportFrom { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_import_conventions/rules/unconventional_import_alias.rs b/crates/ruff_linter/src/rules/flake8_import_conventions/rules/unconventional_import_alias.rs index 2ebe87f48d586..bdd50e33974be 100644 --- a/crates/ruff_linter/src/rules/flake8_import_conventions/rules/unconventional_import_alias.rs +++ b/crates/ruff_linter/src/rules/flake8_import_conventions/rules/unconventional_import_alias.rs @@ -1,7 +1,7 @@ use rustc_hash::FxHashMap; use ruff_diagnostics::{Diagnostic, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::{Binding, Imported}; use ruff_text_size::Ranged; @@ -34,8 +34,8 @@ use crate::renamer::Renamer; /// ## Options /// - `lint.flake8-import-conventions.aliases` /// - `lint.flake8-import-conventions.extend-aliases` -#[violation] -pub struct UnconventionalImportAlias { +#[derive(ViolationMetadata)] +pub(crate) struct UnconventionalImportAlias { name: String, asname: String, } diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs index 04ecdee793046..037ab40cb3879 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -37,8 +37,8 @@ use crate::importer::ImportRequest; /// ``` /// /// [Logger Objects]: https://docs.python.org/3/library/logging.html#logger-objects -#[violation] -pub struct DirectLoggerInstantiation; +#[derive(ViolationMetadata)] +pub(crate) struct DirectLoggerInstantiation; impl Violation for DirectLoggerInstantiation { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/exception_without_exc_info.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/exception_without_exc_info.rs index 91aba60224e0d..eb7d92d1237e7 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/exception_without_exc_info.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/exception_without_exc_info.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::Truthiness; use ruff_python_ast::{self as ast, Expr, ExprCall}; use ruff_python_semantic::analyze::logging; @@ -30,8 +30,8 @@ use crate::checkers::ast::Checker; /// ```python /// logging.error("...") /// ``` -#[violation] -pub struct ExceptionWithoutExcInfo; +#[derive(ViolationMetadata)] +pub(crate) struct ExceptionWithoutExcInfo; impl Violation for ExceptionWithoutExcInfo { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/invalid_get_logger_argument.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/invalid_get_logger_argument.rs index 6e245cae48dd6..83b401f6a64ca 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/invalid_get_logger_argument.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/invalid_get_logger_argument.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -40,8 +40,8 @@ use crate::checkers::ast::Checker; /// ``` /// /// [logging documentation]: https://docs.python.org/3/library/logging.html#logger-objects -#[violation] -pub struct InvalidGetLoggerArgument; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidGetLoggerArgument; impl Violation for InvalidGetLoggerArgument { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/root_logger_call.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/root_logger_call.rs index f0fc6af0f23cc..dab4d2a47e2ce 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/root_logger_call.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/root_logger_call.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::ExprCall; use ruff_python_semantic::Modules; @@ -27,8 +27,8 @@ use crate::checkers::ast::Checker; /// logger = logging.getLogger(__name__) /// logger.info("Foobar") /// ``` -#[violation] -pub struct RootLoggerCall { +#[derive(ViolationMetadata)] +pub(crate) struct RootLoggerCall { attr: String, } diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/undocumented_warn.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/undocumented_warn.rs index 3064a135c671b..82466c4157632 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/undocumented_warn.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/undocumented_warn.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -32,8 +32,8 @@ use crate::importer::ImportRequest; /// /// logging.basicConfig(level=logging.WARNING) /// ``` -#[violation] -pub struct UndocumentedWarn; +#[derive(ViolationMetadata)] +pub(crate) struct UndocumentedWarn; impl Violation for UndocumentedWarn { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_logging_format/violations.rs b/crates/ruff_linter/src/rules/flake8_logging_format/violations.rs index d11accc41cd84..ad6c399afa6ad 100644 --- a/crates/ruff_linter/src/rules/flake8_logging_format/violations.rs +++ b/crates/ruff_linter/src/rules/flake8_logging_format/violations.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for uses of `str.format` to format logging messages. @@ -73,8 +73,8 @@ use ruff_macros::{derive_message_formats, violation}; /// ## References /// - [Python documentation: `logging`](https://docs.python.org/3/library/logging.html) /// - [Python documentation: Optimization](https://docs.python.org/3/howto/logging.html#optimization) -#[violation] -pub struct LoggingStringFormat; +#[derive(ViolationMetadata)] +pub(crate) struct LoggingStringFormat; impl Violation for LoggingStringFormat { #[derive_message_formats] @@ -157,8 +157,8 @@ impl Violation for LoggingStringFormat { /// ## References /// - [Python documentation: `logging`](https://docs.python.org/3/library/logging.html) /// - [Python documentation: Optimization](https://docs.python.org/3/howto/logging.html#optimization) -#[violation] -pub struct LoggingPercentFormat; +#[derive(ViolationMetadata)] +pub(crate) struct LoggingPercentFormat; impl Violation for LoggingPercentFormat { #[derive_message_formats] @@ -240,8 +240,8 @@ impl Violation for LoggingPercentFormat { /// ## References /// - [Python documentation: `logging`](https://docs.python.org/3/library/logging.html) /// - [Python documentation: Optimization](https://docs.python.org/3/howto/logging.html#optimization) -#[violation] -pub struct LoggingStringConcat; +#[derive(ViolationMetadata)] +pub(crate) struct LoggingStringConcat; impl Violation for LoggingStringConcat { #[derive_message_formats] @@ -322,8 +322,8 @@ impl Violation for LoggingStringConcat { /// ## References /// - [Python documentation: `logging`](https://docs.python.org/3/library/logging.html) /// - [Python documentation: Optimization](https://docs.python.org/3/howto/logging.html#optimization) -#[violation] -pub struct LoggingFString; +#[derive(ViolationMetadata)] +pub(crate) struct LoggingFString; impl Violation for LoggingFString { #[derive_message_formats] @@ -373,8 +373,8 @@ impl Violation for LoggingFString { /// ## References /// - [Python documentation: `logging.warning`](https://docs.python.org/3/library/logging.html#logging.warning) /// - [Python documentation: `logging.Logger.warning`](https://docs.python.org/3/library/logging.html#logging.Logger.warning) -#[violation] -pub struct LoggingWarn; +#[derive(ViolationMetadata)] +pub(crate) struct LoggingWarn; impl AlwaysFixableViolation for LoggingWarn { #[derive_message_formats] @@ -440,8 +440,8 @@ impl AlwaysFixableViolation for LoggingWarn { /// /// ## References /// - [Python documentation: LogRecord attributes](https://docs.python.org/3/library/logging.html#logrecord-attributes) -#[violation] -pub struct LoggingExtraAttrClash(pub String); +#[derive(ViolationMetadata)] +pub(crate) struct LoggingExtraAttrClash(pub String); impl Violation for LoggingExtraAttrClash { #[derive_message_formats] @@ -502,8 +502,8 @@ impl Violation for LoggingExtraAttrClash { /// - [Python documentation: `exception`](https://docs.python.org/3/library/logging.html#logging.Logger.exception) /// - [Python documentation: `logging.error`](https://docs.python.org/3/library/logging.html#logging.error) /// - [Python documentation: `error`](https://docs.python.org/3/library/logging.html#logging.Logger.error) -#[violation] -pub struct LoggingExcInfo; +#[derive(ViolationMetadata)] +pub(crate) struct LoggingExcInfo; impl Violation for LoggingExcInfo { #[derive_message_formats] @@ -564,8 +564,8 @@ impl Violation for LoggingExcInfo { /// - [Python documentation: `exception`](https://docs.python.org/3/library/logging.html#logging.Logger.exception) /// - [Python documentation: `logging.error`](https://docs.python.org/3/library/logging.html#logging.error) /// - [Python documentation: `error`](https://docs.python.org/3/library/logging.html#logging.Logger.error) -#[violation] -pub struct LoggingRedundantExcInfo; +#[derive(ViolationMetadata)] +pub(crate) struct LoggingRedundantExcInfo; impl Violation for LoggingRedundantExcInfo { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_no_pep420/rules/implicit_namespace_package.rs b/crates/ruff_linter/src/rules/flake8_no_pep420/rules/implicit_namespace_package.rs index 7590092eeece8..c0b916bbdc8fc 100644 --- a/crates/ruff_linter/src/rules/flake8_no_pep420/rules/implicit_namespace_package.rs +++ b/crates/ruff_linter/src/rules/flake8_no_pep420/rules/implicit_namespace_package.rs @@ -1,7 +1,7 @@ use std::path::{Path, PathBuf}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::script::ScriptTag; use ruff_python_ast::PySourceType; use ruff_python_trivia::CommentRanges; @@ -31,8 +31,8 @@ use crate::Locator; /// /// ## Options /// - `namespace-packages` -#[violation] -pub struct ImplicitNamespacePackage { +#[derive(ViolationMetadata)] +pub(crate) struct ImplicitNamespacePackage { filename: String, parent: Option, } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs index e50af0ec2fc8c..3e5d2a0156381 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs @@ -2,7 +2,7 @@ use rustc_hash::FxHashSet; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::{AlwaysFixableViolation, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::any_over_expr; use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_text_size::Ranged; @@ -31,8 +31,8 @@ use crate::fix; /// name = Tom /// ... /// ``` -#[violation] -pub struct DuplicateClassFieldDefinition { +#[derive(ViolationMetadata)] +pub(crate) struct DuplicateClassFieldDefinition { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs index 6eaee62631ac0..836912df74b71 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs @@ -10,7 +10,7 @@ use ruff_python_ast::{self as ast, Arguments, BoolOp, Expr, ExprContext, Identif use ruff_diagnostics::AlwaysFixableViolation; use ruff_diagnostics::{Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::checkers::ast::Checker; @@ -48,8 +48,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: `str.startswith`](https://docs.python.org/3/library/stdtypes.html#str.startswith) /// - [Python documentation: `str.endswith`](https://docs.python.org/3/library/stdtypes.html#str.endswith) -#[violation] -pub struct MultipleStartsEndsWith { +#[derive(ViolationMetadata)] +pub(crate) struct MultipleStartsEndsWith { attr: String, } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/non_unique_enums.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/non_unique_enums.rs index 3b41b15e75d66..66d488c2b90a3 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/non_unique_enums.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/non_unique_enums.rs @@ -2,7 +2,7 @@ use rustc_hash::FxHashSet; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::{self as ast, Expr, PySourceType, Stmt}; use ruff_text_size::Ranged; @@ -40,8 +40,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `enum.Enum`](https://docs.python.org/3/library/enum.html#enum.Enum) -#[violation] -pub struct NonUniqueEnums { +#[derive(ViolationMetadata)] +pub(crate) struct NonUniqueEnums { value: String, } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_container_builtin.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_container_builtin.rs index c085d235d1568..ce04478051b14 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_container_builtin.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_container_builtin.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{Expr, ExprLambda}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_diagnostics::{FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -37,8 +37,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `list`](https://docs.python.org/3/library/functions.html#func-list) -#[violation] -pub struct ReimplementedContainerBuiltin { +#[derive(ViolationMetadata)] +pub(crate) struct ReimplementedContainerBuiltin { container: Container, } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs index d83287489f190..43bfaec38733d 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs @@ -2,7 +2,7 @@ use itertools::Itertools; use rustc_hash::{FxBuildHasher, FxHashSet}; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::{self as ast, Expr}; use ruff_python_stdlib::identifiers::is_identifier; @@ -39,8 +39,8 @@ use crate::fix::edits::{remove_argument, Parentheses}; /// ## References /// - [Python documentation: Dictionary displays](https://docs.python.org/3/reference/expressions.html#dictionary-displays) /// - [Python documentation: Calls](https://docs.python.org/3/reference/expressions.html#calls) -#[violation] -pub struct UnnecessaryDictKwargs; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryDictKwargs; impl Violation for UnnecessaryDictKwargs { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_placeholder.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_placeholder.rs index cc424e986ba32..c88aef8353695 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_placeholder.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_placeholder.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::{AlwaysFixableViolation, Applicability}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::map_subscript; use ruff_python_ast::whitespace::trailing_comment_start_offset; use ruff_python_ast::{Expr, ExprStringLiteral, Stmt, StmtExpr}; @@ -58,8 +58,8 @@ use crate::fix; /// /// ## References /// - [Python documentation: The `pass` statement](https://docs.python.org/3/reference/simple_stmts.html#the-pass-statement) -#[violation] -pub struct UnnecessaryPlaceholder { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryPlaceholder { kind: Placeholder, } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs index 5dfb2c5b91e6a..1deb7376370ce 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::Diagnostic; use ruff_diagnostics::{AlwaysFixableViolation, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -27,8 +27,8 @@ use crate::fix::edits::{remove_argument, Parentheses}; /// /// ## References /// - [Python documentation: `range`](https://docs.python.org/3/library/stdtypes.html#range) -#[violation] -pub struct UnnecessaryRangeStart; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryRangeStart; impl AlwaysFixableViolation for UnnecessaryRangeStart { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_spread.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_spread.rs index c2673aff8d457..15dd9b883bc29 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_spread.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_spread.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_text_size::{Ranged, TextSize}; @@ -28,8 +28,8 @@ use crate::Locator; /// /// ## References /// - [Python documentation: Dictionary displays](https://docs.python.org/3/reference/expressions.html#dictionary-displays) -#[violation] -pub struct UnnecessarySpread; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessarySpread; impl Violation for UnnecessarySpread { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs b/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs index 791784360016b..09e7c81357a43 100644 --- a/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs +++ b/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_text_size::Ranged; @@ -32,8 +32,8 @@ use crate::registry::AsRule; /// ## Fix safety /// This rule's fix is marked as unsafe, as it may remove `print` statements /// that are used beyond debugging purposes. -#[violation] -pub struct Print; +#[derive(ViolationMetadata)] +pub(crate) struct Print; impl Violation for Print { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; @@ -79,8 +79,8 @@ impl Violation for Print { /// ## Fix safety /// This rule's fix is marked as unsafe, as it may remove `pprint` statements /// that are used beyond debugging purposes. -#[violation] -pub struct PPrint; +#[derive(ViolationMetadata)] +pub(crate) struct PPrint; impl Violation for PPrint { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs index 86a13f41ff889..83df7ce4537c5 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Parameters; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -41,8 +41,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: The `Any` type](https://docs.python.org/3/library/typing.html#the-any-type) /// - [Mypy documentation: Any vs. object](https://mypy.readthedocs.io/en/latest/dynamic_typing.html#any-vs-object) -#[violation] -pub struct AnyEqNeAnnotation { +#[derive(ViolationMetadata)] +pub(crate) struct AnyEqNeAnnotation { method_name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_generator_return_type.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_generator_return_type.rs index 1406bb4bd2073..7aad7fb4793e6 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_generator_return_type.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_generator_return_type.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::helpers::map_subscript; use ruff_python_ast::identifier::Identifier; @@ -58,8 +58,8 @@ use crate::importer::ImportRequest; /// applied to runtime Python (`.py` files). As such, the fix is marked as /// unsafe for any `__iter__` or `__aiter__` method in a `.py` file that has /// more than two statements (including docstrings) in its body. -#[violation] -pub struct GeneratorReturnFromIterMethod { +#[derive(ViolationMetadata)] +pub(crate) struct GeneratorReturnFromIterMethod { return_type: Iterator, method: Method, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs index 5f09722aeb3cd..b606470452c2c 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, CmpOp, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -51,8 +51,8 @@ use crate::registry::Rule; /// ``` /// /// [preview]: https://docs.astral.sh/ruff/preview/ -#[violation] -pub struct BadVersionInfoComparison; +#[derive(ViolationMetadata)] +pub(crate) struct BadVersionInfoComparison; impl Violation for BadVersionInfoComparison { #[derive_message_formats] @@ -100,8 +100,8 @@ impl Violation for BadVersionInfoComparison { /// ``` /// /// [preview]: https://docs.astral.sh/ruff/preview/ -#[violation] -pub struct BadVersionInfoOrder; +#[derive(ViolationMetadata)] +pub(crate) struct BadVersionInfoOrder; impl Violation for BadVersionInfoOrder { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/bytestring_usage.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/bytestring_usage.rs index c8bf140491dd9..7da5b0b348ec6 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/bytestring_usage.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/bytestring_usage.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -27,8 +27,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: The `ByteString` type](https://docs.python.org/3/library/typing.html#typing.ByteString) -#[violation] -pub struct ByteStringUsage { +#[derive(ViolationMetadata)] +pub(crate) struct ByteStringUsage { origin: ByteStringOrigin, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/collections_named_tuple.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/collections_named_tuple.rs index e56b4023877b2..8192184d1b656 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/collections_named_tuple.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/collections_named_tuple.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -35,8 +35,8 @@ use crate::checkers::ast::Checker; /// name: str /// age: int /// ``` -#[violation] -pub struct CollectionsNamedTuple; +#[derive(ViolationMetadata)] +pub(crate) struct CollectionsNamedTuple; impl Violation for CollectionsNamedTuple { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_assignment_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_assignment_in_stub.rs index 2a018cb6b8e5f..508868d613caa 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_assignment_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_assignment_in_stub.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{Expr, StmtAssign}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::checkers::ast::Checker; @@ -41,8 +41,8 @@ use crate::checkers::ast::Checker; /// class Klass: /// X: TypeAlias = int /// ``` -#[violation] -pub struct ComplexAssignmentInStub; +#[derive(ViolationMetadata)] +pub(crate) struct ComplexAssignmentInStub; impl Violation for ComplexAssignmentInStub { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_if_statement_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_if_statement_in_stub.rs index ca075c48bc5f6..be20c05c42599 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_if_statement_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/complex_if_statement_in_stub.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -31,8 +31,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Typing documentation: Version and platform checking](https://typing.readthedocs.io/en/latest/spec/directives.html#version-and-platform-checks) -#[violation] -pub struct ComplexIfStatementInStub; +#[derive(ViolationMetadata)] +pub(crate) struct ComplexIfStatementInStub; impl Violation for ComplexIfStatementInStub { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs index 5baf7907d2ad6..3bf5bc76ab300 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs @@ -2,7 +2,7 @@ use crate::checkers::ast::Checker; use crate::importer::ImportRequest; use itertools::Itertools; use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::helpers::map_subscript; use ruff_python_ast::{Expr, Parameters, TypeParam, TypeParams}; @@ -56,8 +56,8 @@ use ruff_text_size::{Ranged, TextRange}; /// /// [PEP 673]: https://peps.python.org/pep-0673/#motivation /// [PEP 695]: https://peps.python.org/pep-0695/ -#[violation] -pub struct CustomTypeVarReturnType { +#[derive(ViolationMetadata)] +pub(crate) struct CustomTypeVarReturnType { method_name: String, in_stub: bool, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/docstring_in_stubs.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/docstring_in_stubs.rs index 188d87cf09ca3..c7529fbad3809 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/docstring_in_stubs.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/docstring_in_stubs.rs @@ -1,7 +1,7 @@ use ruff_python_ast::ExprStringLiteral; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use ruff_python_semantic::Definition; @@ -28,8 +28,8 @@ use crate::checkers::ast::Checker; /// ```pyi /// def func(param: int) -> str: ... /// ``` -#[violation] -pub struct DocstringInStub; +#[derive(ViolationMetadata)] +pub(crate) struct DocstringInStub; impl AlwaysFixableViolation for DocstringInStub { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs index cc67e93ad0bfb..d5c7125bd219b 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs @@ -3,7 +3,7 @@ use std::collections::HashSet; use rustc_hash::FxHashSet; use ruff_diagnostics::{AlwaysFixableViolation, Applicability, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::{self as ast, Expr, ExprContext}; use ruff_python_semantic::analyze::typing::traverse_literal; @@ -35,8 +35,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `typing.Literal`](https://docs.python.org/3/library/typing.html#typing.Literal) -#[violation] -pub struct DuplicateLiteralMember { +#[derive(ViolationMetadata)] +pub(crate) struct DuplicateLiteralMember { duplicate_name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs index 711a60c87a362..e98064e965c96 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs @@ -6,7 +6,7 @@ use ruff_python_ast::name::Name; use rustc_hash::FxHashSet; use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::{Expr, ExprBinOp, ExprContext, ExprName, ExprSubscript, ExprTuple, Operator}; use ruff_python_semantic::analyze::typing::traverse_union; @@ -39,8 +39,8 @@ use crate::importer::ImportRequest; /// /// ## References /// - [Python documentation: `typing.Union`](https://docs.python.org/3/library/typing.html#typing.Union) -#[violation] -pub struct DuplicateUnionMember { +#[derive(ViolationMetadata)] +pub(crate) struct DuplicateUnionMember { duplicate_name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs index 6cba3408bd5d3..f1e06cd632b30 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Stmt, StmtExpr}; use ruff_text_size::Ranged; @@ -26,8 +26,8 @@ use crate::fix; /// class Foo: /// value: int /// ``` -#[violation] -pub struct EllipsisInNonEmptyClassBody; +#[derive(ViolationMetadata)] +pub(crate) struct EllipsisInNonEmptyClassBody; impl Violation for EllipsisInNonEmptyClassBody { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs index 15a92bae415b4..dc4b4ce768ebb 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs @@ -7,7 +7,7 @@ use ruff_python_ast::{ use smallvec::SmallVec; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::{analyze::visibility::is_overload, SemanticModel}; use ruff_text_size::{Ranged, TextRange}; @@ -46,8 +46,8 @@ use crate::checkers::ast::Checker; /// tb: TracebackType | None, /// ) -> None: ... /// ``` -#[violation] -pub struct BadExitAnnotation { +#[derive(ViolationMetadata)] +pub(crate) struct BadExitAnnotation { func_kind: FuncKind, error_kind: ErrorKind, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs index 1ab38e4b68aab..f8a0662dd129f 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs @@ -1,7 +1,7 @@ use ruff_python_ast::StmtImportFrom; use ruff_diagnostics::{Diagnostic, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::{checkers::ast::Checker, fix}; @@ -17,8 +17,8 @@ use crate::{checkers::ast::Checker, fix}; /// /// ## References /// - [Static Typing with Python: Type Stubs](https://typing.readthedocs.io/en/latest/source/stubs.html) -#[violation] -pub struct FutureAnnotationsInStub; +#[derive(ViolationMetadata)] +pub(crate) struct FutureAnnotationsInStub; impl Violation for FutureAnnotationsInStub { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/generic_not_last_base_class.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/generic_not_last_base_class.rs index 23dbaa4222cd0..af36e505afba9 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/generic_not_last_base_class.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/generic_not_last_base_class.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, helpers::map_subscript}; use ruff_text_size::Ranged; @@ -47,8 +47,8 @@ use crate::fix::edits::{add_argument, remove_argument, Parentheses}; /// - [`typing.Generic` documentation](https://docs.python.org/3/library/typing.html#typing.Generic) /// /// [1]: https://github.com/python/cpython/issues/106102 -#[violation] -pub struct GenericNotLastBaseClass; +#[derive(ViolationMetadata)] +pub(crate) struct GenericNotLastBaseClass; impl Violation for GenericNotLastBaseClass { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/iter_method_return_iterable.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/iter_method_return_iterable.rs index e989c31e0bbfe..a5b5c4a66bd89 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/iter_method_return_iterable.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/iter_method_return_iterable.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::map_subscript; use ruff_text_size::Ranged; @@ -68,8 +68,8 @@ use crate::checkers::ast::Checker; /// class Klass: /// def __iter__(self) -> collections.abc.Iterator[str]: ... /// ``` -#[violation] -pub struct IterMethodReturnIterable { +#[derive(ViolationMetadata)] +pub(crate) struct IterMethodReturnIterable { is_async: bool, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/no_return_argument_annotation.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/no_return_argument_annotation.rs index e07f868407b23..23494e01cf53a 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/no_return_argument_annotation.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/no_return_argument_annotation.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_text_size::Ranged; @@ -40,8 +40,8 @@ use crate::settings::types::PythonVersion::Py311; /// - [Python documentation: `typing.NoReturn`](https://docs.python.org/3/library/typing.html#typing.NoReturn) /// /// [bottom type]: https://en.wikipedia.org/wiki/Bottom_type -#[violation] -pub struct NoReturnArgumentAnnotationInStub { +#[derive(ViolationMetadata)] +pub(crate) struct NoReturnArgumentAnnotationInStub { module: TypingModule, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_empty_stub_body.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_empty_stub_body.rs index 4d867e08865c6..1b6f512f3f046 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_empty_stub_body.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_empty_stub_body.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_docstring_stmt; use ruff_python_ast::{self as ast, Stmt}; use ruff_text_size::Ranged; @@ -27,8 +27,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Typing documentation - Writing and Maintaining Stub Files](https://typing.readthedocs.io/en/latest/guides/writing_stubs.html) -#[violation] -pub struct NonEmptyStubBody; +#[derive(ViolationMetadata)] +pub(crate) struct NonEmptyStubBody; impl AlwaysFixableViolation for NonEmptyStubBody { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs index eb67537f77e25..db9fa5dc93f0b 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs @@ -3,7 +3,7 @@ use ruff_python_ast::{self as ast, Decorator, Expr, Parameters, Stmt}; use crate::checkers::ast::Checker; use crate::importer::ImportRequest; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::map_subscript; use ruff_python_ast::identifier::Identifier; use ruff_python_semantic::analyze; @@ -73,8 +73,8 @@ use ruff_text_size::{Ranged, TextRange}; /// ``` /// ## References /// - [Python documentation: `typing.Self`](https://docs.python.org/3/library/typing.html#typing.Self) -#[violation] -pub struct NonSelfReturnType { +#[derive(ViolationMetadata)] +pub(crate) struct NonSelfReturnType { class_name: String, method_name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs index c7a7202bb9b7b..d9ca48e1417cb 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs @@ -2,7 +2,7 @@ use ruff_python_ast::Expr; use ruff_text_size::{Ranged, TextSize}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::checkers::ast::Checker; @@ -29,8 +29,8 @@ use crate::checkers::ast::Checker; /// ```pyi /// def foo(arg: int = ...) -> None: ... /// ``` -#[violation] -pub struct NumericLiteralTooLong; +#[derive(ViolationMetadata)] +pub(crate) struct NumericLiteralTooLong; impl AlwaysFixableViolation for NumericLiteralTooLong { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_in_class_body.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_in_class_body.rs index 3fab6b848cc07..f1c9c0d54f457 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_in_class_body.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_in_class_body.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast}; use ruff_text_size::Ranged; @@ -26,8 +26,8 @@ use crate::fix; /// class MyClass: /// x: int /// ``` -#[violation] -pub struct PassInClassBody; +#[derive(ViolationMetadata)] +pub(crate) struct PassInClassBody; impl AlwaysFixableViolation for PassInClassBody { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs index b6c67ff3fc7ed..cedd0251f8d1a 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Stmt; use ruff_text_size::Ranged; @@ -24,8 +24,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Typing documentation - Writing and Maintaining Stub Files](https://typing.readthedocs.io/en/latest/guides/writing_stubs.html) -#[violation] -pub struct PassStatementStubBody; +#[derive(ViolationMetadata)] +pub(crate) struct PassStatementStubBody; impl AlwaysFixableViolation for PassStatementStubBody { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/pre_pep570_positional_argument.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/pre_pep570_positional_argument.rs index 4757f09d52539..f76a8c2ae9275 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/pre_pep570_positional_argument.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/pre_pep570_positional_argument.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::{self as ast, ParameterWithDefault}; use ruff_python_semantic::analyze::function_type; @@ -39,8 +39,8 @@ use crate::settings::types::PythonVersion; /// /// [PEP 484]: https://peps.python.org/pep-0484/#positional-only-arguments /// [PEP 570]: https://peps.python.org/pep-0570 -#[violation] -pub struct Pep484StylePositionalOnlyParameter; +#[derive(ViolationMetadata)] +pub(crate) struct Pep484StylePositionalOnlyParameter; impl Violation for Pep484StylePositionalOnlyParameter { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/prefix_type_params.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/prefix_type_params.rs index a1f696d39990a..7b908f131ff3c 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/prefix_type_params.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/prefix_type_params.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -45,8 +45,8 @@ impl fmt::Display for VarKind { /// /// _T = TypeVar("_T") /// ``` -#[violation] -pub struct UnprefixedTypeParam { +#[derive(ViolationMetadata)] +pub(crate) struct UnprefixedTypeParam { kind: VarKind, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs index d58e82034b661..99bbc83710051 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs @@ -1,7 +1,7 @@ use ruff_text_size::TextRange; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::checkers::ast::Checker; @@ -28,8 +28,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Typing documentation - Writing and Maintaining Stub Files](https://typing.readthedocs.io/en/latest/guides/writing_stubs.html) -#[violation] -pub struct QuotedAnnotationInStub; +#[derive(ViolationMetadata)] +pub(crate) struct QuotedAnnotationInStub; impl AlwaysFixableViolation for QuotedAnnotationInStub { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_final_literal.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_final_literal.rs index 65291db74210a..767d33a797834 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_final_literal.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_final_literal.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, comparable::ComparableExpr}; use ruff_text_size::{Ranged, TextSize}; @@ -33,8 +33,8 @@ use crate::Locator; /// x: Final = 42 /// y: Final = 42 /// ``` -#[violation] -pub struct RedundantFinalLiteral { +#[derive(ViolationMetadata)] +pub(crate) struct RedundantFinalLiteral { literal: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs index 282e17d71c19f..d0e579c547e2a 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs @@ -3,7 +3,7 @@ use std::fmt; use rustc_hash::FxHashSet; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, LiteralExpressionRef}; use ruff_python_semantic::analyze::typing::traverse_union; use ruff_python_semantic::SemanticModel; @@ -36,8 +36,8 @@ use crate::fix::snippet::SourceCodeSnippet; /// /// x: Literal[b"B"] | str /// ``` -#[violation] -pub struct RedundantLiteralUnion { +#[derive(ViolationMetadata)] +pub(crate) struct RedundantLiteralUnion { literal: SourceCodeSnippet, builtin_type: ExprType, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_none_literal.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_none_literal.rs index 9a23fff1b8762..9d0dd1e7c16bf 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_none_literal.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_none_literal.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Expr, ExprBinOp, ExprNoneLiteral, ExprSubscript, Operator}; use ruff_python_semantic::{ analyze::typing::{traverse_literal, traverse_union}, @@ -39,8 +39,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Typing documentation: Legal parameters for `Literal` at type check time](https://typing.readthedocs.io/en/latest/spec/literal.html#legal-parameters-for-literal-at-type-check-time) -#[violation] -pub struct RedundantNoneLiteral { +#[derive(ViolationMetadata)] +pub(crate) struct RedundantNoneLiteral { other_literal_elements_seen: bool, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_numeric_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_numeric_union.rs index 37e3f287c19b1..85d75ff23c21f 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_numeric_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_numeric_union.rs @@ -3,7 +3,7 @@ use bitflags::bitflags; use anyhow::Result; use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{ name::Name, AnyParameterRef, Expr, ExprBinOp, ExprContext, ExprName, ExprSubscript, ExprTuple, Operator, Parameters, @@ -55,8 +55,8 @@ use crate::{checkers::ast::Checker, importer::ImportRequest}; /// - [PEP 484: The numeric tower](https://peps.python.org/pep-0484/#the-numeric-tower) /// /// [typing specification]: https://typing.readthedocs.io/en/latest/spec/special-types.html#special-cases-for-float-and-complex -#[violation] -pub struct RedundantNumericUnion { +#[derive(ViolationMetadata)] +pub(crate) struct RedundantNumericUnion { redundancy: Redundancy, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs index 30a0793ebf8cf..d8d918bd72781 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::QualifiedName; use ruff_python_ast::{ self as ast, Expr, Operator, ParameterWithDefault, Parameters, Stmt, UnaryOp, @@ -43,8 +43,8 @@ use crate::Locator; /// /// ## References /// - [`flake8-pyi`](https://github.com/PyCQA/flake8-pyi/blob/main/ERRORCODES.md) -#[violation] -pub struct TypedArgumentDefaultInStub; +#[derive(ViolationMetadata)] +pub(crate) struct TypedArgumentDefaultInStub; impl AlwaysFixableViolation for TypedArgumentDefaultInStub { #[derive_message_formats] @@ -89,8 +89,8 @@ impl AlwaysFixableViolation for TypedArgumentDefaultInStub { /// /// ## References /// - [`flake8-pyi`](https://github.com/PyCQA/flake8-pyi/blob/main/ERRORCODES.md) -#[violation] -pub struct ArgumentDefaultInStub; +#[derive(ViolationMetadata)] +pub(crate) struct ArgumentDefaultInStub; impl AlwaysFixableViolation for ArgumentDefaultInStub { #[derive_message_formats] @@ -133,8 +133,8 @@ impl AlwaysFixableViolation for ArgumentDefaultInStub { /// /// ## References /// - [`flake8-pyi`](https://github.com/PyCQA/flake8-pyi/blob/main/ERRORCODES.md) -#[violation] -pub struct AssignmentDefaultInStub; +#[derive(ViolationMetadata)] +pub(crate) struct AssignmentDefaultInStub; impl AlwaysFixableViolation for AssignmentDefaultInStub { #[derive_message_formats] @@ -153,8 +153,8 @@ impl AlwaysFixableViolation for AssignmentDefaultInStub { /// ## Why is this bad? /// Stub files exist to provide type hints, and are never executed. As such, /// all assignments in stub files should be annotated with a type. -#[violation] -pub struct UnannotatedAssignmentInStub { +#[derive(ViolationMetadata)] +pub(crate) struct UnannotatedAssignmentInStub { name: String, } @@ -184,8 +184,8 @@ impl Violation for UnannotatedAssignmentInStub { /// ```pyi /// __all__: list[str] = ["foo", "bar"] /// ``` -#[violation] -pub struct UnassignedSpecialVariableInStub { +#[derive(ViolationMetadata)] +pub(crate) struct UnassignedSpecialVariableInStub { name: String, } @@ -220,8 +220,8 @@ impl Violation for UnassignedSpecialVariableInStub { /// /// Vector: TypeAlias = list[float] /// ``` -#[violation] -pub struct TypeAliasWithoutAnnotation { +#[derive(ViolationMetadata)] +pub(crate) struct TypeAliasWithoutAnnotation { module: TypingModule, name: String, value: String, diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs index ed50e59850afd..60202d9d2f0bd 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs @@ -2,7 +2,7 @@ use ruff_python_ast as ast; use ruff_python_ast::Stmt; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use ruff_python_semantic::analyze::visibility::is_abstract; @@ -23,8 +23,8 @@ use crate::fix::edits::delete_stmt; /// class Foo: /// def __repr__(self) -> str: ... /// ``` -#[violation] -pub struct StrOrReprDefinedInStub { +#[derive(ViolationMetadata)] +pub(crate) struct StrOrReprDefinedInStub { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs index 5bb20a25bd6a4..610d7f5d1b73c 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_docstring_stmt; use ruff_python_ast::{self as ast, StringLike}; use ruff_python_semantic::SemanticModel; @@ -32,8 +32,8 @@ use crate::checkers::ast::Checker; /// ```pyi /// def foo(arg: str = ...) -> None: ... /// ``` -#[violation] -pub struct StringOrBytesTooLong; +#[derive(ViolationMetadata)] +pub(crate) struct StringOrBytesTooLong; impl AlwaysFixableViolation for StringOrBytesTooLong { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/stub_body_multiple_statements.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/stub_body_multiple_statements.rs index 4b340f5432609..a4456cc6536a5 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/stub_body_multiple_statements.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/stub_body_multiple_statements.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::Stmt; @@ -28,8 +28,8 @@ use crate::checkers::ast::Checker; /// ```pyi /// def function(): ... /// ``` -#[violation] -pub struct StubBodyMultipleStatements; +#[derive(ViolationMetadata)] +pub(crate) struct StubBodyMultipleStatements; impl Violation for StubBodyMultipleStatements { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/type_alias_naming.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/type_alias_naming.rs index 937b7ac5cd1cc..dee8c3525d816 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/type_alias_naming.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/type_alias_naming.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::checkers::ast::Checker; @@ -21,8 +21,8 @@ use crate::checkers::ast::Checker; /// ```pyi /// TypeAliasName: TypeAlias = int /// ``` -#[violation] -pub struct SnakeCaseTypeAlias { +#[derive(ViolationMetadata)] +pub(crate) struct SnakeCaseTypeAlias { name: String, } @@ -60,8 +60,8 @@ impl Violation for SnakeCaseTypeAlias { /// /// ## References /// - [PEP 484: Type Aliases](https://peps.python.org/pep-0484/#type-aliases) -#[violation] -pub struct TSuffixedTypeAlias { +#[derive(ViolationMetadata)] +pub(crate) struct TSuffixedTypeAlias { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/type_comment_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/type_comment_in_stub.rs index 0f20be94577ae..2000edeb950d1 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/type_comment_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/type_comment_in_stub.rs @@ -3,7 +3,7 @@ use std::sync::LazyLock; use regex::Regex; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_trivia::CommentRanges; use crate::Locator; @@ -26,8 +26,8 @@ use crate::Locator; /// ```pyi /// x: int = 1 /// ``` -#[violation] -pub struct TypeCommentInStub; +#[derive(ViolationMetadata)] +pub(crate) struct TypeCommentInStub; impl Violation for TypeCommentInStub { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unaliased_collections_abc_set_import.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unaliased_collections_abc_set_import.rs index 5efd6b2adce5f..cc1cc6b942e47 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unaliased_collections_abc_set_import.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unaliased_collections_abc_set_import.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Applicability, Diagnostic, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Imported; use ruff_python_semantic::{Binding, BindingKind, Scope}; use ruff_text_size::Ranged; @@ -40,8 +40,8 @@ use crate::renamer::Renamer; /// re-exported if they are included in `__all__`, use a "redundant" /// `import foo as foo` alias, or are imported via a `*` import. As such, the /// fix is marked as safe in more cases for `.pyi` files. -#[violation] -pub struct UnaliasedCollectionsAbcSetImport; +#[derive(ViolationMetadata)] +pub(crate) struct UnaliasedCollectionsAbcSetImport; impl Violation for UnaliasedCollectionsAbcSetImport { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs index 9008aab1be34a..301f2b702fa4e 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::pep_604_union; use ruff_python_ast::{self as ast, Expr, ExprContext}; use ruff_python_semantic::analyze::typing::traverse_union; @@ -30,8 +30,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `typing.Literal`](https://docs.python.org/3/library/typing.html#typing.Literal) -#[violation] -pub struct UnnecessaryLiteralUnion { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryLiteralUnion { members: Vec, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs index 0a498264c856d..2dec5021b66e9 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs @@ -1,6 +1,6 @@ use ast::ExprContext; use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::pep_604_union; use ruff_python_ast::name::Name; use ruff_python_ast::{self as ast, Expr}; @@ -31,8 +31,8 @@ use crate::checkers::ast::Checker; /// /// Note that while the fix may flatten nested unions into a single top-level union, /// the semantics of the annotation will remain unchanged. -#[violation] -pub struct UnnecessaryTypeUnion { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryTypeUnion { members: Vec, union_kind: UnionKind, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_platform.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_platform.rs index ba1e1726c585c..6f747eea25cd6 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_platform.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_platform.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, CmpOp, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -41,8 +41,8 @@ use crate::registry::Rule; /// /// ## References /// - [Typing documentation: Version and Platform checking](https://typing.readthedocs.io/en/latest/spec/directives.html#version-and-platform-checks) -#[violation] -pub struct UnrecognizedPlatformCheck; +#[derive(ViolationMetadata)] +pub(crate) struct UnrecognizedPlatformCheck; impl Violation for UnrecognizedPlatformCheck { #[derive_message_formats] @@ -75,8 +75,8 @@ impl Violation for UnrecognizedPlatformCheck { /// /// ## References /// - [Typing documentation: Version and Platform checking](https://typing.readthedocs.io/en/latest/spec/directives.html#version-and-platform-checks) -#[violation] -pub struct UnrecognizedPlatformName { +#[derive(ViolationMetadata)] +pub(crate) struct UnrecognizedPlatformName { platform: String, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_version_info.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_version_info.rs index ac282eebf1fb5..7bd9f7d143762 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_version_info.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unrecognized_version_info.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::map_subscript; use ruff_python_ast::{self as ast, CmpOp, Expr, Int}; use ruff_text_size::Ranged; @@ -32,8 +32,8 @@ use crate::registry::Rule; /// /// ## References /// - [Typing documentation: Version and Platform checking](https://typing.readthedocs.io/en/latest/spec/directives.html#version-and-platform-checks) -#[violation] -pub struct UnrecognizedVersionInfoCheck; +#[derive(ViolationMetadata)] +pub(crate) struct UnrecognizedVersionInfoCheck; impl Violation for UnrecognizedVersionInfoCheck { #[derive_message_formats] @@ -71,8 +71,8 @@ impl Violation for UnrecognizedVersionInfoCheck { /// /// ## References /// - [Typing documentation: Version and Platform checking](https://typing.readthedocs.io/en/latest/spec/directives.html#version-and-platform-checks) -#[violation] -pub struct PatchVersionComparison; +#[derive(ViolationMetadata)] +pub(crate) struct PatchVersionComparison; impl Violation for PatchVersionComparison { #[derive_message_formats] @@ -107,8 +107,8 @@ impl Violation for PatchVersionComparison { /// /// ## References /// - [Typing documentation: Version and Platform checking](https://typing.readthedocs.io/en/latest/spec/directives.html#version-and-platform-checks) -#[violation] -pub struct WrongTupleLengthVersionComparison { +#[derive(ViolationMetadata)] +pub(crate) struct WrongTupleLengthVersionComparison { expected_length: usize, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs index 5697c0d0a4d59..d51e67a28728b 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unsupported_method_call_on_all.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -40,8 +40,8 @@ use crate::checkers::ast::Checker; /// if sys.version_info >= (3, 10): /// __all__ += ["C"] /// ``` -#[violation] -pub struct UnsupportedMethodCallOnAll { +#[derive(ViolationMetadata)] +pub(crate) struct UnsupportedMethodCallOnAll { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unused_private_type_definition.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unused_private_type_definition.rs index 2a75d7e55cbef..8727d7fe2e30b 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unused_private_type_definition.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unused_private_type_definition.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::map_subscript; use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_python_semantic::{Scope, SemanticModel}; @@ -23,8 +23,8 @@ use crate::checkers::ast::Checker; /// _T = typing.TypeVar("_T") /// _Ts = typing_extensions.TypeVarTuple("_Ts") /// ``` -#[violation] -pub struct UnusedPrivateTypeVar { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedPrivateTypeVar { type_var_like_name: String, type_var_like_kind: String, } @@ -67,8 +67,8 @@ impl Violation for UnusedPrivateTypeVar { /// /// def func(arg: _PrivateProtocol) -> None: ... /// ``` -#[violation] -pub struct UnusedPrivateProtocol { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedPrivateProtocol { name: String, } @@ -105,8 +105,8 @@ impl Violation for UnusedPrivateProtocol { /// /// def func(arg: _UsedTypeAlias) -> _UsedTypeAlias: ... /// ``` -#[violation] -pub struct UnusedPrivateTypeAlias { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedPrivateTypeAlias { name: String, } @@ -145,8 +145,8 @@ impl Violation for UnusedPrivateTypeAlias { /// /// def func(arg: _UsedPrivateTypedDict) -> _UsedPrivateTypedDict: ... /// ``` -#[violation] -pub struct UnusedPrivateTypedDict { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedPrivateTypedDict { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs index fd79b92e9a3ae..f6fc9beea6d33 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs @@ -8,7 +8,7 @@ use libcst_native::{ }; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::Truthiness; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::visitor::Visitor; @@ -58,8 +58,8 @@ use super::unittest_assert::UnittestAssert; /// assert not something /// assert not something_else /// ``` -#[violation] -pub struct PytestCompositeAssertion; +#[derive(ViolationMetadata)] +pub(crate) struct PytestCompositeAssertion; impl Violation for PytestCompositeAssertion { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; @@ -105,8 +105,8 @@ impl Violation for PytestCompositeAssertion { /// /// ## References /// - [`pytest` documentation: `pytest.raises`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-raises) -#[violation] -pub struct PytestAssertInExcept { +#[derive(ViolationMetadata)] +pub(crate) struct PytestAssertInExcept { name: String, } @@ -146,8 +146,8 @@ impl Violation for PytestAssertInExcept { /// /// References /// - [`pytest` documentation: `pytest.fail`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-fail) -#[violation] -pub struct PytestAssertAlwaysFalse; +#[derive(ViolationMetadata)] +pub(crate) struct PytestAssertAlwaysFalse; impl Violation for PytestAssertAlwaysFalse { #[derive_message_formats] @@ -186,8 +186,8 @@ impl Violation for PytestAssertAlwaysFalse { /// ## References /// - [`pytest` documentation: Assertion introspection details](https://docs.pytest.org/en/7.1.x/how-to/assert.html#assertion-introspection-details) -#[violation] -pub struct PytestUnittestAssertion { +#[derive(ViolationMetadata)] +pub(crate) struct PytestUnittestAssertion { assertion: String, } @@ -343,8 +343,8 @@ pub(crate) fn unittest_assertion( /// /// ## References /// - [`pytest` documentation: Assertions about expected exceptions](https://docs.pytest.org/en/latest/how-to/assert.html#assertions-about-expected-exceptions) -#[violation] -pub struct PytestUnittestRaisesAssertion { +#[derive(ViolationMetadata)] +pub(crate) struct PytestUnittestRaisesAssertion { assertion: String, } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fail.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fail.rs index b00ea5b0dbbdc..cbfad41ecd291 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fail.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fail.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast}; use ruff_text_size::Ranged; @@ -45,8 +45,8 @@ use super::helpers::{is_empty_or_null_string, is_pytest_fail}; /// /// ## References /// - [`pytest` documentation: `pytest.fail`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-fail) -#[violation] -pub struct PytestFailWithoutMessage; +#[derive(ViolationMetadata)] +pub(crate) struct PytestFailWithoutMessage; impl Violation for PytestFailWithoutMessage { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs index 6562d4d032887..5959fb797392e 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::{AlwaysFixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::UnqualifiedName; use ruff_python_ast::visitor; use ruff_python_ast::visitor::Visitor; @@ -60,8 +60,8 @@ use super::helpers::{ /// /// ## References /// - [`pytest` documentation: API Reference: Fixtures](https://docs.pytest.org/en/latest/reference/reference.html#fixtures-api) -#[violation] -pub struct PytestFixtureIncorrectParenthesesStyle { +#[derive(ViolationMetadata)] +pub(crate) struct PytestFixtureIncorrectParenthesesStyle { expected: Parentheses, actual: Parentheses, } @@ -111,8 +111,8 @@ impl AlwaysFixableViolation for PytestFixtureIncorrectParenthesesStyle { /// /// ## References /// - [`pytest` documentation: `@pytest.fixture` functions](https://docs.pytest.org/en/latest/reference/reference.html#pytest-fixture) -#[violation] -pub struct PytestFixturePositionalArgs { +#[derive(ViolationMetadata)] +pub(crate) struct PytestFixturePositionalArgs { function: String, } @@ -152,8 +152,8 @@ impl Violation for PytestFixturePositionalArgs { /// /// ## References /// - [`pytest` documentation: `@pytest.fixture` functions](https://docs.pytest.org/en/latest/reference/reference.html#pytest-fixture) -#[violation] -pub struct PytestExtraneousScopeFunction; +#[derive(ViolationMetadata)] +pub(crate) struct PytestExtraneousScopeFunction; impl AlwaysFixableViolation for PytestExtraneousScopeFunction { #[derive_message_formats] @@ -214,9 +214,9 @@ impl AlwaysFixableViolation for PytestExtraneousScopeFunction { /// /// ## References /// - [`pytest` documentation: `@pytest.fixture` functions](https://docs.pytest.org/en/latest/reference/reference.html#pytest-fixture) -#[violation] +#[derive(ViolationMetadata)] #[deprecated(note = "PT004 has been removed")] -pub struct PytestMissingFixtureNameUnderscore; +pub(crate) struct PytestMissingFixtureNameUnderscore; #[allow(deprecated)] impl Violation for PytestMissingFixtureNameUnderscore { @@ -279,9 +279,9 @@ impl Violation for PytestMissingFixtureNameUnderscore { /// /// ## References /// - [`pytest` documentation: `@pytest.fixture` functions](https://docs.pytest.org/en/latest/reference/reference.html#pytest-fixture) -#[violation] +#[derive(ViolationMetadata)] #[deprecated(note = "PT005 has been removed")] -pub struct PytestIncorrectFixtureNameUnderscore; +pub(crate) struct PytestIncorrectFixtureNameUnderscore; #[allow(deprecated)] impl Violation for PytestIncorrectFixtureNameUnderscore { @@ -339,8 +339,8 @@ impl Violation for PytestIncorrectFixtureNameUnderscore { /// /// ## References /// - [`pytest` documentation: `pytest.mark.usefixtures`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-mark-usefixtures) -#[violation] -pub struct PytestFixtureParamWithoutValue { +#[derive(ViolationMetadata)] +pub(crate) struct PytestFixtureParamWithoutValue { name: String, } @@ -387,8 +387,8 @@ impl Violation for PytestFixtureParamWithoutValue { /// /// ## References /// - [`pytest` documentation: `yield_fixture` functions](https://docs.pytest.org/en/latest/yieldfixture.html) -#[violation] -pub struct PytestDeprecatedYieldFixture; +#[derive(ViolationMetadata)] +pub(crate) struct PytestDeprecatedYieldFixture; impl Violation for PytestDeprecatedYieldFixture { #[derive_message_formats] @@ -446,8 +446,8 @@ impl Violation for PytestDeprecatedYieldFixture { /// ## References /// - [`pytest` documentation: Adding finalizers directly](https://docs.pytest.org/en/latest/how-to/fixtures.html#adding-finalizers-directly) /// - [`pytest` documentation: Factories as fixtures](https://docs.pytest.org/en/latest/how-to/fixtures.html#factories-as-fixtures) -#[violation] -pub struct PytestFixtureFinalizerCallback; +#[derive(ViolationMetadata)] +pub(crate) struct PytestFixtureFinalizerCallback; impl Violation for PytestFixtureFinalizerCallback { #[derive_message_formats] @@ -494,8 +494,8 @@ impl Violation for PytestFixtureFinalizerCallback { /// /// ## References /// - [`pytest` documentation: Teardown/Cleanup](https://docs.pytest.org/en/latest/how-to/fixtures.html#teardown-cleanup-aka-fixture-finalization) -#[violation] -pub struct PytestUselessYieldFixture { +#[derive(ViolationMetadata)] +pub(crate) struct PytestUselessYieldFixture { name: String, } @@ -551,8 +551,8 @@ impl AlwaysFixableViolation for PytestUselessYieldFixture { /// /// ## References /// - [`pytest` documentation: `pytest.mark.usefixtures`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-mark-usefixtures) -#[violation] -pub struct PytestErroneousUseFixturesOnFixture; +#[derive(ViolationMetadata)] +pub(crate) struct PytestErroneousUseFixturesOnFixture; impl AlwaysFixableViolation for PytestErroneousUseFixturesOnFixture { #[derive_message_formats] @@ -594,8 +594,8 @@ impl AlwaysFixableViolation for PytestErroneousUseFixturesOnFixture { /// /// ## References /// - [PyPI: `pytest-asyncio`](https://pypi.org/project/pytest-asyncio/) -#[violation] -pub struct PytestUnnecessaryAsyncioMarkOnFixture; +#[derive(ViolationMetadata)] +pub(crate) struct PytestUnnecessaryAsyncioMarkOnFixture; impl AlwaysFixableViolation for PytestUnnecessaryAsyncioMarkOnFixture { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/imports.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/imports.rs index 632fafdedfef3..a77816d8477b0 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/imports.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/imports.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Stmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; /// ## What it does @@ -21,8 +21,8 @@ use ruff_text_size::Ranged; /// ```python /// import pytest /// ``` -#[violation] -pub struct PytestIncorrectPytestImport; +#[derive(ViolationMetadata)] +pub(crate) struct PytestIncorrectPytestImport; impl Violation for PytestIncorrectPytestImport { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs index aff1bf2680ad7..761513caf6dcb 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Arguments, Decorator, Expr}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -49,8 +49,8 @@ use super::helpers::{get_mark_decorators, Parentheses}; /// /// ## References /// - [`pytest` documentation: Marks](https://docs.pytest.org/en/latest/reference/reference.html#marks) -#[violation] -pub struct PytestIncorrectMarkParenthesesStyle { +#[derive(ViolationMetadata)] +pub(crate) struct PytestIncorrectMarkParenthesesStyle { mark_name: String, expected_parens: Parentheses, actual_parens: Parentheses, @@ -105,8 +105,8 @@ impl AlwaysFixableViolation for PytestIncorrectMarkParenthesesStyle { /// ## References /// - [`pytest` documentation: `pytest.mark.usefixtures`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-mark-usefixtures) -#[violation] -pub struct PytestUseFixturesWithoutParameters; +#[derive(ViolationMetadata)] +pub(crate) struct PytestUseFixturesWithoutParameters; impl AlwaysFixableViolation for PytestUseFixturesWithoutParameters { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs index c5b89f9e71552..28caa5b0c5532 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs @@ -1,7 +1,7 @@ use rustc_hash::{FxBuildHasher, FxHashMap}; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::AstNode; @@ -66,8 +66,8 @@ use super::helpers::{is_pytest_parametrize, split_names}; /// /// ## References /// - [`pytest` documentation: How to parametrize fixtures and test functions](https://docs.pytest.org/en/latest/how-to/parametrize.html#pytest-mark-parametrize) -#[violation] -pub struct PytestParametrizeNamesWrongType { +#[derive(ViolationMetadata)] +pub(crate) struct PytestParametrizeNamesWrongType { single_argument: bool, expected: types::ParametrizeNameType, } @@ -198,8 +198,8 @@ impl Violation for PytestParametrizeNamesWrongType { /// /// ## References /// - [`pytest` documentation: How to parametrize fixtures and test functions](https://docs.pytest.org/en/latest/how-to/parametrize.html#pytest-mark-parametrize) -#[violation] -pub struct PytestParametrizeValuesWrongType { +#[derive(ViolationMetadata)] +pub(crate) struct PytestParametrizeValuesWrongType { values: types::ParametrizeValuesType, row: types::ParametrizeValuesRowType, } @@ -262,8 +262,8 @@ impl Violation for PytestParametrizeValuesWrongType { /// /// ## References /// - [`pytest` documentation: How to parametrize fixtures and test functions](https://docs.pytest.org/en/latest/how-to/parametrize.html#pytest-mark-parametrize) -#[violation] -pub struct PytestDuplicateParametrizeTestCases { +#[derive(ViolationMetadata)] +pub(crate) struct PytestDuplicateParametrizeTestCases { index: usize, } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/patch.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/patch.rs index 0c5d680c8b8cb..7fb57225fb9eb 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/patch.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/patch.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::UnqualifiedName; use ruff_python_ast::visitor; use ruff_python_ast::visitor::Visitor; @@ -39,8 +39,8 @@ use ruff_text_size::Ranged; /// ## References /// - [Python documentation: `unittest.mock.patch`](https://docs.python.org/3/library/unittest.mock.html#unittest.mock.patch) /// - [PyPI: `pytest-mock`](https://pypi.org/project/pytest-mock/) -#[violation] -pub struct PytestPatchWithLambda; +#[derive(ViolationMetadata)] +pub(crate) struct PytestPatchWithLambda; impl Violation for PytestPatchWithLambda { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs index a0ec3fa5671c0..42ae92e68d82c 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_compound_statement; use ruff_python_ast::{self as ast, Expr, Stmt, WithItem}; use ruff_python_semantic::SemanticModel; @@ -45,8 +45,8 @@ use super::helpers::is_empty_or_null_string; /// /// ## References /// - [`pytest` documentation: `pytest.raises`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-raises) -#[violation] -pub struct PytestRaisesWithMultipleStatements; +#[derive(ViolationMetadata)] +pub(crate) struct PytestRaisesWithMultipleStatements; impl Violation for PytestRaisesWithMultipleStatements { #[derive_message_formats] @@ -96,8 +96,8 @@ impl Violation for PytestRaisesWithMultipleStatements { /// /// ## References /// - [`pytest` documentation: `pytest.raises`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-raises) -#[violation] -pub struct PytestRaisesTooBroad { +#[derive(ViolationMetadata)] +pub(crate) struct PytestRaisesTooBroad { exception: String, } @@ -141,8 +141,8 @@ impl Violation for PytestRaisesTooBroad { /// /// ## References /// - [`pytest` documentation: `pytest.raises`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-raises) -#[violation] -pub struct PytestRaisesWithoutException; +#[derive(ViolationMetadata)] +pub(crate) struct PytestRaisesWithoutException; impl Violation for PytestRaisesWithoutException { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_quotes/rules/avoidable_escaped_quote.rs b/crates/ruff_linter/src/rules/flake8_quotes/rules/avoidable_escaped_quote.rs index 9b491dcf91147..bf9b354be6edd 100644 --- a/crates/ruff_linter/src/rules/flake8_quotes/rules/avoidable_escaped_quote.rs +++ b/crates/ruff_linter/src/rules/flake8_quotes/rules/avoidable_escaped_quote.rs @@ -1,7 +1,7 @@ use flake8_quotes::helpers::{contains_escaped_quote, raw_contents, unescape_string}; use flake8_quotes::settings::Quote; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::visitor::{walk_f_string, Visitor}; use ruff_python_ast::{self as ast, AnyStringFlags, StringFlags, StringLike}; use ruff_text_size::{Ranged, TextRange, TextSize}; @@ -35,8 +35,8 @@ use crate::Locator; /// redundant. /// /// [formatter]: https://docs.astral.sh/ruff/formatter -#[violation] -pub struct AvoidableEscapedQuote; +#[derive(ViolationMetadata)] +pub(crate) struct AvoidableEscapedQuote; impl AlwaysFixableViolation for AvoidableEscapedQuote { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_quotes/rules/check_string_quotes.rs b/crates/ruff_linter/src/rules/flake8_quotes/rules/check_string_quotes.rs index d2f61174d094c..7d2cc9874039e 100644 --- a/crates/ruff_linter/src/rules/flake8_quotes/rules/check_string_quotes.rs +++ b/crates/ruff_linter/src/rules/flake8_quotes/rules/check_string_quotes.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::StringLike; use ruff_text_size::{Ranged, TextRange}; @@ -36,8 +36,8 @@ use super::super::settings::Quote; /// redundant. /// /// [formatter]: https://docs.astral.sh/ruff/formatter -#[violation] -pub struct BadQuotesInlineString { +#[derive(ViolationMetadata)] +pub(crate) struct BadQuotesInlineString { preferred_quote: Quote, } @@ -93,8 +93,8 @@ impl Violation for BadQuotesInlineString { /// redundant. /// /// [formatter]: https://docs.astral.sh/ruff/formatter -#[violation] -pub struct BadQuotesMultilineString { +#[derive(ViolationMetadata)] +pub(crate) struct BadQuotesMultilineString { preferred_quote: Quote, } @@ -148,8 +148,8 @@ impl AlwaysFixableViolation for BadQuotesMultilineString { /// redundant. /// /// [formatter]: https://docs.astral.sh/ruff/formatter -#[violation] -pub struct BadQuotesDocstring { +#[derive(ViolationMetadata)] +pub(crate) struct BadQuotesDocstring { preferred_quote: Quote, } diff --git a/crates/ruff_linter/src/rules/flake8_quotes/rules/unnecessary_escaped_quote.rs b/crates/ruff_linter/src/rules/flake8_quotes/rules/unnecessary_escaped_quote.rs index 18e87ba16b27a..d47fd82f3a607 100644 --- a/crates/ruff_linter/src/rules/flake8_quotes/rules/unnecessary_escaped_quote.rs +++ b/crates/ruff_linter/src/rules/flake8_quotes/rules/unnecessary_escaped_quote.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, AnyStringFlags, StringFlags, StringLike}; use ruff_text_size::{Ranged, TextRange}; @@ -31,8 +31,8 @@ use super::super::helpers::{contains_escaped_quote, raw_contents, unescape_strin /// redundant. /// /// [formatter]: https://docs.astral.sh/ruff/formatter -#[violation] -pub struct UnnecessaryEscapedQuote; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryEscapedQuote; impl AlwaysFixableViolation for UnnecessaryEscapedQuote { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs b/crates/ruff_linter/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs index 655f4a340385c..16cb02e00bac9 100644 --- a/crates/ruff_linter/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Applicability, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::BindingKind; use ruff_text_size::Ranged; @@ -38,8 +38,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: The `raise` statement](https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement) -#[violation] -pub struct UnnecessaryParenOnRaiseException; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryParenOnRaiseException; impl AlwaysFixableViolation for UnnecessaryParenOnRaiseException { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_return/rules/function.rs b/crates/ruff_linter/src/rules/flake8_return/rules/function.rs index 52c8b8a92794e..00c44487faf84 100644 --- a/crates/ruff_linter/src/rules/flake8_return/rules/function.rs +++ b/crates/ruff_linter/src/rules/flake8_return/rules/function.rs @@ -4,7 +4,7 @@ use anyhow::Result; use ruff_diagnostics::{AlwaysFixableViolation, FixAvailability, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::{is_const_false, is_const_true}; use ruff_python_ast::stmt_if::elif_else_range; use ruff_python_ast::visitor::Visitor; @@ -54,8 +54,8 @@ use super::super::visitor::{ReturnVisitor, Stack}; /// return /// return /// ``` -#[violation] -pub struct UnnecessaryReturnNone; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryReturnNone; impl AlwaysFixableViolation for UnnecessaryReturnNone { #[derive_message_formats] @@ -95,8 +95,8 @@ impl AlwaysFixableViolation for UnnecessaryReturnNone { /// return None /// return 1 /// ``` -#[violation] -pub struct ImplicitReturnValue; +#[derive(ViolationMetadata)] +pub(crate) struct ImplicitReturnValue; impl AlwaysFixableViolation for ImplicitReturnValue { #[derive_message_formats] @@ -133,8 +133,8 @@ impl AlwaysFixableViolation for ImplicitReturnValue { /// return 1 /// return None /// ``` -#[violation] -pub struct ImplicitReturn; +#[derive(ViolationMetadata)] +pub(crate) struct ImplicitReturn; impl AlwaysFixableViolation for ImplicitReturn { #[derive_message_formats] @@ -168,8 +168,8 @@ impl AlwaysFixableViolation for ImplicitReturn { /// def foo(): /// return 1 /// ``` -#[violation] -pub struct UnnecessaryAssign { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryAssign { name: String, } @@ -210,8 +210,8 @@ impl AlwaysFixableViolation for UnnecessaryAssign { /// return 1 /// return baz /// ``` -#[violation] -pub struct SuperfluousElseReturn { +#[derive(ViolationMetadata)] +pub(crate) struct SuperfluousElseReturn { branch: Branch, } @@ -254,8 +254,8 @@ impl Violation for SuperfluousElseReturn { /// raise Exception(bar) /// raise Exception(baz) /// ``` -#[violation] -pub struct SuperfluousElseRaise { +#[derive(ViolationMetadata)] +pub(crate) struct SuperfluousElseRaise { branch: Branch, } @@ -300,8 +300,8 @@ impl Violation for SuperfluousElseRaise { /// continue /// x = 0 /// ``` -#[violation] -pub struct SuperfluousElseContinue { +#[derive(ViolationMetadata)] +pub(crate) struct SuperfluousElseContinue { branch: Branch, } @@ -346,8 +346,8 @@ impl Violation for SuperfluousElseContinue { /// break /// x = 0 /// ``` -#[violation] -pub struct SuperfluousElseBreak { +#[derive(ViolationMetadata)] +pub(crate) struct SuperfluousElseBreak { branch: Branch, } diff --git a/crates/ruff_linter/src/rules/flake8_self/rules/private_member_access.rs b/crates/ruff_linter/src/rules/flake8_self/rules/private_member_access.rs index 31cec1cd48be0..a6548cbd30584 100644 --- a/crates/ruff_linter/src/rules/flake8_self/rules/private_member_access.rs +++ b/crates/ruff_linter/src/rules/flake8_self/rules/private_member_access.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::UnqualifiedName; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::{BindingKind, ScopeKind}; @@ -50,8 +50,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [_What is the meaning of single or double underscores before an object name?_](https://stackoverflow.com/questions/1301346/what-is-the-meaning-of-single-and-double-underscore-before-an-object-name) -#[violation] -pub struct PrivateMemberAccess { +#[derive(ViolationMetadata)] +pub(crate) struct PrivateMemberAccess { access: String, } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs index 5097e1f56a2e6..ca1b1c759fb7a 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs @@ -7,7 +7,7 @@ use ruff_python_ast::{self as ast, Arguments, BoolOp, CmpOp, Expr, ExprContext, use ruff_text_size::{Ranged, TextRange}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::helpers::{contains_effect, Truthiness}; use ruff_python_ast::name::Name; @@ -44,8 +44,8 @@ use crate::fix::edits::pad; /// /// ## References /// - [Python documentation: `isinstance`](https://docs.python.org/3/library/functions.html#isinstance) -#[violation] -pub struct DuplicateIsinstanceCall { +#[derive(ViolationMetadata)] +pub(crate) struct DuplicateIsinstanceCall { name: Option, } @@ -92,8 +92,8 @@ impl Violation for DuplicateIsinstanceCall { /// /// ## References /// - [Python documentation: Membership test operations](https://docs.python.org/3/reference/expressions.html#membership-test-operations) -#[violation] -pub struct CompareWithTuple { +#[derive(ViolationMetadata)] +pub(crate) struct CompareWithTuple { replacement: String, } @@ -125,8 +125,8 @@ impl AlwaysFixableViolation for CompareWithTuple { /// /// ## References /// - [Python documentation: Boolean operations](https://docs.python.org/3/reference/expressions.html#boolean-operations) -#[violation] -pub struct ExprAndNotExpr { +#[derive(ViolationMetadata)] +pub(crate) struct ExprAndNotExpr { name: String, } @@ -157,8 +157,8 @@ impl AlwaysFixableViolation for ExprAndNotExpr { /// /// ## References /// - [Python documentation: Boolean operations](https://docs.python.org/3/reference/expressions.html#boolean-operations) -#[violation] -pub struct ExprOrNotExpr { +#[derive(ViolationMetadata)] +pub(crate) struct ExprOrNotExpr { name: String, } @@ -209,8 +209,8 @@ pub(crate) enum ContentAround { /// /// a = x or [1] /// ``` -#[violation] -pub struct ExprOrTrue { +#[derive(ViolationMetadata)] +pub(crate) struct ExprOrTrue { expr: String, remove: ContentAround, } @@ -261,8 +261,8 @@ impl AlwaysFixableViolation for ExprOrTrue { /// /// a = x and [] /// ``` -#[violation] -pub struct ExprAndFalse { +#[derive(ViolationMetadata)] +pub(crate) struct ExprAndFalse { expr: String, remove: ContentAround, } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs index 27faec8c4d8e0..50c17cfeba759 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs @@ -5,7 +5,7 @@ use ruff_text_size::Ranged; use crate::fix::snippet::SourceCodeSnippet; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::analyze::typing::is_dict; use ruff_python_semantic::Modules; @@ -36,8 +36,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `os.environ`](https://docs.python.org/3/library/os.html#os.environ) -#[violation] -pub struct UncapitalizedEnvironmentVariables { +#[derive(ViolationMetadata)] +pub(crate) struct UncapitalizedEnvironmentVariables { expected: SourceCodeSnippet, actual: SourceCodeSnippet, } @@ -86,8 +86,8 @@ impl Violation for UncapitalizedEnvironmentVariables { /// /// ## References /// - [Python documentation: `dict.get`](https://docs.python.org/3/library/stdtypes.html#dict.get) -#[violation] -pub struct DictGetWithNoneDefault { +#[derive(ViolationMetadata)] +pub(crate) struct DictGetWithNoneDefault { expected: SourceCodeSnippet, actual: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs index e7d54b248391e..313e37ebd509d 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Arguments, Expr, ExprContext, UnaryOp}; use ruff_text_size::{Ranged, TextRange}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::{is_const_false, is_const_true}; use ruff_python_ast::name::Name; use ruff_python_ast::parenthesize::parenthesized_range; @@ -29,8 +29,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing) -#[violation] -pub struct IfExprWithTrueFalse { +#[derive(ViolationMetadata)] +pub(crate) struct IfExprWithTrueFalse { is_compare: bool, } @@ -77,8 +77,8 @@ impl Violation for IfExprWithTrueFalse { /// /// ## References /// - [Python documentation: Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing) -#[violation] -pub struct IfExprWithFalseTrue; +#[derive(ViolationMetadata)] +pub(crate) struct IfExprWithFalseTrue; impl AlwaysFixableViolation for IfExprWithFalseTrue { #[derive_message_formats] @@ -110,8 +110,8 @@ impl AlwaysFixableViolation for IfExprWithFalseTrue { /// /// ## References /// - [Python documentation: Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing) -#[violation] -pub struct IfExprWithTwistedArms { +#[derive(ViolationMetadata)] +pub(crate) struct IfExprWithTwistedArms { expr_body: String, expr_else: String, } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs index 02526e4509644..afc2ab3f115a1 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Arguments, CmpOp, Expr, ExprContext, Stmt, Un use ruff_text_size::{Ranged, TextRange}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::Name; use ruff_python_semantic::ScopeKind; @@ -27,8 +27,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: Comparisons](https://docs.python.org/3/reference/expressions.html#comparisons) -#[violation] -pub struct NegateEqualOp { +#[derive(ViolationMetadata)] +pub(crate) struct NegateEqualOp { left: String, right: String, } @@ -64,8 +64,8 @@ impl AlwaysFixableViolation for NegateEqualOp { /// /// ## References /// - [Python documentation: Comparisons](https://docs.python.org/3/reference/expressions.html#comparisons) -#[violation] -pub struct NegateNotEqualOp { +#[derive(ViolationMetadata)] +pub(crate) struct NegateNotEqualOp { left: String, right: String, } @@ -101,8 +101,8 @@ impl AlwaysFixableViolation for NegateNotEqualOp { /// /// ## References /// - [Python documentation: Comparisons](https://docs.python.org/3/reference/expressions.html#comparisons) -#[violation] -pub struct DoubleNegation { +#[derive(ViolationMetadata)] +pub(crate) struct DoubleNegation { expr: String, } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs index 8bc87a3b0d38a..7bfe65c9295b6 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs @@ -3,7 +3,7 @@ use log::error; use ruff_diagnostics::{Diagnostic, Fix}; use ruff_diagnostics::{FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Stmt, WithItem}; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_text_size::{Ranged, TextRange}; @@ -47,8 +47,8 @@ use super::fix_with; /// /// ## References /// - [Python documentation: The `with` statement](https://docs.python.org/3/reference/compound_stmts.html#the-with-statement) -#[violation] -pub struct MultipleWithStatements; +#[derive(ViolationMetadata)] +pub(crate) struct MultipleWithStatements; impl Violation for MultipleWithStatements { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs index 9657a8fe5ae71..c32ced436b524 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs @@ -5,7 +5,7 @@ use libcst_native::ParenthesizedNode; use log::error; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::AnyNodeRef; use ruff_python_ast::{self as ast, whitespace, ElifElseClause, Expr, Stmt}; use ruff_python_codegen::Stylist; @@ -46,8 +46,8 @@ use crate::Locator; /// ## References /// - [Python documentation: The `if` statement](https://docs.python.org/3/reference/compound_stmts.html#the-if-statement) /// - [Python documentation: Boolean operations](https://docs.python.org/3/reference/expressions.html#boolean-operations) -#[violation] -pub struct CollapsibleIf; +#[derive(ViolationMetadata)] +pub(crate) struct CollapsibleIf; impl Violation for CollapsibleIf { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/enumerate_for_loop.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/enumerate_for_loop.rs index 03fc7b09f494f..bcace9ac01e0e 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/enumerate_for_loop.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/enumerate_for_loop.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor}; use ruff_python_ast::{self as ast, Expr, Int, Number, Operator, Stmt}; use ruff_python_semantic::analyze::typing; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `enumerate`](https://docs.python.org/3/library/functions.html#enumerate) -#[violation] -pub struct EnumerateForLoop { +#[derive(ViolationMetadata)] +pub(crate) struct EnumerateForLoop { index: String, } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs index f14374dfa99c6..2b9f2fdbc1784 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::helpers::contains_effect; use ruff_python_ast::{ @@ -48,8 +48,8 @@ use crate::fix::edits::fits; /// /// ## References /// - [Python documentation: Mapping Types](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict) -#[violation] -pub struct IfElseBlockInsteadOfDictGet { +#[derive(ViolationMetadata)] +pub(crate) struct IfElseBlockInsteadOfDictGet { contents: String, } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_lookup.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_lookup.rs index cee8ef68b130a..2c4aa4ce2f3d4 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_lookup.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_lookup.rs @@ -1,7 +1,7 @@ use rustc_hash::FxHashSet; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableLiteral; use ruff_python_ast::helpers::contains_effect; use ruff_python_ast::{self as ast, CmpOp, ElifElseClause, Expr, Stmt}; @@ -30,8 +30,8 @@ use crate::checkers::ast::Checker; /// ```python /// return {1: "Hello", 2: "Goodbye"}.get(x, "Goodnight") /// ``` -#[violation] -pub struct IfElseBlockInsteadOfDictLookup; +#[derive(ViolationMetadata)] +pub(crate) struct IfElseBlockInsteadOfDictLookup; impl Violation for IfElseBlockInsteadOfDictLookup { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs index 81c86bf760a96..8e2b40a966d8f 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::helpers::contains_effect; use ruff_python_ast::{self as ast, BoolOp, ElifElseClause, Expr, Stmt}; @@ -58,8 +58,8 @@ use crate::fix::edits::fits; /// /// [preview]: https://docs.astral.sh/ruff/preview/ /// [code coverage]: https://github.com/nedbat/coveragepy/issues/509 -#[violation] -pub struct IfElseBlockInsteadOfIfExp { +#[derive(ViolationMetadata)] +pub(crate) struct IfElseBlockInsteadOfIfExp { /// The ternary or binary expression to replace the `if`-`else`-block. contents: String, /// Whether to use a binary or ternary assignment. diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs index 7d66f1da24c01..829826d982e96 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use anyhow::Result; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableStmt; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::stmt_if::{if_elif_branches, IfElifBranch}; @@ -35,8 +35,8 @@ use crate::Locator; /// if x == 1 or x == 2: /// print("Hello") /// ``` -#[violation] -pub struct IfWithSameArms; +#[derive(ViolationMetadata)] +pub(crate) struct IfWithSameArms; impl Violation for IfWithSameArms { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs index ef4d7c7f59661..f73c91bde5b5f 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_diagnostics::{Applicability, Edit}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::AnyNodeRef; use ruff_python_ast::{self as ast, Arguments, CmpOp, Comprehension, Expr}; @@ -37,8 +37,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: Mapping Types](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict) -#[violation] -pub struct InDictKeys { +#[derive(ViolationMetadata)] +pub(crate) struct InDictKeys { operator: String, } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs index cd8ae1e28cc8d..5ab3994de17c7 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::Name; use ruff_python_ast::traversal; use ruff_python_ast::{self as ast, Arguments, ElifElseClause, Expr, ExprContext, Stmt}; @@ -44,8 +44,8 @@ use crate::fix::snippet::SourceCodeSnippet; /// /// ## References /// - [Python documentation: Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing) -#[violation] -pub struct NeedlessBool { +#[derive(ViolationMetadata)] +pub(crate) struct NeedlessBool { condition: Option, negate: bool, } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs index cc2cd55c8efe3..9d1c72d709674 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/open_file_with_context_handler.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::{ScopeKind, SemanticModel}; use ruff_text_size::Ranged; @@ -33,8 +33,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `open`](https://docs.python.org/3/library/functions.html#open) -#[violation] -pub struct OpenFileWithContextHandler; +#[derive(ViolationMetadata)] +pub(crate) struct OpenFileWithContextHandler; impl Violation for OpenFileWithContextHandler { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs index 4e10108dac6a3..4109a0e3febb1 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::any_over_expr; use ruff_python_ast::name::Name; use ruff_python_ast::traversal; @@ -37,8 +37,8 @@ use crate::line_width::LineWidthBuilder; /// ## References /// - [Python documentation: `any`](https://docs.python.org/3/library/functions.html#any) /// - [Python documentation: `all`](https://docs.python.org/3/library/functions.html#all) -#[violation] -pub struct ReimplementedBuiltin { +#[derive(ViolationMetadata)] +pub(crate) struct ReimplementedBuiltin { replacement: String, } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/return_in_try_except_finally.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/return_in_try_except_finally.rs index 6f7110fe3a364..5682dd6c4252e 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/return_in_try_except_finally.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/return_in_try_except_finally.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, ExceptHandler, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -40,8 +40,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: Defining Clean-up Actions](https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions) -#[violation] -pub struct ReturnInTryExceptFinally; +#[derive(ViolationMetadata)] +pub(crate) struct ReturnInTryExceptFinally; impl Violation for ReturnInTryExceptFinally { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs index b5c50f6c67c48..7d6797188b808 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs @@ -1,7 +1,7 @@ use std::cmp::Ordering; use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{ Expr, ExprCall, ExprContext, ExprList, ExprStringLiteral, ExprUnaryOp, StringLiteral, StringLiteralFlags, StringLiteralValue, UnaryOp, @@ -42,8 +42,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: `str.split`](https://docs.python.org/3/library/stdtypes.html#str.split) /// ``` -#[violation] -pub struct SplitStaticString; +#[derive(ViolationMetadata)] +pub(crate) struct SplitStaticString; impl Violation for SplitStaticString { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs index fe17fe5106f81..d5659bb839275 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers; use ruff_python_ast::name::UnqualifiedName; use ruff_python_ast::{self as ast, ExceptHandler, Stmt}; @@ -42,8 +42,8 @@ use crate::importer::ImportRequest; /// - [Python documentation: `contextlib.suppress`](https://docs.python.org/3/library/contextlib.html#contextlib.suppress) /// - [Python documentation: `try` statement](https://docs.python.org/3/reference/compound_stmts.html#the-try-statement) /// - [a simpler `try`/`except` (and why maybe shouldn't)](https://www.youtube.com/watch?v=MZAJ8qnC7mk) -#[violation] -pub struct SuppressibleException { +#[derive(ViolationMetadata)] +pub(crate) struct SuppressibleException { exception: String, } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs index c71aace115cc9..78449f2d2ae15 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs @@ -4,7 +4,7 @@ use anyhow::Result; use libcst_native::CompOp; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, CmpOp, Expr, UnaryOp}; use ruff_python_codegen::Stylist; use ruff_python_stdlib::str::{self}; @@ -47,8 +47,8 @@ use crate::Locator; /// ## References /// - [Python documentation: Comparisons](https://docs.python.org/3/reference/expressions.html#comparisons) /// - [Python documentation: Assignment statements](https://docs.python.org/3/reference/simple_stmts.html#assignment-statements) -#[violation] -pub struct YodaConditions { +#[derive(ViolationMetadata)] +pub(crate) struct YodaConditions { suggestion: Option, } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs index f2b9888350a65..1bd0f485eb1d9 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/zip_dict_keys_and_values.rs @@ -1,5 +1,5 @@ use ast::{ExprAttribute, ExprName, Identifier}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Arguments, Expr}; use ruff_text_size::Ranged; @@ -31,8 +31,8 @@ use ruff_python_semantic::analyze::typing::is_dict; /// /// ## References /// - [Python documentation: `dict.items`](https://docs.python.org/3/library/stdtypes.html#dict.items) -#[violation] -pub struct ZipDictKeysAndValues { +#[derive(ViolationMetadata)] +pub(crate) struct ZipDictKeysAndValues { expected: SourceCodeSnippet, actual: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs index 6e8bcf50ce4a1..4e8b53f2730db 100644 --- a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs +++ b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_namedtuple_subclass.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, identifier::Identifier, Arguments, Expr, Stmt, StmtClassDef}; use ruff_python_semantic::SemanticModel; @@ -46,8 +46,8 @@ use crate::rules::flake8_slots::rules::helpers::has_slots; /// /// ## References /// - [Python documentation: `__slots__`](https://docs.python.org/3/reference/datamodel.html#slots) -#[violation] -pub struct NoSlotsInNamedtupleSubclass(NamedTupleKind); +#[derive(ViolationMetadata)] +pub(crate) struct NoSlotsInNamedtupleSubclass(NamedTupleKind); impl Violation for NoSlotsInNamedtupleSubclass { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs index 7479dc7821e58..c86cc9affa31b 100644 --- a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs +++ b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_str_subclass.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::{Arguments, Expr, Stmt, StmtClassDef}; use ruff_python_semantic::{analyze::class::is_enumeration, SemanticModel}; @@ -38,8 +38,8 @@ use crate::rules::flake8_slots::rules::helpers::has_slots; /// /// ## References /// - [Python documentation: `__slots__`](https://docs.python.org/3/reference/datamodel.html#slots) -#[violation] -pub struct NoSlotsInStrSubclass; +#[derive(ViolationMetadata)] +pub(crate) struct NoSlotsInStrSubclass; impl Violation for NoSlotsInStrSubclass { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs index 5cf1dacb774d9..be2724efc9fd9 100644 --- a/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs +++ b/crates/ruff_linter/src/rules/flake8_slots/rules/no_slots_in_tuple_subclass.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{Arguments, Stmt, StmtClassDef}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::map_subscript; use ruff_python_ast::identifier::Identifier; @@ -39,8 +39,8 @@ use crate::rules::flake8_slots::rules::helpers::has_slots; /// /// ## References /// - [Python documentation: `__slots__`](https://docs.python.org/3/reference/datamodel.html#slots) -#[violation] -pub struct NoSlotsInTupleSubclass; +#[derive(ViolationMetadata)] +pub(crate) struct NoSlotsInTupleSubclass; impl Violation for NoSlotsInTupleSubclass { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_api.rs b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_api.rs index 625e7316a48c9..867463b95dfc1 100644 --- a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_api.rs +++ b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_api.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::QualifiedName; use ruff_text_size::Ranged; @@ -24,8 +24,8 @@ use crate::rules::flake8_tidy_imports::matchers::NameMatchPolicy; /// /// ## Options /// - `lint.flake8-tidy-imports.banned-api` -#[violation] -pub struct BannedApi { +#[derive(ViolationMetadata)] +pub(crate) struct BannedApi { name: String, message: String, } diff --git a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_module_level_imports.rs b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_module_level_imports.rs index 53b2601bea26e..f8faa2e50ebdd 100644 --- a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_module_level_imports.rs +++ b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/banned_module_level_imports.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -39,8 +39,8 @@ use crate::rules::flake8_tidy_imports::matchers::NameMatchPolicy; /// /// ## Options /// - `lint.flake8-tidy-imports.banned-module-level-imports` -#[violation] -pub struct BannedModuleLevelImports { +#[derive(ViolationMetadata)] +pub(crate) struct BannedModuleLevelImports { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs index 4dad4e2f4d5f0..edd1ccbb96641 100644 --- a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs +++ b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Identifier, Stmt}; use ruff_text_size::{Ranged, TextRange}; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::resolve_imported_module_path; use ruff_python_codegen::Generator; use ruff_python_stdlib::identifiers::is_identifier; @@ -45,8 +45,8 @@ use crate::rules::flake8_tidy_imports::settings::Strictness; /// - `lint.flake8-tidy-imports.ban-relative-imports` /// /// [PEP 8]: https://peps.python.org/pep-0008/#imports -#[violation] -pub struct RelativeImports { +#[derive(ViolationMetadata)] +pub(crate) struct RelativeImports { strictness: Strictness, } diff --git a/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs b/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs index 7b620f0cbbf2d..d21b423d723ae 100644 --- a/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs +++ b/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs @@ -3,7 +3,7 @@ use std::sync::LazyLock; use regex::RegexSet; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_trivia::CommentRanges; use ruff_text_size::{TextLen, TextRange, TextSize}; @@ -29,8 +29,8 @@ use crate::Locator; /// ```python /// # TODO(ruff): this is now fixed! /// ``` -#[violation] -pub struct InvalidTodoTag { +#[derive(ViolationMetadata)] +pub(crate) struct InvalidTodoTag { pub tag: String, } @@ -59,8 +59,8 @@ impl Violation for InvalidTodoTag { /// ```python /// # TODO(charlie): now an author is assigned /// ``` -#[violation] -pub struct MissingTodoAuthor; +#[derive(ViolationMetadata)] +pub(crate) struct MissingTodoAuthor; impl Violation for MissingTodoAuthor { #[derive_message_formats] @@ -94,8 +94,8 @@ impl Violation for MissingTodoAuthor { /// # TODO(charlie): this comment has an issue code of (up to) 6 characters, then digits /// # SIXCHR-003 /// ``` -#[violation] -pub struct MissingTodoLink; +#[derive(ViolationMetadata)] +pub(crate) struct MissingTodoLink; impl Violation for MissingTodoLink { #[derive_message_formats] @@ -123,8 +123,8 @@ impl Violation for MissingTodoLink { /// ```python /// # TODO(charlie): colon fixed /// ``` -#[violation] -pub struct MissingTodoColon; +#[derive(ViolationMetadata)] +pub(crate) struct MissingTodoColon; impl Violation for MissingTodoColon { #[derive_message_formats] @@ -150,8 +150,8 @@ impl Violation for MissingTodoColon { /// ```python /// # TODO(charlie): fix some issue /// ``` -#[violation] -pub struct MissingTodoDescription; +#[derive(ViolationMetadata)] +pub(crate) struct MissingTodoDescription; impl Violation for MissingTodoDescription { #[derive_message_formats] @@ -177,8 +177,8 @@ impl Violation for MissingTodoDescription { /// ```python /// # TODO(charlie): this is capitalized /// ``` -#[violation] -pub struct InvalidTodoCapitalization { +#[derive(ViolationMetadata)] +pub(crate) struct InvalidTodoCapitalization { tag: String, } @@ -214,8 +214,8 @@ impl AlwaysFixableViolation for InvalidTodoCapitalization { /// ```python /// # TODO(charlie): fix this /// ``` -#[violation] -pub struct MissingSpaceAfterTodoColon; +#[derive(ViolationMetadata)] +pub(crate) struct MissingSpaceAfterTodoColon; impl Violation for MissingSpaceAfterTodoColon { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs index 0935425b718c7..52eee84523f08 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs @@ -1,7 +1,7 @@ use ruff_python_ast as ast; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::analyze::typing; use ruff_text_size::Ranged; @@ -32,8 +32,8 @@ use crate::fix; /// /// ## References /// - [PEP 563: Runtime annotation resolution and `TYPE_CHECKING`](https://peps.python.org/pep-0563/#runtime-annotation-resolution-and-type-checking) -#[violation] -pub struct EmptyTypeCheckingBlock; +#[derive(ViolationMetadata)] +pub(crate) struct EmptyTypeCheckingBlock; impl AlwaysFixableViolation for EmptyTypeCheckingBlock { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_cast_value.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_cast_value.rs index 94dc641736866..329d8bcf59857 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_cast_value.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_cast_value.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -31,8 +31,8 @@ use crate::rules::flake8_type_checking::helpers::quote_type_expression; /// ## Fix safety /// This fix is safe as long as the type expression doesn't span multiple /// lines and includes comments on any of the lines apart from the last one. -#[violation] -pub struct RuntimeCastValue; +#[derive(ViolationMetadata)] +pub(crate) struct RuntimeCastValue; impl Violation for RuntimeCastValue { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_import_in_type_checking_block.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_import_in_type_checking_block.rs index b7ef64f96f30c..623800f71fe58 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_import_in_type_checking_block.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_import_in_type_checking_block.rs @@ -4,7 +4,7 @@ use anyhow::Result; use rustc_hash::FxHashMap; use ruff_diagnostics::{Diagnostic, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::{Imported, NodeId, Scope}; use ruff_text_size::Ranged; @@ -52,8 +52,8 @@ use crate::rules::flake8_type_checking::imports::ImportBinding; /// /// ## References /// - [PEP 563: Runtime annotation resolution and `TYPE_CHECKING`](https://peps.python.org/pep-0563/#runtime-annotation-resolution-and-type-checking) -#[violation] -pub struct RuntimeImportInTypeCheckingBlock { +#[derive(ViolationMetadata)] +pub(crate) struct RuntimeImportInTypeCheckingBlock { qualified_name: String, strategy: Strategy, } diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_string_union.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_string_union.rs index 900d6f4cce05e..ab849880897ca 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_string_union.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_string_union.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::{Expr, Operator}; use ruff_text_size::Ranged; @@ -41,8 +41,8 @@ use crate::checkers::ast::Checker; /// - [PEP 604 – Allow writing union types as `X | Y`](https://peps.python.org/pep-0604/) /// /// [PEP 604]: https://peps.python.org/pep-0604/ -#[violation] -pub struct RuntimeStringUnion; +#[derive(ViolationMetadata)] +pub(crate) struct RuntimeStringUnion; impl Violation for RuntimeStringUnion { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/type_alias_quotes.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/type_alias_quotes.rs index e2f9fbc7f22e7..b601caa8431e5 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/type_alias_quotes.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/type_alias_quotes.rs @@ -1,7 +1,7 @@ use crate::registry::Rule; use ast::{ExprContext, Operator}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::{Expr, Stmt}; use ruff_python_semantic::{Binding, SemanticModel}; @@ -46,8 +46,8 @@ use crate::rules::flake8_type_checking::helpers::quote_type_expression; /// - [PEP 613 – Explicit Type Aliases](https://peps.python.org/pep-0613/) /// /// [PEP 613]: https://peps.python.org/pep-0613/ -#[violation] -pub struct UnquotedTypeAlias; +#[derive(ViolationMetadata)] +pub(crate) struct UnquotedTypeAlias; impl Violation for UnquotedTypeAlias { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; @@ -109,8 +109,8 @@ impl Violation for UnquotedTypeAlias { /// [PEP 604]: https://peps.python.org/pep-0604/ /// [PEP 613]: https://peps.python.org/pep-0613/ /// [PEP 695]: https://peps.python.org/pep-0695/#generic-type-alias -#[violation] -pub struct QuotedTypeAlias; +#[derive(ViolationMetadata)] +pub(crate) struct QuotedTypeAlias; impl AlwaysFixableViolation for QuotedTypeAlias { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/typing_only_runtime_import.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/typing_only_runtime_import.rs index 8bd9d57c0e257..237484d797b37 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/typing_only_runtime_import.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/typing_only_runtime_import.rs @@ -4,7 +4,7 @@ use anyhow::Result; use rustc_hash::FxHashMap; use ruff_diagnostics::{Diagnostic, DiagnosticKind, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::{Binding, Imported, NodeId, Scope}; use ruff_text_size::Ranged; @@ -72,8 +72,8 @@ use crate::rules::isort::{categorize, ImportSection, ImportType}; /// /// ## References /// - [PEP 563: Runtime annotation resolution and `TYPE_CHECKING`](https://peps.python.org/pep-0563/#runtime-annotation-resolution-and-type-checking) -#[violation] -pub struct TypingOnlyFirstPartyImport { +#[derive(ViolationMetadata)] +pub(crate) struct TypingOnlyFirstPartyImport { qualified_name: String, } @@ -147,8 +147,8 @@ impl Violation for TypingOnlyFirstPartyImport { /// /// ## References /// - [PEP 563: Runtime annotation resolution and `TYPE_CHECKING`](https://peps.python.org/pep-0563/#runtime-annotation-resolution-and-type-checking) -#[violation] -pub struct TypingOnlyThirdPartyImport { +#[derive(ViolationMetadata)] +pub(crate) struct TypingOnlyThirdPartyImport { qualified_name: String, } @@ -222,8 +222,8 @@ impl Violation for TypingOnlyThirdPartyImport { /// /// ## References /// - [PEP 563: Runtime annotation resolution and `TYPE_CHECKING`](https://peps.python.org/pep-0563/#runtime-annotation-resolution-and-type-checking) -#[violation] -pub struct TypingOnlyStandardLibraryImport { +#[derive(ViolationMetadata)] +pub(crate) struct TypingOnlyStandardLibraryImport { qualified_name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs b/crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs index 1405823ba8a8d..3124293a28960 100644 --- a/crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs +++ b/crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs @@ -4,7 +4,7 @@ use ruff_python_ast::{Parameter, Parameters, Stmt, StmtExpr, StmtFunctionDef, St use ruff_diagnostics::DiagnosticKind; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::analyze::{function_type, visibility}; use ruff_python_semantic::{Scope, ScopeKind, SemanticModel}; use ruff_text_size::Ranged; @@ -37,8 +37,8 @@ use crate::registry::Rule; /// /// ## Options /// - `lint.dummy-variable-rgx` -#[violation] -pub struct UnusedFunctionArgument { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedFunctionArgument { name: String, } @@ -77,8 +77,8 @@ impl Violation for UnusedFunctionArgument { /// /// ## Options /// - `lint.dummy-variable-rgx` -#[violation] -pub struct UnusedMethodArgument { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedMethodArgument { name: String, } @@ -119,8 +119,8 @@ impl Violation for UnusedMethodArgument { /// /// ## Options /// - `lint.dummy-variable-rgx` -#[violation] -pub struct UnusedClassMethodArgument { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedClassMethodArgument { name: String, } @@ -161,8 +161,8 @@ impl Violation for UnusedClassMethodArgument { /// /// ## Options /// - `lint.dummy-variable-rgx` -#[violation] -pub struct UnusedStaticMethodArgument { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedStaticMethodArgument { name: String, } @@ -200,8 +200,8 @@ impl Violation for UnusedStaticMethodArgument { /// /// ## Options /// - `lint.dummy-variable-rgx` -#[violation] -pub struct UnusedLambdaArgument { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedLambdaArgument { name: String, } diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/glob_rule.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/glob_rule.rs index 4a09654faafd7..487cc1c294c5a 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/glob_rule.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/glob_rule.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for the use of `glob` and `iglob`. @@ -41,8 +41,8 @@ use ruff_macros::{derive_message_formats, violation}; /// - [Python documentation: `Path.rglob`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.rglob) /// - [Python documentation: `glob.glob`](https://docs.python.org/3/library/glob.html#glob.glob) /// - [Python documentation: `glob.iglob`](https://docs.python.org/3/library/glob.html#glob.iglob) -#[violation] -pub struct Glob { +#[derive(ViolationMetadata)] +pub(crate) struct Glob { pub function: String, } diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getatime.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getatime.rs index e7f916ebe1c69..5feaf9c08e377 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getatime.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getatime.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for uses of `os.path.getatime`. @@ -36,8 +36,8 @@ use ruff_macros::{derive_message_formats, violation}; /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathGetatime; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathGetatime; impl Violation for OsPathGetatime { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getctime.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getctime.rs index 8fddb4570f2a7..2ad153208780c 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getctime.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getctime.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for uses of `os.path.getctime`. @@ -36,8 +36,8 @@ use ruff_macros::{derive_message_formats, violation}; /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathGetctime; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathGetctime; impl Violation for OsPathGetctime { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getmtime.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getmtime.rs index d9b0a4b08e47b..eef65f31a448f 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getmtime.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getmtime.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for uses of `os.path.getmtime`. @@ -36,8 +36,8 @@ use ruff_macros::{derive_message_formats, violation}; /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathGetmtime; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathGetmtime; impl Violation for OsPathGetmtime { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getsize.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getsize.rs index 36307ebf0a615..d6f9db0718a1b 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getsize.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getsize.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for uses of `os.path.getsize`. @@ -36,8 +36,8 @@ use ruff_macros::{derive_message_formats, violation}; /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathGetsize; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathGetsize; impl Violation for OsPathGetsize { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_sep_split.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_sep_split.rs index 474cb86598624..b4e0390c86fcd 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_sep_split.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_sep_split.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, ExprAttribute}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -42,8 +42,8 @@ use crate::checkers::ast::Checker; /// if any(part in blocklist for part in Path("my/file/path").parts): /// ... /// ``` -#[violation] -pub struct OsSepSplit; +#[derive(ViolationMetadata)] +pub(crate) struct OsSepSplit; impl Violation for OsSepSplit { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs index c633f0953bbab..bf8bf7ea3cc49 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, ExprCall}; use crate::checkers::ast::Checker; @@ -28,8 +28,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path) -#[violation] -pub struct PathConstructorCurrentDirectory; +#[derive(ViolationMetadata)] +pub(crate) struct PathConstructorCurrentDirectory; impl AlwaysFixableViolation for PathConstructorCurrentDirectory { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs index b72155306ec8a..01e88ea89b85c 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for uses of `os.path.abspath`. @@ -34,8 +34,8 @@ use ruff_macros::{derive_message_formats, violation}; /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathAbspath; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathAbspath; impl Violation for OsPathAbspath { #[derive_message_formats] @@ -77,8 +77,8 @@ impl Violation for OsPathAbspath { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsChmod; +#[derive(ViolationMetadata)] +pub(crate) struct OsChmod; impl Violation for OsChmod { #[derive_message_formats] @@ -120,8 +120,8 @@ impl Violation for OsChmod { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsMakedirs; +#[derive(ViolationMetadata)] +pub(crate) struct OsMakedirs; impl Violation for OsMakedirs { #[derive_message_formats] @@ -163,8 +163,8 @@ impl Violation for OsMakedirs { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsMkdir; +#[derive(ViolationMetadata)] +pub(crate) struct OsMkdir; impl Violation for OsMkdir { #[derive_message_formats] @@ -206,8 +206,8 @@ impl Violation for OsMkdir { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsRename; +#[derive(ViolationMetadata)] +pub(crate) struct OsRename; impl Violation for OsRename { #[derive_message_formats] @@ -249,8 +249,8 @@ impl Violation for OsRename { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsReplace; +#[derive(ViolationMetadata)] +pub(crate) struct OsReplace; impl Violation for OsReplace { #[derive_message_formats] @@ -292,8 +292,8 @@ impl Violation for OsReplace { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsRmdir; +#[derive(ViolationMetadata)] +pub(crate) struct OsRmdir; impl Violation for OsRmdir { #[derive_message_formats] @@ -335,8 +335,8 @@ impl Violation for OsRmdir { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsRemove; +#[derive(ViolationMetadata)] +pub(crate) struct OsRemove; impl Violation for OsRemove { #[derive_message_formats] @@ -378,8 +378,8 @@ impl Violation for OsRemove { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsUnlink; +#[derive(ViolationMetadata)] +pub(crate) struct OsUnlink; impl Violation for OsUnlink { #[derive_message_formats] @@ -422,8 +422,8 @@ impl Violation for OsUnlink { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsGetcwd; +#[derive(ViolationMetadata)] +pub(crate) struct OsGetcwd; impl Violation for OsGetcwd { #[derive_message_formats] @@ -465,8 +465,8 @@ impl Violation for OsGetcwd { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathExists; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathExists; impl Violation for OsPathExists { #[derive_message_formats] @@ -508,8 +508,8 @@ impl Violation for OsPathExists { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathExpanduser; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathExpanduser; impl Violation for OsPathExpanduser { #[derive_message_formats] @@ -551,8 +551,8 @@ impl Violation for OsPathExpanduser { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathIsdir; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathIsdir; impl Violation for OsPathIsdir { #[derive_message_formats] @@ -594,8 +594,8 @@ impl Violation for OsPathIsdir { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathIsfile; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathIsfile; impl Violation for OsPathIsfile { #[derive_message_formats] @@ -637,8 +637,8 @@ impl Violation for OsPathIsfile { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathIslink; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathIslink; impl Violation for OsPathIslink { #[derive_message_formats] @@ -680,8 +680,8 @@ impl Violation for OsPathIslink { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsReadlink; +#[derive(ViolationMetadata)] +pub(crate) struct OsReadlink; impl Violation for OsReadlink { #[derive_message_formats] @@ -732,8 +732,8 @@ impl Violation for OsReadlink { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsStat; +#[derive(ViolationMetadata)] +pub(crate) struct OsStat; impl Violation for OsStat { #[derive_message_formats] @@ -778,8 +778,8 @@ impl Violation for OsStat { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathIsabs; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathIsabs; impl Violation for OsPathIsabs { #[derive_message_formats] @@ -821,8 +821,8 @@ impl Violation for OsPathIsabs { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathJoin { +#[derive(ViolationMetadata)] +pub(crate) struct OsPathJoin { pub(crate) module: String, pub(crate) joiner: Joiner, } @@ -881,8 +881,8 @@ pub(crate) enum Joiner { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathBasename; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathBasename; impl Violation for OsPathBasename { #[derive_message_formats] @@ -924,8 +924,8 @@ impl Violation for OsPathBasename { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathDirname; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathDirname; impl Violation for OsPathDirname { #[derive_message_formats] @@ -967,8 +967,8 @@ impl Violation for OsPathDirname { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathSamefile; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathSamefile; impl Violation for OsPathSamefile { #[derive_message_formats] @@ -1019,8 +1019,8 @@ impl Violation for OsPathSamefile { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct OsPathSplitext; +#[derive(ViolationMetadata)] +pub(crate) struct OsPathSplitext; impl Violation for OsPathSplitext { #[derive_message_formats] @@ -1059,8 +1059,8 @@ impl Violation for OsPathSplitext { /// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[violation] -pub struct BuiltinOpen; +#[derive(ViolationMetadata)] +pub(crate) struct BuiltinOpen; impl Violation for BuiltinOpen { #[derive_message_formats] @@ -1094,8 +1094,8 @@ impl Violation for BuiltinOpen { /// ## References /// - [Python documentation: `Pathlib`](https://docs.python.org/3/library/pathlib.html) /// - [Path repository](https://github.com/jaraco/path) -#[violation] -pub struct PyPath; +#[derive(ViolationMetadata)] +pub(crate) struct PyPath; impl Violation for PyPath { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs b/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs index 3f274be6535a8..af100938e9159 100644 --- a/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs +++ b/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs @@ -3,7 +3,7 @@ use itertools::Itertools; use crate::fix::edits::pad; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Arguments, Expr}; use ruff_text_size::{Ranged, TextRange}; @@ -30,8 +30,8 @@ use crate::rules::flynt::helpers; /// /// ## References /// - [Python documentation: f-strings](https://docs.python.org/3/reference/lexical_analysis.html#f-strings) -#[violation] -pub struct StaticJoinToFString { +#[derive(ViolationMetadata)] +pub(crate) struct StaticJoinToFString { expression: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/isort/rules/add_required_imports.rs b/crates/ruff_linter/src/rules/isort/rules/add_required_imports.rs index 9e1144c61e1ca..b3c8d6cd1c04c 100644 --- a/crates/ruff_linter/src/rules/isort/rules/add_required_imports.rs +++ b/crates/ruff_linter/src/rules/isort/rules/add_required_imports.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_docstring_stmt; use ruff_python_ast::{self as ast, ModModule, PySourceType, Stmt}; use ruff_python_codegen::Stylist; @@ -37,8 +37,8 @@ use crate::Locator; /// /// ## Options /// - `lint.isort.required-imports` -#[violation] -pub struct MissingRequiredImport(pub String); +#[derive(ViolationMetadata)] +pub(crate) struct MissingRequiredImport(pub String); impl AlwaysFixableViolation for MissingRequiredImport { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs b/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs index 4b67296ea12bb..0a8ab9d758ecd 100644 --- a/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs +++ b/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs @@ -1,7 +1,7 @@ use itertools::{EitherOrBoth, Itertools}; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::whitespace::trailing_lines_end; use ruff_python_ast::{PySourceType, Stmt}; use ruff_python_codegen::Stylist; @@ -36,8 +36,8 @@ use crate::Locator; /// import numpy as np /// import pandas /// ``` -#[violation] -pub struct UnsortedImports; +#[derive(ViolationMetadata)] +pub(crate) struct UnsortedImports; impl Violation for UnsortedImports { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/mccabe/rules/function_is_too_complex.rs b/crates/ruff_linter/src/rules/mccabe/rules/function_is_too_complex.rs index 463ef0a4f550f..e81dfcb02e147 100644 --- a/crates/ruff_linter/src/rules/mccabe/rules/function_is_too_complex.rs +++ b/crates/ruff_linter/src/rules/mccabe/rules/function_is_too_complex.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, ExceptHandler, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; /// ## What it does @@ -45,8 +45,8 @@ use ruff_python_ast::identifier::Identifier; /// /// ## Options /// - `lint.mccabe.max-complexity` -#[violation] -pub struct ComplexStructure { +#[derive(ViolationMetadata)] +pub(crate) struct ComplexStructure { name: String, complexity: usize, max_complexity: usize, diff --git a/crates/ruff_linter/src/rules/numpy/rules/deprecated_function.rs b/crates/ruff_linter/src/rules/numpy/rules/deprecated_function.rs index 8a3d943a797ff..054108afafeb5 100644 --- a/crates/ruff_linter/src/rules/numpy/rules/deprecated_function.rs +++ b/crates/ruff_linter/src/rules/numpy/rules/deprecated_function.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Expr; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -30,8 +30,8 @@ use crate::importer::ImportRequest; /// /// np.all([True, False]) /// ``` -#[violation] -pub struct NumpyDeprecatedFunction { +#[derive(ViolationMetadata)] +pub(crate) struct NumpyDeprecatedFunction { existing: String, replacement: String, } diff --git a/crates/ruff_linter/src/rules/numpy/rules/deprecated_type_alias.rs b/crates/ruff_linter/src/rules/numpy/rules/deprecated_type_alias.rs index 3d5dbef1f6e47..096e43c92c698 100644 --- a/crates/ruff_linter/src/rules/numpy/rules/deprecated_type_alias.rs +++ b/crates/ruff_linter/src/rules/numpy/rules/deprecated_type_alias.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Expr; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -30,8 +30,8 @@ use crate::checkers::ast::Checker; /// ```python /// int /// ``` -#[violation] -pub struct NumpyDeprecatedTypeAlias { +#[derive(ViolationMetadata)] +pub(crate) struct NumpyDeprecatedTypeAlias { type_name: String, } diff --git a/crates/ruff_linter/src/rules/numpy/rules/legacy_random.rs b/crates/ruff_linter/src/rules/numpy/rules/legacy_random.rs index 13050db4abfc7..b175d24fe85f8 100644 --- a/crates/ruff_linter/src/rules/numpy/rules/legacy_random.rs +++ b/crates/ruff_linter/src/rules/numpy/rules/legacy_random.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -45,8 +45,8 @@ use crate::checkers::ast::Checker; /// [Legacy Random Generation]: https://numpy.org/doc/stable/reference/random/legacy.html#legacy /// [Random Sampling]: https://numpy.org/doc/stable/reference/random/index.html#random-quick-start /// [NEP 19]: https://numpy.org/neps/nep-0019-rng-policy.html -#[violation] -pub struct NumpyLegacyRandom { +#[derive(ViolationMetadata)] +pub(crate) struct NumpyLegacyRandom { method_name: String, } diff --git a/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs b/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs index ea219d08042f8..f31b506adec53 100644 --- a/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs +++ b/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::{QualifiedName, QualifiedNameBuilder}; use ruff_python_ast::statement_visitor::StatementVisitor; use ruff_python_ast::visitor::Visitor; @@ -48,8 +48,8 @@ use crate::importer::ImportRequest; /// arr2 = [np.float64(1.5), np.float64(5.1)] /// np.round(arr2) /// ``` -#[violation] -pub struct Numpy2Deprecation { +#[derive(ViolationMetadata)] +pub(crate) struct Numpy2Deprecation { existing: String, migration_guide: Option, code_action: Option, diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/assignment_to_df.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/assignment_to_df.rs index f6ebdf9d268d6..a28a37a9e6ea7 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/assignment_to_df.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/assignment_to_df.rs @@ -1,14 +1,14 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; /// ## What it does /// Checks for assignments to the variable `df`. /// /// ## Why is this bad? -/// Although `df` is a common variable name for a Pandas DataFrame, it's not a +/// Although `df` is a common variable name for a Pandas `DataFrame`, it's not a /// great variable name for production code, as it's non-descriptive and /// prone to name conflicts. /// @@ -27,8 +27,8 @@ use ruff_text_size::Ranged; /// /// animals = pd.read_csv("animals.csv") /// ``` -#[violation] -pub struct PandasDfVariableName; +#[derive(ViolationMetadata)] +pub(crate) struct PandasDfVariableName; impl Violation for PandasDfVariableName { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/attr.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/attr.rs index c87c61394bbd5..af17a18a2a57e 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/attr.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/attr.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -32,8 +32,8 @@ use crate::rules::pandas_vet::helpers::{test_expression, Resolution}; /// /// ## References /// - [Pandas documentation: Accessing the values in a Series or Index](https://pandas.pydata.org/pandas-docs/stable/whatsnew/v0.24.0.html#accessing-the-values-in-a-series-or-index) -#[violation] -pub struct PandasUseOfDotValues; +#[derive(ViolationMetadata)] +pub(crate) struct PandasUseOfDotValues; impl Violation for PandasUseOfDotValues { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/call.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/call.rs index 0ebc0e3f67e12..fcc48e6313b7e 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/call.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/call.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::Violation; use ruff_diagnostics::{Diagnostic, DiagnosticKind}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -39,8 +39,8 @@ use crate::rules::pandas_vet::helpers::{test_expression, Resolution}; /// ## References /// - [Pandas documentation: `isnull`](https://pandas.pydata.org/docs/reference/api/pandas.isnull.html#pandas.isnull) /// - [Pandas documentation: `isna`](https://pandas.pydata.org/docs/reference/api/pandas.isna.html#pandas.isna) -#[violation] -pub struct PandasUseOfDotIsNull; +#[derive(ViolationMetadata)] +pub(crate) struct PandasUseOfDotIsNull; impl Violation for PandasUseOfDotIsNull { #[derive_message_formats] @@ -79,8 +79,8 @@ impl Violation for PandasUseOfDotIsNull { /// ## References /// - [Pandas documentation: `notnull`](https://pandas.pydata.org/docs/reference/api/pandas.notnull.html#pandas.notnull) /// - [Pandas documentation: `notna`](https://pandas.pydata.org/docs/reference/api/pandas.notna.html#pandas.notna) -#[violation] -pub struct PandasUseOfDotNotNull; +#[derive(ViolationMetadata)] +pub(crate) struct PandasUseOfDotNotNull; impl Violation for PandasUseOfDotNotNull { #[derive_message_formats] @@ -115,8 +115,8 @@ impl Violation for PandasUseOfDotNotNull { /// ## References /// - [Pandas documentation: Reshaping and pivot tables](https://pandas.pydata.org/docs/user_guide/reshaping.html) /// - [Pandas documentation: `pivot_table`](https://pandas.pydata.org/docs/reference/api/pandas.pivot_table.html#pandas.pivot_table) -#[violation] -pub struct PandasUseOfDotPivotOrUnstack; +#[derive(ViolationMetadata)] +pub(crate) struct PandasUseOfDotPivotOrUnstack; impl Violation for PandasUseOfDotPivotOrUnstack { #[derive_message_formats] @@ -152,8 +152,8 @@ impl Violation for PandasUseOfDotPivotOrUnstack { /// ## References /// - [Pandas documentation: `melt`](https://pandas.pydata.org/docs/reference/api/pandas.melt.html) /// - [Pandas documentation: `stack`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.stack.html) -#[violation] -pub struct PandasUseOfDotStack; +#[derive(ViolationMetadata)] +pub(crate) struct PandasUseOfDotStack; impl Violation for PandasUseOfDotStack { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs index 66c6877bcf72e..cb56049e983d9 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_const_true; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::{self as ast, Keyword, Stmt}; @@ -34,8 +34,8 @@ use crate::Locator; /// /// ## References /// - [_Why You Should Probably Never Use pandas `inplace=True`_](https://towardsdatascience.com/why-you-should-probably-never-use-pandas-inplace-true-9f9f211849e4) -#[violation] -pub struct PandasUseOfInplaceArgument; +#[derive(ViolationMetadata)] +pub(crate) struct PandasUseOfInplaceArgument; impl Violation for PandasUseOfInplaceArgument { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/nunique_constant_series_check.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/nunique_constant_series_check.rs index 7951fc557ecf1..19dd21259fec9 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/nunique_constant_series_check.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/nunique_constant_series_check.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, CmpOp, Expr, Int}; use ruff_text_size::Ranged; @@ -50,8 +50,8 @@ use crate::rules::pandas_vet::helpers::{test_expression, Resolution}; /// ## References /// - [Pandas Cookbook: "Constant Series"](https://pandas.pydata.org/docs/user_guide/cookbook.html#constant-series) /// - [Pandas documentation: `nunique`](https://pandas.pydata.org/docs/reference/api/pandas.Series.nunique.html) -#[violation] -pub struct PandasNuniqueConstantSeriesCheck; +#[derive(ViolationMetadata)] +pub(crate) struct PandasNuniqueConstantSeriesCheck; impl Violation for PandasNuniqueConstantSeriesCheck { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/pd_merge.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/pd_merge.rs index 6fd925ad1e857..ed5123f5b70ee 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/pd_merge.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/pd_merge.rs @@ -2,14 +2,14 @@ use ruff_python_ast::{self as ast, Expr}; use crate::checkers::ast::Checker; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; /// ## What it does /// Checks for uses of `pd.merge` on Pandas objects. /// /// ## Why is this bad? -/// In Pandas, the `.merge` method (exposed on, e.g., DataFrame objects) and +/// In Pandas, the `.merge` method (exposed on, e.g., `DataFrame` objects) and /// the `pd.merge` function (exposed on the Pandas module) are equivalent. /// /// For consistency, prefer calling `.merge` on an object over calling @@ -41,8 +41,8 @@ use ruff_text_size::Ranged; /// ## References /// - [Pandas documentation: `merge`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.merge.html#pandas.DataFrame.merge) /// - [Pandas documentation: `pd.merge`](https://pandas.pydata.org/docs/reference/api/pandas.merge.html#pandas.merge) -#[violation] -pub struct PandasUseOfPdMerge; +#[derive(ViolationMetadata)] +pub(crate) struct PandasUseOfPdMerge; impl Violation for PandasUseOfPdMerge { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/read_table.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/read_table.rs index ec70a431a074f..0b52c24737adc 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/read_table.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/read_table.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::Expr; use ruff_python_semantic::Modules; @@ -35,8 +35,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Pandas documentation: `read_csv`](https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html#pandas.read_csv) /// - [Pandas documentation: `read_table`](https://pandas.pydata.org/docs/reference/api/pandas.read_table.html#pandas.read_table) -#[violation] -pub struct PandasUseOfDotReadTable; +#[derive(ViolationMetadata)] +pub(crate) struct PandasUseOfDotReadTable; impl Violation for PandasUseOfDotReadTable { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/subscript.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/subscript.rs index 6839aa62fc99f..86a791a3b1f22 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/subscript.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/subscript.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::Violation; use ruff_diagnostics::{Diagnostic, DiagnosticKind}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -39,8 +39,8 @@ use crate::rules::pandas_vet::helpers::{test_expression, Resolution}; /// - [Pandas release notes: Deprecate `.ix`](https://pandas.pydata.org/pandas-docs/version/0.20/whatsnew.html#deprecate-ix) /// - [Pandas documentation: `loc`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.loc.html) /// - [Pandas documentation: `iloc`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.iloc.html) -#[violation] -pub struct PandasUseOfDotIx; +#[derive(ViolationMetadata)] +pub(crate) struct PandasUseOfDotIx; impl Violation for PandasUseOfDotIx { #[derive_message_formats] @@ -53,7 +53,7 @@ impl Violation for PandasUseOfDotIx { /// Checks for uses of `.at` on Pandas objects. /// /// ## Why is this bad? -/// The `.at` method selects a single value from a DataFrame or Series based on +/// The `.at` method selects a single value from a `DataFrame` or Series based on /// a label index, and is slightly faster than using `.loc`. However, `.loc` is /// more idiomatic and versatile, as it can be used to select multiple values at /// once. @@ -81,8 +81,8 @@ impl Violation for PandasUseOfDotIx { /// ## References /// - [Pandas documentation: `loc`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.loc.html) /// - [Pandas documentation: `at`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.at.html) -#[violation] -pub struct PandasUseOfDotAt; +#[derive(ViolationMetadata)] +pub(crate) struct PandasUseOfDotAt; impl Violation for PandasUseOfDotAt { #[derive_message_formats] @@ -95,7 +95,7 @@ impl Violation for PandasUseOfDotAt { /// Checks for uses of `.iat` on Pandas objects. /// /// ## Why is this bad? -/// The `.iat` method selects a single value from a DataFrame or Series based +/// The `.iat` method selects a single value from a `DataFrame` or Series based /// on an ordinal index, and is slightly faster than using `.iloc`. However, /// `.iloc` is more idiomatic and versatile, as it can be used to select /// multiple values at once. @@ -132,8 +132,8 @@ impl Violation for PandasUseOfDotAt { /// ## References /// - [Pandas documentation: `iloc`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.iloc.html) /// - [Pandas documentation: `iat`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.iat.html) -#[violation] -pub struct PandasUseOfDotIat; +#[derive(ViolationMetadata)] +pub(crate) struct PandasUseOfDotIat; impl Violation for PandasUseOfDotIat { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs index bb26d2190b607..7d3487a707aaa 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_acronym.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Alias, Stmt}; use ruff_python_stdlib::str::{self}; use ruff_text_size::Ranged; @@ -39,8 +39,8 @@ use crate::rules::pep8_naming::helpers; /// - `lint.flake8-import-conventions.aliases` /// /// [PEP 8]: https://peps.python.org/pep-0008/ -#[violation] -pub struct CamelcaseImportedAsAcronym { +#[derive(ViolationMetadata)] +pub(crate) struct CamelcaseImportedAsAcronym { name: String, asname: String, } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs index f805bd2915e91..61f8b377b5d4b 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_constant.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{Alias, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_stdlib::str::{self}; use ruff_text_size::Ranged; @@ -31,8 +31,8 @@ use crate::rules::pep8_naming::settings::IgnoreNames; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/ -#[violation] -pub struct CamelcaseImportedAsConstant { +#[derive(ViolationMetadata)] +pub(crate) struct CamelcaseImportedAsConstant { name: String, asname: String, } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_lowercase.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_lowercase.rs index 5a006d6260cc4..0ed58bc0aada5 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_lowercase.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/camelcase_imported_as_lowercase.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{Alias, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::rules::pep8_naming::helpers; @@ -30,8 +30,8 @@ use crate::rules::pep8_naming::settings::IgnoreNames; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/ -#[violation] -pub struct CamelcaseImportedAsLowercase { +#[derive(ViolationMetadata)] +pub(crate) struct CamelcaseImportedAsLowercase { name: String, asname: String, } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs index 0f81043f60200..124a61c436616 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/constant_imported_as_non_constant.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Alias, Stmt}; use ruff_python_stdlib::str; use ruff_text_size::Ranged; @@ -30,8 +30,8 @@ use crate::rules::pep8_naming::settings::IgnoreNames; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/ -#[violation] -pub struct ConstantImportedAsNonConstant { +#[derive(ViolationMetadata)] +pub(crate) struct ConstantImportedAsNonConstant { name: String, asname: String, } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/dunder_function_name.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/dunder_function_name.rs index 027185f4c66f8..c2d2d92a79132 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/dunder_function_name.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/dunder_function_name.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Stmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use ruff_python_semantic::analyze::visibility; use ruff_python_semantic::{Scope, ScopeKind}; @@ -32,8 +32,8 @@ use crate::rules::pep8_naming::settings::IgnoreNames; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/ -#[violation] -pub struct DunderFunctionName; +#[derive(ViolationMetadata)] +pub(crate) struct DunderFunctionName; impl Violation for DunderFunctionName { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs index 5cab715917152..ecec6e610e92b 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/error_suffix_on_exception_name.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Arguments, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use crate::rules::pep8_naming::settings::IgnoreNames; @@ -29,8 +29,8 @@ use crate::rules::pep8_naming::settings::IgnoreNames; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#exception-names -#[violation] -pub struct ErrorSuffixOnExceptionName { +#[derive(ViolationMetadata)] +pub(crate) struct ErrorSuffixOnExceptionName { name: String, } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_argument_name.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_argument_name.rs index 5856a03f4ecb7..9d4cd1acdb432 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_argument_name.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_argument_name.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Parameter; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_stdlib::str; use ruff_text_size::Ranged; @@ -15,12 +15,12 @@ use crate::rules::pep8_naming::settings::IgnoreNames; /// by underscores (also known as `snake_case`). /// /// > Function names should be lowercase, with words separated by underscores -/// as necessary to improve readability. +/// > as necessary to improve readability. /// > /// > Variable names follow the same convention as function names. /// > /// > mixedCase is allowed only in contexts where that’s already the -/// prevailing style (e.g. threading.py), to retain backwards compatibility. +/// > prevailing style (e.g. threading.py), to retain backwards compatibility. /// /// ## Example /// ```python @@ -35,8 +35,8 @@ use crate::rules::pep8_naming::settings::IgnoreNames; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#function-and-method-arguments -#[violation] -pub struct InvalidArgumentName { +#[derive(ViolationMetadata)] +pub(crate) struct InvalidArgumentName { name: String, } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_class_name.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_class_name.rs index edcccf663d98b..564937d543655 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_class_name.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_class_name.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Stmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use crate::rules::pep8_naming::settings::IgnoreNames; @@ -35,8 +35,8 @@ use crate::rules::pep8_naming::settings::IgnoreNames; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#class-names -#[violation] -pub struct InvalidClassName { +#[derive(ViolationMetadata)] +pub(crate) struct InvalidClassName { name: String, } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_first_argument_name.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_first_argument_name.rs index fcf1cb79d5c4d..80ec7424727d8 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_first_argument_name.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_first_argument_name.rs @@ -1,7 +1,7 @@ use anyhow::Result; use ruff_diagnostics::{Diagnostic, DiagnosticKind, Fix, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::ParameterWithDefault; use ruff_python_codegen::Stylist; @@ -58,8 +58,8 @@ use crate::renamer::Renamer; /// - `lint.pep8-naming.extend-ignore-names` /// /// [PEP 8]: https://peps.python.org/pep-0008/#function-and-method-arguments -#[violation] -pub struct InvalidFirstArgumentNameForMethod { +#[derive(ViolationMetadata)] +pub(crate) struct InvalidFirstArgumentNameForMethod { argument_name: String, } @@ -124,8 +124,8 @@ impl Violation for InvalidFirstArgumentNameForMethod { /// - `lint.pep8-naming.extend-ignore-names` /// /// [PEP 8]: https://peps.python.org/pep-0008/#function-and-method-arguments -#[violation] -pub struct InvalidFirstArgumentNameForClassMethod { +#[derive(ViolationMetadata)] +pub(crate) struct InvalidFirstArgumentNameForClassMethod { argument_name: String, } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_function_name.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_function_name.rs index 0a10458f6d42f..508aeb689eaf1 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_function_name.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_function_name.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{Decorator, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use ruff_python_semantic::analyze::visibility; use ruff_python_semantic::SemanticModel; @@ -42,8 +42,8 @@ use crate::rules::pep8_naming::settings::IgnoreNames; /// - `lint.pep8-naming.extend-ignore-names` /// /// [PEP 8]: https://peps.python.org/pep-0008/#function-and-variable-names -#[violation] -pub struct InvalidFunctionName { +#[derive(ViolationMetadata)] +pub(crate) struct InvalidFunctionName { name: String, } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_module_name.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_module_name.rs index 1637bd574239c..702efa3962f31 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_module_name.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/invalid_module_name.rs @@ -4,7 +4,7 @@ use std::path::Path; use crate::package::PackageRoot; use crate::rules::pep8_naming::settings::IgnoreNames; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::PySourceType; use ruff_python_stdlib::identifiers::{is_migration_name, is_module_name}; use ruff_python_stdlib::path::is_module_file; @@ -35,8 +35,8 @@ use ruff_text_size::TextRange; /// - Instead of `ExampleModule`, use `example_module`. /// /// [PEP 8]: https://peps.python.org/pep-0008/#package-and-module-names -#[violation] -pub struct InvalidModuleName { +#[derive(ViolationMetadata)] +pub(crate) struct InvalidModuleName { name: String, } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/lowercase_imported_as_non_lowercase.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/lowercase_imported_as_non_lowercase.rs index 097e0f394896f..c7fc24d3c86cc 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/lowercase_imported_as_non_lowercase.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/lowercase_imported_as_non_lowercase.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Alias, Stmt}; use ruff_python_stdlib::str; use ruff_text_size::Ranged; @@ -29,8 +29,8 @@ use crate::rules::pep8_naming::settings::IgnoreNames; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/ -#[violation] -pub struct LowercaseImportedAsNonLowercase { +#[derive(ViolationMetadata)] +pub(crate) struct LowercaseImportedAsNonLowercase { name: String, asname: String, } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_class_scope.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_class_scope.rs index 15b11ac894bd1..86856052f833d 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_class_scope.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_class_scope.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -14,12 +14,12 @@ use crate::rules::pep8_naming::helpers; /// by underscores (also known as `snake_case`). /// /// > Function names should be lowercase, with words separated by underscores -/// as necessary to improve readability. +/// > as necessary to improve readability. /// > /// > Variable names follow the same convention as function names. /// > /// > mixedCase is allowed only in contexts where that’s already the -/// prevailing style (e.g. threading.py), to retain backwards compatibility. +/// > prevailing style (e.g. threading.py), to retain backwards compatibility. /// /// ## Example /// ```python @@ -36,8 +36,8 @@ use crate::rules::pep8_naming::helpers; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#function-and-method-arguments -#[violation] -pub struct MixedCaseVariableInClassScope { +#[derive(ViolationMetadata)] +pub(crate) struct MixedCaseVariableInClassScope { name: String, } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_global_scope.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_global_scope.rs index 383e7c260831a..8ddadbd95b62a 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_global_scope.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/mixed_case_variable_in_global_scope.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -16,21 +16,21 @@ use crate::rules::pep8_naming::helpers; /// /// > ### Global Variable Names /// > (Let’s hope that these variables are meant for use inside one module -/// only.) The conventions are about the same as those for functions. +/// > only.) The conventions are about the same as those for functions. /// > /// > Modules that are designed for use via from M import * should use the -/// __all__ mechanism to prevent exporting globals, or use the older -/// convention of prefixing such globals with an underscore (which you might -/// want to do to indicate these globals are “module non-public”). +/// > __all__ mechanism to prevent exporting globals, or use the older +/// > convention of prefixing such globals with an underscore (which you might +/// > want to do to indicate these globals are “module non-public”). /// > /// > ### Function and Variable Names /// > Function names should be lowercase, with words separated by underscores -/// as necessary to improve readability. +/// > as necessary to improve readability. /// > /// > Variable names follow the same convention as function names. /// > /// > mixedCase is allowed only in contexts where that’s already the prevailing -/// style (e.g. threading.py), to retain backwards compatibility. +/// > style (e.g. threading.py), to retain backwards compatibility. /// /// ## Example /// ```python @@ -47,8 +47,8 @@ use crate::rules::pep8_naming::helpers; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#global-variable-names -#[violation] -pub struct MixedCaseVariableInGlobalScope { +#[derive(ViolationMetadata)] +pub(crate) struct MixedCaseVariableInGlobalScope { name: String, } diff --git a/crates/ruff_linter/src/rules/pep8_naming/rules/non_lowercase_variable_in_function.rs b/crates/ruff_linter/src/rules/pep8_naming/rules/non_lowercase_variable_in_function.rs index be992b13af8ec..99e28b43eda66 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/rules/non_lowercase_variable_in_function.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/rules/non_lowercase_variable_in_function.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_stdlib::str; use ruff_text_size::Ranged; @@ -38,8 +38,8 @@ use crate::rules::pep8_naming::helpers; /// - `lint.pep8-naming.extend-ignore-names` /// /// [PEP 8]: https://peps.python.org/pep-0008/#function-and-variable-names -#[violation] -pub struct NonLowercaseVariableInFunction { +#[derive(ViolationMetadata)] +pub(crate) struct NonLowercaseVariableInFunction { name: String, } diff --git a/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs b/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs index 6d7fc992c6c41..f262d65c17dbc 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::{Arguments, Expr}; use ruff_text_size::Ranged; @@ -43,8 +43,8 @@ use crate::fix::edits::pad; /// incorrect fix if the object in question does not duck-type as a mapping /// (e.g., if it is missing a `.keys()` or `.values()` method, or if those /// methods behave differently than they do on standard mapping types). -#[violation] -pub struct IncorrectDictIterator { +#[derive(ViolationMetadata)] +pub(crate) struct IncorrectDictIterator { subset: DictSubset, } diff --git a/crates/ruff_linter/src/rules/perflint/rules/manual_dict_comprehension.rs b/crates/ruff_linter/src/rules/perflint/rules/manual_dict_comprehension.rs index 31c5219372f27..413a3b4d90e02 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/manual_dict_comprehension.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/manual_dict_comprehension.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::helpers::any_over_expr; use ruff_python_ast::{self as ast, Expr, Stmt}; @@ -41,8 +41,8 @@ use crate::checkers::ast::Checker; /// pairs = (("a", 1), ("b", 2)) /// result.update({x: y for x, y in pairs if y % 2}) /// ``` -#[violation] -pub struct ManualDictComprehension; +#[derive(ViolationMetadata)] +pub(crate) struct ManualDictComprehension; impl Violation for ManualDictComprehension { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/perflint/rules/manual_list_comprehension.rs b/crates/ruff_linter/src/rules/perflint/rules/manual_list_comprehension.rs index e9c3a35da0da0..ff3671f72c154 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/manual_list_comprehension.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/manual_list_comprehension.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Arguments, Expr, Stmt}; use anyhow::{anyhow, Result}; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::helpers::any_over_expr; use ruff_python_semantic::{analyze::typing::is_list, Binding}; @@ -47,8 +47,8 @@ use crate::checkers::ast::Checker; /// original = list(range(10000)) /// filtered.extend(x for x in original if x % 2) /// ``` -#[violation] -pub struct ManualListComprehension { +#[derive(ViolationMetadata)] +pub(crate) struct ManualListComprehension { is_async: bool, comprehension_type: Option, } diff --git a/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs b/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs index 1ed0c7553a096..6b42bcbfa4fe9 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::any_over_expr; use ruff_python_ast::{self as ast, Arguments, Expr, Stmt}; use ruff_python_semantic::analyze::typing::is_list; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// original = list(range(10000)) /// filtered = list(original) /// ``` -#[violation] -pub struct ManualListCopy; +#[derive(ViolationMetadata)] +pub(crate) struct ManualListCopy; impl Violation for ManualListCopy { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/perflint/rules/try_except_in_loop.rs b/crates/ruff_linter/src/rules/perflint/rules/try_except_in_loop.rs index 43ef7e61cc31b..64136aab35634 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/try_except_in_loop.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/try_except_in_loop.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor}; use ruff_python_ast::{self as ast, Stmt}; use ruff_text_size::Ranged; @@ -77,8 +77,8 @@ use crate::settings::types::PythonVersion; /// /// ## Options /// - `target-version` -#[violation] -pub struct TryExceptInLoop; +#[derive(ViolationMetadata)] +pub(crate) struct TryExceptInLoop; impl Violation for TryExceptInLoop { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs b/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs index db03993304326..ed60d3e276d1b 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor}; use ruff_python_ast::{self as ast, Arguments, Expr, Stmt}; use ruff_python_semantic::analyze::typing::find_assigned_value; @@ -35,8 +35,8 @@ use crate::checkers::ast::Checker; /// for i in items: /// print(i) /// ``` -#[violation] -pub struct UnnecessaryListCast; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryListCast; impl AlwaysFixableViolation for UnnecessaryListCast { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_class_name.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_class_name.rs index 0729cdab66743..44d1236c95150 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_class_name.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_class_name.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Identifier; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::rules::pycodestyle::helpers::is_ambiguous_name; @@ -24,8 +24,8 @@ use crate::rules::pycodestyle::helpers::is_ambiguous_name; /// ```python /// class Integer(object): ... /// ``` -#[violation] -pub struct AmbiguousClassName(pub String); +#[derive(ViolationMetadata)] +pub(crate) struct AmbiguousClassName(pub String); impl Violation for AmbiguousClassName { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_function_name.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_function_name.rs index 6601929c9819e..6c1b88f8d9e59 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_function_name.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_function_name.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Identifier; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::rules::pycodestyle::helpers::is_ambiguous_name; @@ -24,8 +24,8 @@ use crate::rules::pycodestyle::helpers::is_ambiguous_name; /// ```python /// def long_name(x): ... /// ``` -#[violation] -pub struct AmbiguousFunctionName(pub String); +#[derive(ViolationMetadata)] +pub(crate) struct AmbiguousFunctionName(pub String); impl Violation for AmbiguousFunctionName { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_variable_name.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_variable_name.rs index cfc16d4e82d75..1924f9804b451 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_variable_name.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/ambiguous_variable_name.rs @@ -1,7 +1,7 @@ use ruff_text_size::TextRange; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::checkers::ast::Checker; use crate::rules::pycodestyle::helpers::is_ambiguous_name; @@ -33,8 +33,8 @@ use crate::rules::pycodestyle::helpers::is_ambiguous_name; /// i = 42 /// ``` /// -#[violation] -pub struct AmbiguousVariableName(pub String); +#[derive(ViolationMetadata)] +pub(crate) struct AmbiguousVariableName(pub String); impl Violation for AmbiguousVariableName { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/bare_except.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/bare_except.rs index afa55beb2434f..ebf49db0d6e65 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/bare_except.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/bare_except.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::except; use ruff_python_ast::{self as ast, ExceptHandler, Expr, Stmt}; @@ -44,8 +44,8 @@ use crate::Locator; /// ## References /// - [Python documentation: Exception hierarchy](https://docs.python.org/3/library/exceptions.html#exception-hierarchy) /// - [Google Python Style Guide: "Exceptions"](https://google.github.io/styleguide/pyguide.html#24-exceptions) -#[violation] -pub struct BareExcept; +#[derive(ViolationMetadata)] +pub(crate) struct BareExcept; impl Violation for BareExcept { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs index 59867fa15cd95..bb99f68ce6aab 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs @@ -9,7 +9,7 @@ use ruff_diagnostics::AlwaysFixableViolation; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Edit; use ruff_diagnostics::Fix; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_notebook::CellOffsets; use ruff_python_ast::PySourceType; use ruff_python_codegen::Stylist; @@ -64,8 +64,8 @@ const BLANK_LINES_NESTED_LEVEL: u32 = 1; /// - [PEP 8: Blank Lines](https://peps.python.org/pep-0008/#blank-lines) /// - [Flake 8 rule](https://www.flake8rules.com/rules/E301.html) /// - [Typing Style Guide](https://typing.readthedocs.io/en/latest/source/stubs.html#blank-lines) -#[violation] -pub struct BlankLineBetweenMethods; +#[derive(ViolationMetadata)] +pub(crate) struct BlankLineBetweenMethods; impl AlwaysFixableViolation for BlankLineBetweenMethods { #[derive_message_formats] @@ -117,8 +117,8 @@ impl AlwaysFixableViolation for BlankLineBetweenMethods { /// - [PEP 8: Blank Lines](https://peps.python.org/pep-0008/#blank-lines) /// - [Flake 8 rule](https://www.flake8rules.com/rules/E302.html) /// - [Typing Style Guide](https://typing.readthedocs.io/en/latest/source/stubs.html#blank-lines) -#[violation] -pub struct BlankLinesTopLevel { +#[derive(ViolationMetadata)] +pub(crate) struct BlankLinesTopLevel { actual_blank_lines: u32, expected_blank_lines: u32, } @@ -184,8 +184,8 @@ impl AlwaysFixableViolation for BlankLinesTopLevel { /// - [PEP 8: Blank Lines](https://peps.python.org/pep-0008/#blank-lines) /// - [Flake 8 rule](https://www.flake8rules.com/rules/E303.html) /// - [Typing Style Guide](https://typing.readthedocs.io/en/latest/source/stubs.html#blank-lines) -#[violation] -pub struct TooManyBlankLines { +#[derive(ViolationMetadata)] +pub(crate) struct TooManyBlankLines { actual_blank_lines: u32, } @@ -230,8 +230,8 @@ impl AlwaysFixableViolation for TooManyBlankLines { /// ## References /// - [PEP 8: Blank Lines](https://peps.python.org/pep-0008/#blank-lines) /// - [Flake 8 rule](https://www.flake8rules.com/rules/E304.html) -#[violation] -pub struct BlankLineAfterDecorator { +#[derive(ViolationMetadata)] +pub(crate) struct BlankLineAfterDecorator { actual_blank_lines: u32, } @@ -281,8 +281,8 @@ impl AlwaysFixableViolation for BlankLineAfterDecorator { /// - [PEP 8: Blank Lines](https://peps.python.org/pep-0008/#blank-lines) /// - [Flake 8 rule](https://www.flake8rules.com/rules/E305.html) /// - [Typing Style Guide](https://typing.readthedocs.io/en/latest/source/stubs.html#blank-lines) -#[violation] -pub struct BlankLinesAfterFunctionOrClass { +#[derive(ViolationMetadata)] +pub(crate) struct BlankLinesAfterFunctionOrClass { actual_blank_lines: u32, } @@ -335,8 +335,8 @@ impl AlwaysFixableViolation for BlankLinesAfterFunctionOrClass { /// - [PEP 8: Blank Lines](https://peps.python.org/pep-0008/#blank-lines) /// - [Flake 8 rule](https://www.flake8rules.com/rules/E306.html) /// - [Typing Style Guide](https://typing.readthedocs.io/en/latest/source/stubs.html#blank-lines) -#[violation] -pub struct BlankLinesBeforeNestedDefinition; +#[derive(ViolationMetadata)] +pub(crate) struct BlankLinesBeforeNestedDefinition; impl AlwaysFixableViolation for BlankLinesBeforeNestedDefinition { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs index c6e08175daf62..93d44372c5b6b 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::{AlwaysFixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_notebook::CellOffsets; use ruff_python_ast::PySourceType; use ruff_python_index::Indexer; @@ -27,8 +27,8 @@ use crate::Locator; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#other-recommendations -#[violation] -pub struct MultipleStatementsOnOneLineColon; +#[derive(ViolationMetadata)] +pub(crate) struct MultipleStatementsOnOneLineColon; impl Violation for MultipleStatementsOnOneLineColon { #[derive_message_formats] @@ -57,8 +57,8 @@ impl Violation for MultipleStatementsOnOneLineColon { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#other-recommendations -#[violation] -pub struct MultipleStatementsOnOneLineSemicolon; +#[derive(ViolationMetadata)] +pub(crate) struct MultipleStatementsOnOneLineSemicolon; impl Violation for MultipleStatementsOnOneLineSemicolon { #[derive_message_formats] @@ -82,8 +82,8 @@ impl Violation for MultipleStatementsOnOneLineSemicolon { /// ```python /// do_four() /// ``` -#[violation] -pub struct UselessSemicolon; +#[derive(ViolationMetadata)] +pub(crate) struct UselessSemicolon; impl AlwaysFixableViolation for UselessSemicolon { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/doc_line_too_long.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/doc_line_too_long.rs index 5661f62036f66..cc11ee34957f8 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/doc_line_too_long.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/doc_line_too_long.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_trivia::CommentRanges; use ruff_source_file::Line; @@ -70,8 +70,8 @@ use crate::settings::LinterSettings; /// - `lint.pycodestyle.ignore-overlong-task-comments` /// /// [PEP 8]: https://peps.python.org/pep-0008/#maximum-line-length -#[violation] -pub struct DocLineTooLong(usize, usize); +#[derive(ViolationMetadata)] +pub(crate) struct DocLineTooLong(usize, usize); impl Violation for DocLineTooLong { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/errors.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/errors.rs index d96de51762129..25eefaeb673cd 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/errors.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/errors.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// This is not a regular diagnostic; instead, it's raised when a file cannot be read @@ -23,7 +23,7 @@ use ruff_macros::{derive_message_formats, violation}; /// ## References /// - [UNIX Permissions introduction](https://mason.gmu.edu/~montecin/UNIXpermiss.htm) /// - [Command Line Basics: Symbolic Links](https://www.digitalocean.com/community/tutorials/workflow-symbolic-links) -#[violation] +#[derive(ViolationMetadata)] pub struct IOError { pub message: String, } @@ -62,9 +62,9 @@ impl Violation for IOError { /// /// ## References /// - [Python documentation: Syntax Errors](https://docs.python.org/3/tutorial/errors.html#syntax-errors) -#[violation] +#[derive(ViolationMetadata)] #[deprecated(note = "E999 has been removed")] -pub struct SyntaxError; +pub(crate) struct SyntaxError; #[allow(deprecated)] impl Violation for SyntaxError { diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/invalid_escape_sequence.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/invalid_escape_sequence.rs index 5d34eaf79d0f5..68d13e0a4174c 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/invalid_escape_sequence.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/invalid_escape_sequence.rs @@ -1,7 +1,7 @@ use memchr::memchr_iter; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{AnyStringFlags, FStringElement, StringLike, StringLikePart}; use ruff_text_size::{Ranged, TextLen, TextRange, TextSize}; @@ -37,8 +37,8 @@ use crate::Locator; /// /// ## References /// - [Python documentation: String and Bytes literals](https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals) -#[violation] -pub struct InvalidEscapeSequence { +#[derive(ViolationMetadata)] +pub(crate) struct InvalidEscapeSequence { ch: char, fix_title: FixTitle, } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs index d4a61f047acaa..fbe1967c027f5 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{ self as ast, Expr, Identifier, Parameter, ParameterWithDefault, Parameters, Stmt, }; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#programming-recommendations -#[violation] -pub struct LambdaAssignment { +#[derive(ViolationMetadata)] +pub(crate) struct LambdaAssignment { name: String, } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/line_too_long.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/line_too_long.rs index fe1d1b089a60f..599c01a32c692 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/line_too_long.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/line_too_long.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_trivia::CommentRanges; use ruff_source_file::Line; @@ -68,8 +68,8 @@ use crate::settings::LinterSettings; /// - `lint.pycodestyle.max-line-length` /// /// [PEP 8]: https://peps.python.org/pep-0008/#maximum-line-length -#[violation] -pub struct LineTooLong(usize, usize); +#[derive(ViolationMetadata)] +pub(crate) struct LineTooLong(usize, usize); impl Violation for LineTooLong { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs index 1fc12f5bf5297..018cc4f0ae4ec 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs @@ -1,7 +1,7 @@ use rustc_hash::FxHashMap; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers; use ruff_python_ast::helpers::generate_comparison; use ruff_python_ast::{self as ast, CmpOp, Expr}; @@ -57,8 +57,8 @@ impl EqCmpOp { /// /// [PEP 8]: https://peps.python.org/pep-0008/#programming-recommendations /// [this issue]: https://github.com/astral-sh/ruff/issues/4560 -#[violation] -pub struct NoneComparison(EqCmpOp); +#[derive(ViolationMetadata)] +pub(crate) struct NoneComparison(EqCmpOp); impl AlwaysFixableViolation for NoneComparison { #[derive_message_formats] @@ -119,8 +119,8 @@ impl AlwaysFixableViolation for NoneComparison { /// /// [PEP 8]: https://peps.python.org/pep-0008/#programming-recommendations /// [this issue]: https://github.com/astral-sh/ruff/issues/4560 -#[violation] -pub struct TrueFalseComparison { +#[derive(ViolationMetadata)] +pub(crate) struct TrueFalseComparison { value: bool, op: EqCmpOp, cond: Option, diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs index 3580c8dad16ca..24f6cd90cf13c 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs @@ -2,7 +2,7 @@ use ruff_diagnostics::AlwaysFixableViolation; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Edit; use ruff_diagnostics::Fix; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_parser::TokenKind; use ruff_text_size::{Ranged, TextRange}; @@ -31,8 +31,8 @@ use super::{LogicalLine, Whitespace}; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#pet-peeves -#[violation] -pub struct WhitespaceAfterOpenBracket { +#[derive(ViolationMetadata)] +pub(crate) struct WhitespaceAfterOpenBracket { symbol: char, } @@ -70,8 +70,8 @@ impl AlwaysFixableViolation for WhitespaceAfterOpenBracket { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#pet-peeves -#[violation] -pub struct WhitespaceBeforeCloseBracket { +#[derive(ViolationMetadata)] +pub(crate) struct WhitespaceBeforeCloseBracket { symbol: char, } @@ -107,8 +107,8 @@ impl AlwaysFixableViolation for WhitespaceBeforeCloseBracket { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#pet-peeves -#[violation] -pub struct WhitespaceBeforePunctuation { +#[derive(ViolationMetadata)] +pub(crate) struct WhitespaceBeforePunctuation { symbol: char, } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/indentation.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/indentation.rs index a46a386a966d0..c5f89257842d2 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/indentation.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/indentation.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::DiagnosticKind; use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_parser::TokenKind; use super::LogicalLine; @@ -35,8 +35,8 @@ use super::LogicalLine; /// /// [PEP 8]: https://peps.python.org/pep-0008/#indentation /// [formatter]:https://docs.astral.sh/ruff/formatter/ -#[violation] -pub struct IndentationWithInvalidMultiple { +#[derive(ViolationMetadata)] +pub(crate) struct IndentationWithInvalidMultiple { indent_width: usize, } @@ -78,8 +78,8 @@ impl Violation for IndentationWithInvalidMultiple { /// /// [PEP 8]: https://peps.python.org/pep-0008/#indentation /// [formatter]:https://docs.astral.sh/ruff/formatter/ -#[violation] -pub struct IndentationWithInvalidMultipleComment { +#[derive(ViolationMetadata)] +pub(crate) struct IndentationWithInvalidMultipleComment { indent_width: usize, } @@ -111,8 +111,8 @@ impl Violation for IndentationWithInvalidMultipleComment { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#indentation -#[violation] -pub struct NoIndentedBlock; +#[derive(ViolationMetadata)] +pub(crate) struct NoIndentedBlock; impl Violation for NoIndentedBlock { #[derive_message_formats] @@ -143,8 +143,8 @@ impl Violation for NoIndentedBlock { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#indentation -#[violation] -pub struct NoIndentedBlockComment; +#[derive(ViolationMetadata)] +pub(crate) struct NoIndentedBlockComment; impl Violation for NoIndentedBlockComment { #[derive_message_formats] @@ -172,8 +172,8 @@ impl Violation for NoIndentedBlockComment { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#indentation -#[violation] -pub struct UnexpectedIndentation; +#[derive(ViolationMetadata)] +pub(crate) struct UnexpectedIndentation; impl Violation for UnexpectedIndentation { #[derive_message_formats] @@ -201,8 +201,8 @@ impl Violation for UnexpectedIndentation { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#indentation -#[violation] -pub struct UnexpectedIndentationComment; +#[derive(ViolationMetadata)] +pub(crate) struct UnexpectedIndentationComment; impl Violation for UnexpectedIndentationComment { #[derive_message_formats] @@ -237,8 +237,8 @@ impl Violation for UnexpectedIndentationComment { /// /// [PEP 8]: https://peps.python.org/pep-0008/#indentation /// [formatter]:https://docs.astral.sh/ruff/formatter/ -#[violation] -pub struct OverIndented { +#[derive(ViolationMetadata)] +pub(crate) struct OverIndented { is_comment: bool, } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs index 0e1b13f52d3d9..547ab4859c785 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::Edit; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_parser::TokenKind; use ruff_text_size::Ranged; @@ -23,8 +23,8 @@ use super::{DefinitionState, LogicalLine}; /// ```python /// a = (1, 2) /// ``` -#[violation] -pub struct MissingWhitespace { +#[derive(ViolationMetadata)] +pub(crate) struct MissingWhitespace { token: TokenKind, } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_after_keyword.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_after_keyword.rs index 78680a680d7da..dfa9a4ece7caa 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_after_keyword.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_after_keyword.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_parser::TokenKind; use ruff_text_size::Ranged; @@ -26,8 +26,8 @@ use crate::rules::pycodestyle::rules::logical_lines::LogicalLine; /// /// ## References /// - [Python documentation: Keywords](https://docs.python.org/3/reference/lexical_analysis.html#keywords) -#[violation] -pub struct MissingWhitespaceAfterKeyword; +#[derive(ViolationMetadata)] +pub(crate) struct MissingWhitespaceAfterKeyword; impl AlwaysFixableViolation for MissingWhitespaceAfterKeyword { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs index 9a36c9f209981..73edb01e41954 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, DiagnosticKind, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_parser::TokenKind; use ruff_text_size::Ranged; @@ -28,8 +28,8 @@ use crate::rules::pycodestyle::rules::logical_lines::LogicalLine; /// /// [PEP 8]: https://peps.python.org/pep-0008/#pet-peeves // E225 -#[violation] -pub struct MissingWhitespaceAroundOperator; +#[derive(ViolationMetadata)] +pub(crate) struct MissingWhitespaceAroundOperator; impl AlwaysFixableViolation for MissingWhitespaceAroundOperator { #[derive_message_formats] @@ -61,8 +61,8 @@ impl AlwaysFixableViolation for MissingWhitespaceAroundOperator { /// /// [PEP 8]: https://peps.python.org/pep-0008/#pet-peeves // E226 -#[violation] -pub struct MissingWhitespaceAroundArithmeticOperator; +#[derive(ViolationMetadata)] +pub(crate) struct MissingWhitespaceAroundArithmeticOperator; impl AlwaysFixableViolation for MissingWhitespaceAroundArithmeticOperator { #[derive_message_formats] @@ -94,8 +94,8 @@ impl AlwaysFixableViolation for MissingWhitespaceAroundArithmeticOperator { /// /// [PEP 8]: https://peps.python.org/pep-0008/#pet-peeves // E227 -#[violation] -pub struct MissingWhitespaceAroundBitwiseOrShiftOperator; +#[derive(ViolationMetadata)] +pub(crate) struct MissingWhitespaceAroundBitwiseOrShiftOperator; impl AlwaysFixableViolation for MissingWhitespaceAroundBitwiseOrShiftOperator { #[derive_message_formats] @@ -127,8 +127,8 @@ impl AlwaysFixableViolation for MissingWhitespaceAroundBitwiseOrShiftOperator { /// /// [PEP 8]: https://peps.python.org/pep-0008/#other-recommendations // E228 -#[violation] -pub struct MissingWhitespaceAroundModuloOperator; +#[derive(ViolationMetadata)] +pub(crate) struct MissingWhitespaceAroundModuloOperator; impl AlwaysFixableViolation for MissingWhitespaceAroundModuloOperator { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/redundant_backslash.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/redundant_backslash.rs index 2237ec579c84a..a6c348b780244 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/redundant_backslash.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/redundant_backslash.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_index::Indexer; use ruff_python_parser::TokenKind; use ruff_source_file::LineRanges; @@ -29,8 +29,8 @@ use super::LogicalLine; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#maximum-line-length -#[violation] -pub struct RedundantBackslash; +#[derive(ViolationMetadata)] +pub(crate) struct RedundantBackslash; impl AlwaysFixableViolation for RedundantBackslash { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/space_around_operator.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/space_around_operator.rs index 09c3a97a92263..7069ede17a3fc 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/space_around_operator.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/space_around_operator.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_parser::TokenKind; use ruff_text_size::{Ranged, TextRange}; @@ -25,8 +25,8 @@ use super::{LogicalLine, Whitespace}; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#whitespace-in-expressions-and-statements -#[violation] -pub struct TabBeforeOperator; +#[derive(ViolationMetadata)] +pub(crate) struct TabBeforeOperator; impl AlwaysFixableViolation for TabBeforeOperator { #[derive_message_formats] @@ -57,8 +57,8 @@ impl AlwaysFixableViolation for TabBeforeOperator { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#whitespace-in-expressions-and-statements -#[violation] -pub struct MultipleSpacesBeforeOperator; +#[derive(ViolationMetadata)] +pub(crate) struct MultipleSpacesBeforeOperator; impl AlwaysFixableViolation for MultipleSpacesBeforeOperator { #[derive_message_formats] @@ -89,8 +89,8 @@ impl AlwaysFixableViolation for MultipleSpacesBeforeOperator { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#whitespace-in-expressions-and-statements -#[violation] -pub struct TabAfterOperator; +#[derive(ViolationMetadata)] +pub(crate) struct TabAfterOperator; impl AlwaysFixableViolation for TabAfterOperator { #[derive_message_formats] @@ -121,8 +121,8 @@ impl AlwaysFixableViolation for TabAfterOperator { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#whitespace-in-expressions-and-statements -#[violation] -pub struct MultipleSpacesAfterOperator; +#[derive(ViolationMetadata)] +pub(crate) struct MultipleSpacesAfterOperator; impl AlwaysFixableViolation for MultipleSpacesAfterOperator { #[derive_message_formats] @@ -151,8 +151,8 @@ impl AlwaysFixableViolation for MultipleSpacesAfterOperator { /// a = 4, 5 /// ``` /// -#[violation] -pub struct TabAfterComma; +#[derive(ViolationMetadata)] +pub(crate) struct TabAfterComma; impl AlwaysFixableViolation for TabAfterComma { #[derive_message_formats] @@ -181,8 +181,8 @@ impl AlwaysFixableViolation for TabAfterComma { /// ```python /// a = 4, 5 /// ``` -#[violation] -pub struct MultipleSpacesAfterComma; +#[derive(ViolationMetadata)] +pub(crate) struct MultipleSpacesAfterComma; impl AlwaysFixableViolation for MultipleSpacesAfterComma { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_around_keywords.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_around_keywords.rs index cf67dd75ebbb5..aa9b7eaf52b04 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_around_keywords.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_around_keywords.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::{Ranged, TextRange}; use crate::checkers::logical_lines::LogicalLinesContext; @@ -21,8 +21,8 @@ use super::{LogicalLine, Whitespace}; /// ```python /// True and False /// ``` -#[violation] -pub struct MultipleSpacesAfterKeyword; +#[derive(ViolationMetadata)] +pub(crate) struct MultipleSpacesAfterKeyword; impl AlwaysFixableViolation for MultipleSpacesAfterKeyword { #[derive_message_formats] @@ -50,8 +50,8 @@ impl AlwaysFixableViolation for MultipleSpacesAfterKeyword { /// ```python /// True and False /// ``` -#[violation] -pub struct MultipleSpacesBeforeKeyword; +#[derive(ViolationMetadata)] +pub(crate) struct MultipleSpacesBeforeKeyword; impl AlwaysFixableViolation for MultipleSpacesBeforeKeyword { #[derive_message_formats] @@ -79,8 +79,8 @@ impl AlwaysFixableViolation for MultipleSpacesBeforeKeyword { /// ```python /// True and False /// ``` -#[violation] -pub struct TabAfterKeyword; +#[derive(ViolationMetadata)] +pub(crate) struct TabAfterKeyword; impl AlwaysFixableViolation for TabAfterKeyword { #[derive_message_formats] @@ -108,8 +108,8 @@ impl AlwaysFixableViolation for TabAfterKeyword { /// ```python /// True and False /// ``` -#[violation] -pub struct TabBeforeKeyword; +#[derive(ViolationMetadata)] +pub(crate) struct TabBeforeKeyword; impl AlwaysFixableViolation for TabBeforeKeyword { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_around_named_parameter_equals.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_around_named_parameter_equals.rs index 4a017ef831307..b4d6d4bacfc34 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_around_named_parameter_equals.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_around_named_parameter_equals.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_parser::TokenKind; use ruff_text_size::{Ranged, TextRange, TextSize}; @@ -31,8 +31,8 @@ use crate::rules::pycodestyle::rules::logical_lines::{DefinitionState, LogicalLi /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#whitespace-in-expressions-and-statements -#[violation] -pub struct UnexpectedSpacesAroundKeywordParameterEquals; +#[derive(ViolationMetadata)] +pub(crate) struct UnexpectedSpacesAroundKeywordParameterEquals; impl AlwaysFixableViolation for UnexpectedSpacesAroundKeywordParameterEquals { #[derive_message_formats] @@ -70,8 +70,8 @@ impl AlwaysFixableViolation for UnexpectedSpacesAroundKeywordParameterEquals { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#whitespace-in-expressions-and-statements -#[violation] -pub struct MissingWhitespaceAroundParameterEquals; +#[derive(ViolationMetadata)] +pub(crate) struct MissingWhitespaceAroundParameterEquals; impl AlwaysFixableViolation for MissingWhitespaceAroundParameterEquals { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_comment.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_comment.rs index 238ae280c5d41..90cc6bb182c23 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_comment.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_comment.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_parser::TokenKind; use ruff_python_trivia::PythonWhitespace; use ruff_source_file::LineRanges; @@ -30,8 +30,8 @@ use crate::Locator; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#comments -#[violation] -pub struct TooFewSpacesBeforeInlineComment; +#[derive(ViolationMetadata)] +pub(crate) struct TooFewSpacesBeforeInlineComment; impl AlwaysFixableViolation for TooFewSpacesBeforeInlineComment { #[derive_message_formats] @@ -66,8 +66,8 @@ impl AlwaysFixableViolation for TooFewSpacesBeforeInlineComment { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#comments -#[violation] -pub struct NoSpaceAfterInlineComment; +#[derive(ViolationMetadata)] +pub(crate) struct NoSpaceAfterInlineComment; impl AlwaysFixableViolation for NoSpaceAfterInlineComment { #[derive_message_formats] @@ -103,8 +103,8 @@ impl AlwaysFixableViolation for NoSpaceAfterInlineComment { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#comments -#[violation] -pub struct NoSpaceAfterBlockComment; +#[derive(ViolationMetadata)] +pub(crate) struct NoSpaceAfterBlockComment; impl AlwaysFixableViolation for NoSpaceAfterBlockComment { #[derive_message_formats] @@ -149,8 +149,8 @@ impl AlwaysFixableViolation for NoSpaceAfterBlockComment { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#comments -#[violation] -pub struct MultipleLeadingHashesForBlockComment; +#[derive(ViolationMetadata)] +pub(crate) struct MultipleLeadingHashesForBlockComment; impl AlwaysFixableViolation for MultipleLeadingHashesForBlockComment { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs index 0f0dc8763e2a8..227a20c67ca0f 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_parser::TokenKind; use ruff_text_size::{Ranged, TextRange, TextSize}; @@ -25,8 +25,8 @@ use crate::rules::pycodestyle::rules::logical_lines::LogicalLine; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#pet-peeves -#[violation] -pub struct WhitespaceBeforeParameters { +#[derive(ViolationMetadata)] +pub(crate) struct WhitespaceBeforeParameters { bracket: TokenKind, } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs index b037a24dfb238..e5cd7c49eaae4 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_codegen::Stylist; use ruff_text_size::{TextLen, TextRange}; @@ -22,8 +22,8 @@ use crate::Locator; /// ```python /// spam(1)\n /// ``` -#[violation] -pub struct MissingNewlineAtEndOfFile; +#[derive(ViolationMetadata)] +pub(crate) struct MissingNewlineAtEndOfFile; impl AlwaysFixableViolation for MissingNewlineAtEndOfFile { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/mixed_spaces_and_tabs.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/mixed_spaces_and_tabs.rs index 93e1e88ce8e12..fb50e2d12a188 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/mixed_spaces_and_tabs.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/mixed_spaces_and_tabs.rs @@ -1,7 +1,7 @@ use ruff_text_size::{TextLen, TextRange}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_trivia::leading_indentation; use ruff_source_file::Line; @@ -25,8 +25,8 @@ use ruff_source_file::Line; /// ```python /// if a == 0:\n a = 1\n b = 1 /// ``` -#[violation] -pub struct MixedSpacesAndTabs; +#[derive(ViolationMetadata)] +pub(crate) struct MixedSpacesAndTabs; impl Violation for MixedSpacesAndTabs { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/module_import_not_at_top_of_file.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/module_import_not_at_top_of_file.rs index a26fe095e5c25..a8381ed6b3b4d 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/module_import_not_at_top_of_file.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/module_import_not_at_top_of_file.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{PySourceType, Stmt}; use ruff_text_size::Ranged; @@ -39,8 +39,8 @@ use crate::checkers::ast::Checker; /// For Jupyter notebooks, this rule checks for imports that are not at the top of a *cell*. /// /// [PEP 8]: https://peps.python.org/pep-0008/#imports -#[violation] -pub struct ModuleImportNotAtTopOfFile { +#[derive(ViolationMetadata)] +pub(crate) struct ModuleImportNotAtTopOfFile { source_type: PySourceType, } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/multiple_imports_on_one_line.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/multiple_imports_on_one_line.rs index 70040fbdf62eb..73d429d9719b6 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/multiple_imports_on_one_line.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/multiple_imports_on_one_line.rs @@ -1,7 +1,7 @@ use itertools::Itertools; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Alias, Stmt}; use ruff_python_codegen::Stylist; use ruff_python_index::Indexer; @@ -30,8 +30,8 @@ use crate::Locator; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#imports -#[violation] -pub struct MultipleImportsOnOneLine; +#[derive(ViolationMetadata)] +pub(crate) struct MultipleImportsOnOneLine; impl Violation for MultipleImportsOnOneLine { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/not_tests.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/not_tests.rs index 65bcfe7dddd9f..8846160a719e2 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/not_tests.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/not_tests.rs @@ -1,6 +1,6 @@ use crate::fix::edits::pad; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::generate_comparison; use ruff_python_ast::{self as ast, CmpOp, Expr}; use ruff_text_size::Ranged; @@ -27,8 +27,8 @@ use crate::registry::Rule; /// if X.B not in Y: /// pass /// ``` -#[violation] -pub struct NotInTest; +#[derive(ViolationMetadata)] +pub(crate) struct NotInTest; impl AlwaysFixableViolation for NotInTest { #[derive_message_formats] @@ -63,8 +63,8 @@ impl AlwaysFixableViolation for NotInTest { /// ``` /// /// [PEP8]: https://peps.python.org/pep-0008/#programming-recommendations -#[violation] -pub struct NotIsTest; +#[derive(ViolationMetadata)] +pub(crate) struct NotIsTest; impl AlwaysFixableViolation for NotIsTest { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/tab_indentation.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/tab_indentation.rs index 30157899b6217..9945f7f8f3b32 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/tab_indentation.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/tab_indentation.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_index::Indexer; use ruff_source_file::LineRanges; use ruff_text_size::{TextRange, TextSize}; @@ -22,8 +22,8 @@ use crate::Locator; /// /// [PEP 8]: https://peps.python.org/pep-0008/#tabs-or-spaces /// [formatter]: https://docs.astral.sh/ruff/formatter -#[violation] -pub struct TabIndentation; +#[derive(ViolationMetadata)] +pub(crate) struct TabIndentation; impl Violation for TabIndentation { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/too_many_newlines_at_end_of_file.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/too_many_newlines_at_end_of_file.rs index 5deab0ffe1757..ae2af5e9c328b 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/too_many_newlines_at_end_of_file.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/too_many_newlines_at_end_of_file.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_parser::{TokenKind, Tokens}; use ruff_text_size::{Ranged, TextRange, TextSize}; @@ -20,8 +20,8 @@ use ruff_text_size::{Ranged, TextRange, TextSize}; /// ```python /// spam(1)\n /// ``` -#[violation] -pub struct TooManyNewlinesAtEndOfFile { +#[derive(ViolationMetadata)] +pub(crate) struct TooManyNewlinesAtEndOfFile { num_trailing_newlines: u32, } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/trailing_whitespace.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/trailing_whitespace.rs index 09cb9c9fd75c3..215dc880a8d51 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/trailing_whitespace.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/trailing_whitespace.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Applicability, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_index::Indexer; use ruff_source_file::Line; use ruff_text_size::{TextLen, TextRange, TextSize}; @@ -26,8 +26,8 @@ use crate::Locator; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#other-recommendations -#[violation] -pub struct TrailingWhitespace; +#[derive(ViolationMetadata)] +pub(crate) struct TrailingWhitespace; impl AlwaysFixableViolation for TrailingWhitespace { #[derive_message_formats] @@ -58,8 +58,8 @@ impl AlwaysFixableViolation for TrailingWhitespace { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#other-recommendations -#[violation] -pub struct BlankLineWithWhitespace; +#[derive(ViolationMetadata)] +pub(crate) struct BlankLineWithWhitespace; impl AlwaysFixableViolation for BlankLineWithWhitespace { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs index 1464accfbe5cb..386d29f8518ac 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs @@ -1,6 +1,6 @@ use itertools::Itertools; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, CmpOp, Expr}; use ruff_python_semantic::SemanticModel; @@ -48,8 +48,8 @@ use crate::checkers::ast::Checker; /// if isinstance(obj, int): /// pass /// ``` -#[violation] -pub struct TypeComparison; +#[derive(ViolationMetadata)] +pub(crate) struct TypeComparison; impl Violation for TypeComparison { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/whitespace_after_decorator.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/whitespace_after_decorator.rs index 290a28719daa3..64eb36ee17865 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/whitespace_after_decorator.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/whitespace_after_decorator.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Decorator; use ruff_python_trivia::is_python_whitespace; use ruff_text_size::{Ranged, TextRange, TextSize}; @@ -30,8 +30,8 @@ use crate::checkers::ast::Checker; /// /// [PEP 8]: https://peps.python.org/pep-0008/#maximum-line-length -#[violation] -pub struct WhitespaceAfterDecorator; +#[derive(ViolationMetadata)] +pub(crate) struct WhitespaceAfterDecorator; impl AlwaysFixableViolation for WhitespaceAfterDecorator { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs b/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs index 7f355ef6ed3bc..3e1a25572d0bc 100644 --- a/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs +++ b/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs @@ -1,7 +1,7 @@ use itertools::Itertools; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::map_callable; use ruff_python_ast::helpers::map_subscript; use ruff_python_ast::name::QualifiedName; @@ -55,8 +55,8 @@ use crate::rules::pydocstyle::settings::Convention; /// """ /// return distance / time /// ``` -#[violation] -pub struct DocstringMissingReturns; +#[derive(ViolationMetadata)] +pub(crate) struct DocstringMissingReturns; impl Violation for DocstringMissingReturns { #[derive_message_formats] @@ -105,8 +105,8 @@ impl Violation for DocstringMissingReturns { /// for _ in range(n): /// print("Hello!") /// ``` -#[violation] -pub struct DocstringExtraneousReturns; +#[derive(ViolationMetadata)] +pub(crate) struct DocstringExtraneousReturns; impl Violation for DocstringExtraneousReturns { #[derive_message_formats] @@ -157,8 +157,8 @@ impl Violation for DocstringExtraneousReturns { /// for i in range(1, n + 1): /// yield i /// ``` -#[violation] -pub struct DocstringMissingYields; +#[derive(ViolationMetadata)] +pub(crate) struct DocstringMissingYields; impl Violation for DocstringMissingYields { #[derive_message_formats] @@ -207,8 +207,8 @@ impl Violation for DocstringMissingYields { /// for _ in range(n): /// print("Hello!") /// ``` -#[violation] -pub struct DocstringExtraneousYields; +#[derive(ViolationMetadata)] +pub(crate) struct DocstringExtraneousYields; impl Violation for DocstringExtraneousYields { #[derive_message_formats] @@ -270,8 +270,8 @@ impl Violation for DocstringExtraneousYields { /// except ZeroDivisionError as exc: /// raise FasterThanLightError from exc /// ``` -#[violation] -pub struct DocstringMissingException { +#[derive(ViolationMetadata)] +pub(crate) struct DocstringMissingException { id: String, } @@ -330,8 +330,8 @@ impl Violation for DocstringMissingException { /// """ /// return distance / time /// ``` -#[violation] -pub struct DocstringExtraneousException { +#[derive(ViolationMetadata)] +pub(crate) struct DocstringExtraneousException { ids: Vec, } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/backslashes.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/backslashes.rs index d7755d28aade5..c2bcc593e9344 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/backslashes.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/backslashes.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -41,8 +41,8 @@ use crate::docstrings::Docstring; /// ## References /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [Python documentation: String and Bytes literals](https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals) -#[violation] -pub struct EscapeSequenceInDocstring; +#[derive(ViolationMetadata)] +pub(crate) struct EscapeSequenceInDocstring; impl Violation for EscapeSequenceInDocstring { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs index 2521880f48cbd..c6e773725cbdd 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines}; use ruff_text_size::Ranged; @@ -40,8 +40,8 @@ use crate::docstrings::Docstring; /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) /// /// [PEP 257]: https://peps.python.org/pep-0257/ -#[violation] -pub struct BlankLineAfterSummary { +#[derive(ViolationMetadata)] +pub(crate) struct BlankLineAfterSummary { num_lines: usize, } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs index b7bf2251cc233..745427bb7ef63 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_trivia::{indentation_at_offset, PythonWhitespace}; use ruff_source_file::{Line, LineRanges, UniversalNewlineIterator}; use ruff_text_size::Ranged; @@ -42,8 +42,8 @@ use crate::registry::Rule; /// - `lint.pydocstyle.convention` /// /// [D211]: https://docs.astral.sh/ruff/rules/blank-line-before-class -#[violation] -pub struct OneBlankLineBeforeClass; +#[derive(ViolationMetadata)] +pub(crate) struct OneBlankLineBeforeClass; impl AlwaysFixableViolation for OneBlankLineBeforeClass { #[derive_message_formats] @@ -94,8 +94,8 @@ impl AlwaysFixableViolation for OneBlankLineBeforeClass { /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) /// /// [PEP 257]: https://peps.python.org/pep-0257/ -#[violation] -pub struct OneBlankLineAfterClass; +#[derive(ViolationMetadata)] +pub(crate) struct OneBlankLineAfterClass; impl AlwaysFixableViolation for OneBlankLineAfterClass { #[derive_message_formats] @@ -141,8 +141,8 @@ impl AlwaysFixableViolation for OneBlankLineAfterClass { /// - `lint.pydocstyle.convention` /// /// [D203]: https://docs.astral.sh/ruff/rules/one-blank-line-before-class -#[violation] -pub struct BlankLineBeforeClass; +#[derive(ViolationMetadata)] +pub(crate) struct BlankLineBeforeClass; impl AlwaysFixableViolation for BlankLineBeforeClass { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs index 11027c562dee3..00313474dbe21 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs @@ -2,7 +2,7 @@ use regex::Regex; use std::sync::LazyLock; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_trivia::PythonWhitespace; use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines}; use ruff_text_size::Ranged; @@ -37,8 +37,8 @@ use crate::registry::Rule; /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct NoBlankLineBeforeFunction { +#[derive(ViolationMetadata)] +pub(crate) struct NoBlankLineBeforeFunction { num_lines: usize, } @@ -81,8 +81,8 @@ impl AlwaysFixableViolation for NoBlankLineBeforeFunction { /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct NoBlankLineAfterFunction { +#[derive(ViolationMetadata)] +pub(crate) struct NoBlankLineAfterFunction { num_lines: usize, } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/capitalized.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/capitalized.rs index 88f02716764d0..dbb861b75b8ab 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/capitalized.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/capitalized.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use ruff_text_size::{TextLen, TextRange}; @@ -29,8 +29,8 @@ use crate::docstrings::Docstring; /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct FirstLineCapitalized { +#[derive(ViolationMetadata)] +pub(crate) struct FirstLineCapitalized { first_word: String, capitalized_word: String, } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs index 7193a5c33ad56..c50602e3a28a4 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs @@ -2,7 +2,7 @@ use ruff_text_size::TextLen; use strum::IntoEnumIterator; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines}; use ruff_text_size::Ranged; @@ -44,8 +44,8 @@ use crate::rules::pydocstyle::helpers::logical_line; /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) /// /// [PEP 257]: https://peps.python.org/pep-0257/ -#[violation] -pub struct EndsInPeriod; +#[derive(ViolationMetadata)] +pub(crate) struct EndsInPeriod; impl Violation for EndsInPeriod { /// `None` in the case a fix is never available or otherwise Some diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs index 68579b28a94e9..b32cbe898ce30 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs @@ -2,7 +2,7 @@ use ruff_text_size::TextLen; use strum::IntoEnumIterator; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines}; use ruff_text_size::Ranged; @@ -43,8 +43,8 @@ use crate::rules::pydocstyle::helpers::logical_line; /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct EndsInPunctuation; +#[derive(ViolationMetadata)] +pub(crate) struct EndsInPunctuation; impl Violation for EndsInPunctuation { /// `None` in the case a fix is never available or otherwise Some diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/if_needed.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/if_needed.rs index 9b937c58079d0..d7ab3230fbafa 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/if_needed.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/if_needed.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use ruff_python_semantic::analyze::visibility::is_overload; @@ -66,8 +66,8 @@ use crate::docstrings::Docstring; /// ## References /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [Python documentation: `typing.overload`](https://docs.python.org/3/library/typing.html#typing.overload) -#[violation] -pub struct OverloadWithDocstring; +#[derive(ViolationMetadata)] +pub(crate) struct OverloadWithDocstring; impl Violation for OverloadWithDocstring { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs index 705fd107e4efd..fe287104ad3a1 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs @@ -1,6 +1,6 @@ use ruff_diagnostics::{AlwaysFixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::docstrings::{clean_space, leading_space}; use ruff_source_file::{Line, NewlineWithTrailingNewline}; use ruff_text_size::{Ranged, TextSize}; @@ -10,6 +10,7 @@ use crate::checkers::ast::Checker; use crate::docstrings::Docstring; use crate::registry::Rule; +#[allow(clippy::tabs_in_doc_comments)] /// ## What it does /// Checks for docstrings that are indented with tabs. /// @@ -50,8 +51,8 @@ use crate::registry::Rule; /// /// [PEP 8]: https://peps.python.org/pep-0008/#tabs-or-spaces /// [formatter]: https://docs.astral.sh/ruff/formatter -#[violation] -pub struct IndentWithSpaces; +#[derive(ViolationMetadata)] +pub(crate) struct IndentWithSpaces; impl Violation for IndentWithSpaces { #[derive_message_formats] @@ -98,8 +99,8 @@ impl Violation for IndentWithSpaces { /// /// [PEP 257]: https://peps.python.org/pep-0257/ /// [formatter]: https://docs.astral.sh/ruff/formatter/ -#[violation] -pub struct UnderIndentation; +#[derive(ViolationMetadata)] +pub(crate) struct UnderIndentation; impl AlwaysFixableViolation for UnderIndentation { #[derive_message_formats] @@ -150,8 +151,8 @@ impl AlwaysFixableViolation for UnderIndentation { /// /// [PEP 257]: https://peps.python.org/pep-0257/ /// [formatter]:https://docs.astral.sh/ruff/formatter/ -#[violation] -pub struct OverIndentation; +#[derive(ViolationMetadata)] +pub(crate) struct OverIndentation; impl AlwaysFixableViolation for OverIndentation { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs index 36bb9f3aad1ba..3351dd67b57a0 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::str::{is_triple_quote, leading_quote}; use ruff_python_semantic::Definition; use ruff_source_file::{LineRanges, NewlineWithTrailingNewline, UniversalNewlineIterator}; @@ -58,8 +58,8 @@ use crate::registry::Rule; /// /// [D213]: https://docs.astral.sh/ruff/rules/multi-line-summary-second-line /// [PEP 257]: https://peps.python.org/pep-0257 -#[violation] -pub struct MultiLineSummaryFirstLine; +#[derive(ViolationMetadata)] +pub(crate) struct MultiLineSummaryFirstLine; impl AlwaysFixableViolation for MultiLineSummaryFirstLine { #[derive_message_formats] @@ -121,8 +121,8 @@ impl AlwaysFixableViolation for MultiLineSummaryFirstLine { /// /// [D212]: https://docs.astral.sh/ruff/rules/multi-line-summary-first-line /// [PEP 257]: https://peps.python.org/pep-0257 -#[violation] -pub struct MultiLineSummarySecondLine; +#[derive(ViolationMetadata)] +pub(crate) struct MultiLineSummarySecondLine; impl AlwaysFixableViolation for MultiLineSummarySecondLine { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs index 7ba6b0ce2e5ce..d3fade6023b9c 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs @@ -1,7 +1,7 @@ use ruff_text_size::{TextLen, TextSize}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::docstrings::clean_space; use ruff_source_file::{NewlineWithTrailingNewline, UniversalNewlines}; use ruff_text_size::Ranged; @@ -43,8 +43,8 @@ use crate::docstrings::Docstring; /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) /// /// [PEP 257]: https://peps.python.org/pep-0257/ -#[violation] -pub struct NewLineAfterLastParagraph; +#[derive(ViolationMetadata)] +pub(crate) struct NewLineAfterLastParagraph; impl AlwaysFixableViolation for NewLineAfterLastParagraph { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs index bb363ed93df8a..6daeeb5045f30 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_source_file::UniversalNewlines; use ruff_text_size::Ranged; @@ -40,8 +40,8 @@ use crate::docstrings::Docstring; /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) /// /// [PEP 257]: https://peps.python.org/pep-0257/ -#[violation] -pub struct NoSignature; +#[derive(ViolationMetadata)] +pub(crate) struct NoSignature; impl Violation for NoSignature { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs index bb49b5ab52a64..23f802cc3869b 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_source_file::NewlineWithTrailingNewline; use ruff_text_size::Ranged; use ruff_text_size::{TextLen, TextRange}; @@ -31,8 +31,8 @@ use crate::rules::pydocstyle::helpers::ends_with_backslash; /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct SurroundingWhitespace; +#[derive(ViolationMetadata)] +pub(crate) struct SurroundingWhitespace; impl Violation for SurroundingWhitespace { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/non_imperative_mood.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/non_imperative_mood.rs index f35be7d7119e4..a66f4bb03ab48 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/non_imperative_mood.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/non_imperative_mood.rs @@ -3,7 +3,7 @@ use std::sync::LazyLock; use imperative::Mood; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::analyze::visibility::{is_property, is_test}; use ruff_source_file::UniversalNewlines; use ruff_text_size::Ranged; @@ -50,8 +50,8 @@ static MOOD: LazyLock = LazyLock::new(Mood::new); /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// /// [PEP 257]: https://peps.python.org/pep-0257/ -#[violation] -pub struct NonImperativeMood { +#[derive(ViolationMetadata)] +pub(crate) struct NonImperativeMood { first_line: String, } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/not_empty.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/not_empty.rs index 0f96dc77b2d46..dd13f99b86946 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/not_empty.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/not_empty.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -29,8 +29,8 @@ use crate::registry::Rule; /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct EmptyDocstring; +#[derive(ViolationMetadata)] +pub(crate) struct EmptyDocstring; impl Violation for EmptyDocstring { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/not_missing.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/not_missing.rs index 45ba22cc4ad7b..b5b90b5530b97 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/not_missing.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/not_missing.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use ruff_python_semantic::analyze::visibility::{ is_call, is_init, is_magic, is_new, is_overload, is_override, Visibility, @@ -61,8 +61,8 @@ use crate::registry::Rule; /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct UndocumentedPublicModule; +#[derive(ViolationMetadata)] +pub(crate) struct UndocumentedPublicModule; impl Violation for UndocumentedPublicModule { #[derive_message_formats] @@ -144,8 +144,8 @@ impl Violation for UndocumentedPublicModule { /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct UndocumentedPublicClass; +#[derive(ViolationMetadata)] +pub(crate) struct UndocumentedPublicClass; impl Violation for UndocumentedPublicClass { #[derive_message_formats] @@ -226,8 +226,8 @@ impl Violation for UndocumentedPublicClass { /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct UndocumentedPublicMethod; +#[derive(ViolationMetadata)] +pub(crate) struct UndocumentedPublicMethod; impl Violation for UndocumentedPublicMethod { #[derive_message_formats] @@ -316,8 +316,8 @@ impl Violation for UndocumentedPublicMethod { /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Style Python Docstrings](https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings) -#[violation] -pub struct UndocumentedPublicFunction; +#[derive(ViolationMetadata)] +pub(crate) struct UndocumentedPublicFunction; impl Violation for UndocumentedPublicFunction { #[derive_message_formats] @@ -359,8 +359,8 @@ impl Violation for UndocumentedPublicFunction { /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Style Python Docstrings](https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings) -#[violation] -pub struct UndocumentedPublicPackage; +#[derive(ViolationMetadata)] +pub(crate) struct UndocumentedPublicPackage; impl Violation for UndocumentedPublicPackage { #[derive_message_formats] @@ -416,8 +416,8 @@ impl Violation for UndocumentedPublicPackage { /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Style Python Docstrings](https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings) -#[violation] -pub struct UndocumentedMagicMethod; +#[derive(ViolationMetadata)] +pub(crate) struct UndocumentedMagicMethod; impl Violation for UndocumentedMagicMethod { #[derive_message_formats] @@ -471,8 +471,8 @@ impl Violation for UndocumentedMagicMethod { /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Style Python Docstrings](https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings) -#[violation] -pub struct UndocumentedPublicNestedClass; +#[derive(ViolationMetadata)] +pub(crate) struct UndocumentedPublicNestedClass; impl Violation for UndocumentedPublicNestedClass { #[derive_message_formats] @@ -519,8 +519,8 @@ impl Violation for UndocumentedPublicNestedClass { /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Style Python Docstrings](https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings) -#[violation] -pub struct UndocumentedPublicInit; +#[derive(ViolationMetadata)] +pub(crate) struct UndocumentedPublicInit; impl Violation for UndocumentedPublicInit { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs index 4ced610c2e471..d4b422138e929 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::str::{leading_quote, trailing_quote}; use ruff_source_file::NewlineWithTrailingNewline; use ruff_text_size::Ranged; @@ -32,8 +32,8 @@ use crate::docstrings::Docstring; /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// /// [PEP 257]: https://peps.python.org/pep-0257/ -#[violation] -pub struct FitsOnOneLine; +#[derive(ViolationMetadata)] +pub(crate) struct FitsOnOneLine; impl Violation for FitsOnOneLine { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs index 52b89de956e9f..7f5c120867bf7 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs @@ -5,7 +5,7 @@ use std::sync::LazyLock; use ruff_diagnostics::{AlwaysFixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::docstrings::{clean_space, leading_space}; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::ParameterWithDefault; @@ -89,8 +89,8 @@ use crate::rules::pydocstyle::settings::Convention; /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct SectionNotOverIndented { +#[derive(ViolationMetadata)] +pub(crate) struct SectionNotOverIndented { name: String, } @@ -192,8 +192,8 @@ impl AlwaysFixableViolation for SectionNotOverIndented { /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) -#[violation] -pub struct SectionUnderlineNotOverIndented { +#[derive(ViolationMetadata)] +pub(crate) struct SectionUnderlineNotOverIndented { name: String, } @@ -275,8 +275,8 @@ impl AlwaysFixableViolation for SectionUnderlineNotOverIndented { /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct CapitalizeSectionName { +#[derive(ViolationMetadata)] +pub(crate) struct CapitalizeSectionName { name: String, } @@ -373,8 +373,8 @@ impl AlwaysFixableViolation for CapitalizeSectionName { /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) -#[violation] -pub struct NewLineAfterSectionName { +#[derive(ViolationMetadata)] +pub(crate) struct NewLineAfterSectionName { name: String, } @@ -476,8 +476,8 @@ impl AlwaysFixableViolation for NewLineAfterSectionName { /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) -#[violation] -pub struct DashedUnderlineAfterSection { +#[derive(ViolationMetadata)] +pub(crate) struct DashedUnderlineAfterSection { name: String, } @@ -582,8 +582,8 @@ impl AlwaysFixableViolation for DashedUnderlineAfterSection { /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) -#[violation] -pub struct SectionUnderlineAfterName { +#[derive(ViolationMetadata)] +pub(crate) struct SectionUnderlineAfterName { name: String, } @@ -686,8 +686,8 @@ impl AlwaysFixableViolation for SectionUnderlineAfterName { /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) -#[violation] -pub struct SectionUnderlineMatchesSectionLength { +#[derive(ViolationMetadata)] +pub(crate) struct SectionUnderlineMatchesSectionLength { name: String, } @@ -783,8 +783,8 @@ impl AlwaysFixableViolation for SectionUnderlineMatchesSectionLength { /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Style Guide](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct NoBlankLineAfterSection { +#[derive(ViolationMetadata)] +pub(crate) struct NoBlankLineAfterSection { name: String, } @@ -876,8 +876,8 @@ impl AlwaysFixableViolation for NoBlankLineAfterSection { /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) -#[violation] -pub struct NoBlankLineBeforeSection { +#[derive(ViolationMetadata)] +pub(crate) struct NoBlankLineBeforeSection { name: String, } @@ -971,8 +971,8 @@ impl AlwaysFixableViolation for NoBlankLineBeforeSection { /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) -#[violation] -pub struct BlankLineAfterLastSection { +#[derive(ViolationMetadata)] +pub(crate) struct BlankLineAfterLastSection { name: String, } @@ -1060,8 +1060,8 @@ impl AlwaysFixableViolation for BlankLineAfterLastSection { /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Style Guide](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct EmptyDocstringSection { +#[derive(ViolationMetadata)] +pub(crate) struct EmptyDocstringSection { name: String, } @@ -1137,8 +1137,8 @@ impl Violation for EmptyDocstringSection { /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [Google Style Guide](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct SectionNameEndsInColon { +#[derive(ViolationMetadata)] +pub(crate) struct SectionNameEndsInColon { name: String, } @@ -1220,8 +1220,8 @@ impl AlwaysFixableViolation for SectionNameEndsInColon { /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct UndocumentedParam { +#[derive(ViolationMetadata)] +pub(crate) struct UndocumentedParam { /// The name of the function being documented. definition: String, /// The names of the undocumented parameters. @@ -1302,8 +1302,8 @@ impl Violation for UndocumentedParam { /// - [PEP 287 – reStructuredText Docstring Format](https://peps.python.org/pep-0287/) /// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html) /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) -#[violation] -pub struct BlankLinesBetweenHeaderAndContent { +#[derive(ViolationMetadata)] +pub(crate) struct BlankLinesBetweenHeaderAndContent { name: String, } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/starts_with_this.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/starts_with_this.rs index 6fb9fd3a1fce1..127886918314e 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/starts_with_this.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/starts_with_this.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -39,8 +39,8 @@ use crate::rules::pydocstyle::helpers::normalize_word; /// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/) /// /// [PEP 257]: https://peps.python.org/pep-0257/ -#[violation] -pub struct DocstringStartsWithThis; +#[derive(ViolationMetadata)] +pub(crate) struct DocstringStartsWithThis; impl Violation for DocstringStartsWithThis { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/triple_quotes.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/triple_quotes.rs index d7b45c6e2589d..a863c3fc7682b 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/triple_quotes.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/triple_quotes.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::str::Quote; use ruff_text_size::Ranged; @@ -37,8 +37,8 @@ use crate::docstrings::Docstring; /// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) /// /// [formatter]: https://docs.astral.sh/ruff/formatter/ -#[violation] -pub struct TripleSingleQuotes { +#[derive(ViolationMetadata)] +pub(crate) struct TripleSingleQuotes { expected_quote: Quote, } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/assert_tuple.rs b/crates/ruff_linter/src/rules/pyflakes/rules/assert_tuple.rs index 0b8a781aab296..2b7d5c066dea9 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/assert_tuple.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/assert_tuple.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -27,8 +27,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: The `assert` statement](https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement) -#[violation] -pub struct AssertTuple; +#[derive(ViolationMetadata)] +pub(crate) struct AssertTuple; impl Violation for AssertTuple { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/break_outside_loop.rs b/crates/ruff_linter/src/rules/pyflakes/rules/break_outside_loop.rs index 50dabca6f424e..957791cd6c820 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/break_outside_loop.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/break_outside_loop.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; /// ## What it does @@ -19,8 +19,8 @@ use ruff_text_size::Ranged; /// /// ## References /// - [Python documentation: `break`](https://docs.python.org/3/reference/simple_stmts.html#the-break-statement) -#[violation] -pub struct BreakOutsideLoop; +#[derive(ViolationMetadata)] +pub(crate) struct BreakOutsideLoop; impl Violation for BreakOutsideLoop { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/continue_outside_loop.rs b/crates/ruff_linter/src/rules/pyflakes/rules/continue_outside_loop.rs index 6e2782b7f59d5..b09dfc5db677f 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/continue_outside_loop.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/continue_outside_loop.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; /// ## What it does @@ -19,8 +19,8 @@ use ruff_text_size::Ranged; /// /// ## References /// - [Python documentation: `continue`](https://docs.python.org/3/reference/simple_stmts.html#the-continue-statement) -#[violation] -pub struct ContinueOutsideLoop; +#[derive(ViolationMetadata)] +pub(crate) struct ContinueOutsideLoop; impl Violation for ContinueOutsideLoop { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/default_except_not_last.rs b/crates/ruff_linter/src/rules/pyflakes/rules/default_except_not_last.rs index 413f35e6a956c..0b84aa6fc3fc7 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/default_except_not_last.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/default_except_not_last.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::except; use ruff_python_ast::{self as ast, ExceptHandler}; @@ -43,8 +43,8 @@ use crate::Locator; /// /// ## References /// - [Python documentation: `except` clause](https://docs.python.org/3/reference/compound_stmts.html#except-clause) -#[violation] -pub struct DefaultExceptNotLast; +#[derive(ViolationMetadata)] +pub(crate) struct DefaultExceptNotLast; impl Violation for DefaultExceptNotLast { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/f_string_missing_placeholders.rs b/crates/ruff_linter/src/rules/pyflakes/rules/f_string_missing_placeholders.rs index 97dbc50b45f81..6dfdee0cda1f8 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/f_string_missing_placeholders.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/f_string_missing_placeholders.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_text_size::{Ranged, TextRange, TextSize}; @@ -53,8 +53,8 @@ use crate::Locator; /// /// ## References /// - [PEP 498 – Literal String Interpolation](https://peps.python.org/pep-0498/) -#[violation] -pub struct FStringMissingPlaceholders; +#[derive(ViolationMetadata)] +pub(crate) struct FStringMissingPlaceholders; impl AlwaysFixableViolation for FStringMissingPlaceholders { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/forward_annotation_syntax_error.rs b/crates/ruff_linter/src/rules/pyflakes/rules/forward_annotation_syntax_error.rs index 9c74faf79ff00..18852477563b8 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/forward_annotation_syntax_error.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/forward_annotation_syntax_error.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for forward annotations that include invalid syntax. @@ -22,8 +22,8 @@ use ruff_macros::{derive_message_formats, violation}; /// /// ## References /// - [PEP 563 – Postponed Evaluation of Annotations](https://peps.python.org/pep-0563/) -#[violation] -pub struct ForwardAnnotationSyntaxError { +#[derive(ViolationMetadata)] +pub(crate) struct ForwardAnnotationSyntaxError { pub body: String, } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/future_feature_not_defined.rs b/crates/ruff_linter/src/rules/pyflakes/rules/future_feature_not_defined.rs index 18af0d3e303ad..78e10000ef51b 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/future_feature_not_defined.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/future_feature_not_defined.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Alias; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_stdlib::future::is_feature_name; use ruff_text_size::Ranged; @@ -17,8 +17,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `__future__`](https://docs.python.org/3/library/__future__.html) -#[violation] -pub struct FutureFeatureNotDefined { +#[derive(ViolationMetadata)] +pub(crate) struct FutureFeatureNotDefined { name: String, } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/if_tuple.rs b/crates/ruff_linter/src/rules/pyflakes/rules/if_tuple.rs index 50c28fe7993b2..9dba0a2ab0e5c 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/if_tuple.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/if_tuple.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{Expr, StmtIf}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::stmt_if::if_elif_branches; use ruff_text_size::Ranged; @@ -28,8 +28,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: The `if` statement](https://docs.python.org/3/reference/compound_stmts.html#the-if-statement) -#[violation] -pub struct IfTuple; +#[derive(ViolationMetadata)] +pub(crate) struct IfTuple; impl Violation for IfTuple { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/imports.rs b/crates/ruff_linter/src/rules/pyflakes/rules/imports.rs index d6b36ae6a6c93..102f812d9e7e9 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/imports.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/imports.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_source_file::SourceRow; /// ## What it does @@ -29,8 +29,8 @@ use ruff_source_file::SourceRow; /// for filename in files: /// print(filename) /// ``` -#[violation] -pub struct ImportShadowedByLoopVar { +#[derive(ViolationMetadata)] +pub(crate) struct ImportShadowedByLoopVar { pub(crate) name: String, pub(crate) row: SourceRow, } @@ -70,8 +70,8 @@ impl Violation for ImportShadowedByLoopVar { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#imports -#[violation] -pub struct UndefinedLocalWithImportStar { +#[derive(ViolationMetadata)] +pub(crate) struct UndefinedLocalWithImportStar { pub(crate) name: String, } @@ -108,8 +108,8 @@ impl Violation for UndefinedLocalWithImportStar { /// /// ## References /// - [Python documentation: Future statements](https://docs.python.org/3/reference/simple_stmts.html#future) -#[violation] -pub struct LateFutureImport; +#[derive(ViolationMetadata)] +pub(crate) struct LateFutureImport; impl Violation for LateFutureImport { #[derive_message_formats] @@ -152,8 +152,8 @@ impl Violation for LateFutureImport { /// def area(radius): /// return pi * radius**2 /// ``` -#[violation] -pub struct UndefinedLocalWithImportStarUsage { +#[derive(ViolationMetadata)] +pub(crate) struct UndefinedLocalWithImportStarUsage { pub(crate) name: String, } @@ -193,8 +193,8 @@ impl Violation for UndefinedLocalWithImportStarUsage { /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#imports -#[violation] -pub struct UndefinedLocalWithNestedImportStarUsage { +#[derive(ViolationMetadata)] +pub(crate) struct UndefinedLocalWithNestedImportStarUsage { pub(crate) name: String, } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/invalid_literal_comparisons.rs b/crates/ruff_linter/src/rules/pyflakes/rules/invalid_literal_comparisons.rs index 02e475a39ec63..955def2f9a892 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/invalid_literal_comparisons.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/invalid_literal_comparisons.rs @@ -1,7 +1,7 @@ use log::error; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers; use ruff_python_ast::{CmpOp, Expr}; use ruff_python_parser::{TokenKind, Tokens}; @@ -50,8 +50,8 @@ use crate::checkers::ast::Checker; /// - [Python documentation: Identity comparisons](https://docs.python.org/3/reference/expressions.html#is-not) /// - [Python documentation: Value comparisons](https://docs.python.org/3/reference/expressions.html#value-comparisons) /// - [_Why does Python log a SyntaxWarning for ‘is’ with literals?_ by Adam Johnson](https://adamj.eu/tech/2020/01/21/why-does-python-3-8-syntaxwarning-for-is-literal/) -#[violation] -pub struct IsLiteral { +#[derive(ViolationMetadata)] +pub(crate) struct IsLiteral { cmp_op: IsCmpOp, } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/invalid_print_syntax.rs b/crates/ruff_linter/src/rules/pyflakes/rules/invalid_print_syntax.rs index e632708724dec..d13691c69da32 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/invalid_print_syntax.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/invalid_print_syntax.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Expr; use ruff_text_size::Ranged; @@ -46,8 +46,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `print`](https://docs.python.org/3/library/functions.html#print) -#[violation] -pub struct InvalidPrintSyntax; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidPrintSyntax; impl Violation for InvalidPrintSyntax { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs b/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs index 2deda759ca4d9..81b2a14be52e2 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: `NotImplemented`](https://docs.python.org/3/library/constants.html#NotImplemented) /// - [Python documentation: `NotImplementedError`](https://docs.python.org/3/library/exceptions.html#NotImplementedError) -#[violation] -pub struct RaiseNotImplemented; +#[derive(ViolationMetadata)] +pub(crate) struct RaiseNotImplemented; impl Violation for RaiseNotImplemented { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/redefined_while_unused.rs b/crates/ruff_linter/src/rules/pyflakes/rules/redefined_while_unused.rs index f65090d328b6d..b48b120d208aa 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/redefined_while_unused.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/redefined_while_unused.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_source_file::SourceRow; /// ## What it does @@ -22,8 +22,8 @@ use ruff_source_file::SourceRow; /// import foo /// import bar /// ``` -#[violation] -pub struct RedefinedWhileUnused { +#[derive(ViolationMetadata)] +pub(crate) struct RedefinedWhileUnused { pub name: String, pub row: SourceRow, } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs b/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs index 67aeee85e8482..72ded4db1528d 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs @@ -2,7 +2,7 @@ use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet}; use std::collections::hash_map::Entry; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::{ComparableExpr, HashableExpr}; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::{self as ast, Expr}; @@ -42,8 +42,8 @@ use crate::registry::Rule; /// /// ## References /// - [Python documentation: Dictionaries](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) -#[violation] -pub struct MultiValueRepeatedKeyLiteral { +#[derive(ViolationMetadata)] +pub(crate) struct MultiValueRepeatedKeyLiteral { name: SourceCodeSnippet, existing: SourceCodeSnippet, } @@ -108,8 +108,8 @@ impl Violation for MultiValueRepeatedKeyLiteral { /// /// ## References /// - [Python documentation: Dictionaries](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) -#[violation] -pub struct MultiValueRepeatedKeyVariable { +#[derive(ViolationMetadata)] +pub(crate) struct MultiValueRepeatedKeyVariable { name: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/return_outside_function.rs b/crates/ruff_linter/src/rules/pyflakes/rules/return_outside_function.rs index d54ec7b1d963e..658c41c20ea05 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/return_outside_function.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/return_outside_function.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Stmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::ScopeKind; use ruff_text_size::Ranged; @@ -22,8 +22,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `return`](https://docs.python.org/3/reference/simple_stmts.html#the-return-statement) -#[violation] -pub struct ReturnOutsideFunction; +#[derive(ViolationMetadata)] +pub(crate) struct ReturnOutsideFunction; impl Violation for ReturnOutsideFunction { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/starred_expressions.rs b/crates/ruff_linter/src/rules/pyflakes/rules/starred_expressions.rs index 8cdbe6e13a618..9f99355fd02aa 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/starred_expressions.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/starred_expressions.rs @@ -2,7 +2,7 @@ use ruff_python_ast::Expr; use ruff_text_size::TextRange; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for the use of too many expressions in starred assignment statements. @@ -16,8 +16,8 @@ use ruff_macros::{derive_message_formats, violation}; /// /// ## References /// - [PEP 3132 – Extended Iterable Unpacking](https://peps.python.org/pep-3132/) -#[violation] -pub struct ExpressionsInStarAssignment; +#[derive(ViolationMetadata)] +pub(crate) struct ExpressionsInStarAssignment; impl Violation for ExpressionsInStarAssignment { #[derive_message_formats] @@ -42,8 +42,8 @@ impl Violation for ExpressionsInStarAssignment { /// /// ## References /// - [PEP 3132 – Extended Iterable Unpacking](https://peps.python.org/pep-3132/) -#[violation] -pub struct MultipleStarredExpressions; +#[derive(ViolationMetadata)] +pub(crate) struct MultipleStarredExpressions; impl Violation for MultipleStarredExpressions { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs b/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs index 4d198c9228f89..80fe9f307789f 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs @@ -3,7 +3,7 @@ use std::string::ToString; use rustc_hash::FxHashSet; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::Name; use ruff_python_ast::{self as ast, Expr, Keyword}; use ruff_text_size::{Ranged, TextRange}; @@ -36,8 +36,8 @@ use super::super::format::FormatSummary; /// /// ## References /// - [Python documentation: `printf`-style String Formatting](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting) -#[violation] -pub struct PercentFormatInvalidFormat { +#[derive(ViolationMetadata)] +pub(crate) struct PercentFormatInvalidFormat { pub(crate) message: String, } @@ -75,8 +75,8 @@ impl Violation for PercentFormatInvalidFormat { /// /// ## References /// - [Python documentation: `printf`-style String Formatting](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting) -#[violation] -pub struct PercentFormatExpectedMapping; +#[derive(ViolationMetadata)] +pub(crate) struct PercentFormatExpectedMapping; impl Violation for PercentFormatExpectedMapping { #[derive_message_formats] @@ -111,8 +111,8 @@ impl Violation for PercentFormatExpectedMapping { /// /// ## References /// - [Python documentation: `printf`-style String Formatting](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting) -#[violation] -pub struct PercentFormatExpectedSequence; +#[derive(ViolationMetadata)] +pub(crate) struct PercentFormatExpectedSequence; impl Violation for PercentFormatExpectedSequence { #[derive_message_formats] @@ -140,8 +140,8 @@ impl Violation for PercentFormatExpectedSequence { /// /// ## References /// - [Python documentation: `printf`-style String Formatting](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting) -#[violation] -pub struct PercentFormatExtraNamedArguments { +#[derive(ViolationMetadata)] +pub(crate) struct PercentFormatExtraNamedArguments { missing: Vec, } @@ -180,8 +180,8 @@ impl AlwaysFixableViolation for PercentFormatExtraNamedArguments { /// /// ## References /// - [Python documentation: `printf`-style String Formatting](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting) -#[violation] -pub struct PercentFormatMissingArgument { +#[derive(ViolationMetadata)] +pub(crate) struct PercentFormatMissingArgument { missing: Vec, } @@ -220,8 +220,8 @@ impl Violation for PercentFormatMissingArgument { /// /// ## References /// - [Python documentation: `printf`-style String Formatting](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting) -#[violation] -pub struct PercentFormatMixedPositionalAndNamed; +#[derive(ViolationMetadata)] +pub(crate) struct PercentFormatMixedPositionalAndNamed; impl Violation for PercentFormatMixedPositionalAndNamed { #[derive_message_formats] @@ -250,8 +250,8 @@ impl Violation for PercentFormatMixedPositionalAndNamed { /// /// ## References /// - [Python documentation: `printf`-style String Formatting](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting) -#[violation] -pub struct PercentFormatPositionalCountMismatch { +#[derive(ViolationMetadata)] +pub(crate) struct PercentFormatPositionalCountMismatch { wanted: usize, got: usize, } @@ -288,8 +288,8 @@ impl Violation for PercentFormatPositionalCountMismatch { /// /// ## References /// - [Python documentation: `printf`-style String Formatting](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting) -#[violation] -pub struct PercentFormatStarRequiresSequence; +#[derive(ViolationMetadata)] +pub(crate) struct PercentFormatStarRequiresSequence; impl Violation for PercentFormatStarRequiresSequence { #[derive_message_formats] @@ -318,8 +318,8 @@ impl Violation for PercentFormatStarRequiresSequence { /// /// ## References /// - [Python documentation: `printf`-style String Formatting](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting) -#[violation] -pub struct PercentFormatUnsupportedFormatCharacter { +#[derive(ViolationMetadata)] +pub(crate) struct PercentFormatUnsupportedFormatCharacter { pub(crate) char: char, } @@ -349,8 +349,8 @@ impl Violation for PercentFormatUnsupportedFormatCharacter { /// /// ## References /// - [Python documentation: `str.format`](https://docs.python.org/3/library/stdtypes.html#str.format) -#[violation] -pub struct StringDotFormatInvalidFormat { +#[derive(ViolationMetadata)] +pub(crate) struct StringDotFormatInvalidFormat { pub(crate) message: String, } @@ -381,8 +381,8 @@ impl Violation for StringDotFormatInvalidFormat { /// /// ## References /// - [Python documentation: `str.format`](https://docs.python.org/3/library/stdtypes.html#str.format) -#[violation] -pub struct StringDotFormatExtraNamedArguments { +#[derive(ViolationMetadata)] +pub(crate) struct StringDotFormatExtraNamedArguments { missing: Vec, } @@ -422,8 +422,8 @@ impl Violation for StringDotFormatExtraNamedArguments { /// /// ## References /// - [Python documentation: `str.format`](https://docs.python.org/3/library/stdtypes.html#str.format) -#[violation] -pub struct StringDotFormatExtraPositionalArguments { +#[derive(ViolationMetadata)] +pub(crate) struct StringDotFormatExtraPositionalArguments { missing: Vec, } @@ -465,8 +465,8 @@ impl Violation for StringDotFormatExtraPositionalArguments { /// /// ## References /// - [Python documentation: `str.format`](https://docs.python.org/3/library/stdtypes.html#str.format) -#[violation] -pub struct StringDotFormatMissingArguments { +#[derive(ViolationMetadata)] +pub(crate) struct StringDotFormatMissingArguments { missing: Vec, } @@ -503,8 +503,8 @@ impl Violation for StringDotFormatMissingArguments { /// /// ## References /// - [Python documentation: `str.format`](https://docs.python.org/3/library/stdtypes.html#str.format) -#[violation] -pub struct StringDotFormatMixingAutomatic; +#[derive(ViolationMetadata)] +pub(crate) struct StringDotFormatMixingAutomatic; impl Violation for StringDotFormatMixingAutomatic { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/undefined_export.rs b/crates/ruff_linter/src/rules/pyflakes/rules/undefined_export.rs index a922c43b3efd1..06f8b390e8802 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/undefined_export.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/undefined_export.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for undefined names in `__all__`. @@ -38,8 +38,8 @@ use ruff_macros::{derive_message_formats, violation}; /// - [Python documentation: `__all__`](https://docs.python.org/3/tutorial/modules.html#importing-from-a-package) /// /// [preview]: https://docs.astral.sh/ruff/preview/ -#[violation] -pub struct UndefinedExport { +#[derive(ViolationMetadata)] +pub(crate) struct UndefinedExport { pub name: String, } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/undefined_local.rs b/crates/ruff_linter/src/rules/pyflakes/rules/undefined_local.rs index c727464f8bda2..d13aa29107864 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/undefined_local.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/undefined_local.rs @@ -1,7 +1,7 @@ use std::string::ToString; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::{Scope, ScopeId}; use ruff_text_size::Ranged; @@ -32,8 +32,8 @@ use crate::checkers::ast::Checker; /// global x /// x += 1 /// ``` -#[violation] -pub struct UndefinedLocal { +#[derive(ViolationMetadata)] +pub(crate) struct UndefinedLocal { name: String, } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/undefined_name.rs b/crates/ruff_linter/src/rules/pyflakes/rules/undefined_name.rs index 0c46c14a44a21..cdfffe1f463b8 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/undefined_name.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/undefined_name.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for uses of undefined names. @@ -25,8 +25,8 @@ use ruff_macros::{derive_message_formats, violation}; /// /// ## References /// - [Python documentation: Naming and binding](https://docs.python.org/3/reference/executionmodel.html#naming-and-binding) -#[violation] -pub struct UndefinedName { +#[derive(ViolationMetadata)] +pub(crate) struct UndefinedName { pub(crate) name: String, pub(crate) minor_version_builtin_added: Option, } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/unused_annotation.rs b/crates/ruff_linter/src/rules/pyflakes/rules/unused_annotation.rs index 1310f2dca2f1e..40684d1d10491 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/unused_annotation.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/unused_annotation.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Scope; use ruff_text_size::Ranged; @@ -20,8 +20,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [PEP 484 – Type Hints](https://peps.python.org/pep-0484/) -#[violation] -pub struct UnusedAnnotation { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedAnnotation { name: String, } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs b/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs index 879f89284bdf7..09e4149b32c98 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs @@ -5,7 +5,7 @@ use anyhow::{anyhow, bail, Result}; use std::collections::BTreeMap; use ruff_diagnostics::{Applicability, Diagnostic, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::QualifiedName; use ruff_python_ast::{self as ast, Stmt}; use ruff_python_semantic::{ @@ -94,8 +94,8 @@ use crate::rules::{isort, isort::ImportSection, isort::ImportType}; /// - [Python documentation: `import`](https://docs.python.org/3/reference/simple_stmts.html#the-import-statement) /// - [Python documentation: `importlib.util.find_spec`](https://docs.python.org/3/library/importlib.html#importlib.util.find_spec) /// - [Typing documentation: interface conventions](https://typing.readthedocs.io/en/latest/source/libraries.html#library-interface-public-and-private-symbols) -#[violation] -pub struct UnusedImport { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedImport { /// Qualified name of the import name: String, /// Unqualified name of the import diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs b/crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs index 1bd813f65a54c..eca9622a16b2f 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs @@ -1,7 +1,7 @@ use itertools::Itertools; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::contains_effect; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::{self as ast, Stmt}; @@ -43,8 +43,8 @@ use crate::fix::edits::delete_stmt; /// /// ## Options /// - `lint.dummy-variable-rgx` -#[violation] -pub struct UnusedVariable { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedVariable { pub name: String, } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/yield_outside_function.rs b/crates/ruff_linter/src/rules/pyflakes/rules/yield_outside_function.rs index 2657882a69038..c7f8d852a2a68 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/yield_outside_function.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/yield_outside_function.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Expr; use ruff_text_size::Ranged; @@ -45,8 +45,8 @@ impl fmt::Display for DeferralKeyword { /// - [Python documentation: `yield`](https://docs.python.org/3/reference/simple_stmts.html#the-yield-statement) /// /// [autoawait]: https://ipython.readthedocs.io/en/stable/interactive/autoawait.html -#[violation] -pub struct YieldOutsideFunction { +#[derive(ViolationMetadata)] +pub(crate) struct YieldOutsideFunction { keyword: DeferralKeyword, } diff --git a/crates/ruff_linter/src/rules/pygrep_hooks/rules/blanket_noqa.rs b/crates/ruff_linter/src/rules/pygrep_hooks/rules/blanket_noqa.rs index 488666ec2df75..53bca7c9e564a 100644 --- a/crates/ruff_linter/src/rules/pygrep_hooks/rules/blanket_noqa.rs +++ b/crates/ruff_linter/src/rules/pygrep_hooks/rules/blanket_noqa.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_trivia::Cursor; use ruff_text_size::{Ranged, TextRange}; @@ -43,8 +43,8 @@ use crate::Locator; /// - [Ruff documentation](https://docs.astral.sh/ruff/configuration/#error-suppression) /// /// [preview]: https://docs.astral.sh/ruff/preview/ -#[violation] -pub struct BlanketNOQA { +#[derive(ViolationMetadata)] +pub(crate) struct BlanketNOQA { missing_colon: bool, space_before_colon: bool, file_exemption: bool, diff --git a/crates/ruff_linter/src/rules/pygrep_hooks/rules/blanket_type_ignore.rs b/crates/ruff_linter/src/rules/pygrep_hooks/rules/blanket_type_ignore.rs index 05dd25ec8681c..a520720e2098d 100644 --- a/crates/ruff_linter/src/rules/pygrep_hooks/rules/blanket_type_ignore.rs +++ b/crates/ruff_linter/src/rules/pygrep_hooks/rules/blanket_type_ignore.rs @@ -5,7 +5,7 @@ use memchr::memchr_iter; use regex::Regex; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_trivia::CommentRanges; use ruff_text_size::TextSize; @@ -40,8 +40,8 @@ use crate::Locator; /// [tool.mypy] /// enable_error_code = ["ignore-without-code"] /// ``` -#[violation] -pub struct BlanketTypeIgnore; +#[derive(ViolationMetadata)] +pub(crate) struct BlanketTypeIgnore; impl Violation for BlanketTypeIgnore { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs b/crates/ruff_linter/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs index a03ea962f1872..7f4faef4a0879 100644 --- a/crates/ruff_linter/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs +++ b/crates/ruff_linter/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## Removed /// This rule is identical to [G010] which should be used instead. @@ -32,8 +32,8 @@ use ruff_macros::{derive_message_formats, violation}; /// - [Python documentation: `logger.Logger.warning`](https://docs.python.org/3/library/logging.html#logging.Logger.warning) /// /// [G010]: https://docs.astral.sh/ruff/rules/logging-warn/ -#[violation] -pub struct DeprecatedLogWarn; +#[derive(ViolationMetadata)] +pub(crate) struct DeprecatedLogWarn; /// PGH002 impl Violation for DeprecatedLogWarn { diff --git a/crates/ruff_linter/src/rules/pygrep_hooks/rules/invalid_mock_access.rs b/crates/ruff_linter/src/rules/pygrep_hooks/rules/invalid_mock_access.rs index 06b513485a3d0..86c65f5cf98ac 100644 --- a/crates/ruff_linter/src/rules/pygrep_hooks/rules/invalid_mock_access.rs +++ b/crates/ruff_linter/src/rules/pygrep_hooks/rules/invalid_mock_access.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -32,8 +32,8 @@ enum Reason { /// ```python /// my_mock.assert_called() /// ``` -#[violation] -pub struct InvalidMockAccess { +#[derive(ViolationMetadata)] +pub(crate) struct InvalidMockAccess { reason: Reason, } diff --git a/crates/ruff_linter/src/rules/pygrep_hooks/rules/no_eval.rs b/crates/ruff_linter/src/rules/pygrep_hooks/rules/no_eval.rs index e2fbe4ab01a47..65e2ec28b61e9 100644 --- a/crates/ruff_linter/src/rules/pygrep_hooks/rules/no_eval.rs +++ b/crates/ruff_linter/src/rules/pygrep_hooks/rules/no_eval.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## Removed /// This rule is identical to [S307] which should be used instead. @@ -29,8 +29,8 @@ use ruff_macros::{derive_message_formats, violation}; /// - [_Eval really is dangerous_ by Ned Batchelder](https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html) /// /// [S307]: https://docs.astral.sh/ruff/rules/suspicious-eval-usage/ -#[violation] -pub struct Eval; +#[derive(ViolationMetadata)] +pub(crate) struct Eval; /// PGH001 impl Violation for Eval { diff --git a/crates/ruff_linter/src/rules/pylint/rules/and_or_ternary.rs b/crates/ruff_linter/src/rules/pylint/rules/and_or_ternary.rs index c13ea44495764..8baf775f86bc8 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/and_or_ternary.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/and_or_ternary.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::violation; +use ruff_macros::ViolationMetadata; /// ## Removal /// This rule was removed from Ruff because it was common for it to introduce behavioral changes. @@ -27,8 +27,8 @@ use ruff_macros::violation; /// x, y = 1, 2 /// maximum = x if x >= y else y /// ``` -#[violation] -pub struct AndOrTernary; +#[derive(ViolationMetadata)] +pub(crate) struct AndOrTernary; /// PLR1706 impl Violation for AndOrTernary { diff --git a/crates/ruff_linter/src/rules/pylint/rules/assert_on_string_literal.rs b/crates/ruff_linter/src/rules/pylint/rules/assert_on_string_literal.rs index d8cdd3a968dbb..f81f5b9ec9ee0 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/assert_on_string_literal.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/assert_on_string_literal.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -25,8 +25,8 @@ enum Kind { /// ```python /// assert "always true" /// ``` -#[violation] -pub struct AssertOnStringLiteral { +#[derive(ViolationMetadata)] +pub(crate) struct AssertOnStringLiteral { kind: Kind, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/await_outside_async.rs b/crates/ruff_linter/src/rules/pylint/rules/await_outside_async.rs index d7ed9c45549a2..39b9e1935212e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/await_outside_async.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/await_outside_async.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::{GeneratorKind, ScopeKind}; use ruff_text_size::Ranged; @@ -38,8 +38,8 @@ use crate::checkers::ast::Checker; /// - [PEP 492: Await Expression](https://peps.python.org/pep-0492/#await-expression) /// /// [autoawait]: https://ipython.readthedocs.io/en/stable/interactive/autoawait.html -#[violation] -pub struct AwaitOutsideAsync; +#[derive(ViolationMetadata)] +pub(crate) struct AwaitOutsideAsync; impl Violation for AwaitOutsideAsync { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs index 8e83c07cc1cdc..3ef1236a20750 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::identifier::Identifier; use ruff_python_semantic::analyze::visibility; @@ -42,8 +42,8 @@ use crate::rules::pylint::helpers::is_known_dunder_method; /// /// ## Options /// - `lint.pylint.allow-dunder-method-names` -#[violation] -pub struct BadDunderMethodName { +#[derive(ViolationMetadata)] +pub(crate) struct BadDunderMethodName { name: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs index acd081f3274ef..00c8b42614072 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::SemanticModel; use ruff_python_stdlib::open_mode::OpenMode; @@ -35,8 +35,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `open`](https://docs.python.org/3/library/functions.html#open) -#[violation] -pub struct BadOpenMode { +#[derive(ViolationMetadata)] +pub(crate) struct BadOpenMode { mode: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_staticmethod_argument.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_staticmethod_argument.rs index 05974be70239b..b0166b16ba244 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_staticmethod_argument.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_staticmethod_argument.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::ParameterWithDefault; use ruff_python_semantic::analyze::function_type; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#function-and-method-arguments -#[violation] -pub struct BadStaticmethodArgument { +#[derive(ViolationMetadata)] +pub(crate) struct BadStaticmethodArgument { argument_name: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_str_strip_call.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_str_strip_call.rs index 77d375c03faa5..0f396ed7cab40 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_str_strip_call.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_str_strip_call.rs @@ -4,7 +4,7 @@ use ruff_python_ast::{self as ast, Expr}; use rustc_hash::FxHashSet; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -45,8 +45,8 @@ use crate::settings::types::PythonVersion; /// /// ## References /// - [Python documentation: `str.strip`](https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.strip) -#[violation] -pub struct BadStrStripCall { +#[derive(ViolationMetadata)] +pub(crate) struct BadStrStripCall { strip: StripKind, removal: Option, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_character.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_character.rs index 334f8d2330db4..8cac142199311 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_character.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_character.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Expr, ExprStringLiteral, StringFlags, StringLiteral}; use ruff_python_literal::{ cformat::{CFormatErrorType, CFormatString}, @@ -26,8 +26,8 @@ use crate::checkers::ast::Checker; /// /// print("{:z}".format("1")) /// ``` -#[violation] -pub struct BadStringFormatCharacter { +#[derive(ViolationMetadata)] +pub(crate) struct BadStringFormatCharacter { format_char: char, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs index 978fbce40dbcf..8fb1cf28b8879 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs @@ -6,7 +6,7 @@ use ruff_text_size::Ranged; use rustc_hash::FxHashMap; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::analyze::type_inference::{NumberLike, PythonType, ResolvedPythonType}; use crate::checkers::ast::Checker; @@ -27,8 +27,8 @@ use crate::checkers::ast::Checker; /// ```python /// print("%d" % 1) /// ``` -#[violation] -pub struct BadStringFormatType; +#[derive(ViolationMetadata)] +pub(crate) struct BadStringFormatType; impl Violation for BadStringFormatType { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/bidirectional_unicode.rs b/crates/ruff_linter/src/rules/pylint/rules/bidirectional_unicode.rs index a41cd3b55115b..09d775b1e9513 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bidirectional_unicode.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bidirectional_unicode.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_source_file::Line; const BIDI_UNICODE: [char; 10] = [ @@ -41,8 +41,8 @@ const BIDI_UNICODE: [char; 10] = [ /// /// ## References /// - [PEP 672: Bidirectional Text](https://peps.python.org/pep-0672/#bidirectional-text) -#[violation] -pub struct BidirectionalUnicode; +#[derive(ViolationMetadata)] +pub(crate) struct BidirectionalUnicode; impl Violation for BidirectionalUnicode { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/binary_op_exception.rs b/crates/ruff_linter/src/rules/pylint/rules/binary_op_exception.rs index c3f0ec82befd1..8458c48f2008a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/binary_op_exception.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/binary_op_exception.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, ExceptHandler, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -46,8 +46,8 @@ impl From<&ast::BoolOp> for BoolOp { /// except (A, B): /// pass /// ``` -#[violation] -pub struct BinaryOpException { +#[derive(ViolationMetadata)] +pub(crate) struct BinaryOpException { op: BoolOp, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/boolean_chained_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/boolean_chained_comparison.rs index 3443a15c26488..244dbd24098fb 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/boolean_chained_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/boolean_chained_comparison.rs @@ -1,8 +1,8 @@ use itertools::Itertools; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{ - name::Name, parenthesize::parenthesized_range, BoolOp, CmpOp, Expr, ExprBoolOp, ExprCompare, + parenthesize::parenthesized_range, BoolOp, CmpOp, Expr, ExprBoolOp, ExprCompare, }; use ruff_text_size::{Ranged, TextRange}; @@ -33,10 +33,8 @@ use crate::checkers::ast::Checker; /// if a < b < c: /// pass /// ``` -#[violation] -pub struct BooleanChainedComparison { - variable: Name, -} +#[derive(ViolationMetadata)] +pub(crate) struct BooleanChainedComparison; impl Violation for BooleanChainedComparison { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; @@ -120,9 +118,7 @@ pub(crate) fn boolean_chained_comparison(checker: &mut Checker, expr_bool_op: &E }; let mut diagnostic = Diagnostic::new( - BooleanChainedComparison { - variable: left_compare_right.id().clone(), - }, + BooleanChainedComparison, TextRange::new(left_compare.start(), right_compare.end()), ); diff --git a/crates/ruff_linter/src/rules/pylint/rules/collapsible_else_if.rs b/crates/ruff_linter/src/rules/pylint/rules/collapsible_else_if.rs index 3431bbf4ecf60..a7855cfd44994 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/collapsible_else_if.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/collapsible_else_if.rs @@ -2,7 +2,7 @@ use anyhow::Result; use ast::whitespace::indentation; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, ElifElseClause, Stmt}; use ruff_python_codegen::Stylist; use ruff_python_index::Indexer; @@ -45,8 +45,8 @@ use crate::Locator; /// /// ## References /// - [Python documentation: `if` Statements](https://docs.python.org/3/tutorial/controlflow.html#if-statements) -#[violation] -pub struct CollapsibleElseIf; +#[derive(ViolationMetadata)] +pub(crate) struct CollapsibleElseIf; impl Violation for CollapsibleElseIf { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pylint/rules/compare_to_empty_string.rs b/crates/ruff_linter/src/rules/pylint/rules/compare_to_empty_string.rs index db7d246ec6166..7f7685d9bf664 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/compare_to_empty_string.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/compare_to_empty_string.rs @@ -3,7 +3,7 @@ use itertools::Itertools; use ruff_python_ast::{self as ast, CmpOp, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -40,8 +40,8 @@ use crate::checkers::ast::Checker; /// - [Python documentation: Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing) /// /// [#4282]: https://github.com/astral-sh/ruff/issues/4282 -#[violation] -pub struct CompareToEmptyString { +#[derive(ViolationMetadata)] +pub(crate) struct CompareToEmptyString { existing: String, replacement: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs b/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs index f55906a324988..5958979019a76 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs @@ -2,7 +2,7 @@ use itertools::Itertools; use ruff_python_ast::{CmpOp, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -27,8 +27,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: Comparisons](https://docs.python.org/3/reference/expressions.html#comparisons) -#[violation] -pub struct ComparisonOfConstant { +#[derive(ViolationMetadata)] +pub(crate) struct ComparisonOfConstant { left_constant: String, op: CmpOp, right_constant: String, diff --git a/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs b/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs index 06a4c2196dd31..c15e85b928fdf 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs @@ -2,7 +2,7 @@ use itertools::Itertools; use crate::fix::snippet::SourceCodeSnippet; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{CmpOp, Expr}; use ruff_text_size::Ranged; @@ -30,8 +30,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: Comparisons](https://docs.python.org/3/reference/expressions.html#comparisons) -#[violation] -pub struct ComparisonWithItself { +#[derive(ViolationMetadata)] +pub(crate) struct ComparisonWithItself { actual: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/continue_in_finally.rs b/crates/ruff_linter/src/rules/pylint/rules/continue_in_finally.rs index cf19a0085299c..ad3615b9cd2d7 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/continue_in_finally.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/continue_in_finally.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -36,8 +36,8 @@ use crate::checkers::ast::Checker; /// /// ## Options /// - `target-version` -#[violation] -pub struct ContinueInFinally; +#[derive(ViolationMetadata)] +pub(crate) struct ContinueInFinally; impl Violation for ContinueInFinally { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/dict_index_missing_items.rs b/crates/ruff_linter/src/rules/pylint/rules/dict_index_missing_items.rs index f08c4bde9cd80..a4b1932a129b0 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/dict_index_missing_items.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/dict_index_missing_items.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::{ self as ast, @@ -47,8 +47,8 @@ use crate::checkers::ast::Checker; /// print(f"{instrument}: {section}") /// ``` -#[violation] -pub struct DictIndexMissingItems; +#[derive(ViolationMetadata)] +pub(crate) struct DictIndexMissingItems; impl Violation for DictIndexMissingItems { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs b/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs index 8bfccdee4ddbd..5296d477efd1c 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{Expr, Stmt}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::analyze::typing::is_dict; use ruff_python_semantic::{Binding, SemanticModel}; use ruff_text_size::Ranged; @@ -49,8 +49,8 @@ use crate::checkers::ast::Checker; /// /// ## Fix safety /// Due to the known problem with tuple keys, this fix is unsafe. -#[violation] -pub struct DictIterMissingItems; +#[derive(ViolationMetadata)] +pub(crate) struct DictIterMissingItems; impl AlwaysFixableViolation for DictIterMissingItems { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs b/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs index 506f53b9d5209..83fa4a5f4549a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Arguments, Expr}; use rustc_hash::{FxBuildHasher, FxHashSet}; use ruff_diagnostics::{Diagnostic, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -36,8 +36,8 @@ use crate::fix::edits::{remove_argument, Parentheses}; /// /// ## References /// - [Python documentation: Class definitions](https://docs.python.org/3/reference/compound_stmts.html#class-definitions) -#[violation] -pub struct DuplicateBases { +#[derive(ViolationMetadata)] +pub(crate) struct DuplicateBases { base: String, class: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/empty_comment.rs b/crates/ruff_linter/src/rules/pylint/rules/empty_comment.rs index a8f544e711b31..f36265fb4ae4f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/empty_comment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/empty_comment.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_trivia::{is_python_whitespace, CommentRanges}; use ruff_source_file::LineRanges; use ruff_text_size::{TextRange, TextSize}; @@ -27,8 +27,8 @@ use crate::Locator; /// /// ## References /// - [Pylint documentation](https://pylint.pycqa.org/en/latest/user_guide/messages/refactor/empty-comment.html) -#[violation] -pub struct EmptyComment; +#[derive(ViolationMetadata)] +pub(crate) struct EmptyComment; impl Violation for EmptyComment { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Always; diff --git a/crates/ruff_linter/src/rules/pylint/rules/eq_without_hash.rs b/crates/ruff_linter/src/rules/pylint/rules/eq_without_hash.rs index af0e350fb4d67..d69b99a8ff781 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/eq_without_hash.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/eq_without_hash.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_text_size::Ranged; @@ -40,8 +40,8 @@ use crate::checkers::ast::Checker; /// def __hash__(self): /// return hash(self.name) /// ``` -#[violation] -pub struct EqWithoutHash; +#[derive(ViolationMetadata)] +pub(crate) struct EqWithoutHash; impl Violation for EqWithoutHash { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/global_at_module_level.rs b/crates/ruff_linter/src/rules/pylint/rules/global_at_module_level.rs index 7e30f3b5a3b31..ab9cf87e0f7aa 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/global_at_module_level.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/global_at_module_level.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Stmt; use ruff_text_size::Ranged; @@ -14,8 +14,8 @@ use crate::checkers::ast::Checker; /// /// At the module level, all names are global by default, so the `global` /// keyword is redundant. -#[violation] -pub struct GlobalAtModuleLevel; +#[derive(ViolationMetadata)] +pub(crate) struct GlobalAtModuleLevel; impl Violation for GlobalAtModuleLevel { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/global_statement.rs b/crates/ruff_linter/src/rules/pylint/rules/global_statement.rs index c359cf4511d83..b19faabf0f159 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/global_statement.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/global_statement.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::checkers::ast::Checker; @@ -38,8 +38,8 @@ use crate::checkers::ast::Checker; /// var = foo() /// print(var) /// ``` -#[violation] -pub struct GlobalStatement { +#[derive(ViolationMetadata)] +pub(crate) struct GlobalStatement { name: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/global_variable_not_assigned.rs b/crates/ruff_linter/src/rules/pylint/rules/global_variable_not_assigned.rs index 34857086de693..17a9f828b7494 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/global_variable_not_assigned.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/global_variable_not_assigned.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for `global` variables that are not assigned a value in the current @@ -35,8 +35,8 @@ use ruff_macros::{derive_message_formats, violation}; /// /// ## References /// - [Python documentation: The `global` statement](https://docs.python.org/3/reference/simple_stmts.html#the-global-statement) -#[violation] -pub struct GlobalVariableNotAssigned { +#[derive(ViolationMetadata)] +pub(crate) struct GlobalVariableNotAssigned { pub name: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/if_stmt_min_max.rs b/crates/ruff_linter/src/rules/pylint/rules/if_stmt_min_max.rs index 1ac7204bd9c55..75eb01f1baa66 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/if_stmt_min_max.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/if_stmt_min_max.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::{self as ast, CmpOp, Stmt}; @@ -32,8 +32,8 @@ use crate::fix::snippet::SourceCodeSnippet; /// ## References /// - [Python documentation: `max`](https://docs.python.org/3/library/functions.html#max) /// - [Python documentation: `min`](https://docs.python.org/3/library/functions.html#min) -#[violation] -pub struct IfStmtMinMax { +#[derive(ViolationMetadata)] +pub(crate) struct IfStmtMinMax { min_max: MinMax, replacement: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/import_outside_top_level.rs b/crates/ruff_linter/src/rules/pylint/rules/import_outside_top_level.rs index acc33fc0f7c3b..91a1a81bc96b5 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/import_outside_top_level.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/import_outside_top_level.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Stmt; use ruff_text_size::Ranged; @@ -42,8 +42,8 @@ use crate::checkers::ast::Checker; /// ``` /// /// [PEP 8]: https://peps.python.org/pep-0008/#imports -#[violation] -pub struct ImportOutsideTopLevel; +#[derive(ViolationMetadata)] +pub(crate) struct ImportOutsideTopLevel; impl Violation for ImportOutsideTopLevel { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/import_private_name.rs b/crates/ruff_linter/src/rules/pylint/rules/import_private_name.rs index 44468db41732c..65f3d04a19a00 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/import_private_name.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/import_private_name.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use itertools::Itertools; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::QualifiedName; use ruff_python_semantic::{FromImport, Import, Imported, ResolvedReference, Scope}; use ruff_text_size::Ranged; @@ -49,8 +49,8 @@ use crate::package::PackageRoot; /// /// [PEP 8]: https://peps.python.org/pep-0008/ /// [PEP 420]: https://peps.python.org/pep-0420/ -#[violation] -pub struct ImportPrivateName { +#[derive(ViolationMetadata)] +pub(crate) struct ImportPrivateName { name: String, module: Option, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/import_self.rs b/crates/ruff_linter/src/rules/pylint/rules/import_self.rs index 9ab1185f62754..62b9c1e54f6cd 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/import_self.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/import_self.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Alias; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::resolve_imported_module_path; use ruff_text_size::Ranged; @@ -21,8 +21,8 @@ use ruff_text_size::Ranged; /// /// def foo(): ... /// ``` -#[violation] -pub struct ImportSelf { +#[derive(ViolationMetadata)] +pub(crate) struct ImportSelf { name: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_all_format.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_all_format.rs index 3f0c8b65848a0..2cf8ed1688c8b 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_all_format.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_all_format.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Binding; use ruff_text_size::Ranged; @@ -25,8 +25,8 @@ use ruff_text_size::Ranged; /// /// ## References /// - [Python documentation: The `import` statement](https://docs.python.org/3/reference/simple_stmts.html#the-import-statement) -#[violation] -pub struct InvalidAllFormat; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidAllFormat; impl Violation for InvalidAllFormat { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_all_object.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_all_object.rs index d5691c6c20c1f..e3d17caa28dd8 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_all_object.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_all_object.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Binding; use ruff_text_size::Ranged; @@ -25,8 +25,8 @@ use ruff_text_size::Ranged; /// /// ## References /// - [Python documentation: The `import` statement](https://docs.python.org/3/reference/simple_stmts.html#the-import-statement) -#[violation] -pub struct InvalidAllObject; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidAllObject; impl Violation for InvalidAllObject { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_bool_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_bool_return.rs index 8ac7bfeaff319..fd4f48f0d6e56 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_bool_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_bool_return.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::ReturnStatementVisitor; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::visitor::Visitor; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: The `__bool__` method](https://docs.python.org/3/reference/datamodel.html#object.__bool__) -#[violation] -pub struct InvalidBoolReturnType; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidBoolReturnType; impl Violation for InvalidBoolReturnType { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_bytes_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_bytes_return.rs index 3d7acb27afdd0..93330d5472bad 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_bytes_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_bytes_return.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::ReturnStatementVisitor; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::visitor::Visitor; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: The `__bytes__` method](https://docs.python.org/3/reference/datamodel.html#object.__bytes__) -#[violation] -pub struct InvalidBytesReturnType; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidBytesReturnType; impl Violation for InvalidBytesReturnType { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_default.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_default.rs index 6ec7435279c6a..72c4f6df85139 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_default.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_default.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::analyze::type_inference::{PythonType, ResolvedPythonType}; use ruff_python_semantic::Modules; @@ -32,8 +32,8 @@ use crate::checkers::ast::Checker; /// /// int(os.getenv("FOO", "1")) /// ``` -#[violation] -pub struct InvalidEnvvarDefault; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidEnvvarDefault; impl Violation for InvalidEnvvarDefault { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_value.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_value.rs index c157a10761489..5ff818c600548 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_value.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_envvar_value.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::analyze::type_inference::{PythonType, ResolvedPythonType}; use ruff_python_semantic::Modules; @@ -25,8 +25,8 @@ use crate::checkers::ast::Checker; /// ```python /// os.getenv("1") /// ``` -#[violation] -pub struct InvalidEnvvarValue; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidEnvvarValue; impl Violation for InvalidEnvvarValue { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_hash_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_hash_return.rs index ee1ae6960b96c..59e68ad547790 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_hash_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_hash_return.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::ReturnStatementVisitor; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::visitor::Visitor; @@ -38,8 +38,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: The `__hash__` method](https://docs.python.org/3/reference/datamodel.html#object.__hash__) -#[violation] -pub struct InvalidHashReturnType; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidHashReturnType; impl Violation for InvalidHashReturnType { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_index_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_index_return.rs index c1cc229d3f676..d71d7d60be6e6 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_index_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_index_return.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::ReturnStatementVisitor; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::visitor::Visitor; @@ -19,7 +19,7 @@ use crate::checkers::ast::Checker; /// type may cause unexpected behavior. /// /// Note: `bool` is a subclass of `int`, so it's technically valid for `__index__` to -/// return `True` or `False`. However, a DeprecationWarning (`DeprecationWarning: +/// return `True` or `False`. However, a `DeprecationWarning` (`DeprecationWarning: /// __index__ returned non-int (type bool)`) for such cases was already introduced, /// thus this is a conscious difference between the original pylint rule and the /// current ruff implementation. @@ -40,8 +40,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: The `__index__` method](https://docs.python.org/3/reference/datamodel.html#object.__index__) -#[violation] -pub struct InvalidIndexReturnType; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidIndexReturnType; impl Violation for InvalidIndexReturnType { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_length_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_length_return.rs index 5e913b63c2e4d..72814967880ee 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_length_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_length_return.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::ReturnStatementVisitor; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::visitor::Visitor; @@ -39,8 +39,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: The `__len__` method](https://docs.python.org/3/reference/datamodel.html#object.__len__) -#[violation] -pub struct InvalidLengthReturnType; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidLengthReturnType; impl Violation for InvalidLengthReturnType { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_str_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_str_return.rs index befa18f5d714f..ae4cbb0f905a7 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_str_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_str_return.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::ReturnStatementVisitor; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::visitor::Visitor; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: The `__str__` method](https://docs.python.org/3/reference/datamodel.html#object.__str__) -#[violation] -pub struct InvalidStrReturnType; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidStrReturnType; impl Violation for InvalidStrReturnType { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_string_characters.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_string_characters.rs index 7b004a3311036..efa6219a5d75b 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_string_characters.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_string_characters.rs @@ -1,7 +1,7 @@ use ruff_diagnostics::AlwaysFixableViolation; use ruff_diagnostics::Edit; use ruff_diagnostics::{Diagnostic, DiagnosticKind, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_parser::TokenKind; use ruff_text_size::{TextLen, TextRange, TextSize}; @@ -26,8 +26,8 @@ use crate::Locator; /// ```python /// x = "\b" /// ``` -#[violation] -pub struct InvalidCharacterBackspace; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidCharacterBackspace; impl AlwaysFixableViolation for InvalidCharacterBackspace { #[derive_message_formats] @@ -59,8 +59,8 @@ impl AlwaysFixableViolation for InvalidCharacterBackspace { /// ```python /// x = "\x1a" /// ``` -#[violation] -pub struct InvalidCharacterSub; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidCharacterSub; impl AlwaysFixableViolation for InvalidCharacterSub { #[derive_message_formats] @@ -92,8 +92,8 @@ impl AlwaysFixableViolation for InvalidCharacterSub { /// ```python /// x = "\x1b" /// ``` -#[violation] -pub struct InvalidCharacterEsc; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidCharacterEsc; impl AlwaysFixableViolation for InvalidCharacterEsc { #[derive_message_formats] @@ -125,8 +125,8 @@ impl AlwaysFixableViolation for InvalidCharacterEsc { /// ```python /// x = "\0" /// ``` -#[violation] -pub struct InvalidCharacterNul; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidCharacterNul; impl AlwaysFixableViolation for InvalidCharacterNul { #[derive_message_formats] @@ -157,8 +157,8 @@ impl AlwaysFixableViolation for InvalidCharacterNul { /// ```python /// x = "Dear Sir\u200b/\u200bMadam" # zero width space /// ``` -#[violation] -pub struct InvalidCharacterZeroWidthSpace; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidCharacterZeroWidthSpace; impl AlwaysFixableViolation for InvalidCharacterZeroWidthSpace { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/iteration_over_set.rs b/crates/ruff_linter/src/rules/pylint/rules/iteration_over_set.rs index fc3bd4a1ddd91..03e0d31bfd0ce 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/iteration_over_set.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/iteration_over_set.rs @@ -1,7 +1,7 @@ use rustc_hash::{FxBuildHasher, FxHashSet}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::HashableExpr; use ruff_python_ast::Expr; use ruff_text_size::Ranged; @@ -30,8 +30,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `set`](https://docs.python.org/3/library/stdtypes.html#set) -#[violation] -pub struct IterationOverSet; +#[derive(ViolationMetadata)] +pub(crate) struct IterationOverSet; impl AlwaysFixableViolation for IterationOverSet { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/len_test.rs b/crates/ruff_linter/src/rules/pylint/rules/len_test.rs index e4892b35fb9e6..44b56f64c1050 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/len_test.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/len_test.rs @@ -1,7 +1,7 @@ use crate::checkers::ast::Checker; use crate::fix::snippet::SourceCodeSnippet; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, ExprCall}; use ruff_python_semantic::analyze::type_inference::{PythonType, ResolvedPythonType}; use ruff_python_semantic::analyze::typing::find_binding_value; @@ -42,8 +42,8 @@ use ruff_text_size::Ranged; /// /// ## References /// [PEP 8: Programming Recommendations](https://peps.python.org/pep-0008/#programming-recommendations) -#[violation] -pub struct LenTest { +#[derive(ViolationMetadata)] +pub(crate) struct LenTest { expression: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/literal_membership.rs b/crates/ruff_linter/src/rules/pylint/rules/literal_membership.rs index 72cad54c72d29..3ff08e9549b87 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/literal_membership.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/literal_membership.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, CmpOp, Expr}; use ruff_python_semantic::analyze::typing; use ruff_text_size::Ranged; @@ -31,8 +31,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [What’s New In Python 3.2](https://docs.python.org/3/whatsnew/3.2.html#optimizations) -#[violation] -pub struct LiteralMembership; +#[derive(ViolationMetadata)] +pub(crate) struct LiteralMembership; impl AlwaysFixableViolation for LiteralMembership { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/load_before_global_declaration.rs b/crates/ruff_linter/src/rules/pylint/rules/load_before_global_declaration.rs index 5646eead41905..f3d6e1d64743c 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/load_before_global_declaration.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/load_before_global_declaration.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_source_file::SourceRow; use ruff_text_size::Ranged; @@ -40,8 +40,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: The `global` statement](https://docs.python.org/3/reference/simple_stmts.html#the-global-statement) -#[violation] -pub struct LoadBeforeGlobalDeclaration { +#[derive(ViolationMetadata)] +pub(crate) struct LoadBeforeGlobalDeclaration { name: String, row: SourceRow, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/logging.rs b/crates/ruff_linter/src/rules/pylint/rules/logging.rs index 1603fbd5e8224..99f22ae6caf9a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/logging.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/logging.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::analyze::logging; use ruff_python_stdlib::logging::LoggingLevel; @@ -36,8 +36,8 @@ use crate::rules::pyflakes::cformat::CFormatSummary; /// logging.error("%s error occurred: %s", type(e), e) /// raise /// ``` -#[violation] -pub struct LoggingTooFewArgs; +#[derive(ViolationMetadata)] +pub(crate) struct LoggingTooFewArgs; impl Violation for LoggingTooFewArgs { #[derive_message_formats] @@ -73,8 +73,8 @@ impl Violation for LoggingTooFewArgs { /// logging.error("%s error occurred: %s", type(e), e) /// raise /// ``` -#[violation] -pub struct LoggingTooManyArgs; +#[derive(ViolationMetadata)] +pub(crate) struct LoggingTooManyArgs; impl Violation for LoggingTooManyArgs { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs index 4a6572b9767cd..4ba10f132c69a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs @@ -2,7 +2,7 @@ use itertools::Itertools; use ruff_python_ast::{self as ast, Expr, Int, LiteralExpressionRef, UnaryOp}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -45,8 +45,8 @@ use crate::rules::pylint::settings::ConstantType; /// - `lint.pylint.allow-magic-value-types` /// /// [PEP 8]: https://peps.python.org/pep-0008/#constants -#[violation] -pub struct MagicValueComparison { +#[derive(ViolationMetadata)] +pub(crate) struct MagicValueComparison { value: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs b/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs index 001a6098cddff..b2a58b64ab551 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Alias, Identifier, Stmt}; use ruff_text_size::{Ranged, TextRange}; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::checkers::ast::Checker; @@ -25,8 +25,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: Submodules](https://docs.python.org/3/reference/import.html#submodules) -#[violation] -pub struct ManualFromImport { +#[derive(ViolationMetadata)] +pub(crate) struct ManualFromImport { module: String, name: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/misplaced_bare_raise.rs b/crates/ruff_linter/src/rules/pylint/rules/misplaced_bare_raise.rs index c68c24db94fa6..22007bac8973a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/misplaced_bare_raise.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/misplaced_bare_raise.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_text_size::Ranged; @@ -40,8 +40,8 @@ use crate::rules::pylint::helpers::in_dunder_method; /// if obj is None: /// raise ValueError("`obj` cannot be `None`") /// ``` -#[violation] -pub struct MisplacedBareRaise; +#[derive(ViolationMetadata)] +pub(crate) struct MisplacedBareRaise; impl Violation for MisplacedBareRaise { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/modified_iterating_set.rs b/crates/ruff_linter/src/rules/pylint/rules/modified_iterating_set.rs index ad2ef7e8d9903..f918f65f25309 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/modified_iterating_set.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/modified_iterating_set.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::any_over_body; use ruff_python_ast::name::Name; use ruff_python_ast::{self as ast, Expr, StmtFor}; @@ -40,8 +40,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `set`](https://docs.python.org/3/library/stdtypes.html#set) -#[violation] -pub struct ModifiedIteratingSet { +#[derive(ViolationMetadata)] +pub(crate) struct ModifiedIteratingSet { name: Name, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/named_expr_without_context.rs b/crates/ruff_linter/src/rules/pylint/rules/named_expr_without_context.rs index b86071bdfcc25..f062e21a3e09c 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/named_expr_without_context.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/named_expr_without_context.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::checkers::ast::Checker; @@ -24,8 +24,8 @@ use crate::checkers::ast::Checker; /// ```python /// a = 42 /// ``` -#[violation] -pub struct NamedExprWithoutContext; +#[derive(ViolationMetadata)] +pub(crate) struct NamedExprWithoutContext; impl Violation for NamedExprWithoutContext { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs index 238a4dfd5c4b7..6ee5f6b25ba5e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::SemanticModel; use ruff_text_size::Ranged; @@ -31,8 +31,8 @@ use crate::checkers::ast::Checker; /// pass /// ``` /// -#[violation] -pub struct NanComparison { +#[derive(ViolationMetadata)] +pub(crate) struct NanComparison { nan: Nan, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs b/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs index c6799864ba6bc..6c7cfcf2a4d09 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Arguments, Expr, Keyword}; use ruff_text_size::{Ranged, TextRange}; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::SemanticModel; use crate::checkers::ast::Checker; @@ -37,8 +37,8 @@ pub(crate) enum MinMax { /// ## References /// - [Python documentation: `min`](https://docs.python.org/3/library/functions.html#min) /// - [Python documentation: `max`](https://docs.python.org/3/library/functions.html#max) -#[violation] -pub struct NestedMinMax { +#[derive(ViolationMetadata)] +pub(crate) struct NestedMinMax { func: MinMax, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs b/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs index 0e3380fdaaa8f..d9047f858c5c9 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/no_method_decorator.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, DiagnosticKind, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::Name; use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_python_trivia::indentation_at_offset; @@ -32,8 +32,8 @@ use crate::fix; /// @classmethod /// def bar(cls): ... /// ``` -#[violation] -pub struct NoClassmethodDecorator; +#[derive(ViolationMetadata)] +pub(crate) struct NoClassmethodDecorator; impl AlwaysFixableViolation for NoClassmethodDecorator { #[derive_message_formats] @@ -68,8 +68,8 @@ impl AlwaysFixableViolation for NoClassmethodDecorator { /// @staticmethod /// def bar(arg1, arg2): ... /// ``` -#[violation] -pub struct NoStaticmethodDecorator; +#[derive(ViolationMetadata)] +pub(crate) struct NoStaticmethodDecorator; impl AlwaysFixableViolation for NoStaticmethodDecorator { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs b/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs index f2a032731fab7..2e604dcd69f49 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::identifier::Identifier; use ruff_python_semantic::{ @@ -37,8 +37,8 @@ use crate::checkers::ast::Checker; /// def greeting(): /// print("Greetings friend!") /// ``` -#[violation] -pub struct NoSelfUse { +#[derive(ViolationMetadata)] +pub(crate) struct NoSelfUse { method_name: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/non_ascii_module_import.rs b/crates/ruff_linter/src/rules/pylint/rules/non_ascii_module_import.rs index a34fcf0cda37d..8ac75c6f6e190 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/non_ascii_module_import.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/non_ascii_module_import.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Alias; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -29,8 +29,8 @@ use crate::checkers::ast::Checker; /// ``` /// /// [PEP 672]: https://peps.python.org/pep-0672/ -#[violation] -pub struct NonAsciiImportName { +#[derive(ViolationMetadata)] +pub(crate) struct NonAsciiImportName { name: String, kind: Kind, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/non_ascii_name.rs b/crates/ruff_linter/src/rules/pylint/rules/non_ascii_name.rs index ea5a862646759..4bd54b3c035d2 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/non_ascii_name.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/non_ascii_name.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::{Binding, BindingKind}; use ruff_text_size::Ranged; @@ -25,8 +25,8 @@ use crate::Locator; /// ``` /// /// [PEP 672]: https://peps.python.org/pep-0672/ -#[violation] -pub struct NonAsciiName { +#[derive(ViolationMetadata)] +pub(crate) struct NonAsciiName { name: String, kind: Kind, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs index a0b2ccf3bb0b7..b2de97bb62d59 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs @@ -1,6 +1,6 @@ use ast::{Expr, StmtAugAssign}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::Operator; @@ -16,7 +16,7 @@ use crate::checkers::ast::Checker; /// ## Why is this bad? /// If the right-hand side of an assignment statement consists of a binary /// operation in which one operand is the same as the assignment target, -/// it can be rewritten as an augmented assignment. For example, `x = x + 1 +/// it can be rewritten as an augmented assignment. For example, `x = x + 1` /// can be rewritten as `x += 1`. /// /// When performing such an operation, an augmented assignment is more concise @@ -68,8 +68,8 @@ use crate::checkers::ast::Checker; /// foo += [2] /// assert (foo, bar) == ([1, 2], [1, 2]) /// ``` -#[violation] -pub struct NonAugmentedAssignment { +#[derive(ViolationMetadata)] +pub(crate) struct NonAugmentedAssignment { operator: AugmentedOperator, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs index 3e2d8a7bc9e52..029876b1ae7a5 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs @@ -1,7 +1,7 @@ use rustc_hash::FxHashSet; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_text_size::{Ranged, TextRange}; @@ -46,8 +46,8 @@ use crate::checkers::ast::Checker; /// def setup(self): /// pass /// ``` -#[violation] -pub struct NonSlotAssignment { +#[derive(ViolationMetadata)] +pub(crate) struct NonSlotAssignment { name: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/nonlocal_and_global.rs b/crates/ruff_linter/src/rules/pylint/rules/nonlocal_and_global.rs index 6d7d25736a025..d1193264b9854 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/nonlocal_and_global.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/nonlocal_and_global.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use crate::checkers::ast::Checker; @@ -40,8 +40,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: The `global` statement](https://docs.python.org/3/reference/simple_stmts.html#the-global-statement) /// - [Python documentation: The `nonlocal` statement](https://docs.python.org/3/reference/simple_stmts.html#nonlocal) -#[violation] -pub struct NonlocalAndGlobal { +#[derive(ViolationMetadata)] +pub(crate) struct NonlocalAndGlobal { pub(crate) name: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/nonlocal_without_binding.rs b/crates/ruff_linter/src/rules/pylint/rules/nonlocal_without_binding.rs index 9ec8a014f4a9d..b37ffe540cc48 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/nonlocal_without_binding.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/nonlocal_without_binding.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for `nonlocal` names without bindings. @@ -28,8 +28,8 @@ use ruff_macros::{derive_message_formats, violation}; /// ## References /// - [Python documentation: The `nonlocal` statement](https://docs.python.org/3/reference/simple_stmts.html#nonlocal) /// - [PEP 3104 – Access to Names in Outer Scopes](https://peps.python.org/pep-3104/) -#[violation] -pub struct NonlocalWithoutBinding { +#[derive(ViolationMetadata)] +pub(crate) struct NonlocalWithoutBinding { pub(crate) name: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/potential_index_error.rs b/crates/ruff_linter/src/rules/pylint/rules/potential_index_error.rs index 683a60534829e..59e2446979652 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/potential_index_error.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/potential_index_error.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -18,8 +18,8 @@ use crate::checkers::ast::Checker; /// ```python /// print([0, 1, 2][3]) /// ``` -#[violation] -pub struct PotentialIndexError; +#[derive(ViolationMetadata)] +pub(crate) struct PotentialIndexError; impl Violation for PotentialIndexError { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/property_with_parameters.rs b/crates/ruff_linter/src/rules/pylint/rules/property_with_parameters.rs index 01cd87358e362..681406e742335 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/property_with_parameters.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/property_with_parameters.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{identifier::Identifier, Decorator, Parameters, Stmt}; use ruff_python_semantic::analyze::visibility::is_property; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `property`](https://docs.python.org/3/library/functions.html#property) -#[violation] -pub struct PropertyWithParameters; +#[derive(ViolationMetadata)] +pub(crate) struct PropertyWithParameters; impl Violation for PropertyWithParameters { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/redeclared_assigned_name.rs b/crates/ruff_linter/src/rules/pylint/rules/redeclared_assigned_name.rs index a2380e59d4c9d..cb0e361bf8a29 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/redeclared_assigned_name.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/redeclared_assigned_name.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::Name; use ruff_text_size::Ranged; @@ -28,8 +28,8 @@ use crate::checkers::ast::Checker; /// print(a) # 3 /// ``` /// -#[violation] -pub struct RedeclaredAssignedName { +#[derive(ViolationMetadata)] +pub(crate) struct RedeclaredAssignedName { name: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/redefined_argument_from_local.rs b/crates/ruff_linter/src/rules/pylint/rules/redefined_argument_from_local.rs index ce3be6512500a..3462305e7c559 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/redefined_argument_from_local.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/redefined_argument_from_local.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for variables defined in `for`, `try`, `with` statements @@ -29,8 +29,8 @@ use ruff_macros::{derive_message_formats, violation}; /// ## References /// - [Pylint documentation](https://pylint.readthedocs.io/en/latest/user_guide/messages/refactor/redefined-argument-from-local.html) -#[violation] -pub struct RedefinedArgumentFromLocal { +#[derive(ViolationMetadata)] +pub(crate) struct RedefinedArgumentFromLocal { pub(crate) name: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs b/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs index 3ca8936641686..3fb716d12f325 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/redefined_loop_name.rs @@ -4,7 +4,7 @@ use regex::Regex; use ruff_python_ast::{self as ast, Arguments, Expr, ExprContext, Stmt, WithItem}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor}; use ruff_python_semantic::SemanticModel; @@ -48,8 +48,8 @@ use crate::checkers::ast::Checker; /// f = path2.open() /// print(f.readline()) # prints a line from path2 /// ``` -#[violation] -pub struct RedefinedLoopName { +#[derive(ViolationMetadata)] +pub(crate) struct RedefinedLoopName { name: String, outer_kind: OuterBindingKind, inner_kind: InnerBindingKind, diff --git a/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs index b56aaaeaeb345..942cc71bb9f17 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs @@ -3,7 +3,7 @@ use rustc_hash::{FxBuildHasher, FxHashMap}; use ast::ExprContext; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::helpers::{any_over_expr, contains_effect}; use ruff_python_ast::{self as ast, BoolOp, CmpOp, Expr}; @@ -48,8 +48,8 @@ use crate::Locator; /// - [Python documentation: `set`](https://docs.python.org/3/library/stdtypes.html#set) /// /// [preview]: https://docs.astral.sh/ruff/preview/ -#[violation] -pub struct RepeatedEqualityComparison { +#[derive(ViolationMetadata)] +pub(crate) struct RepeatedEqualityComparison { expression: SourceCodeSnippet, all_hashable: bool, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/repeated_isinstance_calls.rs b/crates/ruff_linter/src/rules/pylint/rules/repeated_isinstance_calls.rs index 3e3d3aac269c0..c319e4b7f2779 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/repeated_isinstance_calls.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/repeated_isinstance_calls.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::AlwaysFixableViolation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::fix::snippet::SourceCodeSnippet; @@ -48,8 +48,8 @@ use crate::fix::snippet::SourceCodeSnippet; /// - [Python documentation: `isinstance`](https://docs.python.org/3/library/functions.html#isinstance) /// /// [SIM101]: https://docs.astral.sh/ruff/rules/duplicate-isinstance-call/ -#[violation] -pub struct RepeatedIsinstanceCalls { +#[derive(ViolationMetadata)] +pub(crate) struct RepeatedIsinstanceCalls { expression: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs b/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs index 3c2b54f74c05d..9e6a95cbe9cdd 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs @@ -1,7 +1,7 @@ use rustc_hash::{FxBuildHasher, FxHashSet}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Expr, ExprCall, ExprStringLiteral}; use ruff_text_size::Ranged; @@ -22,8 +22,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: Argument](https://docs.python.org/3/glossary.html#term-argument) -#[violation] -pub struct RepeatedKeywordArgument { +#[derive(ViolationMetadata)] +pub(crate) struct RepeatedKeywordArgument { duplicate_keyword: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/return_in_init.rs b/crates/ruff_linter/src/rules/pylint/rules/return_in_init.rs index c9da5a9dc91bd..46dcf30c1746f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/return_in_init.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/return_in_init.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; @@ -34,8 +34,8 @@ use crate::rules::pylint::helpers::in_dunder_method; /// /// ## References /// - [CodeQL: `py-explicit-return-in-init`](https://codeql.github.com/codeql-query-help/python/py-explicit-return-in-init/) -#[violation] -pub struct ReturnInInit; +#[derive(ViolationMetadata)] +pub(crate) struct ReturnInInit; impl Violation for ReturnInInit { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/self_assigning_variable.rs b/crates/ruff_linter/src/rules/pylint/rules/self_assigning_variable.rs index b90cdc80d5826..60ff30a9d3bb0 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/self_assigning_variable.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/self_assigning_variable.rs @@ -2,7 +2,7 @@ use itertools::Itertools; use ruff_python_ast::{self as ast, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -23,8 +23,8 @@ use crate::checkers::ast::Checker; /// ```python /// country = "Poland" /// ``` -#[violation] -pub struct SelfAssigningVariable { +#[derive(ViolationMetadata)] +pub(crate) struct SelfAssigningVariable { name: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs index 7f3c1a4b9fa94..3e28dae9fb93f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, ParameterWithDefault}; use ruff_python_semantic::analyze::function_type::{self as function_type, FunctionType}; use ruff_python_semantic::ScopeKind; @@ -42,8 +42,8 @@ use crate::checkers::ast::Checker; /// supercls = cls.__mro__[-1] /// return supercls /// ``` -#[violation] -pub struct SelfOrClsAssignment { +#[derive(ViolationMetadata)] +pub(crate) struct SelfOrClsAssignment { method_type: MethodType, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/shallow_copy_environ.rs b/crates/ruff_linter/src/rules/pylint/rules/shallow_copy_environ.rs index 84649db53e463..4b715bd4bb0dc 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/shallow_copy_environ.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/shallow_copy_environ.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -35,8 +35,8 @@ use crate::checkers::ast::Checker; /// - [Python documentation: `os.environ`](https://docs.python.org/3/library/os.html#os.environ) /// /// [#15373]: https://bugs.python.org/issue15373 -#[violation] -pub struct ShallowCopyEnviron; +#[derive(ViolationMetadata)] +pub(crate) struct ShallowCopyEnviron; impl AlwaysFixableViolation for ShallowCopyEnviron { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/single_string_slots.rs b/crates/ruff_linter/src/rules/pylint/rules/single_string_slots.rs index dcefdeb40a557..1b3f528905a37 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/single_string_slots.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/single_string_slots.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr, Stmt, StmtClassDef}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use crate::checkers::ast::Checker; @@ -47,8 +47,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `__slots__`](https://docs.python.org/3/reference/datamodel.html#slots) -#[violation] -pub struct SingleStringSlots; +#[derive(ViolationMetadata)] +pub(crate) struct SingleStringSlots; impl Violation for SingleStringSlots { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/singledispatch_method.rs b/crates/ruff_linter/src/rules/pylint/rules/singledispatch_method.rs index b14eb78169371..b5048bee1f94b 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/singledispatch_method.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/singledispatch_method.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::analyze::function_type; use ruff_python_semantic::Scope; @@ -42,8 +42,8 @@ use crate::importer::ImportRequest; /// ## Fix safety /// This rule's fix is marked as unsafe, as migrating from `@singledispatch` to /// `@singledispatchmethod` may change the behavior of the code. -#[violation] -pub struct SingledispatchMethod; +#[derive(ViolationMetadata)] +pub(crate) struct SingledispatchMethod; impl Violation for SingledispatchMethod { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pylint/rules/singledispatchmethod_function.rs b/crates/ruff_linter/src/rules/pylint/rules/singledispatchmethod_function.rs index eed25e2f61094..9aaa9cff5b389 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/singledispatchmethod_function.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/singledispatchmethod_function.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::analyze::function_type; use ruff_python_semantic::Scope; @@ -40,8 +40,8 @@ use crate::importer::ImportRequest; /// ## Fix safety /// This rule's fix is marked as unsafe, as migrating from `@singledispatchmethod` to /// `@singledispatch` may change the behavior of the code. -#[violation] -pub struct SingledispatchmethodFunction; +#[derive(ViolationMetadata)] +pub(crate) struct SingledispatchmethodFunction; impl Violation for SingledispatchmethodFunction { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pylint/rules/subprocess_popen_preexec_fn.rs b/crates/ruff_linter/src/rules/pylint/rules/subprocess_popen_preexec_fn.rs index fc40495733d4c..09db5f8083ea2 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/subprocess_popen_preexec_fn.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/subprocess_popen_preexec_fn.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast}; use ruff_python_semantic::Modules; @@ -39,8 +39,8 @@ use crate::checkers::ast::Checker; /// - [Why `preexec_fn` in `subprocess.Popen` may lead to deadlock?](https://discuss.python.org/t/why-preexec-fn-in-subprocess-popen-may-lead-to-deadlock/16908/2) /// /// [targeted for deprecation]: https://github.com/python/cpython/issues/82616 -#[violation] -pub struct SubprocessPopenPreexecFn; +#[derive(ViolationMetadata)] +pub(crate) struct SubprocessPopenPreexecFn; impl Violation for SubprocessPopenPreexecFn { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/subprocess_run_without_check.rs b/crates/ruff_linter/src/rules/pylint/rules/subprocess_run_without_check.rs index c7780c890027a..4644226152ff8 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/subprocess_run_without_check.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/subprocess_run_without_check.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Applicability, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -45,8 +45,8 @@ use crate::fix::edits::add_argument; /// /// ## References /// - [Python documentation: `subprocess.run`](https://docs.python.org/3/library/subprocess.html#subprocess.run) -#[violation] -pub struct SubprocessRunWithoutCheck; +#[derive(ViolationMetadata)] +pub(crate) struct SubprocessRunWithoutCheck; impl AlwaysFixableViolation for SubprocessRunWithoutCheck { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs b/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs index df604a088801e..43d68e5d783a0 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::{analyze::function_type, ScopeKind}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -46,8 +46,8 @@ use crate::checkers::ast::Checker; /// original_speak = super().speak() # Correct: `super().speak()` /// return f"{original_speak} But as a dog, it barks!" /// ``` -#[violation] -pub struct SuperWithoutBrackets; +#[derive(ViolationMetadata)] +pub(crate) struct SuperWithoutBrackets; impl AlwaysFixableViolation for SuperWithoutBrackets { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs b/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs index e50cab524eff6..7e498cb471c67 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Expr; use ruff_text_size::Ranged; @@ -35,8 +35,8 @@ use crate::importer::ImportRequest; /// /// ## References /// - [Python documentation: Constants added by the `site` module](https://docs.python.org/3/library/constants.html#constants-added-by-the-site-module) -#[violation] -pub struct SysExitAlias { +#[derive(ViolationMetadata)] +pub(crate) struct SysExitAlias { name: String, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_arguments.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_arguments.rs index 3b643abc353a7..0bd87f6a013ec 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_arguments.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_arguments.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::identifier::Identifier; use ruff_python_semantic::analyze::{function_type, visibility}; @@ -43,8 +43,8 @@ use crate::checkers::ast::Checker; /// /// ## Options /// - `lint.pylint.max-args` -#[violation] -pub struct TooManyArguments { +#[derive(ViolationMetadata)] +pub(crate) struct TooManyArguments { c_args: usize, max_args: usize, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_boolean_expressions.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_boolean_expressions.rs index 152a335f99cf6..96047fa979738 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_boolean_expressions.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_boolean_expressions.rs @@ -1,6 +1,6 @@ use ast::{Expr, StmtIf}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_text_size::Ranged; @@ -25,8 +25,8 @@ use crate::checkers::ast::Checker; /// /// ## Options /// - `lint.pylint.max-bool-expr` -#[violation] -pub struct TooManyBooleanExpressions { +#[derive(ViolationMetadata)] +pub(crate) struct TooManyBooleanExpressions { expressions: usize, max_expressions: usize, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_branches.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_branches.rs index e2b76a4101ff8..15bfed361f412 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_branches.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_branches.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, ExceptHandler, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; /// ## What it does @@ -142,8 +142,8 @@ use ruff_python_ast::identifier::Identifier; /// /// ## Options /// - `lint.pylint.max-branches` -#[violation] -pub struct TooManyBranches { +#[derive(ViolationMetadata)] +pub(crate) struct TooManyBranches { branches: usize, max_branches: usize, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_locals.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_locals.rs index 2f4a4c6d6ed0f..3293a9a586443 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_locals.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_locals.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use ruff_python_semantic::{Scope, ScopeKind}; @@ -19,8 +19,8 @@ use crate::checkers::ast::Checker; /// /// ## Options /// - `lint.pylint.max-locals` -#[violation] -pub struct TooManyLocals { +#[derive(ViolationMetadata)] +pub(crate) struct TooManyLocals { current_amount: usize, max_amount: usize, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_nested_blocks.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_nested_blocks.rs index 3d406f047ffeb..c796402adb080 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_nested_blocks.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_nested_blocks.rs @@ -1,6 +1,6 @@ use ast::ExceptHandler; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Stmt}; use ruff_text_size::Ranged; @@ -18,8 +18,8 @@ use crate::checkers::ast::Checker; /// /// ## Options /// - `lint.pylint.max-nested-blocks` -#[violation] -pub struct TooManyNestedBlocks { +#[derive(ViolationMetadata)] +pub(crate) struct TooManyNestedBlocks { nested_blocks: usize, max_nested_blocks: usize, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_positional_arguments.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_positional_arguments.rs index f0da07a6c0f0e..970ccbe56a1b5 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_positional_arguments.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_positional_arguments.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, identifier::Identifier}; use ruff_python_semantic::analyze::{function_type, visibility}; @@ -41,8 +41,8 @@ use crate::checkers::ast::Checker; /// /// ## Options /// - `lint.pylint.max-positional-args` -#[violation] -pub struct TooManyPositionalArguments { +#[derive(ViolationMetadata)] +pub(crate) struct TooManyPositionalArguments { c_pos: usize, max_pos: usize, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_public_methods.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_public_methods.rs index 5da094aacdd7c..ee010b946fc40 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_public_methods.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_public_methods.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::analyze::visibility::{self, Visibility::Public}; use ruff_text_size::Ranged; @@ -82,8 +82,8 @@ use crate::checkers::ast::Checker; /// /// ## Options /// - `lint.pylint.max-public-methods` -#[violation] -pub struct TooManyPublicMethods { +#[derive(ViolationMetadata)] +pub(crate) struct TooManyPublicMethods { methods: usize, max_methods: usize, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_return_statements.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_return_statements.rs index 5e6e34dba86b0..6680f64efcf3a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_return_statements.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_return_statements.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Stmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::ReturnStatementVisitor; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::visitor::Visitor; @@ -51,8 +51,8 @@ use ruff_python_ast::visitor::Visitor; /// /// ## Options /// - `lint.pylint.max-returns` -#[violation] -pub struct TooManyReturnStatements { +#[derive(ViolationMetadata)] +pub(crate) struct TooManyReturnStatements { returns: usize, max_returns: usize, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_statements.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_statements.rs index 3ab6f9fb15d1b..7ce15e254e03c 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_statements.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_statements.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, ExceptHandler, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; /// ## What it does @@ -45,8 +45,8 @@ use ruff_python_ast::identifier::Identifier; /// /// ## Options /// - `lint.pylint.max-statements` -#[violation] -pub struct TooManyStatements { +#[derive(ViolationMetadata)] +pub(crate) struct TooManyStatements { statements: usize, max_statements: usize, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/type_bivariance.rs b/crates/ruff_linter/src/rules/pylint/rules/type_bivariance.rs index 2fd82e175d751..c639e33840118 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/type_bivariance.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/type_bivariance.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_const_true; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -53,8 +53,8 @@ use crate::rules::pylint::helpers::type_param_name; /// - [Python documentation: `typing` — Support for type hints](https://docs.python.org/3/library/typing.html) /// - [PEP 483 – The Theory of Type Hints: Covariance and Contravariance](https://peps.python.org/pep-0483/#covariance-and-contravariance) /// - [PEP 484 – Type Hints: Covariance and contravariance](https://peps.python.org/pep-0484/#covariance-and-contravariance) -#[violation] -pub struct TypeBivariance { +#[derive(ViolationMetadata)] +pub(crate) struct TypeBivariance { kind: VarKind, param_name: Option, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs b/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs index 2c17c1a4623f3..37dd7f544cb74 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_const_true; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -42,8 +42,8 @@ use crate::rules::pylint::helpers::type_param_name; /// - [PEP 484 – Type Hints: Covariance and contravariance](https://peps.python.org/pep-0484/#covariance-and-contravariance) /// /// [PEP 484]: https://peps.python.org/pep-0484/ -#[violation] -pub struct TypeNameIncorrectVariance { +#[derive(ViolationMetadata)] +pub(crate) struct TypeNameIncorrectVariance { kind: VarKind, param_name: String, variance: VarVariance, diff --git a/crates/ruff_linter/src/rules/pylint/rules/type_param_name_mismatch.rs b/crates/ruff_linter/src/rules/pylint/rules/type_param_name_mismatch.rs index 805f98e97c676..04dfb50b6736f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/type_param_name_mismatch.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/type_param_name_mismatch.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -38,8 +38,8 @@ use crate::rules::pylint::helpers::type_param_name; /// - [PEP 484 – Type Hints: Generics](https://peps.python.org/pep-0484/#generics) /// /// [PEP 484]:https://peps.python.org/pep-0484/#generics -#[violation] -pub struct TypeParamNameMismatch { +#[derive(ViolationMetadata)] +pub(crate) struct TypeParamNameMismatch { kind: VarKind, var_name: String, param_name: String, diff --git a/crates/ruff_linter/src/rules/pylint/rules/unexpected_special_method_signature.rs b/crates/ruff_linter/src/rules/pylint/rules/unexpected_special_method_signature.rs index 09182ef38461e..dac7bc9655d31 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unexpected_special_method_signature.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unexpected_special_method_signature.rs @@ -3,7 +3,7 @@ use std::cmp::Ordering; use ruff_python_ast::{Decorator, Parameters, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use ruff_python_semantic::analyze::visibility::is_staticmethod; @@ -110,8 +110,8 @@ impl ExpectedParams { /// /// ## References /// - [Python documentation: Data model](https://docs.python.org/3/reference/datamodel.html) -#[violation] -pub struct UnexpectedSpecialMethodSignature { +#[derive(ViolationMetadata)] +pub(crate) struct UnexpectedSpecialMethodSignature { method_name: String, expected_params: ExpectedParams, actual_params: usize, diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dict_index_lookup.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dict_index_lookup.rs index 35ad5910ddb35..26003fa609b98 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dict_index_lookup.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dict_index_lookup.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::visitor::Visitor; use ruff_python_ast::{self as ast, Expr, StmtFor}; use ruff_text_size::Ranged; @@ -30,8 +30,8 @@ use crate::rules::pylint::helpers::SequenceIndexVisitor; /// for fruit_name, fruit_count in FRUITS.items(): /// print(fruit_count) /// ``` -#[violation] -pub struct UnnecessaryDictIndexLookup; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryDictIndexLookup; impl AlwaysFixableViolation for UnnecessaryDictIndexLookup { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_direct_lambda_call.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_direct_lambda_call.rs index c9b2eeaf2f4a5..ddb77bcbe3b17 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_direct_lambda_call.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_direct_lambda_call.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -25,8 +25,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: Lambdas](https://docs.python.org/3/reference/expressions.html#lambda) -#[violation] -pub struct UnnecessaryDirectLambdaCall; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryDirectLambdaCall; impl Violation for UnnecessaryDirectLambdaCall { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs index 12a4a6fa5dd1f..9120d39d5ce86 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_dunder_call.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_python_semantic::SemanticModel; use ruff_text_size::Ranged; @@ -35,8 +35,8 @@ use crate::settings::types::PythonVersion; /// return x > 2 /// ``` /// -#[violation] -pub struct UnnecessaryDunderCall { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryDunderCall { method: String, replacement: Option, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs index 6ae3f607a1a63..73e373fb89ee9 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Applicability, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::visitor::Visitor; use ruff_python_ast::{self as ast, visitor, Expr, ExprLambda, Parameter, ParameterWithDefault}; use ruff_text_size::Ranged; @@ -43,8 +43,8 @@ use crate::checkers::ast::Checker; /// breaking change for callers that execute the lambda by passing arguments by /// name, as in: `foo(x=1, y=2)`. Since `func` does not define the arguments /// `x` and `y`, unlike the lambda, the call would raise a `TypeError`. -#[violation] -pub struct UnnecessaryLambda; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryLambda; impl AlwaysFixableViolation for UnnecessaryLambda { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs index e5c8c1fddaf7b..94a1f80898b2e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::visitor::Visitor; use ruff_python_ast::{self as ast, Expr, Int, Number, StmtFor}; use ruff_python_semantic::SemanticModel; @@ -31,8 +31,8 @@ use crate::rules::pylint::helpers::SequenceIndexVisitor; /// for index, letter in enumerate(letters): /// print(letter) /// ``` -#[violation] -pub struct UnnecessaryListIndexLookup; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryListIndexLookup; impl AlwaysFixableViolation for UnnecessaryListIndexLookup { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs b/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs index 377f872125579..287304889334a 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs @@ -1,7 +1,7 @@ use std::fmt::{Display, Formatter}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::QualifiedName; use ruff_python_ast::{self as ast, Expr, StringLiteralFlags}; use ruff_python_semantic::SemanticModel; @@ -42,8 +42,8 @@ use crate::fix::edits::add_argument; /// - [Python documentation: `open`](https://docs.python.org/3/library/functions.html#open) /// /// [PEP 597]: https://peps.python.org/pep-0597/ -#[violation] -pub struct UnspecifiedEncoding { +#[derive(ViolationMetadata)] +pub(crate) struct UnspecifiedEncoding { function_name: String, mode: ModeArgument, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/useless_else_on_loop.rs b/crates/ruff_linter/src/rules/pylint/rules/useless_else_on_loop.rs index 70f33d842c114..19ebcf1dfebf6 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/useless_else_on_loop.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/useless_else_on_loop.rs @@ -2,7 +2,7 @@ use anyhow::Result; use ast::whitespace::indentation; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier; use ruff_python_ast::{self as ast, ExceptHandler, MatchCase, Stmt}; use ruff_python_codegen::Stylist; @@ -46,8 +46,8 @@ use crate::Locator; /// /// ## References /// - [Python documentation: `break` and `continue` Statements, and `else` Clauses on Loops](https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops) -#[violation] -pub struct UselessElseOnLoop; +#[derive(ViolationMetadata)] +pub(crate) struct UselessElseOnLoop; impl Violation for UselessElseOnLoop { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pylint/rules/useless_exception_statement.rs b/crates/ruff_linter/src/rules/pylint/rules/useless_exception_statement.rs index f46da3e269526..633be017357e2 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/useless_exception_statement.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/useless_exception_statement.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::SemanticModel; use ruff_python_stdlib::builtins; @@ -33,8 +33,8 @@ use crate::settings::types::PythonVersion; /// ## Fix safety /// This rule's fix is marked as unsafe, as converting a useless exception /// statement to a `raise` statement will change the program's behavior. -#[violation] -pub struct UselessExceptionStatement; +#[derive(ViolationMetadata)] +pub(crate) struct UselessExceptionStatement; impl Violation for UselessExceptionStatement { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pylint/rules/useless_import_alias.rs b/crates/ruff_linter/src/rules/pylint/rules/useless_import_alias.rs index 6934c39f91787..25ea96e35c60f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/useless_import_alias.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/useless_import_alias.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Alias; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -27,8 +27,8 @@ use crate::checkers::ast::Checker; /// ```python /// import numpy /// ``` -#[violation] -pub struct UselessImportAlias { +#[derive(ViolationMetadata)] +pub(crate) struct UselessImportAlias { required_import_conflict: bool, } diff --git a/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs b/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs index 4dfb72aa77f28..83bb4a838c8f0 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::ReturnStatementVisitor; use ruff_python_ast::visitor::Visitor; use ruff_python_ast::{self as ast, Expr, Stmt}; @@ -28,8 +28,8 @@ use crate::fix; /// def f(): /// print(5) /// ``` -#[violation] -pub struct UselessReturn; +#[derive(ViolationMetadata)] +pub(crate) struct UselessReturn; impl AlwaysFixableViolation for UselessReturn { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/useless_with_lock.rs b/crates/ruff_linter/src/rules/pylint/rules/useless_with_lock.rs index b5f258c3c2320..378013cde8c23 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/useless_with_lock.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/useless_with_lock.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast}; use ruff_text_size::Ranged; @@ -47,8 +47,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `Lock Objects`](https://docs.python.org/3/library/threading.html#lock-objects) -#[violation] -pub struct UselessWithLock; +#[derive(ViolationMetadata)] +pub(crate) struct UselessWithLock; impl Violation for UselessWithLock { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/yield_from_in_async_function.rs b/crates/ruff_linter/src/rules/pylint/rules/yield_from_in_async_function.rs index 38df8d41b1f04..7ea7771f4fd91 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/yield_from_in_async_function.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/yield_from_in_async_function.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast}; use ruff_python_semantic::ScopeKind; use ruff_text_size::Ranged; @@ -27,8 +27,8 @@ use crate::checkers::ast::Checker; /// async for number in [1, 2, 3, 4, 5]: /// yield number /// ``` -#[violation] -pub struct YieldFromInAsyncFunction; +#[derive(ViolationMetadata)] +pub(crate) struct YieldFromInAsyncFunction; impl Violation for YieldFromInAsyncFunction { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pylint/rules/yield_in_init.rs b/crates/ruff_linter/src/rules/pylint/rules/yield_in_init.rs index d3bb3d1c82b82..5ce1903803af4 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/yield_in_init.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/yield_in_init.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -28,8 +28,8 @@ use crate::rules::pylint::helpers::in_dunder_method; /// /// ## References /// - [CodeQL: `py-init-method-is-generator`](https://codeql.github.com/codeql-query-help/python/py-init-method-is-generator/) -#[violation] -pub struct YieldInInit; +#[derive(ViolationMetadata)] +pub(crate) struct YieldInInit; impl Violation for YieldInInit { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs index 9044bda474bd6..80710ed40e937 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs @@ -1,7 +1,7 @@ use log::debug; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_dunder; use ruff_python_ast::name::Name; use ruff_python_ast::{self as ast, Arguments, Expr, ExprContext, Identifier, Keyword, Stmt}; @@ -43,8 +43,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `typing.NamedTuple`](https://docs.python.org/3/library/typing.html#typing.NamedTuple) -#[violation] -pub struct ConvertNamedTupleFunctionalToClass { +#[derive(ViolationMetadata)] +pub(crate) struct ConvertNamedTupleFunctionalToClass { name: String, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs index c00e8757996f0..1621f3a5ed074 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_dunder; use ruff_python_ast::{self as ast, Arguments, Expr, ExprContext, Identifier, Keyword, Stmt}; use ruff_python_codegen::Generator; @@ -39,8 +39,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `typing.TypedDict`](https://docs.python.org/3/library/typing.html#typing.TypedDict) -#[violation] -pub struct ConvertTypedDictFunctionalToClass { +#[derive(ViolationMetadata)] +pub(crate) struct ConvertTypedDictFunctionalToClass { name: String, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/datetime_utc_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/datetime_utc_alias.rs index 4771b55b5df44..a7adefa18dcfa 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/datetime_utc_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/datetime_utc_alias.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -33,8 +33,8 @@ use crate::importer::ImportRequest; /// /// ## References /// - [Python documentation: `datetime.UTC`](https://docs.python.org/3/library/datetime.html#datetime.UTC) -#[violation] -pub struct DatetimeTimezoneUTC; +#[derive(ViolationMetadata)] +pub(crate) struct DatetimeTimezoneUTC; impl Violation for DatetimeTimezoneUTC { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs index 5daed1b6c1c38..0511d3c631813 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Stmt}; use ruff_text_size::Ranged; @@ -24,8 +24,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `xml.etree.ElementTree`](https://docs.python.org/3/library/xml.etree.elementtree.html) -#[violation] -pub struct DeprecatedCElementTree; +#[derive(ViolationMetadata)] +pub(crate) struct DeprecatedCElementTree; impl AlwaysFixableViolation for DeprecatedCElementTree { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs index afea8339ca5c9..7fd186eb343d1 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs @@ -1,7 +1,7 @@ use itertools::Itertools; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::whitespace::indentation; use ruff_python_ast::{Alias, StmtImportFrom}; use ruff_python_codegen::Stylist; @@ -60,8 +60,8 @@ enum Deprecation { /// ```python /// from collections.abc import Sequence /// ``` -#[violation] -pub struct DeprecatedImport { +#[derive(ViolationMetadata)] +pub(crate) struct DeprecatedImport { deprecation: Deprecation, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_mock_import.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_mock_import.rs index a5b64150a74ca..4a0c6998e3eac 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_mock_import.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_mock_import.rs @@ -6,7 +6,7 @@ use libcst_native::{ use log::error; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::UnqualifiedName; use ruff_python_ast::whitespace::indentation; use ruff_python_ast::{self as ast, Stmt}; @@ -47,8 +47,8 @@ pub(crate) enum MockReference { /// ## References /// - [Python documentation: `unittest.mock`](https://docs.python.org/3/library/unittest.mock.html) /// - [PyPI: `mock`](https://pypi.org/project/mock/) -#[violation] -pub struct DeprecatedMockImport { +#[derive(ViolationMetadata)] +pub(crate) struct DeprecatedMockImport { reference_type: MockReference, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs index 431ef71b90fac..97a81149dfd99 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs @@ -3,7 +3,7 @@ use rustc_hash::FxHashMap; use std::sync::LazyLock; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -38,8 +38,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python 3.11 documentation: Deprecated aliases](https://docs.python.org/3.11/library/unittest.html#deprecated-aliases) -#[violation] -pub struct DeprecatedUnittestAlias { +#[derive(ViolationMetadata)] +pub(crate) struct DeprecatedUnittestAlias { alias: String, target: String, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/extraneous_parentheses.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/extraneous_parentheses.rs index 01ae1bca21d8b..630fccae242e1 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/extraneous_parentheses.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/extraneous_parentheses.rs @@ -1,7 +1,7 @@ use std::slice::Iter; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_parser::{Token, TokenKind, Tokens}; use ruff_text_size::{Ranged, TextRange}; @@ -23,8 +23,8 @@ use crate::Locator; /// ```python /// print("Hello, world") /// ``` -#[violation] -pub struct ExtraneousParentheses; +#[derive(ViolationMetadata)] +pub(crate) struct ExtraneousParentheses; impl AlwaysFixableViolation for ExtraneousParentheses { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs index 35074fffa838d..213126c32b9db 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs @@ -4,7 +4,7 @@ use anyhow::{Context, Result}; use rustc_hash::{FxHashMap, FxHashSet}; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::any_over_expr; use ruff_python_ast::str::{leading_quote, trailing_quote}; use ruff_python_ast::{self as ast, Expr, Keyword}; @@ -39,8 +39,8 @@ use crate::Locator; /// /// ## References /// - [Python documentation: f-strings](https://docs.python.org/3/reference/lexical_analysis.html#f-strings) -#[violation] -pub struct FString; +#[derive(ViolationMetadata)] +pub(crate) struct FString; impl Violation for FString { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs index fbf589f95974b..372320060eaf8 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs @@ -5,7 +5,7 @@ use libcst_native::{Arg, Expression}; use regex::Regex; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_codegen::Stylist; use ruff_text_size::Ranged; @@ -42,8 +42,8 @@ use crate::Locator; /// ## References /// - [Python documentation: Format String Syntax](https://docs.python.org/3/library/string.html#format-string-syntax) /// - [Python documentation: `str.format`](https://docs.python.org/3/library/stdtypes.html#str.format) -#[violation] -pub struct FormatLiterals; +#[derive(ViolationMetadata)] +pub(crate) struct FormatLiterals; impl Violation for FormatLiterals { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs index e1dba97c40a19..5051ad8b5a12c 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Arguments, Decorator, Expr, Keyword}; use ruff_text_size::{Ranged, TextRange}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::checkers::ast::Checker; use crate::importer::ImportRequest; @@ -40,8 +40,8 @@ use crate::importer::ImportRequest; /// /// ## References /// - [Python documentation: `@functools.cache`](https://docs.python.org/3/library/functools.html#functools.cache) -#[violation] -pub struct LRUCacheWithMaxsizeNone; +#[derive(ViolationMetadata)] +pub(crate) struct LRUCacheWithMaxsizeNone; impl AlwaysFixableViolation for LRUCacheWithMaxsizeNone { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs index 323499934e140..da04f10073b13 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Decorator, Expr}; use ruff_text_size::{Ranged, TextRange}; @@ -38,8 +38,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: `@functools.lru_cache`](https://docs.python.org/3/library/functools.html#functools.lru_cache) /// - [Let lru_cache be used as a decorator with no arguments](https://github.com/python/cpython/issues/80953) -#[violation] -pub struct LRUCacheWithoutParameters; +#[derive(ViolationMetadata)] +pub(crate) struct LRUCacheWithoutParameters; impl AlwaysFixableViolation for LRUCacheWithoutParameters { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs index e916c9d50c833..4e71ee73ae0d4 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs @@ -2,7 +2,7 @@ use std::fmt; use std::str::FromStr; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Int, LiteralExpressionRef, UnaryOp}; use ruff_text_size::{Ranged, TextRange}; @@ -109,8 +109,8 @@ impl fmt::Display for LiteralType { /// - [Python documentation: `int`](https://docs.python.org/3/library/functions.html#int) /// - [Python documentation: `float`](https://docs.python.org/3/library/functions.html#float) /// - [Python documentation: `bool`](https://docs.python.org/3/library/functions.html#bool) -#[violation] -pub struct NativeLiterals { +#[derive(ViolationMetadata)] +pub(crate) struct NativeLiterals { literal_type: LiteralType, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/open_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/open_alias.rs index e66972a4b481e..ad9903850994d 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/open_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/open_alias.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -29,8 +29,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `io.open`](https://docs.python.org/3/library/io.html#io.open) -#[violation] -pub struct OpenAlias; +#[derive(ViolationMetadata)] +pub(crate) struct OpenAlias; impl Violation for OpenAlias { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs index 242ebbc45a992..72b34ecb42760 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs @@ -3,7 +3,7 @@ use ruff_text_size::{Ranged, TextRange}; use crate::fix::edits::pad; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::{Name, UnqualifiedName}; use ruff_python_semantic::SemanticModel; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `OSError`](https://docs.python.org/3/library/exceptions.html#OSError) -#[violation] -pub struct OSErrorAlias { +#[derive(ViolationMetadata)] +pub(crate) struct OSErrorAlias { name: Option, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs index 3ddc582a88447..4bf05db158ae0 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs @@ -3,7 +3,7 @@ use std::cmp::Ordering; use anyhow::Result; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::map_subscript; use ruff_python_ast::stmt_if::{if_elif_branches, BranchKind, IfElifBranch}; use ruff_python_ast::whitespace::indentation; @@ -46,8 +46,8 @@ use crate::settings::types::PythonVersion; /// /// ## References /// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info) -#[violation] -pub struct OutdatedVersionBlock { +#[derive(ViolationMetadata)] +pub(crate) struct OutdatedVersionBlock { reason: Reason, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs index c6b9597c967fc..36f764de95efe 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use std::str::FromStr; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, whitespace::indentation, AnyStringFlags, Expr, StringFlags}; use ruff_python_codegen::Stylist; use ruff_python_literal::cformat::{ @@ -73,8 +73,8 @@ use crate::Locator; /// ## References /// - [Python documentation: `printf`-style String Formatting](https://docs.python.org/3/library/stdtypes.html#old-string-formatting) /// - [Python documentation: `str.format`](https://docs.python.org/3/library/stdtypes.html#str.format) -#[violation] -pub struct PrintfStringFormatting; +#[derive(ViolationMetadata)] +pub(crate) struct PrintfStringFormatting; impl Violation for PrintfStringFormatting { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/quoted_annotation.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/quoted_annotation.rs index eccac9bf7ee0b..7ee7cee03a919 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/quoted_annotation.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/quoted_annotation.rs @@ -1,7 +1,7 @@ use ruff_text_size::TextRange; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::checkers::ast::Checker; @@ -57,8 +57,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [PEP 563 – Postponed Evaluation of Annotations](https://peps.python.org/pep-0563/) /// - [Python documentation: `__future__`](https://docs.python.org/3/library/__future__.html#module-__future__) -#[violation] -pub struct QuotedAnnotation; +#[derive(ViolationMetadata)] +pub(crate) struct QuotedAnnotation; impl AlwaysFixableViolation for QuotedAnnotation { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs index 321907aae44b1..1b4dccc0c27ea 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs @@ -1,6 +1,6 @@ use anyhow::Result; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_codegen::Stylist; use ruff_python_parser::{TokenKind, Tokens}; @@ -30,8 +30,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `open`](https://docs.python.org/3/library/functions.html#open) -#[violation] -pub struct RedundantOpenModes { +#[derive(ViolationMetadata)] +pub(crate) struct RedundantOpenModes { replacement: String, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_stdout_stderr.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_stdout_stderr.rs index eb3975445df33..b6088e65f12dc 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_stdout_stderr.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_stdout_stderr.rs @@ -1,7 +1,7 @@ use anyhow::Result; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Keyword}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -36,8 +36,8 @@ use crate::fix::edits::{remove_argument, Parentheses}; /// ## References /// - [Python 3.7 release notes](https://docs.python.org/3/whatsnew/3.7.html#subprocess) /// - [Python documentation: `subprocess.run`](https://docs.python.org/3/library/subprocess.html#subprocess.run) -#[violation] -pub struct ReplaceStdoutStderr; +#[derive(ViolationMetadata)] +pub(crate) struct ReplaceStdoutStderr; impl Violation for ReplaceStdoutStderr { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs index a5c9daaa63ed6..75a7adf0c57f4 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_str_enum.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::identifier::Identifier; use ruff_text_size::Ranged; @@ -77,8 +77,8 @@ use crate::importer::ImportRequest; /// /// [breaking change]: https://blog.pecar.me/python-enum -#[violation] -pub struct ReplaceStrEnum { +#[derive(ViolationMetadata)] +pub(crate) struct ReplaceStrEnum { name: String, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_universal_newlines.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_universal_newlines.rs index 8f146650b8ea7..b951f05d04c7f 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_universal_newlines.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_universal_newlines.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -34,8 +34,8 @@ use crate::fix::edits::{remove_argument, Parentheses}; /// ## References /// - [Python 3.7 release notes](https://docs.python.org/3/whatsnew/3.7.html#subprocess) /// - [Python documentation: `subprocess.run`](https://docs.python.org/3/library/subprocess.html#subprocess.run) -#[violation] -pub struct ReplaceUniversalNewlines; +#[derive(ViolationMetadata)] +pub(crate) struct ReplaceUniversalNewlines; impl AlwaysFixableViolation for ReplaceUniversalNewlines { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs index 4535ffdca482d..132dddb2ce983 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Parameter, ParameterWithDefault, Stmt}; use ruff_text_size::{Ranged, TextSize}; @@ -43,8 +43,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: `super`](https://docs.python.org/3/library/functions.html#super) /// - [super/MRO, Python's most misunderstood feature.](https://www.youtube.com/watch?v=X1PQ7zzltz4) -#[violation] -pub struct SuperCallWithParameters; +#[derive(ViolationMetadata)] +pub(crate) struct SuperCallWithParameters; impl AlwaysFixableViolation for SuperCallWithParameters { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs index cd1e45eafcfc3..3591c9940b478 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs @@ -3,7 +3,7 @@ use ruff_text_size::{Ranged, TextRange}; use crate::fix::edits::pad; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::{Name, UnqualifiedName}; use ruff_python_semantic::SemanticModel; @@ -37,8 +37,8 @@ use crate::settings::types::PythonVersion; /// /// ## References /// - [Python documentation: `TimeoutError`](https://docs.python.org/3/library/exceptions.html#TimeoutError) -#[violation] -pub struct TimeoutErrorAlias { +#[derive(ViolationMetadata)] +pub(crate) struct TimeoutErrorAlias { name: Option, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs index 5ab47cb0c9c2d..2dffa3c81d8af 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs @@ -2,7 +2,7 @@ use ruff_python_ast::Expr; use crate::fix::edits::pad; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -30,8 +30,8 @@ use super::super::types::Primitive; /// ## References /// - [Python documentation: `type()`](https://docs.python.org/3/library/functions.html#type) /// - [Python documentation: Built-in types](https://docs.python.org/3/library/stdtypes.html) -#[violation] -pub struct TypeOfPrimitive { +#[derive(ViolationMetadata)] +pub(crate) struct TypeOfPrimitive { primitive: Primitive, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs index 36ee53e368663..51d1516a40225 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -29,8 +29,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `typing.Text`](https://docs.python.org/3/library/typing.html#typing.Text) -#[violation] -pub struct TypingTextStrAlias; +#[derive(ViolationMetadata)] +pub(crate) struct TypingTextStrAlias; impl Violation for TypingTextStrAlias { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs index 4ff21b5e0139f..33d68c9281ab5 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::StringLiteral; use ruff_text_size::{Ranged, TextRange, TextSize}; @@ -24,8 +24,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: Unicode HOWTO](https://docs.python.org/3/howto/unicode.html) -#[violation] -pub struct UnicodeKindPrefix; +#[derive(ViolationMetadata)] +pub(crate) struct UnicodeKindPrefix; impl AlwaysFixableViolation for UnicodeKindPrefix { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs index ccb7d12c353c6..167cfd1406c1f 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs @@ -2,7 +2,7 @@ use itertools::Itertools; use ruff_python_ast::{Alias, Stmt}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -29,8 +29,8 @@ use crate::fix; /// /// ## References /// - [Python documentation: The Python Standard Library](https://docs.python.org/3/library/index.html) -#[violation] -pub struct UnnecessaryBuiltinImport { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryBuiltinImport { pub names: Vec, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs index d37cf32428e91..5e9703b0f71d5 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast}; use ruff_text_size::Ranged; @@ -24,8 +24,8 @@ use crate::checkers::ast::Checker; /// class Foo: /// ... /// ``` -#[violation] -pub struct UnnecessaryClassParentheses; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryClassParentheses; impl AlwaysFixableViolation for UnnecessaryClassParentheses { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs index 10addc6770cd3..1a0160bf8320d 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs @@ -3,7 +3,7 @@ use std::sync::LazyLock; use regex::Regex; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_index::Indexer; use ruff_python_trivia::CommentRanges; use ruff_source_file::LineRanges; @@ -30,8 +30,8 @@ use crate::Locator; /// ``` /// /// [PEP 3120]: https://peps.python.org/pep-3120/ -#[violation] -pub struct UTF8EncodingDeclaration; +#[derive(ViolationMetadata)] +pub(crate) struct UTF8EncodingDeclaration; impl AlwaysFixableViolation for UTF8EncodingDeclaration { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_default_type_args.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_default_type_args.rs index 3cf8d65efd5a2..d7783c98de926 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_default_type_args.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_default_type_args.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Applicability, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::{Ranged, TextRange}; @@ -59,8 +59,8 @@ use crate::checkers::ast::Checker; /// - [Annotating generators and coroutines](https://docs.python.org/3/library/typing.html#annotating-generators-and-coroutines) /// - [Python documentation: `typing.Generator`](https://docs.python.org/3/library/typing.html#typing.Generator) /// - [Python documentation: `typing.AsyncGenerator`](https://docs.python.org/3/library/typing.html#typing.AsyncGenerator) -#[violation] -pub struct UnnecessaryDefaultTypeArgs; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryDefaultTypeArgs; impl AlwaysFixableViolation for UnnecessaryDefaultTypeArgs { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs index 47528abb870ad..89f53b46c17a4 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Arguments, Expr, Keyword}; use ruff_python_parser::{TokenKind, Tokens}; use ruff_text_size::{Ranged, TextRange}; @@ -27,8 +27,8 @@ use crate::Locator; /// /// ## References /// - [Python documentation: `str.encode`](https://docs.python.org/3/library/stdtypes.html#str.encode) -#[violation] -pub struct UnnecessaryEncodeUTF8 { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryEncodeUTF8 { reason: Reason, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs index c713a04673d31..6fb174e7fbd84 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs @@ -2,7 +2,7 @@ use itertools::Itertools; use ruff_python_ast::{Alias, Stmt}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -35,8 +35,8 @@ use crate::fix; /// /// ## References /// - [Python documentation: `__future__` — Future statement definitions](https://docs.python.org/3/library/__future__.html) -#[violation] -pub struct UnnecessaryFutureImport { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryFutureImport { pub names: Vec, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs index c9f72d5431435..5c8d28ec462f2 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::violation; +use ruff_macros::ViolationMetadata; /// ## Removed /// There's no [evidence](https://github.com/astral-sh/ruff/issues/12754) that generators are @@ -26,8 +26,8 @@ use ruff_macros::violation; /// ## References /// - [Python documentation: Generator expressions](https://docs.python.org/3/reference/expressions.html#generator-expressions) /// - [Python documentation: List comprehensions](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions) -#[violation] -pub struct UnpackedListComprehension; +#[derive(ViolationMetadata)] +pub(crate) struct UnpackedListComprehension; impl Violation for UnpackedListComprehension { fn message(&self) -> String { diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep585_annotation.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep585_annotation.rs index d44a182dc5155..1e08b7e9aa176 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep585_annotation.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep585_annotation.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::UnqualifiedName; use ruff_python_semantic::analyze::typing::ModuleMember; use ruff_text_size::Ranged; @@ -54,8 +54,8 @@ use crate::settings::types::PythonVersion; /// - `lint.pyupgrade.keep-runtime-typing` /// /// [PEP 585]: https://peps.python.org/pep-0585/ -#[violation] -pub struct NonPEP585Annotation { +#[derive(ViolationMetadata)] +pub(crate) struct NonPEP585Annotation { from: String, to: String, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs index 9a58f984f0348..e4fe1f16d8139 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::{pep_604_optional, pep_604_union}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::analyze::typing::Pep604Operator; @@ -49,8 +49,8 @@ use crate::settings::types::PythonVersion; /// - `lint.pyupgrade.keep-runtime-typing` /// /// [PEP 604]: https://peps.python.org/pep-0604/ -#[violation] -pub struct NonPEP604Annotation; +#[derive(ViolationMetadata)] +pub(crate) struct NonPEP604Annotation; impl Violation for NonPEP604Annotation { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs index 92db5e57b1e5f..d1d9c5cf78722 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::pep_604_union; use ruff_python_ast::Expr; use ruff_text_size::Ranged; @@ -64,8 +64,8 @@ impl CallKind { /// - [Python documentation: `issubclass`](https://docs.python.org/3/library/functions.html#issubclass) /// /// [PEP 604]: https://peps.python.org/pep-0604/ -#[violation] -pub struct NonPEP604Isinstance { +#[derive(ViolationMetadata)] +pub(crate) struct NonPEP604Isinstance { kind: CallKind, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep646_unpack.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep646_unpack.rs index 080f21fbcf337..b31e59a537bed 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep646_unpack.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep646_unpack.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::ExprSubscript; use ruff_python_semantic::SemanticModel; @@ -35,8 +35,8 @@ use crate::{checkers::ast::Checker, settings::types::PythonVersion}; /// the fix should be safe to apply. /// /// [PEP 646]: https://peps.python.org/pep-0646/ -#[violation] -pub struct NonPEP646Unpack; +#[derive(ViolationMetadata)] +pub(crate) struct NonPEP646Unpack; impl Violation for NonPEP646Unpack { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Always; diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs index dc3072ff08396..a2b09b46ae72a 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs @@ -1,7 +1,7 @@ use itertools::Itertools; use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::Name; use ruff_python_ast::{ self as ast, @@ -49,8 +49,8 @@ use crate::settings::types::PythonVersion; /// ``` /// /// [PEP 695]: https://peps.python.org/pep-0695/ -#[violation] -pub struct NonPEP695TypeAlias { +#[derive(ViolationMetadata)] +pub(crate) struct NonPEP695TypeAlias { name: String, type_alias_kind: TypeAliasKind, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs index f3df7fe4fd14f..47d6ba5e92aa2 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -28,8 +28,8 @@ use crate::fix; /// /// ## References /// - [PEP 3115 – Metaclasses in Python 3000](https://peps.python.org/pep-3115/) -#[violation] -pub struct UselessMetaclassType; +#[derive(ViolationMetadata)] +pub(crate) struct UselessMetaclassType; impl AlwaysFixableViolation for UselessMetaclassType { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs index bc513b7fb19b4..243ce6e86f6d1 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_text_size::Ranged; @@ -27,8 +27,8 @@ use crate::fix::edits::{remove_argument, Parentheses}; /// /// ## References /// - [PEP 3115 – Metaclasses in Python 3000](https://peps.python.org/pep-3115/) -#[violation] -pub struct UselessObjectInheritance { +#[derive(ViolationMetadata)] +pub(crate) struct UselessObjectInheritance { name: String, } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs index 59b2f93b7228d..ab69c25e180c0 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_text_size::Ranged; @@ -37,8 +37,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: The `yield` statement](https://docs.python.org/3/reference/simple_stmts.html#the-yield-statement) /// - [PEP 380 – Syntax for Delegating to a Subgenerator](https://peps.python.org/pep-0380/) -#[violation] -pub struct YieldInForLoop; +#[derive(ViolationMetadata)] +pub(crate) struct YieldInForLoop; impl AlwaysFixableViolation for YieldInForLoop { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs b/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs index 74daeb508580f..713d5844603d5 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/bit_count.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, ExprAttribute, ExprCall}; use ruff_text_size::Ranged; @@ -31,8 +31,8 @@ use crate::{checkers::ast::Checker, settings::types::PythonVersion}; /// /// ## References /// - [Python documentation:`int.bit_count`](https://docs.python.org/3/library/stdtypes.html#int.bit_count) -#[violation] -pub struct BitCount { +#[derive(ViolationMetadata)] +pub(crate) struct BitCount { existing: SourceCodeSnippet, replacement: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs b/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs index ffa8761b4a6d9..5290d98c37cab 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::helpers::contains_effect; use ruff_python_ast::{self as ast, CmpOp, Expr, Stmt}; @@ -39,8 +39,8 @@ use crate::fix::snippet::SourceCodeSnippet; /// /// ## References /// - [Python documentation: `set.discard()`](https://docs.python.org/3/library/stdtypes.html?highlight=list#frozenset.discard) -#[violation] -pub struct CheckAndRemoveFromSet { +#[derive(ViolationMetadata)] +pub(crate) struct CheckAndRemoveFromSet { element: SourceCodeSnippet, set: String, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/delete_full_slice.rs b/crates/ruff_linter/src/rules/refurb/rules/delete_full_slice.rs index df9712432948c..99df2e9cae1ca 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/delete_full_slice.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/delete_full_slice.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::analyze::typing::{is_dict, is_list}; use ruff_python_semantic::SemanticModel; @@ -43,8 +43,8 @@ use crate::rules::refurb::helpers::generate_method_call; /// ## References /// - [Python documentation: Mutable Sequence Types](https://docs.python.org/3/library/stdtypes.html?highlight=list#mutable-sequence-types) /// - [Python documentation: `dict.clear()`](https://docs.python.org/3/library/stdtypes.html?highlight=list#dict.clear) -#[violation] -pub struct DeleteFullSlice; +#[derive(ViolationMetadata)] +pub(crate) struct DeleteFullSlice; impl Violation for DeleteFullSlice { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/refurb/rules/for_loop_set_mutations.rs b/crates/ruff_linter/src/rules/refurb/rules/for_loop_set_mutations.rs index b019c6bd3c6a5..909ca440d6483 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/for_loop_set_mutations.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/for_loop_set_mutations.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Expr, Stmt, StmtFor}; use ruff_python_semantic::analyze::typing; @@ -36,8 +36,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `set`](https://docs.python.org/3/library/stdtypes.html#set) -#[violation] -pub struct ForLoopSetMutations { +#[derive(ViolationMetadata)] +pub(crate) struct ForLoopSetMutations { method_name: &'static str, batch_method_name: &'static str, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/fstring_number_format.rs b/crates/ruff_linter/src/rules/refurb/rules/fstring_number_format.rs index 096fc1364ec4c..34fc9b84d7fb8 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/fstring_number_format.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/fstring_number_format.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, ExprCall}; use ruff_text_size::Ranged; @@ -24,8 +24,8 @@ use crate::fix::snippet::SourceCodeSnippet; /// ```python /// print(f"{1337:b}") /// ``` -#[violation] -pub struct FStringNumberFormat { +#[derive(ViolationMetadata)] +pub(crate) struct FStringNumberFormat { replacement: Option, base: Base, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/hardcoded_string_charset.rs b/crates/ruff_linter/src/rules/refurb/rules/hardcoded_string_charset.rs index fe6337707773b..a9d3921fa8a57 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/hardcoded_string_charset.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/hardcoded_string_charset.rs @@ -1,7 +1,7 @@ use crate::checkers::ast::Checker; use crate::importer::ImportRequest; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::ExprStringLiteral; use ruff_text_size::TextRange; @@ -27,8 +27,8 @@ use ruff_text_size::TextRange; /// /// ## References /// - [Python documentation: String constants](https://docs.python.org/3/library/string.html#string-constants) -#[violation] -pub struct HardcodedStringCharset { +#[derive(ViolationMetadata)] +pub(crate) struct HardcodedStringCharset { name: &'static str, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/hashlib_digest_hex.rs b/crates/ruff_linter/src/rules/refurb/rules/hashlib_digest_hex.rs index fcd22f435b45e..7b53364063501 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/hashlib_digest_hex.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/hashlib_digest_hex.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Expr, ExprAttribute, ExprCall}; use ruff_text_size::{Ranged, TextRange}; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `hashlib`](https://docs.python.org/3/library/hashlib.html) -#[violation] -pub struct HashlibDigestHex; +#[derive(ViolationMetadata)] +pub(crate) struct HashlibDigestHex; impl Violation for HashlibDigestHex { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/refurb/rules/if_exp_instead_of_or_operator.rs b/crates/ruff_linter/src/rules/refurb/rules/if_exp_instead_of_or_operator.rs index f1651ad2cd3c9..1331c9eb22eb2 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/if_exp_instead_of_or_operator.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/if_exp_instead_of_or_operator.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::helpers::contains_effect; @@ -38,8 +38,8 @@ use crate::Locator; /// For example, `foo` will be called twice in `foo() if foo() else bar()` /// (assuming `foo()` returns a truthy value), but only once in /// `foo() or bar()`. -#[violation] -pub struct IfExpInsteadOfOrOperator; +#[derive(ViolationMetadata)] +pub(crate) struct IfExpInsteadOfOrOperator; impl Violation for IfExpInsteadOfOrOperator { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/refurb/rules/if_expr_min_max.rs b/crates/ruff_linter/src/rules/refurb/rules/if_expr_min_max.rs index 1c25a17e871cd..5e9423e46f613 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/if_expr_min_max.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/if_expr_min_max.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::{self as ast, CmpOp, Expr}; use ruff_text_size::Ranged; @@ -30,8 +30,8 @@ use crate::fix::snippet::SourceCodeSnippet; /// ## References /// - [Python documentation: `min`](https://docs.python.org/3.11/library/functions.html#min) /// - [Python documentation: `max`](https://docs.python.org/3.11/library/functions.html#max) -#[violation] -pub struct IfExprMinMax { +#[derive(ViolationMetadata)] +pub(crate) struct IfExprMinMax { min_max: MinMax, expression: SourceCodeSnippet, replacement: SourceCodeSnippet, diff --git a/crates/ruff_linter/src/rules/refurb/rules/implicit_cwd.rs b/crates/ruff_linter/src/rules/refurb/rules/implicit_cwd.rs index 82c1595b07b41..d60b9850cac4d 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/implicit_cwd.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/implicit_cwd.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, ExprAttribute, ExprCall}; use ruff_text_size::Ranged; @@ -25,8 +25,8 @@ use crate::{checkers::ast::Checker, importer::ImportRequest}; /// ## References /// - [Python documentation: `Path.cwd`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.cwd) -#[violation] -pub struct ImplicitCwd; +#[derive(ViolationMetadata)] +pub(crate) struct ImplicitCwd; impl Violation for ImplicitCwd { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs b/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs index 630508d153d24..28a52cad8b137 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Expr, ExprCall, Identifier}; use ruff_text_size::Ranged; @@ -47,8 +47,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `int`](https://docs.python.org/3/library/functions.html#int) -#[violation] -pub struct IntOnSlicedStr { +#[derive(ViolationMetadata)] +pub(crate) struct IntOnSlicedStr { base: u8, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs b/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs index d08d0442dbe09..e32acd64ccd83 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/isinstance_type_none.rs @@ -1,7 +1,7 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; use ruff_python_ast::{self as ast, Expr, Operator}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -30,8 +30,8 @@ use crate::rules::refurb::helpers::generate_none_identity_comparison; /// - [Python documentation: `None`](https://docs.python.org/3/library/constants.html#None) /// - [Python documentation: `type`](https://docs.python.org/3/library/functions.html#type) /// - [Python documentation: Identity comparisons](https://docs.python.org/3/reference/expressions.html#is-not) -#[violation] -pub struct IsinstanceTypeNone; +#[derive(ViolationMetadata)] +pub(crate) struct IsinstanceTypeNone; impl Violation for IsinstanceTypeNone { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs b/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs index 0f1346fce9ecd..714a43110d43a 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{ Expr, ExprCall, ExprName, ExprSlice, ExprSubscript, ExprUnaryOp, Int, StmtAssign, UnaryOp, }; @@ -46,8 +46,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: More on Lists](https://docs.python.org/3/tutorial/datastructures.html#more-on-lists) -#[violation] -pub struct ListReverseCopy { +#[derive(ViolationMetadata)] +pub(crate) struct ListReverseCopy { name: String, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/math_constant.rs b/crates/ruff_linter/src/rules/refurb/rules/math_constant.rs index 6ec50d7c68a12..e2085cf879bdb 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/math_constant.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/math_constant.rs @@ -1,7 +1,7 @@ use anyhow::Result; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Number}; use ruff_text_size::Ranged; @@ -27,8 +27,8 @@ use crate::importer::ImportRequest; /// /// ## References /// - [Python documentation: `math` constants](https://docs.python.org/3/library/math.html#constants) -#[violation] -pub struct MathConstant { +#[derive(ViolationMetadata)] +pub(crate) struct MathConstant { literal: String, constant: &'static str, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/metaclass_abcmeta.rs b/crates/ruff_linter/src/rules/refurb/rules/metaclass_abcmeta.rs index 5da1cb8429ea9..72c371684470a 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/metaclass_abcmeta.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/metaclass_abcmeta.rs @@ -1,7 +1,7 @@ use itertools::Itertools; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::StmtClassDef; use ruff_text_size::{Ranged, TextRange}; @@ -34,8 +34,8 @@ use crate::importer::ImportRequest; /// ## References /// - [Python documentation: `abc.ABC`](https://docs.python.org/3/library/abc.html#abc.ABC) /// - [Python documentation: `abc.ABCMeta`](https://docs.python.org/3/library/abc.html#abc.ABCMeta) -#[violation] -pub struct MetaClassABCMeta; +#[derive(ViolationMetadata)] +pub(crate) struct MetaClassABCMeta; impl AlwaysFixableViolation for MetaClassABCMeta { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs b/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs index 7ffc2676424a6..f5a6c7de4ab4b 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::contains_effect; use ruff_python_ast::{self as ast, Expr}; use ruff_python_codegen::Generator; @@ -32,8 +32,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `print`](https://docs.python.org/3/library/functions.html#print) -#[violation] -pub struct PrintEmptyString { +#[derive(ViolationMetadata)] +pub(crate) struct PrintEmptyString { reason: Reason, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs b/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs index b0c2424a552d5..2a9db8f2283de 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::visitor::{self, Visitor}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_codegen::Generator; @@ -35,8 +35,8 @@ use super::super::helpers::{find_file_opens, FileOpen}; /// ## References /// - [Python documentation: `Path.read_bytes`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.read_bytes) /// - [Python documentation: `Path.read_text`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.read_text) -#[violation] -pub struct ReadWholeFile { +#[derive(ViolationMetadata)] +pub(crate) struct ReadWholeFile { filename: SourceCodeSnippet, suggestion: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/readlines_in_for.rs b/crates/ruff_linter/src/rules/refurb/rules/readlines_in_for.rs index 29f7546ed869c..120dfa88dd0c7 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/readlines_in_for.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/readlines_in_for.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Comprehension, Expr, StmtFor}; use ruff_python_semantic::analyze::typing; use ruff_python_semantic::analyze::typing::is_io_base_expr; @@ -31,7 +31,7 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `io.IOBase.readlines`](https://docs.python.org/3/library/io.html#io.IOBase.readlines) -#[violation] +#[derive(ViolationMetadata)] pub(crate) struct ReadlinesInFor; impl AlwaysFixableViolation for ReadlinesInFor { diff --git a/crates/ruff_linter/src/rules/refurb/rules/redundant_log_base.rs b/crates/ruff_linter/src/rules/refurb/rules/redundant_log_base.rs index 447a6ef704737..e072b428d17ce 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/redundant_log_base.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/redundant_log_base.rs @@ -1,6 +1,6 @@ use anyhow::Result; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, Number}; use ruff_text_size::Ranged; @@ -41,8 +41,8 @@ use crate::importer::ImportRequest; /// - [Python documentation: `math.log2`](https://docs.python.org/3/library/math.html#math.log2) /// - [Python documentation: `math.log10`](https://docs.python.org/3/library/math.html#math.log10) /// - [Python documentation: `math.e`](https://docs.python.org/3/library/math.html#math.e) -#[violation] -pub struct RedundantLogBase { +#[derive(ViolationMetadata)] +pub(crate) struct RedundantLogBase { base: Base, arg: String, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/regex_flag_alias.rs b/crates/ruff_linter/src/rules/refurb/rules/regex_flag_alias.rs index f04768b0a3162..5798c21501dab 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/regex_flag_alias.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/regex_flag_alias.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Expr; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -32,8 +32,8 @@ use crate::importer::ImportRequest; /// ... /// ``` /// -#[violation] -pub struct RegexFlagAlias { +#[derive(ViolationMetadata)] +pub(crate) struct RegexFlagAlias { flag: RegexFlag, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs index 2a56ce706ef40..42f7760027cfa 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs @@ -5,7 +5,7 @@ use anyhow::Result; use itertools::Itertools; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::any_over_expr; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::{self as ast, Expr, ExprSlice, ExprSubscript, ExprTuple, Parameters, Stmt}; @@ -48,8 +48,8 @@ use crate::Locator; /// `add = lambda x, y: x + y; add(x=1, y=2)`, replacing the lambda with an operator function, e.g., /// `operator.add`, will cause the call to raise a `TypeError`, as functions in `operator` do not allow /// keyword arguments. -#[violation] -pub struct ReimplementedOperator { +#[derive(ViolationMetadata)] +pub(crate) struct ReimplementedOperator { operator: Operator, target: FunctionLikeKind, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs index ad1e1f4a4b2e5..f6cab645d588d 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs @@ -1,6 +1,6 @@ use anyhow::{bail, Result}; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::helpers::any_over_expr; use ruff_python_ast::name::Name; @@ -64,8 +64,8 @@ use crate::importer::ImportRequest; /// /// [PEP 709]: https://peps.python.org/pep-0709/ /// [#7771]: https://github.com/astral-sh/ruff/issues/7771 -#[violation] -pub struct ReimplementedStarmap; +#[derive(ViolationMetadata)] +pub(crate) struct ReimplementedStarmap; impl Violation for ReimplementedStarmap { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs b/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs index 1489932e9f4ed..f650ebb26f965 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs @@ -2,7 +2,7 @@ use rustc_hash::FxHashMap; use ast::traversal; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::traversal::EnclosingSuite; use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_python_codegen::Generator; @@ -44,8 +44,8 @@ use crate::fix::snippet::SourceCodeSnippet; /// /// ## References /// - [Python documentation: More on Lists](https://docs.python.org/3/tutorial/datastructures.html#more-on-lists) -#[violation] -pub struct RepeatedAppend { +#[derive(ViolationMetadata)] +pub(crate) struct RepeatedAppend { name: String, replacement: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/repeated_global.rs b/crates/ruff_linter/src/rules/refurb/rules/repeated_global.rs index 2e1deb0065d65..913318a300ad0 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/repeated_global.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/repeated_global.rs @@ -1,7 +1,7 @@ use itertools::Itertools; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Stmt; use ruff_text_size::Ranged; @@ -36,8 +36,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: the `global` statement](https://docs.python.org/3/reference/simple_stmts.html#the-global-statement) /// - [Python documentation: the `nonlocal` statement](https://docs.python.org/3/reference/simple_stmts.html#the-nonlocal-statement) -#[violation] -pub struct RepeatedGlobal { +#[derive(ViolationMetadata)] +pub(crate) struct RepeatedGlobal { global_kind: GlobalKind, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/single_item_membership_test.rs b/crates/ruff_linter/src/rules/refurb/rules/single_item_membership_test.rs index c9b3e76b4fe1e..2d5cefacc4639 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/single_item_membership_test.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/single_item_membership_test.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::generate_comparison; use ruff_python_ast::{self as ast, CmpOp, Expr, ExprStringLiteral}; use ruff_text_size::Ranged; @@ -28,8 +28,8 @@ use crate::fix::edits::pad; /// ## References /// - [Python documentation: Comparisons](https://docs.python.org/3/reference/expressions.html#comparisons) /// - [Python documentation: Membership test operations](https://docs.python.org/3/reference/expressions.html#membership-test-operations) -#[violation] -pub struct SingleItemMembershipTest { +#[derive(ViolationMetadata)] +pub(crate) struct SingleItemMembershipTest { membership_test: MembershipTest, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/slice_copy.rs b/crates/ruff_linter/src/rules/refurb/rules/slice_copy.rs index d4dda27718e3e..8e79e976dc99a 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/slice_copy.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/slice_copy.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::Name; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::analyze::typing::is_list; @@ -36,8 +36,8 @@ use crate::rules::refurb::helpers::generate_method_call; /// /// ## References /// - [Python documentation: Mutable Sequence Types](https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types) -#[violation] -pub struct SliceCopy; +#[derive(ViolationMetadata)] +pub(crate) struct SliceCopy; impl Violation for SliceCopy { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs b/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs index a8ada080d6850..230c16b01034d 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::SemanticModel; use ruff_text_size::Ranged; @@ -35,9 +35,8 @@ use crate::{checkers::ast::Checker, settings::types::PythonVersion}; /// ```python /// text = text.removeprefix("pre") /// ``` -#[violation] -pub struct SliceToRemovePrefixOrSuffix { - string: String, +#[derive(ViolationMetadata)] +pub(crate) struct SliceToRemovePrefixOrSuffix { affix_kind: AffixKind, stmt_or_expression: StmtOrExpr, } @@ -80,7 +79,6 @@ pub(crate) fn slice_to_remove_affix_expr(checker: &mut Checker, if_expr: &ast::E let mut diagnostic = Diagnostic::new( SliceToRemovePrefixOrSuffix { affix_kind: kind, - string: checker.locator().slice(text).to_string(), stmt_or_expression: StmtOrExpr::Expression, }, if_expr.range, @@ -111,7 +109,6 @@ pub(crate) fn slice_to_remove_affix_stmt(checker: &mut Checker, if_stmt: &ast::S let mut diagnostic = Diagnostic::new( SliceToRemovePrefixOrSuffix { affix_kind: kind, - string: checker.locator().slice(text).to_string(), stmt_or_expression: StmtOrExpr::Statement, }, if_stmt.range, diff --git a/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs b/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs index 25c9dea59f9bb..3f41823596b07 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs @@ -3,7 +3,7 @@ use ruff_diagnostics::Edit; use ruff_diagnostics::Fix; use ruff_diagnostics::FixAvailability; use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Number; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -47,8 +47,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: `min`](https://docs.python.org/3/library/functions.html#min) /// - [Python documentation: `max`](https://docs.python.org/3/library/functions.html#max) -#[violation] -pub struct SortedMinMax { +#[derive(ViolationMetadata)] +pub(crate) struct SortedMinMax { min_max: MinMax, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/subclass_builtin.rs b/crates/ruff_linter/src/rules/refurb/rules/subclass_builtin.rs index 41575b3d341ba..8fed10b623038 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/subclass_builtin.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/subclass_builtin.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Arguments, StmtClassDef}; use ruff_text_size::Ranged; @@ -40,8 +40,8 @@ use crate::{checkers::ast::Checker, importer::ImportRequest}; /// ## References /// /// - [Python documentation: `collections`](https://docs.python.org/3/library/collections.html) -#[violation] -pub struct SubclassBuiltin { +#[derive(ViolationMetadata)] +pub(crate) struct SubclassBuiltin { subclass: String, replacement: String, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/type_none_comparison.rs b/crates/ruff_linter/src/rules/refurb/rules/type_none_comparison.rs index 6f714b99c6f4e..863d3f2e07e64 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/type_none_comparison.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/type_none_comparison.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::Name; use ruff_python_ast::{self as ast, CmpOp, Expr}; use ruff_python_semantic::SemanticModel; @@ -32,8 +32,8 @@ use crate::rules::refurb::helpers::generate_none_identity_comparison; /// - [Python documentation: `None`](https://docs.python.org/3/library/constants.html#None) /// - [Python documentation: `type`](https://docs.python.org/3/library/functions.html#type) /// - [Python documentation: Identity comparisons](https://docs.python.org/3/reference/expressions.html#is-not) -#[violation] -pub struct TypeNoneComparison { +#[derive(ViolationMetadata)] +pub(crate) struct TypeNoneComparison { object: Name, comparison: Comparison, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs index b204767f47432..9e3e890a2fee3 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::name::Name; use ruff_python_ast::{Arguments, Expr, Int}; @@ -57,8 +57,8 @@ use crate::fix::edits::pad; /// - [Python documentation: `enumerate`](https://docs.python.org/3/library/functions.html#enumerate) /// - [Python documentation: `range`](https://docs.python.org/3/library/stdtypes.html#range) /// - [Python documentation: `len`](https://docs.python.org/3/library/functions.html#len) -#[violation] -pub struct UnnecessaryEnumerate { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryEnumerate { subset: EnumerateSubset, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs index f37f6f25a473f..4c5ffe62ccfa0 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_from_float.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, ExprCall}; use ruff_text_size::Ranged; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: `decimal`](https://docs.python.org/3/library/decimal.html) /// - [Python documentation: `fractions`](https://docs.python.org/3/library/fractions.html) -#[violation] -pub struct UnnecessaryFromFloat { +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryFromFloat { method_name: MethodName, constructor: Constructor, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs b/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs index 559458cc57ef8..d13ed51d08b16 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_trivia::PythonWhitespace; use ruff_text_size::Ranged; @@ -37,8 +37,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `decimal`](https://docs.python.org/3/library/decimal.html) -#[violation] -pub struct VerboseDecimalConstructor { +#[derive(ViolationMetadata)] +pub(crate) struct VerboseDecimalConstructor { replacement: String, } diff --git a/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs b/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs index b9993e2b34432..798020c78c9f5 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::relocate::relocate_expr; use ruff_python_ast::visitor::{self, Visitor}; use ruff_python_ast::{self as ast, Expr, Stmt}; @@ -36,8 +36,8 @@ use super::super::helpers::{find_file_opens, FileOpen}; /// ## References /// - [Python documentation: `Path.write_bytes`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.write_bytes) /// - [Python documentation: `Path.write_text`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.write_text) -#[violation] -pub struct WriteWholeFile { +#[derive(ViolationMetadata)] +pub(crate) struct WriteWholeFile { filename: SourceCodeSnippet, suggestion: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs b/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs index 23b6183689dee..dd507ff551d36 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs @@ -3,7 +3,7 @@ use std::fmt; use bitflags::bitflags; use ruff_diagnostics::{Diagnostic, DiagnosticKind, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, StringLike}; use ruff_text_size::{Ranged, TextLen, TextRange, TextSize}; @@ -46,8 +46,8 @@ use crate::Locator; /// - `lint.allowed-confusables` /// /// [preview]: https://docs.astral.sh/ruff/preview/ -#[violation] -pub struct AmbiguousUnicodeCharacterString { +#[derive(ViolationMetadata)] +pub(crate) struct AmbiguousUnicodeCharacterString { confusable: char, representant: char, } @@ -99,8 +99,8 @@ impl Violation for AmbiguousUnicodeCharacterString { /// - `lint.allowed-confusables` /// /// [preview]: https://docs.astral.sh/ruff/preview/ -#[violation] -pub struct AmbiguousUnicodeCharacterDocstring { +#[derive(ViolationMetadata)] +pub(crate) struct AmbiguousUnicodeCharacterDocstring { confusable: char, representant: char, } @@ -152,8 +152,8 @@ impl Violation for AmbiguousUnicodeCharacterDocstring { /// - `lint.allowed-confusables` /// /// [preview]: https://docs.astral.sh/ruff/preview/ -#[violation] -pub struct AmbiguousUnicodeCharacterComment { +#[derive(ViolationMetadata)] +pub(crate) struct AmbiguousUnicodeCharacterComment { confusable: char, representant: char, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs b/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs index 4d2756e1771a3..da9b3de4fc65a 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs @@ -2,7 +2,7 @@ use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_text_size::{Ranged, TextRange}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use crate::checkers::ast::Checker; @@ -37,8 +37,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `assert`](https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement) -#[violation] -pub struct AssertWithPrintMessage; +#[derive(ViolationMetadata)] +pub(crate) struct AssertWithPrintMessage; impl AlwaysFixableViolation for AssertWithPrintMessage { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/assignment_in_assert.rs b/crates/ruff_linter/src/rules/ruff/rules/assignment_in_assert.rs index 9053fdba93ed0..32e5b57e20bfb 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/assignment_in_assert.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/assignment_in_assert.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -33,8 +33,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `-O`](https://docs.python.org/3/using/cmdline.html#cmdoption-O) -#[violation] -pub struct AssignmentInAssert; +#[derive(ViolationMetadata)] +pub(crate) struct AssignmentInAssert; impl Violation for AssignmentInAssert { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/asyncio_dangling_task.rs b/crates/ruff_linter/src/rules/ruff/rules/asyncio_dangling_task.rs index 8613f44e250bc..0c5a3ab5abe3c 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/asyncio_dangling_task.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/asyncio_dangling_task.rs @@ -2,7 +2,7 @@ use std::fmt; use ast::Stmt; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::{analyze::typing, Scope, SemanticModel}; use ruff_text_size::Ranged; @@ -50,8 +50,8 @@ use ruff_text_size::Ranged; /// ## References /// - [_The Heisenbug lurking in your async code_](https://textual.textualize.io/blog/2023/02/11/the-heisenbug-lurking-in-your-async-code/) /// - [The Python Standard Library](https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task) -#[violation] -pub struct AsyncioDanglingTask { +#[derive(ViolationMetadata)] +pub(crate) struct AsyncioDanglingTask { expr: String, method: Method, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs b/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs index 84d2347413583..94f900b44da19 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, ExprContext, Operator}; use ruff_text_size::{Ranged, TextRange}; @@ -36,8 +36,8 @@ use crate::fix::snippet::SourceCodeSnippet; /// ## References /// - [PEP 448 – Additional Unpacking Generalizations](https://peps.python.org/pep-0448/) /// - [Python documentation: Sequence Types — `list`, `tuple`, `range`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) -#[violation] -pub struct CollectionLiteralConcatenation { +#[derive(ViolationMetadata)] +pub(crate) struct CollectionLiteralConcatenation { expression: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/decimal_from_float_literal.rs b/crates/ruff_linter/src/rules/ruff/rules/decimal_from_float_literal.rs index 0cd0fc2dd758d..aed69b9cff9aa 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/decimal_from_float_literal.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/decimal_from_float_literal.rs @@ -1,7 +1,7 @@ use std::fmt; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_codegen::Stylist; use ruff_text_size::{Ranged, TextRange}; @@ -32,8 +32,8 @@ use crate::Locator; /// This rule's fix is marked as unsafe because it changes the underlying value /// of the `Decimal` instance that is constructed. This can lead to unexpected /// behavior if your program relies on the previous value (whether deliberately or not). -#[violation] -pub struct DecimalFromFloatLiteral; +#[derive(ViolationMetadata)] +pub(crate) struct DecimalFromFloatLiteral; impl AlwaysFixableViolation for DecimalFromFloatLiteral { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs b/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs index 965c65feb5862..d305351588239 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs @@ -2,7 +2,7 @@ use anyhow::Result; use ast::Keyword; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::is_constant; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -49,8 +49,8 @@ use crate::Locator; /// defaultdict(int) /// defaultdict(list) /// ``` -#[violation] -pub struct DefaultFactoryKwarg { +#[derive(ViolationMetadata)] +pub(crate) struct DefaultFactoryKwarg { default_factory: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs b/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs index dd5671c9b628d..21a8f98effe30 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs @@ -1,7 +1,7 @@ use anyhow::{bail, Result}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Arguments, Expr}; use ruff_python_codegen::Stylist; use ruff_text_size::Ranged; @@ -37,8 +37,8 @@ use crate::Locator; /// a = "some string" /// f"{a!r}" /// ``` -#[violation] -pub struct ExplicitFStringTypeConversion; +#[derive(ViolationMetadata)] +pub(crate) struct ExplicitFStringTypeConversion; impl AlwaysFixableViolation for ExplicitFStringTypeConversion { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/function_call_in_dataclass_default.rs b/crates/ruff_linter/src/rules/ruff/rules/function_call_in_dataclass_default.rs index 5902584a71b9d..2a7bd4fa50868 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/function_call_in_dataclass_default.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/function_call_in_dataclass_default.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::{QualifiedName, UnqualifiedName}; use ruff_python_semantic::analyze::typing::is_immutable_func; use ruff_text_size::Ranged; @@ -54,8 +54,8 @@ use crate::rules::ruff::rules::helpers::{ /// /// ## Options /// - `lint.flake8-bugbear.extend-immutable-calls` -#[violation] -pub struct FunctionCallInDataclassDefaultArgument { +#[derive(ViolationMetadata)] +pub(crate) struct FunctionCallInDataclassDefaultArgument { name: Option, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs b/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs index a192a0b4269ff..718a39d4093b1 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs @@ -3,7 +3,7 @@ use std::fmt; use anyhow::Result; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::Name; use ruff_python_ast::{self as ast, Expr, Operator, ParameterWithDefault, Parameters}; @@ -74,8 +74,8 @@ use super::super::typing::type_hint_explicitly_allows_none; /// - `target-version` /// /// [PEP 484]: https://peps.python.org/pep-0484/#union-types -#[violation] -pub struct ImplicitOptional { +#[derive(ViolationMetadata)] +pub(crate) struct ImplicitOptional { conversion_type: ConversionType, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/incorrectly_parenthesized_tuple_in_subscript.rs b/crates/ruff_linter/src/rules/ruff/rules/incorrectly_parenthesized_tuple_in_subscript.rs index 6fed23255b031..dbe9ea55fd759 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/incorrectly_parenthesized_tuple_in_subscript.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/incorrectly_parenthesized_tuple_in_subscript.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Expr, ExprSubscript}; use ruff_text_size::Ranged; @@ -37,8 +37,8 @@ use crate::{checkers::ast::Checker, settings::types::PythonVersion}; /// /// ## Options /// - `lint.ruff.parenthesize-tuple-in-subscript` -#[violation] -pub struct IncorrectlyParenthesizedTupleInSubscript { +#[derive(ViolationMetadata)] +pub(crate) struct IncorrectlyParenthesizedTupleInSubscript { prefer_parentheses: bool, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/invalid_assert_message_literal_argument.rs b/crates/ruff_linter/src/rules/ruff/rules/invalid_assert_message_literal_argument.rs index ddb72df5450cb..1942bab772a8c 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/invalid_assert_message_literal_argument.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/invalid_assert_message_literal_argument.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{Expr, StmtAssert}; use ruff_text_size::Ranged; @@ -25,8 +25,8 @@ use crate::checkers::ast::Checker; /// fruits.filter(lambda fruit: fruit.startwith("p")) /// assert len(fruits) == 2 /// ``` -#[violation] -pub struct InvalidAssertMessageLiteralArgument; +#[derive(ViolationMetadata)] +pub(crate) struct InvalidAssertMessageLiteralArgument; impl Violation for InvalidAssertMessageLiteralArgument { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/invalid_formatter_suppression_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/invalid_formatter_suppression_comment.rs index 63c2b2468a27c..6bd4d7c3ac323 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/invalid_formatter_suppression_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/invalid_formatter_suppression_comment.rs @@ -4,7 +4,7 @@ use smallvec::SmallVec; use ast::{StmtClassDef, StmtFunctionDef}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, helpers::comment_indentation_after, AnyNodeRef}; use ruff_python_trivia::{indentation_at_offset, SuppressionKind}; use ruff_text_size::{Ranged, TextLen, TextRange}; @@ -49,8 +49,8 @@ use super::suppression_comment_visitor::{ /// # fmt: on /// # yapf: enable /// ``` -#[violation] -pub struct InvalidFormatterSuppressionComment { +#[derive(ViolationMetadata)] +pub(crate) struct InvalidFormatterSuppressionComment { reason: IgnoredReason, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/invalid_index_type.rs b/crates/ruff_linter/src/rules/ruff/rules/invalid_index_type.rs index 707a3b9db7c84..c2bcab6ed4e1c 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/invalid_index_type.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/invalid_index_type.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{Expr, ExprNumberLiteral, ExprSlice, ExprSubscript, Number}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use std::fmt; @@ -25,8 +25,8 @@ use crate::checkers::ast::Checker; /// ```python /// var = [1, 2, 3][0] /// ``` -#[violation] -pub struct InvalidIndexType { +#[derive(ViolationMetadata)] +pub(crate) struct InvalidIndexType { value_type: String, index_type: String, is_slice: bool, diff --git a/crates/ruff_linter/src/rules/ruff/rules/invalid_pyproject_toml.rs b/crates/ruff_linter/src/rules/ruff/rules/invalid_pyproject_toml.rs index 8d34ea57481d9..b9a1c2f3a7ed0 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/invalid_pyproject_toml.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/invalid_pyproject_toml.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## What it does /// Checks for any pyproject.toml that does not conform to the schema from the relevant PEPs. @@ -30,8 +30,8 @@ use ruff_macros::{derive_message_formats, violation}; /// - [Specification of `[project]` in pyproject.toml](https://packaging.python.org/en/latest/specifications/declaring-project-metadata/) /// - [Specification of `[build-system]` in pyproject.toml](https://peps.python.org/pep-0518/) /// - [Draft but implemented license declaration extensions](https://peps.python.org/pep-0639) -#[violation] -pub struct InvalidPyprojectToml { +#[derive(ViolationMetadata)] +pub(crate) struct InvalidPyprojectToml { pub message: String, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs b/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs index 553f1f9c7cdab..2316e68e13868 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/map_int_version_parsing.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::SemanticModel; use ruff_text_size::Ranged; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// ``` /// /// [version-specifier]: https://packaging.python.org/en/latest/specifications/version-specifiers/#version-specifiers -#[violation] -pub struct MapIntVersionParsing; +#[derive(ViolationMetadata)] +pub(crate) struct MapIntVersionParsing; impl Violation for MapIntVersionParsing { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs b/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs index d128aed28f3e8..a7cee9f3b85cd 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs @@ -2,7 +2,7 @@ use memchr::memchr2_iter; use rustc_hash::FxHashSet; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_literal::format::FormatSpec; use ruff_python_parser::parse_expression; @@ -55,8 +55,8 @@ use crate::Locator; /// [logging]: https://docs.python.org/3/howto/logging-cookbook.html#using-particular-formatting-styles-throughout-your-application /// [gettext]: https://docs.python.org/3/library/gettext.html /// [fastAPI path]: https://fastapi.tiangolo.com/tutorial/path-params/ -#[violation] -pub struct MissingFStringSyntax; +#[derive(ViolationMetadata)] +pub(crate) struct MissingFStringSyntax; impl AlwaysFixableViolation for MissingFStringSyntax { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/mutable_class_default.rs b/crates/ruff_linter/src/rules/ruff/rules/mutable_class_default.rs index 2debe408195af..e4408c85bbd50 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/mutable_class_default.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/mutable_class_default.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::analyze::typing::{is_immutable_annotation, is_mutable_expr}; use ruff_text_size::Ranged; @@ -40,8 +40,8 @@ use crate::rules::ruff::rules::helpers::{ /// mutable_default: ClassVar[list[int]] = [] /// immutable_default: tuple[int, ...] = () /// ``` -#[violation] -pub struct MutableClassDefault; +#[derive(ViolationMetadata)] +pub(crate) struct MutableClassDefault; impl Violation for MutableClassDefault { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/mutable_dataclass_default.rs b/crates/ruff_linter/src/rules/ruff/rules/mutable_dataclass_default.rs index 35645384bd07a..00300421dba16 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/mutable_dataclass_default.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/mutable_dataclass_default.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_semantic::analyze::typing::{is_immutable_annotation, is_mutable_expr}; use ruff_text_size::Ranged; @@ -54,8 +54,8 @@ use crate::rules::ruff::rules::helpers::{dataclass_kind, is_class_var_annotation /// class A: /// mutable_default: ClassVar[list[int]] = [] /// ``` -#[violation] -pub struct MutableDataclassDefault; +#[derive(ViolationMetadata)] +pub(crate) struct MutableDataclassDefault; impl Violation for MutableDataclassDefault { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs b/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs index ffdff5dc30cf3..66068c7a02ed6 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::Name; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::analyze::typing::is_mutable_expr; @@ -48,8 +48,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `dict.fromkeys`](https://docs.python.org/3/library/stdtypes.html#dict.fromkeys) -#[violation] -pub struct MutableFromkeysValue; +#[derive(ViolationMetadata)] +pub(crate) struct MutableFromkeysValue; impl Violation for MutableFromkeysValue { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/ruff/rules/never_union.rs b/crates/ruff_linter/src/rules/ruff/rules/never_union.rs index 2e099e0481e93..fe2a5d8394f5c 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/never_union.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/never_union.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Expr, ExprBinOp, Operator}; use ruff_python_semantic::{analyze::typing::traverse_union, SemanticModel}; use ruff_text_size::{Ranged, TextRange}; @@ -34,8 +34,8 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: `typing.Never`](https://docs.python.org/3/library/typing.html#typing.Never) /// - [Python documentation: `typing.NoReturn`](https://docs.python.org/3/library/typing.html#typing.NoReturn) -#[violation] -pub struct NeverUnion { +#[derive(ViolationMetadata)] +pub(crate) struct NeverUnion { never_like: NeverLike, union_like: UnionLike, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/none_not_at_end_of_union.rs b/crates/ruff_linter/src/rules/ruff/rules/none_not_at_end_of_union.rs index ff6300fb2ddb6..cd8fd93f669d9 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/none_not_at_end_of_union.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/none_not_at_end_of_union.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Expr; use ruff_python_semantic::analyze::typing::traverse_union; use ruff_text_size::Ranged; @@ -29,8 +29,8 @@ use crate::checkers::ast::Checker; /// - [Python documentation: Union type](https://docs.python.org/3/library/stdtypes.html#types-union) /// - [Python documentation: `typing.Optional`](https://docs.python.org/3/library/typing.html#typing.Optional) /// - [Python documentation: `None`](https://docs.python.org/3/library/constants.html#None) -#[violation] -pub struct NoneNotAtEndOfUnion; +#[derive(ViolationMetadata)] +pub(crate) struct NoneNotAtEndOfUnion; impl Violation for NoneNotAtEndOfUnion { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/parenthesize_chained_operators.rs b/crates/ruff_linter/src/rules/ruff/rules/parenthesize_chained_operators.rs index 66084b2bdd419..4e637b4d7023f 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/parenthesize_chained_operators.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/parenthesize_chained_operators.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_text_size::Ranged; @@ -33,8 +33,8 @@ use crate::checkers::ast::Checker; /// d, e, f = 0, 1, 2 /// y = (d and e) or f /// ``` -#[violation] -pub struct ParenthesizeChainedOperators; +#[derive(ViolationMetadata)] +pub(crate) struct ParenthesizeChainedOperators; impl AlwaysFixableViolation for ParenthesizeChainedOperators { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/post_init_default.rs b/crates/ruff_linter/src/rules/ruff/rules/post_init_default.rs index 21a4c20cf7488..dbf5f484ba1ee 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/post_init_default.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/post_init_default.rs @@ -1,7 +1,7 @@ use anyhow::Context; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::{Scope, ScopeKind}; use ruff_python_trivia::{indentation_at_offset, textwrap}; @@ -66,8 +66,8 @@ use super::helpers::{dataclass_kind, DataclassKind}; /// - [Python documentation: Init-only variables](https://docs.python.org/3/library/dataclasses.html#init-only-variables) /// /// [documentation]: https://docs.python.org/3/library/dataclasses.html#init-only-variables -#[violation] -pub struct PostInitDefault; +#[derive(ViolationMetadata)] +pub(crate) struct PostInitDefault; impl Violation for PostInitDefault { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs b/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs index 3ff9354c98ae0..d670f07366a34 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs @@ -2,7 +2,7 @@ use anyhow::Result; use itertools::Itertools; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::AstNode; use ruff_python_ast::{self as ast, Arguments, Expr}; @@ -52,8 +52,8 @@ use crate::importer::ImportRequest; /// - [_How do I make a flat list out of a list of lists?_](https://stackoverflow.com/questions/952914/how-do-i-make-a-flat-list-out-of-a-list-of-lists/953097#953097) /// /// [microbenchmarks]: https://github.com/astral-sh/ruff/issues/5073#issuecomment-1591836349 -#[violation] -pub struct QuadraticListSummation; +#[derive(ViolationMetadata)] +pub(crate) struct QuadraticListSummation; impl AlwaysFixableViolation for QuadraticListSummation { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/redirected_noqa.rs b/crates/ruff_linter/src/rules/ruff/rules/redirected_noqa.rs index 455aa7775e843..5015ce345d2cb 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/redirected_noqa.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/redirected_noqa.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::noqa::{Directive, NoqaDirectives}; @@ -23,8 +23,8 @@ use crate::rule_redirects::get_redirect_target; /// ```python /// x = eval(command) # noqa: S307 /// ``` -#[violation] -pub struct RedirectedNOQA { +#[derive(ViolationMetadata)] +pub(crate) struct RedirectedNOQA { original: String, target: String, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/redundant_bool_literal.rs b/crates/ruff_linter/src/rules/ruff/rules/redundant_bool_literal.rs index 884bab83fc28d..67800ef64cd27 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/redundant_bool_literal.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/redundant_bool_literal.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::Expr; use ruff_python_semantic::analyze::typing::traverse_literal; use ruff_text_size::Ranged; @@ -54,8 +54,8 @@ use crate::checkers::ast::Checker; /// [mypy]: https://github.com/python/mypy/blob/master/mypy/typeops.py#L985 /// [#14764]: https://github.com/python/mypy/issues/14764 /// [#5421]: https://github.com/microsoft/pyright/issues/5421 -#[violation] -pub struct RedundantBoolLiteral { +#[derive(ViolationMetadata)] +pub(crate) struct RedundantBoolLiteral { seen_others: bool, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs index 55f7903fa966b..3c44653f71ac5 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_all.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_source_file::LineRanges; use ruff_text_size::TextRange; @@ -88,8 +88,8 @@ use crate::rules::ruff::rules::sequence_sorting::{ /// could be read by code elsewhere that depends on the exact /// iteration order of the items in `__all__`, in which case this /// rule's fix could theoretically cause breakage. -#[violation] -pub struct UnsortedDunderAll; +#[derive(ViolationMetadata)] +pub(crate) struct UnsortedDunderAll; impl Violation for UnsortedDunderAll { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs index fe5e8f058f167..29c48a4e9e8ef 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use itertools::izip; use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_semantic::Binding; use ruff_source_file::LineRanges; @@ -82,8 +82,8 @@ use crate::Locator; /// could still be read by code outside of the module in which the /// `__slots__` definition occurs, in which case this rule's fix could /// theoretically cause breakage. -#[violation] -pub struct UnsortedDunderSlots { +#[derive(ViolationMetadata)] +pub(crate) struct UnsortedDunderSlots { class_name: ast::name::Name, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/static_key_dict_comprehension.rs b/crates/ruff_linter/src/rules/ruff/rules/static_key_dict_comprehension.rs index d2f14bfb4ba4a..a5b512013cb76 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/static_key_dict_comprehension.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/static_key_dict_comprehension.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## Removed /// This rule was implemented in `flake8-bugbear` and has been remapped to [B035] @@ -26,8 +26,8 @@ use ruff_macros::{derive_message_formats, violation}; /// ``` /// /// [B035]: https://docs.astral.sh/ruff/rules/static-key-dict-comprehension/ -#[violation] -pub struct RuffStaticKeyDictComprehension; +#[derive(ViolationMetadata)] +pub(crate) struct RuffStaticKeyDictComprehension; impl Violation for RuffStaticKeyDictComprehension { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/test_rules.rs b/crates/ruff_linter/src/rules/ruff/rules/test_rules.rs index 8a1c07f8568a3..5faf5242cad1b 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/test_rules.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/test_rules.rs @@ -14,7 +14,7 @@ /// Rules that provide a fix _must_ not raise unconditionally or the linter /// will not converge. use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_trivia::CommentRanges; use ruff_text_size::TextSize; @@ -66,8 +66,8 @@ pub(crate) trait TestRule { /// ```python /// bar /// ``` -#[violation] -pub struct StableTestRule; +#[derive(ViolationMetadata)] +pub(crate) struct StableTestRule; impl Violation for StableTestRule { const FIX_AVAILABILITY: FixAvailability = FixAvailability::None; @@ -102,8 +102,8 @@ impl TestRule for StableTestRule { /// ```python /// bar /// ``` -#[violation] -pub struct StableTestRuleSafeFix; +#[derive(ViolationMetadata)] +pub(crate) struct StableTestRuleSafeFix; impl Violation for StableTestRuleSafeFix { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Always; @@ -143,8 +143,8 @@ impl TestRule for StableTestRuleSafeFix { /// ```python /// bar /// ``` -#[violation] -pub struct StableTestRuleUnsafeFix; +#[derive(ViolationMetadata)] +pub(crate) struct StableTestRuleUnsafeFix; impl Violation for StableTestRuleUnsafeFix { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Always; @@ -187,8 +187,8 @@ impl TestRule for StableTestRuleUnsafeFix { /// ```python /// bar /// ``` -#[violation] -pub struct StableTestRuleDisplayOnlyFix; +#[derive(ViolationMetadata)] +pub(crate) struct StableTestRuleDisplayOnlyFix; impl Violation for StableTestRuleDisplayOnlyFix { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Always; @@ -234,8 +234,8 @@ impl TestRule for StableTestRuleDisplayOnlyFix { /// ```python /// bar /// ``` -#[violation] -pub struct PreviewTestRule; +#[derive(ViolationMetadata)] +pub(crate) struct PreviewTestRule; impl Violation for PreviewTestRule { const FIX_AVAILABILITY: FixAvailability = FixAvailability::None; @@ -270,8 +270,8 @@ impl TestRule for PreviewTestRule { /// ```python /// bar /// ``` -#[violation] -pub struct DeprecatedTestRule; +#[derive(ViolationMetadata)] +pub(crate) struct DeprecatedTestRule; impl Violation for DeprecatedTestRule { const FIX_AVAILABILITY: FixAvailability = FixAvailability::None; @@ -306,8 +306,8 @@ impl TestRule for DeprecatedTestRule { /// ```python /// bar /// ``` -#[violation] -pub struct AnotherDeprecatedTestRule; +#[derive(ViolationMetadata)] +pub(crate) struct AnotherDeprecatedTestRule; impl Violation for AnotherDeprecatedTestRule { const FIX_AVAILABILITY: FixAvailability = FixAvailability::None; @@ -342,8 +342,8 @@ impl TestRule for AnotherDeprecatedTestRule { /// ```python /// bar /// ``` -#[violation] -pub struct RemovedTestRule; +#[derive(ViolationMetadata)] +pub(crate) struct RemovedTestRule; impl Violation for RemovedTestRule { const FIX_AVAILABILITY: FixAvailability = FixAvailability::None; @@ -378,8 +378,8 @@ impl TestRule for RemovedTestRule { /// ```python /// bar /// ``` -#[violation] -pub struct AnotherRemovedTestRule; +#[derive(ViolationMetadata)] +pub(crate) struct AnotherRemovedTestRule; impl Violation for AnotherRemovedTestRule { const FIX_AVAILABILITY: FixAvailability = FixAvailability::None; @@ -414,8 +414,8 @@ impl TestRule for AnotherRemovedTestRule { /// ```python /// bar /// ``` -#[violation] -pub struct RedirectedFromTestRule; +#[derive(ViolationMetadata)] +pub(crate) struct RedirectedFromTestRule; impl Violation for RedirectedFromTestRule { const FIX_AVAILABILITY: FixAvailability = FixAvailability::None; @@ -450,8 +450,8 @@ impl TestRule for RedirectedFromTestRule { /// ```python /// bar /// ``` -#[violation] -pub struct RedirectedToTestRule; +#[derive(ViolationMetadata)] +pub(crate) struct RedirectedToTestRule; impl Violation for RedirectedToTestRule { const FIX_AVAILABILITY: FixAvailability = FixAvailability::None; @@ -486,8 +486,8 @@ impl TestRule for RedirectedToTestRule { /// ```python /// bar /// ``` -#[violation] -pub struct RedirectedFromPrefixTestRule; +#[derive(ViolationMetadata)] +pub(crate) struct RedirectedFromPrefixTestRule; impl Violation for RedirectedFromPrefixTestRule { const FIX_AVAILABILITY: FixAvailability = FixAvailability::None; diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs index c6ce35cf58c87..55b07d14c5233 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Arguments, Comprehension, Expr, Int}; use ruff_python_semantic::SemanticModel; use ruff_python_stdlib::builtins::is_iterator; @@ -53,7 +53,7 @@ use crate::fix::snippet::SourceCodeSnippet; /// /// ## References /// - [Iterators and Iterables in Python: Run Efficient Iterations](https://realpython.com/python-iterators-iterables/#when-to-use-an-iterator-in-python) -#[violation] +#[derive(ViolationMetadata)] pub(crate) struct UnnecessaryIterableAllocationForFirstElement { iterable: SourceCodeSnippet, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_key_check.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_key_check.rs index 727165c04c563..5a8a86fe026f5 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_key_check.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_key_check.rs @@ -2,7 +2,7 @@ use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::{self as ast, BoolOp, CmpOp, Expr}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::contains_effect; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_text_size::Ranged; @@ -28,8 +28,8 @@ use crate::checkers::ast::Checker; /// if dct.get("key"): /// ... /// ``` -#[violation] -pub struct UnnecessaryKeyCheck; +#[derive(ViolationMetadata)] +pub(crate) struct UnnecessaryKeyCheck; impl AlwaysFixableViolation for UnnecessaryKeyCheck { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/unraw_re_pattern.rs b/crates/ruff_linter/src/rules/ruff/rules/unraw_re_pattern.rs index 40014e4fad4a3..0267ba00f8693 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unraw_re_pattern.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unraw_re_pattern.rs @@ -2,7 +2,7 @@ use std::fmt::{Display, Formatter}; use std::str::FromStr; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{ BytesLiteral, Expr, ExprBytesLiteral, ExprCall, ExprStringLiteral, StringLiteral, }; @@ -35,8 +35,8 @@ use crate::checkers::ast::Checker; /// ```python /// re.compile(r"foo\bar") /// ``` -#[violation] -pub struct UnrawRePattern { +#[derive(ViolationMetadata)] +pub(crate) struct UnrawRePattern { module: RegexModule, func: String, kind: PatternKind, diff --git a/crates/ruff_linter/src/rules/ruff/rules/unsafe_markup_use.rs b/crates/ruff_linter/src/rules/ruff/rules/unsafe_markup_use.rs index 21593fbc1b7e6..762c38d738740 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unsafe_markup_use.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unsafe_markup_use.rs @@ -1,7 +1,7 @@ use ruff_python_ast::ExprCall; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::name::QualifiedName; use ruff_python_semantic::Modules; use ruff_text_size::Ranged; @@ -71,8 +71,8 @@ use crate::{checkers::ast::Checker, settings::LinterSettings}; /// /// [markupsafe.Markup]: https://markupsafe.palletsprojects.com/en/stable/escaping/#markupsafe.Markup /// [flake8-markupsafe]: https://github.com/vmagamedov/flake8-markupsafe -#[violation] -pub struct UnsafeMarkupUse { +#[derive(ViolationMetadata)] +pub(crate) struct UnsafeMarkupUse { name: String, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/unused_async.rs b/crates/ruff_linter/src/rules/ruff/rules/unused_async.rs index b3b78c2755447..ca0aa2d6cdefc 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unused_async.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unused_async.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::visitor::source_order; use ruff_python_ast::{self as ast, AnyNodeRef, Expr, Stmt}; @@ -29,8 +29,8 @@ use crate::rules::fastapi::rules::is_fastapi_route; /// def foo(): /// bar() /// ``` -#[violation] -pub struct UnusedAsync { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedAsync { name: String, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs b/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs index 4b6b97bd6d700..02f4bceb444b5 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs @@ -1,10 +1,10 @@ use itertools::Itertools; use ruff_diagnostics::AlwaysFixableViolation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; #[derive(Debug, PartialEq, Eq)] -pub struct UnusedCodes { +pub(crate) struct UnusedCodes { pub disabled: Vec, pub duplicated: Vec, pub unknown: Vec, @@ -41,8 +41,8 @@ pub struct UnusedCodes { /// /// ## References /// - [Ruff error suppression](https://docs.astral.sh/ruff/linter/#error-suppression) -#[violation] -pub struct UnusedNOQA { +#[derive(ViolationMetadata)] +pub(crate) struct UnusedNOQA { pub codes: Option, } diff --git a/crates/ruff_linter/src/rules/ruff/rules/useless_if_else.rs b/crates/ruff_linter/src/rules/ruff/rules/useless_if_else.rs index b3e17ae3b6bc0..1299c94459915 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/useless_if_else.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/useless_if_else.rs @@ -1,6 +1,6 @@ use crate::checkers::ast::Checker; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast as ast; use ruff_python_ast::comparable::ComparableExpr; @@ -25,8 +25,8 @@ use ruff_python_ast::comparable::ComparableExpr; /// # Good /// foo = x /// ``` -#[violation] -pub struct UselessIfElse; +#[derive(ViolationMetadata)] +pub(crate) struct UselessIfElse; impl Violation for UselessIfElse { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs b/crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs index ef7d3825c8ca3..5ad2c78517bd3 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Arguments, Expr, Int}; use ruff_text_size::Ranged; @@ -31,8 +31,8 @@ use crate::{checkers::ast::Checker, importer::ImportRequest}; /// /// ## References /// - [Python documentation: `itertools.pairwise`](https://docs.python.org/3/library/itertools.html#itertools.pairwise) -#[violation] -pub struct ZipInsteadOfPairwise; +#[derive(ViolationMetadata)] +pub(crate) struct ZipInsteadOfPairwise; impl Violation for ZipInsteadOfPairwise { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/error_instead_of_exception.rs b/crates/ruff_linter/src/rules/tryceratops/rules/error_instead_of_exception.rs index b7ed88c02d631..0f5fe6a30b63d 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/error_instead_of_exception.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/error_instead_of_exception.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Applicability, Diagnostic, Edit, Fix, FixAvailability, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::visitor::Visitor; use ruff_python_ast::{self as ast, ExceptHandler, Expr}; use ruff_python_semantic::analyze::logging::exc_info; @@ -51,8 +51,8 @@ use crate::rules::tryceratops::helpers::LoggerCandidateVisitor; /// /// ## References /// - [Python documentation: `logging.exception`](https://docs.python.org/3/library/logging.html#logging.exception) -#[violation] -pub struct ErrorInsteadOfException; +#[derive(ViolationMetadata)] +pub(crate) struct ErrorInsteadOfException; impl Violation for ErrorInsteadOfException { const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_args.rs b/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_args.rs index bf238d14bb3d6..2c1349fe4d342 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_args.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_args.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{self as ast, Arguments, Expr}; use ruff_text_size::Ranged; @@ -43,8 +43,8 @@ use crate::checkers::ast::Checker; /// if x < 0: /// raise CantBeNegative(x) /// ``` -#[violation] -pub struct RaiseVanillaArgs; +#[derive(ViolationMetadata)] +pub(crate) struct RaiseVanillaArgs; impl Violation for RaiseVanillaArgs { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_class.rs b/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_class.rs index 22dc97ebdbc08..744c1e9d40d97 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_class.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/raise_vanilla_class.rs @@ -2,7 +2,7 @@ use ruff_python_ast::helpers::map_callable; use ruff_python_ast::Expr; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -52,8 +52,8 @@ use crate::checkers::ast::Checker; /// except Exception: /// logger.error("Oops") /// ``` -#[violation] -pub struct RaiseVanillaClass; +#[derive(ViolationMetadata)] +pub(crate) struct RaiseVanillaClass; impl Violation for RaiseVanillaClass { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/raise_within_try.rs b/crates/ruff_linter/src/rules/tryceratops/rules/raise_within_try.rs index a4c7439e6870f..d7ae13fffd5b0 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/raise_within_try.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/raise_within_try.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, ExceptHandler, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::{ comparable::ComparableExpr, helpers::{self, map_callable}, @@ -49,8 +49,8 @@ use crate::checkers::ast::Checker; /// except ValueError: /// raise /// ``` -#[violation] -pub struct RaiseWithinTry; +#[derive(ViolationMetadata)] +pub(crate) struct RaiseWithinTry; impl Violation for RaiseWithinTry { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/reraise_no_cause.rs b/crates/ruff_linter/src/rules/tryceratops/rules/reraise_no_cause.rs index 2645baf683ab9..f208306d2480f 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/reraise_no_cause.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/reraise_no_cause.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Violation; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; /// ## Removed /// This rule is identical to [B904] which should be used instead. @@ -35,8 +35,8 @@ use ruff_macros::{derive_message_formats, violation}; /// - [Python documentation: Exception context](https://docs.python.org/3/library/exceptions.html#exception-context) /// /// [B904]: https://docs.astral.sh/ruff/rules/raise-without-from-inside-except/ -#[violation] -pub struct ReraiseNoCause; +#[derive(ViolationMetadata)] +pub(crate) struct ReraiseNoCause; /// TRY200 impl Violation for ReraiseNoCause { diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/try_consider_else.rs b/crates/ruff_linter/src/rules/tryceratops/rules/try_consider_else.rs index 2b780924e71ce..65699ca682491 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/try_consider_else.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/try_consider_else.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, ExceptHandler, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::contains_effect; use ruff_text_size::Ranged; @@ -46,8 +46,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: Errors and Exceptions](https://docs.python.org/3/tutorial/errors.html) -#[violation] -pub struct TryConsiderElse; +#[derive(ViolationMetadata)] +pub(crate) struct TryConsiderElse; impl Violation for TryConsiderElse { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/type_check_without_type_error.rs b/crates/ruff_linter/src/rules/tryceratops/rules/type_check_without_type_error.rs index 8939b51208ed9..1ddd4b01163ef 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/type_check_without_type_error.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/type_check_without_type_error.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::helpers::map_callable; use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor}; use ruff_python_ast::{self as ast, Expr, Stmt, StmtIf}; @@ -35,8 +35,8 @@ use crate::checkers::ast::Checker; /// /// ## References /// - [Python documentation: `TypeError`](https://docs.python.org/3/library/exceptions.html#TypeError) -#[violation] -pub struct TypeCheckWithoutTypeError; +#[derive(ViolationMetadata)] +pub(crate) struct TypeCheckWithoutTypeError; impl Violation for TypeCheckWithoutTypeError { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/useless_try_except.rs b/crates/ruff_linter/src/rules/tryceratops/rules/useless_try_except.rs index 4893761b243c9..c4cdb13053c64 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/useless_try_except.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/useless_try_except.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, ExceptHandler, ExceptHandlerExceptHandler, Expr, Stmt}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -28,8 +28,8 @@ use crate::checkers::ast::Checker; /// def foo(): /// bar() /// ``` -#[violation] -pub struct UselessTryExcept; +#[derive(ViolationMetadata)] +pub(crate) struct UselessTryExcept; impl Violation for UselessTryExcept { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_log_message.rs b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_log_message.rs index 4a80fd40f36e4..1a2ccbae749bf 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_log_message.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_log_message.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, ExceptHandler, Expr}; use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::visitor; use ruff_python_ast::visitor::Visitor; use ruff_python_stdlib::logging::LoggingLevel; @@ -33,8 +33,8 @@ use crate::rules::tryceratops::helpers::LoggerCandidateVisitor; /// except ValueError: /// logger.exception("Found an error") /// ``` -#[violation] -pub struct VerboseLogMessage; +#[derive(ViolationMetadata)] +pub(crate) struct VerboseLogMessage; impl Violation for VerboseLogMessage { #[derive_message_formats] diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs index ffaac8862e668..7e27aa71a5c4c 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, ExceptHandler, Expr, Stmt}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; -use ruff_macros::{derive_message_formats, violation}; +use ruff_macros::{derive_message_formats, ViolationMetadata}; use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor}; use ruff_text_size::Ranged; @@ -35,8 +35,8 @@ use crate::checkers::ast::Checker; /// ## Fix safety /// This rule's fix is marked as unsafe, as it doesn't properly handle bound /// exceptions that are shadowed between the `except` and `raise` statements. -#[violation] -pub struct VerboseRaise; +#[derive(ViolationMetadata)] +pub(crate) struct VerboseRaise; impl AlwaysFixableViolation for VerboseRaise { #[derive_message_formats] diff --git a/crates/ruff_macros/src/lib.rs b/crates/ruff_macros/src/lib.rs index 04b9109982959..00bd4018a453b 100644 --- a/crates/ruff_macros/src/lib.rs +++ b/crates/ruff_macros/src/lib.rs @@ -2,8 +2,9 @@ use crate::cache_key::derive_cache_key; use crate::newtype_index::generate_newtype_index; +use crate::violation_metadata::violation_metadata; use proc_macro::TokenStream; -use syn::{parse_macro_input, DeriveInput, ItemFn, ItemStruct}; +use syn::{parse_macro_input, DeriveInput, Error, ItemFn, ItemStruct}; mod cache_key; mod combine_options; @@ -13,7 +14,7 @@ mod map_codes; mod newtype_index; mod rule_code_prefix; mod rule_namespace; -mod violation; +mod violation_metadata; #[proc_macro_derive(OptionsMetadata, attributes(option, doc, option_group))] pub fn derive_options_metadata(input: TokenStream) -> TokenStream { @@ -47,12 +48,12 @@ pub fn cache_key(input: TokenStream) -> TokenStream { TokenStream::from(stream) } -/// Adds an `explanation()` method from the doc comment. -#[proc_macro_attribute] -pub fn violation(_attr: TokenStream, item: TokenStream) -> TokenStream { - let violation = parse_macro_input!(item as ItemStruct); - violation::violation(&violation) - .unwrap_or_else(syn::Error::into_compile_error) +#[proc_macro_derive(ViolationMetadata)] +pub fn derive_violation_metadata(item: TokenStream) -> TokenStream { + let input: DeriveInput = parse_macro_input!(item); + + violation_metadata(input) + .unwrap_or_else(Error::into_compile_error) .into() } diff --git a/crates/ruff_macros/src/map_codes.rs b/crates/ruff_macros/src/map_codes.rs index 49cdf560691e5..a38f7cc543b99 100644 --- a/crates/ruff_macros/src/map_codes.rs +++ b/crates/ruff_macros/src/map_codes.rs @@ -420,8 +420,7 @@ fn register_rules<'a>(input: impl Iterator) -> TokenStream { rule_fixable_match_arms.extend( quote! {#(#attrs)* Self::#name => <#path as ruff_diagnostics::Violation>::FIX_AVAILABILITY,}, ); - rule_explanation_match_arms - .extend(quote! {#(#attrs)* Self::#name => #path::explanation(),}); + rule_explanation_match_arms.extend(quote! {#(#attrs)* Self::#name => #path::explain(),}); // Enable conversion from `DiagnosticKind` to `Rule`. from_impls_for_diagnostic_kind @@ -457,6 +456,7 @@ fn register_rules<'a>(input: impl Iterator) -> TokenStream { /// Returns the documentation for this rule. pub fn explanation(&self) -> Option<&'static str> { + use ruff_diagnostics::ViolationMetadata; match self { #rule_explanation_match_arms } } @@ -466,6 +466,7 @@ fn register_rules<'a>(input: impl Iterator) -> TokenStream { } } + impl AsRule for ruff_diagnostics::DiagnosticKind { fn rule(&self) -> Rule { match self.name.as_str() { diff --git a/crates/ruff_macros/src/violation.rs b/crates/ruff_macros/src/violation.rs deleted file mode 100644 index 281d2cfcb9217..0000000000000 --- a/crates/ruff_macros/src/violation.rs +++ /dev/null @@ -1,100 +0,0 @@ -use proc_macro2::TokenStream; -use quote::quote; -use syn::{Attribute, Error, ItemStruct, Lit, LitStr, Meta, Result}; - -fn parse_attr<'a, const LEN: usize>( - path: [&'static str; LEN], - attr: &'a Attribute, -) -> Option<&'a LitStr> { - if let Meta::NameValue(name_value) = &attr.meta { - let path_idents = name_value - .path - .segments - .iter() - .map(|segment| &segment.ident); - - if itertools::equal(path_idents, path) { - if let syn::Expr::Lit(syn::ExprLit { - lit: Lit::Str(lit), .. - }) = &name_value.value - { - return Some(lit); - } - } - } - - None -} - -/// Collect all doc comment attributes into a string -fn get_docs(attrs: &[Attribute]) -> Result { - let mut explanation = String::new(); - for attr in attrs { - if attr.path().is_ident("doc") { - if let Some(lit) = parse_attr(["doc"], attr) { - let value = lit.value(); - // `/// ` adds - let line = value.strip_prefix(' ').unwrap_or(&value); - explanation.push_str(line); - explanation.push('\n'); - } else { - return Err(Error::new_spanned(attr, "unimplemented doc comment style")); - } - } - } - Ok(explanation) -} - -pub(crate) fn violation(violation: &ItemStruct) -> Result { - let ident = &violation.ident; - let explanation = get_docs(&violation.attrs)?; - let violation = if explanation.trim().is_empty() { - quote! { - #[derive(Debug, PartialEq, Eq)] - #violation - - #[allow(deprecated)] - #[automatically_derived] - #[allow(deprecated)] - impl From<#ident> for ruff_diagnostics::DiagnosticKind { - fn from(value: #ident) -> Self { - use ruff_diagnostics::Violation; - - Self { - body: Violation::message(&value), - suggestion: Violation::fix_title(&value), - name: stringify!(#ident).to_string(), - } - } - } - } - } else { - quote! { - #[derive(Debug, PartialEq, Eq)] - #violation - - #[automatically_derived] - #[allow(deprecated)] - impl #ident { - pub fn explanation() -> Option<&'static str> { - Some(#explanation) - } - } - - #[allow(deprecated)] - #[automatically_derived] - impl From<#ident> for ruff_diagnostics::DiagnosticKind { - fn from(value: #ident) -> Self { - use ruff_diagnostics::Violation; - - Self { - body: Violation::message(&value), - suggestion: Violation::fix_title(&value), - name: stringify!(#ident).to_string(), - } - } - } - } - }; - Ok(violation) -} diff --git a/crates/ruff_macros/src/violation_metadata.rs b/crates/ruff_macros/src/violation_metadata.rs new file mode 100644 index 0000000000000..c64ee30b211bb --- /dev/null +++ b/crates/ruff_macros/src/violation_metadata.rs @@ -0,0 +1,66 @@ +use proc_macro2::TokenStream; +use quote::quote; +use syn::{Attribute, DeriveInput, Error, Lit, LitStr, Meta}; + +pub(crate) fn violation_metadata(input: DeriveInput) -> syn::Result { + let docs = get_docs(&input.attrs)?; + + let name = input.ident; + + Ok(quote! { + #[automatically_derived] + #[allow(deprecated)] + impl ruff_diagnostics::ViolationMetadata for #name { + fn rule_name() -> &'static str { + stringify!(#name) + } + + fn explain() -> Option<&'static str> { + Some(#docs) + } + } + }) +} + +/// Collect all doc comment attributes into a string +fn get_docs(attrs: &[Attribute]) -> syn::Result { + let mut explanation = String::new(); + for attr in attrs { + if attr.path().is_ident("doc") { + if let Some(lit) = parse_attr(["doc"], attr) { + let value = lit.value(); + // `/// ` adds + let line = value.strip_prefix(' ').unwrap_or(&value); + explanation.push_str(line); + explanation.push('\n'); + } else { + return Err(Error::new_spanned(attr, "unimplemented doc comment style")); + } + } + } + Ok(explanation) +} + +fn parse_attr<'a, const LEN: usize>( + path: [&'static str; LEN], + attr: &'a Attribute, +) -> Option<&'a LitStr> { + if let Meta::NameValue(name_value) = &attr.meta { + let path_idents = name_value + .path + .segments + .iter() + .map(|segment| &segment.ident); + + if itertools::equal(path_idents, path) { + if let syn::Expr::Lit(syn::ExprLit { + lit: Lit::Str(lit), .. + }) = &name_value.value + { + return Some(lit); + } + } + } + + None +} diff --git a/scripts/add_rule.py b/scripts/add_rule.py index fbb2f66b18d0e..f285878670124 100755 --- a/scripts/add_rule.py +++ b/scripts/add_rule.py @@ -93,7 +93,7 @@ def main(*, name: str, prefix: str, code: str, linter: str) -> None: fp.write( f"""\ use ruff_diagnostics::Violation; -use ruff_macros::{{derive_message_formats, violation}}; +use ruff_macros::{{derive_message_formats, ViolationMetadata}}; use crate::checkers::ast::Checker; @@ -108,8 +108,8 @@ def main(*, name: str, prefix: str, code: str, linter: str) -> None: /// Use instead: /// ```python /// ``` -#[violation] -pub struct {name}; +#[derive(ViolationMetadata)] +pub(crate) struct {name}; impl Violation for {name} {{ #[derive_message_formats]