Repository: astral-sh/ruff
File: crates/ruff_linter/src/rules/refurb/rules/metaclass_abcmeta.rs (Rust)

Code before:
/// is semantically identical to setting `metaclass=abc.ABCMeta`, but more
/// succinct.
///
/// ## Example
/// ```python
/// import abc
///
///
/// class C(metaclass=abc.ABCMeta):
///     pass
/// ```
///
/// Use instead:
/// ```python
/// import abc
///
///
/// class C(abc.ABC):
///     pass
/// ```
///
/// ## Fix safety
/// The rule's fix is unsafe if the class has base classes. This is because the base classes might
/// be validating the class's other base classes (e.g., `typing.Protocol` does this) or otherwise
/// alter runtime behavior if more base classes are added.
/// The rule's fix is unsafe too if the class has comments in its definition.
///
///
/// ## 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)
#[derive(ViolationMetadata)]
#[violation_metadata(preview_since = "v0.2.0")]
pub(crate) struct MetaClassABCMeta;

impl AlwaysFixableViolation for MetaClassABCMeta {
    #[derive_message_formats]
    fn message(&self) -> String {
        "Use of `metaclass=abc.ABCMeta` to define abstract base class".to_string()
    }

    fn fix_title(&self) -> String {
        "Replace with `abc.ABC`".to_string()
    }
}

/// FURB180
pub(crate) fn metaclass_abcmeta(checker: &Checker, class_def: &StmtClassDef) {
    // Determine whether the class definition contains at least one argument.
    let Some(arguments) = &class_def.arguments.as_ref() else {
        return;

Review comment (suggestion):
```suggestion
/// The rule's fix will also be marked as unsafe if the class has
/// comments in its argument list that could be deleted.
```

Code after:
/// is semantically identical to setting `metaclass=abc.ABCMeta`, but more
/// succinct.
///
/// ## Example
/// ```python
/// import abc
///
///
/// class C(metaclass=abc.ABCMeta):
///     pass
/// ```
///
/// Use instead:
/// ```python
/// import abc
///
///
/// class C(abc.ABC):
///     pass
/// ```
///
/// ## Fix safety
/// The rule's fix is unsafe if the class has base classes. This is because the base classes might
/// be validating the class's other base classes (e.g., `typing.Protocol` does this) or otherwise
/// alter runtime behavior if more base classes are added.
/// The rule's fix will also be marked as unsafe if the class has
/// comments in its argument list that could be deleted.
///
///
/// ## 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)
#[derive(ViolationMetadata)]
#[violation_metadata(preview_since = "v0.2.0")]
pub(crate) struct MetaClassABCMeta;

impl AlwaysFixableViolation for MetaClassABCMeta {
    #[derive_message_formats]
    fn message(&self) -> String {
        "Use of `metaclass=abc.ABCMeta` to define abstract base class".to_string()
    }

    fn fix_title(&self) -> String {
        "Replace with `abc.ABC`".to_string()
    }
}

/// FURB180
pub(crate) fn metaclass_abcmeta(checker: &Checker, class_def: &StmtClassDef) {
    // Determine whether the class definition contains at least one argument.
    let Some(arguments) = &class_def.arguments.as_ref() else {