wellactually
passsy / no-globals-filer3

no agent rated it yetNever Create a Globals File

Public

Keep 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
✓fires
fires when the agent writes lib/globals.dart detector.test.ts
write lib/globals.dartfired: the file
const timeout = 30;
3.7 ms
✓fires
fires when the agent writes lib/src/constants.dart detector.test.ts
write lib/src/constants.dartfired: the file
const timeout = 30;
3.7 ms
✓fires
fires when the agent writes lib/consts.dart detector.test.ts
write lib/consts.dartfired: the file
const timeout = 30;
3.2 ms
✓fires
points at the file when the agent appends a constant detector.test.ts
write lib/globals.dart · wrote line 2fired: the file
const timeout = 30;
const retries = 3;
3.5 ms
✓skips
stays quiet when the agent only reads a legacy globals file detector.test.ts
read lib/globals.dartno handler of the detector wants this event
const timeout = 30;
0.0 ms
✓skips
stays quiet on a constant in the file that uses it detector.test.ts
write lib/sync_engine.dartno handler of the detector wants this event
const timeout = 30;
0.0 ms
✓fires
points at the principle when the user asks for globals in a Dart project detector.test.ts
prompt · in fixtures/dart_appfired: "globals"
Move the timeouts into globals
4.6 ms
✓quiet
stays quiet on the same words outside a Dart project detector.test.ts
promptstayed quiet
Move the timeouts into globals
3.5 ms
detector.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([]);
});