passsy / no-globals-filer3
Never Create a Globals File
PublicKeep a constant in the file that uses it, or the one it belongs to most, instead of collecting constants in a globals file; only cross-module constants go to main.dart.
tests, run by the registry8 passed · slowest 4.6 ms
✓fires3.7 ms
fires when the agent writes lib/globals.dart
write lib/globals.dartfired: the file
const timeout = 30;
✓fires3.7 ms
fires when the agent writes lib/src/constants.dart
write lib/src/constants.dartfired: the file
const timeout = 30;
✓fires3.2 ms
fires when the agent writes lib/consts.dart
write lib/consts.dartfired: the file
const timeout = 30;
✓fires3.5 ms
points at the file when the agent appends a constant
write lib/globals.dart · wrote line 2fired: the file
const timeout = 30;
const retries = 3;
✓skips0.0 ms
stays quiet when the agent only reads a legacy globals file
read lib/globals.dartno handler of the detector wants this event
const timeout = 30;
✓skips0.0 ms
stays quiet on a constant in the file that uses it
write lib/sync_engine.dartno handler of the detector wants this event
const timeout = 30;
✓fires4.6 ms
points at the principle when the user asks for globals in a Dart project
prompt · in fixtures/dart_appfired: "globals"
Move the timeouts into globals✓quiet3.5 ms
stays quiet on the same words outside a Dart project
promptstayed quiet
Move the timeouts into globalsdetector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, edit, prompt, read, write } from "@wellactually/sdk/v3/test";
test.each(["lib/globals.dart", "lib/src/constants.dart", "lib/consts.dart"])("fires when the agent writes %s", (path) => {
expect(detect(write(path, "const timeout = 30;\n"))).toEqual([{}]);
});
test("points at the file when the agent appends a constant", () => {
const code = "const timeout = 30;\nconst retries = 3;\n";
expect(detect(edit("lib/globals.dart", code, { written: "const retries = 3;" }))).toEqual([{}]);
});
test("stays quiet when the agent only reads a legacy globals file", () => {
expect(detect(read("lib/globals.dart", "const timeout = 30;\n"))).toEqual([]);
});
test("stays quiet on a constant in the file that uses it", () => {
expect(detect(write("lib/sync_engine.dart", "const timeout = 30;\n"))).toEqual([]);
});
const dartApp = { project: "fixtures/dart_app" };
test("points at the principle when the user asks for globals in a Dart project", () => {
expect(detect(prompt("Move the timeouts into globals"), dartApp)).toEqual([{ match: "globals", depth: "pointer" }]);
});
test("stays quiet on the same words outside a Dart project", () => {
expect(detect(prompt("Move the timeouts into globals"))).toEqual([]);
});