registerNodeProcessors method
Registers node processors in the given registry.
The node processors may use the provided context to access information
that is not available from the AST nodes or their associated elements.
Implementation
@override
void registerNodeProcessors(
RuleVisitorRegistry registry, RuleContext context) {
// TODO check analysis_options file for ignored files.
// https://github.com/dart-lang/sdk/issues/61770
final visitor = StringLiteralVisitor.context(
context: () => StringLiteralContext(
filePath: context.currentUnit?.file.path ?? '',
unit: context.currentUnit?.unit,
lineInfo: context.currentUnit?.unit.lineInfo,
),
foundStringLiteral: (foundStringLiteral) {
final file = context.currentUnit?.file;
final options = findAnalysisOptions(file);
if (file != null) {
if (options != null && options.isExcluded(file.path)) {
return;
}
}
final content = context.currentUnit?.content ?? '';
String stringValue() {
if (content.length < foundStringLiteral.charEnd) {
return '';
}
return content
.substring(
foundStringLiteral.charOffset,
foundStringLiteral.charEnd,
)
.trim();
}
final stringCode = foundStringLiteral.stringValue ?? stringValue();
reportAtNode(foundStringLiteral.stringLiteral, arguments: [
stringCode,
]);
});
registry.addSimpleStringLiteral(this, visitor);
registry.addAdjacentStrings(this, visitor);
}