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

Code before:
    let Some((position, keyword)) = class_def.keywords().iter().find_position(|&keyword| {
        keyword
            .arg
            .as_ref()
            .is_some_and(|arg| arg.as_str() == "metaclass")
    }) else {
        return;
    };

    // Determine whether it's assigned to `abc.ABCMeta`.
    if !checker
        .semantic()
        .resolve_qualified_name(&keyword.value)
        .is_some_and(|qualified_name| matches!(qualified_name.segments(), ["abc", "ABCMeta"]))
    {
        return;
    }

    let applicability = if !class_def.bases().is_empty() {
        // The class has base arguments (not just a `metaclass` keyword).
        // Applying the fix may change semantics, so it is considered unsafe.
        Applicability::Unsafe
    } else if checker.comment_ranges().intersects(arguments.range()) {
        // The `metaclass` keyword overlaps with a comment.
        // Applying the fix would remove or alter the comment, so it is unsafe.
        Applicability::Unsafe
    } else {
        // An empty class definition with no overlapping comments.
        // Applying the fix is considered safe.
        Applicability::Safe
    };
    let mut diagnostic = checker.report_diagnostic(MetaClassABCMeta, keyword.range);

    diagnostic.try_set_fix(|| {
        let (import_edit, binding) = checker.importer().get_or_import_symbol(
            &ImportRequest::import("abc", "ABC"),
            keyword.range.start(),
            checker.semantic(),
        )?;

        // Check the `abc.ABC` is in base classes.
        let has_abc = analyze::class::any_qualified_base_class(
            class_def,
            checker.semantic(),
            &|qualified_name| matches!(qualified_name.segments(), ["abc", "ABC"]),
        );

        let delete_metaclass_keyword = remove_argument(
            keyword,
            arguments,
            Parentheses::Remove,

Review comment (suggestion):
I think we could narrow this to `keyword.range` instead of the whole `arguments.range()`, but I'm not totally sure:

```suggestion
    } else if checker.comment_ranges().intersects(keyword.range()) {
```

Code after:
    };

    // Identify the `metaclass` keyword.
    let Some((position, keyword)) = class_def.keywords().iter().find_position(|&keyword| {
        keyword
            .arg
            .as_ref()
            .is_some_and(|arg| arg.as_str() == "metaclass")
    }) else {
        return;
    };

    // Determine whether it's assigned to `abc.ABCMeta`.
    if !checker
        .semantic()
        .resolve_qualified_name(&keyword.value)
        .is_some_and(|qualified_name| matches!(qualified_name.segments(), ["abc", "ABCMeta"]))
    {
        return;
    }

    let applicability = if !class_def.bases().is_empty() {
        // The class has base arguments (not just a `metaclass` keyword).
        // Applying the fix may change semantics, so it is considered unsafe.
        Applicability::Unsafe
    } else if checker.comment_ranges().intersects(arguments.range()) {
        // The `metaclass` keyword overlaps with a comment.
        // Applying the fix would remove or alter the comment, so it is unsafe.
        Applicability::Unsafe
    } else {
        // An empty class definition with no overlapping comments.
        // Applying the fix is considered safe.
        Applicability::Safe
    };
    let mut diagnostic = checker.report_diagnostic(MetaClassABCMeta, keyword.range);

    diagnostic.try_set_fix(|| {
        let (import_edit, binding) = checker.importer().get_or_import_symbol(
            &ImportRequest::import("abc", "ABC"),
            keyword.range.start(),
            checker.semantic(),
        )?;

        // Check the `abc.ABC` is in base classes.
        let has_abc = analyze::class::any_qualified_base_class(
            class_def,
            checker.semantic(),
            &|qualified_name| matches!(qualified_name.segments(), ["abc", "ABC"]),
        );

        let delete_metaclass_keyword = remove_argument(