passsy / place-enums-with-classr3
Place Enums Next to Class
PublicKeep 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
✓fires2.7 ms
fires on an enum the agent puts in a file of its own
write lib/signal_strength.dartfired: line 2
// How strong the trainer signal is.
enum SignalStrength { lost, poor, fair, good, best }✓quiet2.8 ms
stays quiet when the enum sits next to its class
write lib/signal_meter.dartstayed quiet
class SignalMeter {
SignalStrength strength = SignalStrength.lost;
}
enum SignalStrength { lost, poor, fair, good, best }✓quiet2.1 ms
stays quiet when a top-level function gives the file its own reason
write lib/signal_strength.dartstayed quiet
enum SignalStrength { lost, poor, fair, good, best }
SignalStrength? fromRssi(int? rssi) {
return SignalStrength.lost;
}✓quiet2.7 ms
stays quiet when the edit writes no enum
write lib/signal_strength.dart · wrote line 1stayed quiet
// How strong the trainer signal is.
enum SignalStrength { lost, poor, fair, good, best }✓skips0.0 ms
stays quiet on a read and in tests
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 }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([]);
});