linter function

List<LinterIssue> linter(
  1. Parser parser, {
  2. LinterCallback? callback,
  3. List<LinterRule>? rules,
  4. Set<String> excludedRules = const {},
  5. Set<LinterType> excludedTypes = const {LinterType.info},
})

Returns a list of linter issues found when analyzing the parser graph reachable from parser.

The optional callback is triggered during the search for each issue discovered.

A custom list of rules can be provided, otherwise allLinterRules are used and filtered by the set of excludedRules and excludedTypes (rules of LinterType.info are ignored by default).

Implementation

List<LinterIssue> linter(Parser parser,
    {LinterCallback? callback,
    List<LinterRule>? rules,
    Set<String> excludedRules = const {},
    Set<LinterType> excludedTypes = const {LinterType.info}}) {
  final issues = <LinterIssue>[];
  final analyzer = Analyzer(parser);
  final selectedRules = rules ??
      allLinterRules
          .where((rule) =>
              !excludedRules.contains(rule.title) &&
              !excludedTypes.contains(rule.type))
          .toList(growable: false);
  for (final parser in analyzer.parsers) {
    for (final rule in selectedRules) {
      rule.run(analyzer, parser, (issue) {
        if (callback != null) {
          callback(issue);
        }
        issues.add(issue);
      });
    }
  }
  return issues;
}