Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions packages/flutter_tools/lib/src/base/pub_spec_content.dart
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 {
Copy link
Contributor

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 file pubspec_content.dart?

Suggested change
class PubContent {
class PubspecContent {

PubContent(this.content);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, this constructor can be const. for the real tool, we probably won't be able to make any instances const (since we will be reading the content from disk), but maybe in tests?

Suggested change
PubContent(this.content);
const PubContent(this.content);

final YamlMap content;

String? get appName {
return content['name'] as String?;
}

YamlMap get flutterNode {
return content['flutter'] as YamlMap;
}

bool isFlutterPackage() {
Copy link
Contributor

@christopherfujino christopherfujino May 13, 2022

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.

Suggested change
bool isFlutterPackage() {
bool get isFlutterPackage {

return flutterNode != null;
}

bool usesMaterialDesign() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool usesMaterialDesign() {
bool get usesMaterialDesign {

if (!isFlutterPackage() || !flutterNode.containsKey('uses-material-design')){
return false;
}
return flutterNode['uses-material-design'] as bool;
}

bool isPlugin() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool isPlugin() {
bool get isPlugin {

if (!isFlutterPackage()) {
return false;
}
return flutterNode.containsKey('plugin');
}
}
46 changes: 16 additions & 30 deletions packages/flutter_tools/lib/src/project_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:yaml/yaml.dart';

import 'base/pub_spec_content.dart';
import 'project.dart';
import 'project_validator_result.dart';

Expand All @@ -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{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a dartdoc?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These actually need to be /// for them to be parsed by the dartdoc tool: https://dart.dev/guides/language/effective-dart/documentation#do-use--doc-comments-to-document-members-and-types

Copy link
Contributor

Choose a reason for hiding this comment

The 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) {
Expand All @@ -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(
Expand All @@ -63,10 +65,10 @@ class GeneralInfoProjectValidator extends ProjectValidator{
);
}

ProjectValidatorResult isFlutterPackageValidatorResult(YamlMap pubContent) {
ProjectValidatorResult isFlutterPackageValidatorResult(PubContent pubContent) {
String value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two can be final

StatusProjectValidator status;
if (pubContent.containsKey('flutter')) {
if (pubContent.isFlutterPackage()) {
value = 'yes';
status = StatusProjectValidator.success;
} else {
Expand All @@ -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
);
}
Expand Down