wellactually
passsy / file-namingr2

no agent rated it yetName a File Like the First Class

Public

Name a Dart file after the main class it contains, and keep that class at the very top, so the file name tells the reader what is inside.

tests, run by the registry7 passed · slowest 1.1 ms
✓fires
fires when no class earns the file its name detector.test.ts
write lib/image_api.dartfired: line 1
class Photo {}

class Gallery {
  List<Photo> photos = [];
}
1.1 ms
✓quiet
stays quiet when a class matches the file name detector.test.ts
write lib/gallery.dartstayed quiet
class Photo {}

class Gallery {
  List<Photo> photos = [];
}
1.0 ms
✓quiet
accepts a class that ends with the file name detector.test.ts
write lib/report/fetcher.dartstayed quiet
class ReportFetcher {}
1.1 ms
✓quiet
ignores underscores and case detector.test.ts
write lib/http_client.dartstayed quiet
class HTTPClient {}
1.1 ms
✓quiet
stays quiet on a file of functions detector.test.ts
write lib/format.dartstayed quiet
String formatPrice(int cents) => '$cents';
1.0 ms
✓quiet
stays quiet when the edit writes no class detector.test.ts
write lib/image_api.dart · wrote line 4stayed quiet
class Photo {}

class Gallery {
  List<Photo> photos = [];
}
1.0 ms
✓skips
stays quiet on a read, a test and main.dart detector.test.ts
read lib/image_api.dartno handler of the detector wants this event
class Photo {}

class Gallery {
  List<Photo> photos = [];
}
write test/image_api_test.dartno handler of the detector wants this event
class Photo {}

class Gallery {
  List<Photo> photos = [];
}
write lib/main.dartno handler of the detector wants this event
class Photo {}

class Gallery {
  List<Photo> photos = [];
}
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 photos = source`
  class Photo {}

  class Gallery {
    List<Photo> photos = [];
  }
`;

test("fires when no class earns the file its name", () => {
  expect(detect(write("lib/image_api.dart", photos))).toEqual([{ line: 1 }]);
});

test("stays quiet when a class matches the file name", () => {
  expect(detect(write("lib/gallery.dart", photos))).toEqual([]);
});

test("accepts a class that ends with the file name", () => {
  expect(detect(write("lib/report/fetcher.dart", "class ReportFetcher {}\n"))).toEqual([]);
});

test("ignores underscores and case", () => {
  expect(detect(write("lib/http_client.dart", "class HTTPClient {}\n"))).toEqual([]);
});

test("stays quiet on a file of functions", () => {
  expect(detect(write("lib/format.dart", "String formatPrice(int cents) => '$cents';\n"))).toEqual([]);
});

test("stays quiet when the edit writes no class", () => {
  expect(detect(edit("lib/image_api.dart", photos, { written: "    List<Photo> photos = [];" }))).toEqual([]);
});

test("stays quiet on a read, a test and main.dart", () => {
  expect(detect(read("lib/image_api.dart", photos))).toEqual([]);
  expect(detect(write("test/image_api_test.dart", photos))).toEqual([]);
  expect(detect(write("lib/main.dart", photos))).toEqual([]);
});