Replies: 2 comments 13 replies
-
You're not meant to access the ResolvedUnit directly. Instead use context.registry to listen to what you care about. This is a much more efficient way of listening to AstNodes. |
Beta Was this translation helpful? Give feedback.
-
Somewhat related question - you said e.g. Is this not a correct way to add a lint error? context.registry.addMethodInvocation((final node) {
final name = node.toString();
if (regex.hasMatch(name)) {
reporter.reportErrorForNode(code, node);
}
}); |
Beta Was this translation helpful? Give feedback.
-
I don't see that there's any way to access the resolved the unit in an individual lint rule.
run
doesn't return a future, so I can't awaitresolver.getResolvedUnitResult()
without getting a bunch of errors (and no linting). The best I can do seems to be overridestartup
and copyDartLintRule
's startup into my rule (including_stateKey
), then setting its resolvedunit
to a class field. Then I can access the resolved unit just fine inrun
. However, this also requires me to use custom_lint_core'sLinterVisitor
andcontext.registry.nodeLintRegistry
which are both supposed to be internal to the package.Overall the goal is to run a regex on a whole file to pull out some very specific cases that I can't find any other way to cover.
Beta Was this translation helpful? Give feedback.
All reactions