-
Notifications
You must be signed in to change notification settings - Fork 29.9k
[flutter_tools] General info project validator #103653
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
Changes from 1 commit
a349bf7
c3678a1
e5f9fb4
8cffb28
7a08e70
ae692e1
7508a5d
f3546a9
dbd23d1
baf833f
2d9b6e8
6ba7624
ac7f156
0176ce6
e9345c6
f32cecb
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,36 @@ | ||||||
| // Copyright 2014 The Flutter Authors. All rights reserved. | ||||||
| // Use of this source code is governed by a BSD-style license that can be | ||||||
| // found in the LICENSE file. | ||||||
|
|
||||||
| import 'package:yaml/yaml.dart'; | ||||||
|
|
||||||
| class PubContent { | ||||||
| PubContent(this.content); | ||||||
|
||||||
| PubContent(this.content); | |
| const PubContent(this.content); |
Outdated
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.
style nit: this can be a getter, since it doesn't accept any parameters. All call-sites will need to be updated to omit the empty parentheses.
| bool isFlutterPackage() { | |
| bool get isFlutterPackage { |
Outdated
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.
| bool usesMaterialDesign() { | |
| bool get usesMaterialDesign { |
Outdated
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.
| bool isPlugin() { | |
| bool get isPlugin { |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| import 'package:yaml/yaml.dart'; | ||
|
|
||
| import 'base/pub_spec_content.dart'; | ||
| import 'project.dart'; | ||
| import 'project_validator_result.dart'; | ||
|
|
||
|
|
@@ -18,10 +19,12 @@ abstract class ProjectValidator { | |
| ]; | ||
| } | ||
|
|
||
| // Validator run for all platforms that extract information from the pubspec.yaml | ||
| // specific info from different platforms should be written in their own ProjectValidator | ||
| class GeneralInfoProjectValidator extends ProjectValidator{ | ||
|
Contributor
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. Can you add a dartdoc?
Contributor
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. These actually need to be
Contributor
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. Also, this should be of the format: single line summary sentence, followed by empty line, then remainder: https://dart.dev/guides/language/effective-dart/documentation#do-separate-the-first-sentence-of-a-doc-comment-into-its-own-paragraph |
||
| @override | ||
| Future<List<ProjectValidatorResult>> start(FlutterProject project) async { | ||
| final YamlMap pubContent = loadYaml(project.pubspecFile.readAsStringSync()) as YamlMap; | ||
| final PubContent pubContent = PubContent(loadYaml(project.pubspecFile.readAsStringSync()) as YamlMap); | ||
| final ProjectValidatorResult appNameValidatorResult = getAppNameResult(pubContent); | ||
| final String supportedPlatforms = getSupportedPlatforms(project); | ||
| if (supportedPlatforms.isEmpty) { | ||
|
|
@@ -38,16 +41,15 @@ class GeneralInfoProjectValidator extends ProjectValidator{ | |
| supportedPlatformsResult, | ||
| isFlutterPackage, | ||
| ]; | ||
| if (isFlutterPackage.value == 'yes') { | ||
| final YamlMap flutterNode = pubContent['flutter'] as YamlMap; | ||
| result.add(materialDesignResult(flutterNode)); | ||
| result.add(pluginValidatorResult(flutterNode)); | ||
| if (pubContent.isFlutterPackage()) { | ||
| result.add(materialDesignResult(pubContent)); | ||
| result.add(pluginValidatorResult(pubContent)); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| ProjectValidatorResult getAppNameResult(YamlMap pubContent) { | ||
| final String? appName = pubContent['name'] as String?; | ||
| ProjectValidatorResult getAppNameResult(PubContent pubContent) { | ||
| final String? appName = pubContent.appName; | ||
| const String name = 'App Name'; | ||
| if (appName == null) { | ||
| return const ProjectValidatorResult( | ||
|
|
@@ -63,10 +65,10 @@ class GeneralInfoProjectValidator extends ProjectValidator{ | |
| ); | ||
| } | ||
|
|
||
| ProjectValidatorResult isFlutterPackageValidatorResult(YamlMap pubContent) { | ||
| ProjectValidatorResult isFlutterPackageValidatorResult(PubContent pubContent) { | ||
| String value; | ||
|
||
| StatusProjectValidator status; | ||
| if (pubContent.containsKey('flutter')) { | ||
| if (pubContent.isFlutterPackage()) { | ||
| value = 'yes'; | ||
| status = StatusProjectValidator.success; | ||
| } else { | ||
|
|
@@ -81,38 +83,22 @@ class GeneralInfoProjectValidator extends ProjectValidator{ | |
| ); | ||
| } | ||
|
|
||
| ProjectValidatorResult materialDesignResult(YamlMap flutterNode) { | ||
| bool isMaterialDesign; | ||
|
|
||
| if (flutterNode.containsKey('uses-material-design')) { | ||
| isMaterialDesign = flutterNode['uses-material-design'] as bool; | ||
| } else { | ||
| isMaterialDesign = false; | ||
| } | ||
|
|
||
| final String value = isMaterialDesign? 'yes' : 'no'; | ||
| ProjectValidatorResult materialDesignResult(PubContent pubContent) { | ||
| return ProjectValidatorResult( | ||
| name: 'Uses Material Design', | ||
| value: value, | ||
| value: pubContent.usesMaterialDesign()? 'yes' : 'no', | ||
| status: StatusProjectValidator.success | ||
| ); | ||
| } | ||
|
|
||
| String getSupportedPlatforms(FlutterProject project) { | ||
| final List<SupportedPlatform> supportedPlatforms = project.getSupportedPlatforms(); | ||
| final List<String> allPlatforms = <String>[]; | ||
|
|
||
| for (final SupportedPlatform platform in supportedPlatforms) { | ||
| allPlatforms.add(platform.name); | ||
| } | ||
| return allPlatforms.join(', '); | ||
| return project.getSupportedPlatforms().map((SupportedPlatform platform) => platform.name).join(', '); | ||
| } | ||
|
|
||
| ProjectValidatorResult pluginValidatorResult(YamlMap flutterNode) { | ||
| final String value = flutterNode.containsKey('plugin')? 'yes' : 'no'; | ||
| ProjectValidatorResult pluginValidatorResult(PubContent pubContent) { | ||
| return ProjectValidatorResult( | ||
| name: 'Is Plugin', | ||
| value: value, | ||
| value: pubContent.isPlugin()? 'yes' : 'no', | ||
| status: StatusProjectValidator.success | ||
| ); | ||
| } | ||
|
|
||
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. let's call this
PubspecContent, since pub is the name of the tool. Also, can you name this filepubspec_content.dart?