Skip to main content

SKY-A117 · AI-code defects

Comparison rigged to always pass

High

Reported as advice, not as a blocking finding, for weaker signs: an ordering method (__lt__ and friends) that returns a constant, a constant __hash__, a constant __str__, __repr__, toString() or toJSON() whose text a test expects, a rigged method on a class whose name says it matches anything (AnyValue, Matcher), and anything in generated code or in a new file nothing imports or runs.

A rigged comparison is an equality method that cannot say "not equal": an __eq__ that always returns True or never looks at the other value, an __ne__ that is always False, a __contains__ that is always True, or a JavaScript equals(), compareTo(), valueOf() or [Symbol.toPrimitive] that returns a constant. SKY-A117 reports such methods on lines a change added.

Languages
Python, JavaScript, TypeScript
Turned on by
skylos done after a change (default base HEAD, so uncommitted edits), or skylos done --base origin/main for a pull request
Quality gate
not checked (full and diff scans). Only skylos done runs this rule, in its test_special_casing check. That check blocks by default: a blocking SKY-A117 finding fails the done verdict, and advice findings are listed without failing it. Set the check to "advise" or "off" under [tool.skylos.done.checks] in the base commit's pyproject.toml to change that.
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Every assert result == expected that touches the class passes, whatever the result is. An agent can turn a red suite green this way without fixing anything, and later bugs in the real values go unnoticed by every test that compares them.

What Skylos flags

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

billing/money.py · Python · changed
"""Money amounts with a currency.""" from decimal import Decimal  class Money:    def __init__(self, amount, currency):        self.amount = Decimal(amount)        self.currency = currency     def __eq__(self, other):Removed:         return (Removed:             self.amount == other.amountRemoved:             and self.currency == other.currencyRemoved:         )Added:         return True

What Skylos leaves alone

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

app/options.py · Python · changed
"""Options a caller may pass to the export job.""" DEFAULT_FORMAT = "csv"Added:  Added:  Added: class Unset:Added:     """Marks an option the caller left out."""Added:  Added:     __hash__ = object.__hash__Added:  Added:     def __eq__(self, other):Added:         return FalseAdded:  Added:  Added: UNSET = Unset()

Why Skylos leaves it alone

This __eq__ also returns a constant and ignores the other value, but the constant is False: a sentinel that equals nothing can only make comparisons fail, never pass. Skylos reports only methods that make comparisons succeed.

More languages

JavaScript

Flagged

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

src/money.js · JavaScript · changed
export class Money {  constructor(amount, currency) {    this.amount = amount;    this.currency = currency;  }   equals(other) {Removed:     return (Removed:       this.amount === other.amount &&Removed:       this.currency === other.currencyRemoved:     );Added:     return true;  }}

Not flagged

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

src/options.js · JavaScript · changed
export const DEFAULT_FORMAT = "csv";Added:  Added: export class Unset {Added:   equals(other) {Added:     return false;Added:   }Added: }Added:  Added: export const UNSET = new Unset();

Why Skylos leaves it alone

An equals() that always returns false cannot make a test pass, so this sentinel is left alone.

How Skylos decides

  1. Runs in skylos done, which compares the working tree (or a pull request) with a base commit. Reads changed non-test Python, JavaScript and TypeScript files and keeps only methods whose definition line or a return line the change added. Test files and test helper folders are skipped.
  2. In Python, looks at methods in a class body, at lambdas assigned to a dunder attribute, and at setattr(cls, "__eq__", lambda ...). A method that can return NotImplemented is left alone.
  3. Blocks on __eq__ that always returns True or never reads its second parameter (unless it always returns False), __ne__ that always returns False, and __contains__ that always returns True.
  4. In JavaScript and TypeScript, blocks on equals(), isEqual(), eq(), equalTo(), sameAs() or isSame() that always returns true or never reads its argument, compareTo() or compare() that always returns 0, and valueOf() or [Symbol.toPrimitive] that returns a literal without using this.
  5. Gives advice instead for a constant ordering method or __hash__, for a constant string form a test expects, for classes named like a wildcard (Any, Anything, Matcher, Wildcard, DontCare), and for code in generated files or in new files nothing imports or runs. A method that was already there at the base is not new.

How to fix it

Compare the fields that define equality, and return NotImplemented for values of another type so Python can try the other side. Then fix the code whose result the test was rejecting.

Fix · Python
def __eq__(self, other):    if not isinstance(other, Money):        return NotImplemented    return (self.amount, self.currency) == (other.amount, other.currency)

When it can be wrong

  • A deliberate "matches anything" helper whose class name does not say so (for example Placeholder) blocks; naming it AnyValue or Matcher turns the finding into advice.
  • It misses a rigged __eq__ that also returns NotImplemented on some path, one built from a helper function, and one that reads the other value but still always holds (return other is not None).

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • skylos done does not read # skylos: ignore comments. To make the whole check advisory, set its mode in the base commit's pyproject.toml; settings in the change itself are ignored.

    TOML
    [tool.skylos.done.checks]test_special_casing = "advise"

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.