passsy / main-class-at-topr2
Place Main Class at the Top
PublicPut the class a file is named after at the very top of the file, above its helper classes, enums and extensions, so readers meet the main type first.
tests, run by the registry5 passed · slowest 2.0 ms
✓fires1.1 ms
fires on every declaration above the class the file is named after
write lib/image_api.dartfired: line 1, line 3
class Photo {}
enum Size { small, large }
class ImageApi {
List<Photo> getPhotos() => [];
}✓quiet2.0 ms
stays quiet when the main class comes first
write lib/image_api.dartstayed quiet
class ImageApi {
List<Photo> getPhotos() => [];
}
class Photo {}✓quiet1.1 ms
stays quiet when no class is named after the file
write lib/gallery.dartstayed quiet
class Photo {}
enum Size { small, large }
class ImageApi {
List<Photo> getPhotos() => [];
}✓quiet1.1 ms
stays quiet when the edit writes no declaration
write lib/image_api.dart · wrote line 6stayed quiet
class Photo {}
enum Size { small, large }
class ImageApi {
List<Photo> getPhotos() => [];
}✓skips0.0 ms
stays quiet on a read and in tests
read lib/image_api.dartno handler of the detector wants this event
class Photo {}
enum Size { small, large }
class ImageApi {
List<Photo> getPhotos() => [];
}write test/image_api.dartno handler of the detector wants this event
class Photo {}
enum Size { small, large }
class ImageApi {
List<Photo> getPhotos() => [];
}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 bad = source`
class Photo {}
enum Size { small, large }
class ImageApi {
List<Photo> getPhotos() => [];
}
`;
test("fires on every declaration above the class the file is named after", () => {
expect(detect(write("lib/image_api.dart", bad))).toEqual([
{ line: 1 },
{ line: 3 },
]);
});
test("stays quiet when the main class comes first", () => {
const good = source`
class ImageApi {
List<Photo> getPhotos() => [];
}
class Photo {}
`;
expect(detect(write("lib/image_api.dart", good))).toEqual([]);
});
test("stays quiet when no class is named after the file", () => {
expect(detect(write("lib/gallery.dart", bad))).toEqual([]);
});
test("stays quiet when the edit writes no declaration", () => {
expect(detect(edit("lib/image_api.dart", bad, { written: " List<Photo> getPhotos() => [];" }))).toEqual([]);
});
test("stays quiet on a read and in tests", () => {
expect(detect(read("lib/image_api.dart", bad))).toEqual([]);
expect(detect(write("test/image_api.dart", bad))).toEqual([]);
});