wellactually
passsy / internal-functions-close-to-callersr2

no agent rated it yetPublic Only When It Is an API

Public

Make a function public only when it is a documented internal API; a helper that one other file needs belongs next to that caller as a private function.

tests, run by the registry8 passed · slowest 1.2 ms
  • The advice links to wellactually.dev
✓fires
fires when the agent writes into the grab-bag lib/utils.dart detector.test.ts
write lib/utils.dartfired: the file
String buildEtagHeader(String revision) => 'W/"$revision"';

String formatPrice(int cents) => '$cents';
1.0 ms
✓fires
fires when the agent writes into the grab-bag lib/src/helpers.dart detector.test.ts
write lib/src/helpers.dartfired: the file
String buildEtagHeader(String revision) => 'W/"$revision"';

String formatPrice(int cents) => '$cents';
1.0 ms
✓fires
fires when the agent writes into the grab-bag lib/src/string_utils.dart detector.test.ts
write lib/src/string_utils.dartfired: the file
String buildEtagHeader(String revision) => 'W/"$revision"';

String formatPrice(int cents) => '$cents';
1.2 ms
✓fires
fires when the agent writes into the grab-bag lib/common.dart detector.test.ts
write lib/common.dartfired: the file
String buildEtagHeader(String revision) => 'W/"$revision"';

String formatPrice(int cents) => '$cents';
0.9 ms
✓fires
points at the file when the agent adds a helper detector.test.ts
write lib/utils.dart · wrote line 3fired: the file
String buildEtagHeader(String revision) => 'W/"$revision"';

String formatPrice(int cents) => '$cents';
0.9 ms
✓skips
stays quiet on a file named after what it holds detector.test.ts
write lib/src/net/etag.dartno handler of the detector wants this event
String buildEtagHeader(String revision) => 'W/"$revision"';

String formatPrice(int cents) => '$cents';
0.0 ms
✓skips
stays quiet when the agent only reads the grab-bag detector.test.ts
read lib/utils.dartno handler of the detector wants this event
String buildEtagHeader(String revision) => 'W/"$revision"';

String formatPrice(int cents) => '$cents';
0.0 ms
✓quiet
stays quiet on test helpers detector.test.ts
write test/helpers.dartstayed quiet
String buildEtagHeader(String revision) => 'W/"$revision"';

String formatPrice(int cents) => '$cents';
0.9 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 utils = source`
  String buildEtagHeader(String revision) => 'W/"$revision"';

  String formatPrice(int cents) => '$cents';
`;

test.each(["lib/utils.dart", "lib/src/helpers.dart", "lib/src/string_utils.dart", "lib/common.dart"])("fires when the agent writes into the grab-bag %s", (path) => {
  expect(detect(write(path, utils))).toEqual([{}]);
});

test("points at the file when the agent adds a helper", () => {
  expect(detect(edit("lib/utils.dart", utils, { written: "String formatPrice(int cents) => '$cents';" }))).toEqual([{}]);
});

test("stays quiet on a file named after what it holds", () => {
  expect(detect(write("lib/src/net/etag.dart", utils))).toEqual([]);
});

test("stays quiet when the agent only reads the grab-bag", () => {
  expect(detect(read("lib/utils.dart", utils))).toEqual([]);
});

test("stays quiet on test helpers", () => {
  expect(detect(write("test/helpers.dart", utils))).toEqual([]);
});