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.
detector.tsisolate · reads files, writes none · no network · 100 ms · 32 MBEdit
import { onWrite } from "@wellactually/sdk/v3";
import { DART_WITHOUT_TESTS } from "dart-kit";
/**
* An indented private static method: a top-level function wearing a class
* qualifier. Whether it reads the class's own static state, the exception the
* rule allows, is not decidable from one line; the advice explains it.
*/
onWrite({
globs: DART_WITHOUT_TESTS,
*detect(event) {
for (const written of event.written) {
if (/^\s+static\s+[\w<>, ?]+\s+_\w+\(/.test(written.text)) {
yield { line: written.line };
}
}
},
});
package.jsonEdit
{
"name": "top-level-private-functions",
"private": true,
"dependencies": {
"dart-kit": "*"
},
"tags": [
"dart"
]
}