Repository: astral-sh/ruff
File: crates/ty_python_semantic/src/types/class.rs (Rust)

Code before:
            let name = symbol.name();

            let Some(Type::FunctionLiteral(literal)) = attr.place.ignore_possibly_undefined()
            else {
                continue;
            };

            if matches!(name.as_str(), "__setattr__" | "__delattr__") {
                if let CodeGeneratorKind::DataclassLike(_) = field_policy
                    && self.has_dataclass_param(db, field_policy, DataclassFlags::FROZEN)
                {
                    if let Some(builder) = context.report_lint(
                        &INVALID_DATACLASS_OVERRIDE,
                        literal.node(db, context.file(), context.module()),
                    ) {
                        let mut diagnostic = builder.into_diagnostic(format_args!(
                            "Cannot overwrite attribute `{}` in class `{}`",
                            name,
                            self.name(db)
                        ));
                        diagnostic.info(name);
                    }
                }
            }

            if matches!(name.as_str(), "__lt__" | "__le__" | "__gt__" | "__ge__") {
                if let CodeGeneratorKind::DataclassLike(_) = field_policy
                    && self.has_dataclass_param(db, field_policy, DataclassFlags::ORDER)
                {
                    if let Some(builder) = context.report_lint(
                        &INVALID_DATACLASS_OVERRIDE,
                        literal.node(db, context.file(), context.module()),
                    ) {
                        let mut diagnostic = builder.into_diagnostic(format_args!(
                            "Cannot overwrite attribute `{}` in class `{}`",
                            name,
                            self.name(db)
                        ));
                        diagnostic.info(name);
                    }
                }
            }
        }
    }

    /// Returns a list of all annotated attributes defined in the body of this class. This is similar
    /// to the `__annotations__` attribute at runtime, but also contains default values.
    ///
    /// For a class body like
    /// ```py
    /// @dataclass

Review comment (suggestion):
Nit: Use `else if` as the two arms are exclusive to each other or use a match
```suggestion
            else if matches!(name.as_str(), "__lt__" | "__le__" | "__gt__" | "__ge__") {
```

or 

```rust
match name.as_str() {
	"__setattr__" | "__delattr__" => {
	}
	"__lt__" | "__le__" | "__gt__" | "__ge__" => {
		...
	}
	_ => {}
}
	
```

Code after:
        let use_def = use_def_map(db, class_body_scope);
        for (symbol_id, declarations) in use_def.all_end_of_scope_symbol_declarations() {
            let result = place_from_declarations(db, declarations.clone());
            let attr = result.ignore_conflicting_declarations();
            let symbol = table.symbol(symbol_id);
            let name = symbol.name();

            let Some(Type::FunctionLiteral(literal)) = attr.place.ignore_possibly_undefined()
            else {
                continue;
            };

            match name.as_str() {
                "__setattr__" | "__delattr__" => {
                    if let CodeGeneratorKind::DataclassLike(_) = field_policy
                        && self.has_dataclass_param(db, field_policy, DataclassFlags::FROZEN)
                    {
                        if let Some(builder) = context.report_lint(
                            &INVALID_DATACLASS_OVERRIDE,
                            literal.node(db, context.file(), context.module()),
                        ) {
                            let mut diagnostic = builder.into_diagnostic(format_args!(
                                "Cannot overwrite attribute `{}` in frozen dataclass `{}`",
                                name,
                                self.name(db)
                            ));
                            diagnostic.info(name);
                        }
                    }
                }
                "__lt__" | "__le__" | "__gt__" | "__ge__" => {
                    if let CodeGeneratorKind::DataclassLike(_) = field_policy
                        && self.has_dataclass_param(db, field_policy, DataclassFlags::ORDER)
                    {
                        if let Some(builder) = context.report_lint(
                            &INVALID_DATACLASS_OVERRIDE,
                            literal.node(db, context.file(), context.module()),
                        ) {
                            let mut diagnostic = builder.into_diagnostic(format_args!(
                                "Cannot overwrite attribute `{}` in dataclass `{}` with `order=True`",
                                name,
                                self.name(db)
                            ));
                            diagnostic.info(name);
                        }
                    }
                }
                _ => {}
            }
        }
    }