-
Notifications
You must be signed in to change notification settings - Fork 23
Support YAML list format for analysis_options includes, and update tests accordingly #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,19 +31,45 @@ final Logger logger = Logger('dependency_validator'); | |
| String bulletItems(Iterable<String> items) => | ||
| items.map((l) => ' * $l').join('\n'); | ||
|
|
||
| /// Returns the name of the package referenced in the `include:` directive in an | ||
| /// analysis_options.yaml file, or null if there is not one. | ||
| String? getAnalysisOptionsIncludePackage({String? path}) { | ||
| /// Returns the names of the packages referenced in the `include:` directive in an | ||
| /// analysis_options.yaml file, or null if there are none. | ||
| /// | ||
| /// Supports both single string includes: | ||
| /// include: package:flutter_lints/flutter.yaml | ||
| /// | ||
| /// And list includes: | ||
| /// include: | ||
| /// - package:flutter_lints/flutter.yaml | ||
| /// - package:another_package/config.yaml | ||
| Set<String>? getAnalysisOptionsIncludePackage({String? path}) { | ||
| final optionsFile = File(p.join(path ?? p.current, 'analysis_options.yaml')); | ||
| if (!optionsFile.existsSync()) return null; | ||
|
|
||
| final YamlMap? analysisOptions = loadYaml(optionsFile.readAsStringSync()); | ||
| if (analysisOptions == null) return null; | ||
|
|
||
| final String? include = analysisOptions['include']; | ||
| if (include == null || !include.startsWith('package:')) return null; | ||
| final dynamic include = analysisOptions['include']; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Slight preference for |
||
| if (include == null) return null; | ||
|
|
||
| final Set<String> packageNames = <String>{}; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: We generally follow this rule https://dart.dev/effective-dart/design#dont-redundantly-type-annotate-initialized-local-variables so the explicit declaration isn't necessary. |
||
|
|
||
| if (include is String) { | ||
| // Handle single string include | ||
| if (include.startsWith('package:')) { | ||
| final packageName = Uri.parse(include).pathSegments.first; | ||
| packageNames.add(packageName); | ||
| } | ||
| } else if (include is YamlList) { | ||
| // Handle list of includes | ||
| for (final dynamic item in include) { | ||
| if (item is String && item.startsWith('package:')) { | ||
| final packageName = Uri.parse(item).pathSegments.first; | ||
| packageNames.add(packageName); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return Uri.parse(include).pathSegments.first; | ||
| return packageNames.isEmpty ? null : packageNames; | ||
| } | ||
|
|
||
| /// Returns an iterable of all Dart files (files ending in .dart) in the given | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why is this check necessary? Wouldn't
...[]do nothing?