passsy / top-level-private-functionsr3
Private Helpers Are Top-Level Functions
PublicWrite a private helper that does not touch instance state as a top-level function in the file, not a static member, because library privacy already scopes it.
tests, run by the registry6 passed · slowest 2.7 ms
- The advice links to wellactually.dev
✓fires2.2 ms
fires on a private static helper
write lib/invoice_renderer.dartfired: line 7
/// Renders invoices.
class InvoiceRenderer {
String render(List<String> lines) {
return _formatLines(lines).join(', ');
}
static List<String> _formatLines(List<String> lines) {
return lines;
}
}✓quiet2.7 ms
stays quiet on a top-level private helper
write lib/invoice_renderer.dartstayed quiet
/// Renders invoices.
class InvoiceRenderer {
String render(List<String> lines) {
return _formatLines(lines).join(', ');
}
}
List<String> _formatLines(List<String> lines) {
return lines;
}✓quiet2.0 ms
stays quiet on a static const and a public static method
write lib/timeouts.dartstayed quiet
class Timeouts {
static const _zero = Duration.zero;
static Timeouts parse(String raw) {
return Timeouts();
}
}✓skips0.0 ms
stays quiet in test files
write test/helpers_test.dartno handler of the detector wants this event
class TestHelpers {
static String _wrap(String value) {
return value;
}
}
void main() {}✓quiet1.8 ms
stays quiet on a static helper the agent did not write
write lib/invoice_renderer.dart · wrote line 8stayed quiet
/// Renders invoices.
class InvoiceRenderer {
String render(List<String> lines) {
return _formatLines(lines).join(', ');
}
static List<String> _formatLines(List<String> lines) {
return lines;
}
}✓skips0.0 ms
stays quiet when the agent only reads the file
read lib/invoice_renderer.dartno handler of the detector wants this event
/// Renders invoices.
class InvoiceRenderer {
String render(List<String> lines) {
return _formatLines(lines).join(', ');
}
static List<String> _formatLines(List<String> lines) {
return lines;
}
}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 renderer = source`
/// Renders invoices.
class InvoiceRenderer {
String render(List<String> lines) {
return _formatLines(lines).join(', ');
}
static List<String> _formatLines(List<String> lines) {
return lines;
}
}
`;
test("fires on a private static helper", () => {
expect(detect(write("lib/invoice_renderer.dart", renderer))).toEqual([{ line: 7 }]);
});
test("stays quiet on a top-level private helper", () => {
const code = source`
/// Renders invoices.
class InvoiceRenderer {
String render(List<String> lines) {
return _formatLines(lines).join(', ');
}
}
List<String> _formatLines(List<String> lines) {
return lines;
}
`;
expect(detect(write("lib/invoice_renderer.dart", code))).toEqual([]);
});
test("stays quiet on a static const and a public static method", () => {
const code = source`
class Timeouts {
static const _zero = Duration.zero;
static Timeouts parse(String raw) {
return Timeouts();
}
}
`;
expect(detect(write("lib/timeouts.dart", code))).toEqual([]);
});
test("stays quiet in test files", () => {
const code = source`
class TestHelpers {
static String _wrap(String value) {
return value;
}
}
void main() {}
`;
expect(detect(write("test/helpers_test.dart", code))).toEqual([]);
});
test("stays quiet on a static helper the agent did not write", () => {
expect(detect(edit("lib/invoice_renderer.dart", renderer, { written: " return lines;" }))).toEqual([]);
});
test("stays quiet when the agent only reads the file", () => {
expect(detect(read("lib/invoice_renderer.dart", renderer))).toEqual([]);
});