detectExclusionsFromAnalyzer function
Detects files to be excluded from API documentation generation based on analysis_options.yaml
This function reads the analysis_options.yaml file at the specified root directory
and extracts file exclusion patterns from the 'analyzer.exclude' section.
It returns a Set of normalized file paths that match the exclusion patterns.
If the analysis_options.yaml file doesn't exist or doesn't contain exclusion patterns, an empty Set is returned and a message is printed.
Implementation
Set<String> detectExclusionsFromAnalyzer(String root) {
final analysisOptions = File('$root/analysis_options.yaml');
if (!analysisOptions.existsSync()) {
return <String>{};
}
final exclusions = <String>{};
final analysisOptionsContent = analysisOptions.readAsStringSync();
final yaml = loadYaml(analysisOptionsContent);
final exclude = yaml['analyzer']['exclude'] as YamlList?;
if (exclude != null) {
for (final path in exclude) {
var pattern = Glob(path);
for (final file in pattern.listSync(root: root)) {
exclusions.add(normalize(file.path));
}
}
}
return exclusions;
}