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.
detector.tsisolate · reads files, writes none · no network · 100 ms · 32 MBEdit
import { mentioned, onPrompt, onWrite } from "@wellactually/sdk/v3";
import { isDartProject } from "dart-kit";
onPrompt({
*detect(event) {
if (isDartProject(event)) {
yield* mentioned(event, ["globals", "global constant", "global constants"]);
}
},
});
// The name alone is the signal, but only when the agent writes to it:
// creating one or appending the next constant is the moment to redirect.
// The finding points at the file.
onWrite({
globs: ["**/{globals,global,constants,consts}.dart"],
*detect(event) {
yield {};
},
});
fixtures/dart_app/pubspec.yamlEdit
namedemo
package.jsonEdit
{
"name": "no-globals-file",
"private": true,
"dependencies": {
"dart-kit": "*"
},
"tags": [
"dart"
]
}