wellactually
passsy / place-enums-with-classr3

no agent rated it yetPlace Enums Next to Class

Public

Keep an enum in the same file as the class that primarily uses it instead of giving it a file of its own.

tests, run by the registry5 passed · slowest 2.8 ms
✓fires
fires on an enum the agent puts in a file of its own detector.test.ts
write lib/signal_strength.dartfired: line 2
// How strong the trainer signal is.
enum SignalStrength { lost, poor, fair, good, best }
2.7 ms
✓quiet
stays quiet when the enum sits next to its class detector.test.ts
write lib/signal_meter.dartstayed quiet
class SignalMeter {
  SignalStrength strength = SignalStrength.lost;
}

enum SignalStrength { lost, poor, fair, good, best }
2.8 ms
✓quiet
stays quiet when a top-level function gives the file its own reason detector.test.ts
write lib/signal_strength.dartstayed quiet
enum SignalStrength { lost, poor, fair, good, best }

SignalStrength? fromRssi(int? rssi) {
  return SignalStrength.lost;
}
2.1 ms
✓quiet
stays quiet when the edit writes no enum detector.test.ts
write lib/signal_strength.dart · wrote line 1stayed quiet
// How strong the trainer signal is.
enum SignalStrength { lost, poor, fair, good, best }
2.7 ms
✓skips
stays quiet on a read and in tests detector.test.ts
read lib/signal_strength.dartno handler of the detector wants this event
// How strong the trainer signal is.
enum SignalStrength { lost, poor, fair, good, best }
write test/signal_strength_test.dartno handler of the detector wants this event
// How strong the trainer signal is.
enum SignalStrength { lost, poor, fair, good, best }
0.0 ms
detector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, edit, read, source, write } from "@wellactually/sdk/v3/test";

const lonely = source`
  // How strong the trainer signal is.
  enum SignalStrength { lost, poor, fair, good, best }
`;

test("fires on an enum the agent puts in a file of its own", () => {
  expect(detect(write("lib/signal_strength.dart", lonely))).toEqual([{ line: 2 }]);
});

test("stays quiet when the enum sits next to its class", () => {
  const code = source`
    class SignalMeter {
      SignalStrength strength = SignalStrength.lost;
    }

    enum SignalStrength { lost, poor, fair, good, best }
  `;
  expect(detect(write("lib/signal_meter.dart", code))).toEqual([]);
});

test("stays quiet when a top-level function gives the file its own reason", () => {
  const code = source`
    enum SignalStrength { lost, poor, fair, good, best }

    SignalStrength? fromRssi(int? rssi) {
      return SignalStrength.lost;
    }
  `;
  expect(detect(write("lib/signal_strength.dart", code))).toEqual([]);
});

test("stays quiet when the edit writes no enum", () => {
  expect(detect(edit("lib/signal_strength.dart", lonely, { written: "// How strong the trainer signal is." }))).toEqual([]);
});

test("stays quiet on a read and in tests", () => {
  expect(detect(read("lib/signal_strength.dart", lonely))).toEqual([]);
  expect(detect(write("test/signal_strength_test.dart", lonely))).toEqual([]);
});