Closed azizarc88 closed 5 months ago
That specific example is not easily feasible, because the AST of other files is not accessible naturally. You may need to adapt your API to be more accessible to linters. The API design matters a lot when writing lints.
One proposal: Consider having a "key" constant for every registered object:
class Test {
Test(this.data) {
register(object1, "hello");
register(object2, 42);
}
static final object1 = Key<String>();
static final object2 = Key<int>();
static final object3 = Key();
}
You could then implement a lint that warns if a static final name = Key()
is declared but not registered inside the constructor.
In the above example, you'd have a warning because object3
is never registered.
Such an API wouldn't involve reading the AST of other files. And it can make reading/initializing objects type-safe.
Anw, just wondering, is it possible in custom_lint to create some rules that check the "value" are exist in the list in different file ?
file1.dart
file2.dart