| Index: sdk/lib/_internal/pub/lib/src/validator/pubspec_field.dart
|
| diff --git a/sdk/lib/_internal/pub/lib/src/validator/pubspec_field.dart b/sdk/lib/_internal/pub/lib/src/validator/pubspec_field.dart
|
| index e9d2d35452f87f98e005fc7ee28f5c5db7a14667..d43407cf10fa372c1d263e58242357d3c35604ef 100644
|
| --- a/sdk/lib/_internal/pub/lib/src/validator/pubspec_field.dart
|
| +++ b/sdk/lib/_internal/pub/lib/src/validator/pubspec_field.dart
|
| @@ -39,21 +39,41 @@ class PubspecFieldValidator extends Validator {
|
| }
|
| }
|
|
|
| - var homepage = pubspec.fields['homepage'];
|
| - if (homepage == null) {
|
| - errors.add('Your pubspec.yaml is missing a "homepage" field.');
|
| - }
|
| + _validateFieldExists('description');
|
| + _validateFieldExists('version');
|
| + _validateFieldExists('homepage');
|
| + _validateFieldUrl('homepage');
|
| + _validateFieldUrl('documentation');
|
|
|
| - var description = pubspec.fields['description'];
|
| - if (description == null) {
|
| - errors.add('Your pubspec.yaml is missing a "description" field.');
|
| + // Pubspec errors are detected lazily, so we make sure there aren't any
|
| + // here.
|
| + for (var error in pubspec.allErrors) {
|
| + errors.add('In your pubspec.yaml, ${error.message}');
|
| }
|
|
|
| - var version = pubspec.fields['version'];
|
| - if (version == null) {
|
| - errors.add('Your pubspec.yaml is missing a "version" field.');
|
| + return new Future.value();
|
| + }
|
| +
|
| + void _validateFieldExists(String field) {
|
| + if (entrypoint.root.pubspec.fields[field] != null) return;
|
| + errors.add('Your pubspec.yaml is missing a "$field" field.');
|
| + }
|
| +
|
| + /// Adds an error if the given [url] for [field] is invalid.
|
| + void _validateFieldUrl(String field) {
|
| + var url = entrypoint.root.pubspec.fields[field];
|
| + if (url == null) return;
|
| +
|
| + if (url is! String) {
|
| + errors.add('Your pubspec.yaml\'s "$field" field must be a string, but '
|
| + 'it was "$url".');
|
| + return;
|
| }
|
|
|
| - return new Future.value();
|
| + var goodScheme = new RegExp(r'^https?:');
|
| + if (!goodScheme.hasMatch(url)) {
|
| + errors.add('Your pubspec.yaml\'s "$field" field must be an "http:" or '
|
| + '"https:" URL, but it was "$url".');
|
| + }
|
| }
|
| }
|
|
|