Repository: astral-sh/ruff
File: scripts/conformance.py (Python)

Code before:
            diagnostic.multi for diagnostic in self.expected
        )

    def diagnostics_by_source(self, source: Source) -> list[Diagnostic]:
        match source:
            case Source.NEW:
                return self.new or []
            case Source.OLD:
                return self.old or []
            case Source.EXPECTED:
                return self.expected or []
            case _:
                raise ValueError(f"Invalid source: {source}")

    def classify(self, source: Source) -> Classification:
        if source in self.sources and Source.EXPECTED in self.sources:
            assert self.expected is not None
            distinct_lines = len(
                {
                    diagnostic.location.positions.begin.line
                    for diagnostic in self.diagnostics_by_source(source)
                }
            )
            expected_max = len(self.expected) if self.multi else 1

            if 1 <= distinct_lines <= expected_max:
                return Classification.TRUE_POSITIVE
            else:
                return Classification.FALSE_POSITIVE

        elif source in self.sources and Source.EXPECTED not in self.sources:
            return Classification.FALSE_POSITIVE

        elif Source.EXPECTED in self.sources:
            return Classification.FALSE_NEGATIVE

        else:
            return Classification.TRUE_NEGATIVE

    def _render_row(self, diagnostics: list[Diagnostic]):
        locs = []
        check_names = []
        descriptions = []

        for diagnostic in diagnostics:
            loc = (
                diagnostic.location.as_link()
                if diagnostic.location
                else f"`{diagnostic.tag}`"
            )
            locs.append(loc)

Review comment (suggestion):
I can see how classifying too many diagnostics as false positives can be a bit confusing but I think it's the right thing. There's at least one false positive. 

It might be better to count them as both a true positive and false positive, but I suspect that this doesn't play well with how we use those numbers later on.

Code after:
        return bool(self.expected) and all(
            diagnostic.optional for diagnostic in self.expected
        )

    @property
    def multi(self) -> bool:
        return bool(self.expected) and all(
            diagnostic.multi for diagnostic in self.expected
        )

    def diagnostics_by_source(self, source: Source) -> list[Diagnostic]:
        match source:
            case Source.NEW:
                return self.new
            case Source.OLD:
                return self.old
            case Source.EXPECTED:
                return self.expected

    def classify(self, source: Source) -> Evaluation:
        diagnostics = self.diagnostics_by_source(source)

        if source in self.sources:
            if self.optional:
                return Evaluation(
                    classification=Classification.TRUE_POSITIVE,
                    true_positives=len(diagnostics),
                    false_positives=0,
                    true_negatives=0,
                    false_negatives=0,
                )

            if Source.EXPECTED in self.sources:
                distinct_lines = len(
                    {
                        diagnostic.location.positions.begin.line
                        for diagnostic in diagnostics
                    }
                )
                expected_max = len(self.expected) if self.multi else 1

                if 1 <= distinct_lines <= expected_max:
                    return Evaluation(
                        classification=Classification.TRUE_POSITIVE,
                        true_positives=len(diagnostics),
                        false_positives=0,
                        true_negatives=0,
                        false_negatives=0,
                    )
                else:
                    # We select the line with the most diagnostics