Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: utils/pub/validator/pubspec_field.dart

Issue 11557008: Make pub publish more user friendly: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge in path changes. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/pub/validator/name.dart ('k') | utils/tests/pub/directory_tree_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library pubspec_field_validator; 5 library pubspec_field_validator;
6 6
7 import '../entrypoint.dart'; 7 import '../entrypoint.dart';
8 import '../system_cache.dart'; 8 import '../system_cache.dart';
9 import '../validator.dart'; 9 import '../validator.dart';
10 import '../version.dart';
10 11
11 /// A validator that checks that the pubspec has valid "author" and "homepage" 12 /// A validator that checks that the pubspec has valid "author" and "homepage"
12 /// fields. 13 /// fields.
13 class PubspecFieldValidator extends Validator { 14 class PubspecFieldValidator extends Validator {
14 PubspecFieldValidator(Entrypoint entrypoint) 15 PubspecFieldValidator(Entrypoint entrypoint)
15 : super(entrypoint); 16 : super(entrypoint);
16 17
17 Future validate() { 18 Future validate() {
18 // The types of all fields are validated when the pubspec is parsed. 19 // The types of all fields are validated when the pubspec is parsed.
19 var pubspec = entrypoint.root.pubspec; 20 var pubspec = entrypoint.root.pubspec;
20 var author = pubspec.fields['author']; 21 var author = pubspec.fields['author'];
21 var authors = pubspec.fields['authors']; 22 var authors = pubspec.fields['authors'];
22 if (author == null && authors == null) { 23 if (author == null && authors == null) {
23 errors.add('pubspec.yaml is missing an "author" or "authors" field.'); 24 errors.add('Your pubspec.yaml must have an "author" or "authors" field.');
24 } else { 25 } else {
25 if (authors == null) authors = [author]; 26 if (authors == null) authors = [author];
26 27
27 var hasName = new RegExp(r"^ *[^< ]"); 28 var hasName = new RegExp(r"^ *[^< ]");
28 var hasEmail = new RegExp(r"<[^>]+> *$"); 29 var hasEmail = new RegExp(r"<[^>]+> *$");
29 for (var authorName in authors) { 30 for (var authorName in authors) {
30 if (!hasName.hasMatch(authorName)) { 31 if (!hasName.hasMatch(authorName)) {
31 warnings.add('Author "$authorName" in pubspec.yaml is missing a ' 32 warnings.add('Author "$authorName" in pubspec.yaml should have a '
32 'name.'); 33 'name.');
33 } 34 }
34 if (!hasEmail.hasMatch(authorName)) { 35 if (!hasEmail.hasMatch(authorName)) {
35 warnings.add('Author "$authorName" in pubspec.yaml is missing an ' 36 warnings.add('Author "$authorName" in pubspec.yaml should have an '
36 'email address (e.g. "name <email>").'); 37 'email address\n(e.g. "name <email>").');
37 } 38 }
38 } 39 }
39 } 40 }
40 41
41 var homepage = pubspec.fields['homepage']; 42 var homepage = pubspec.fields['homepage'];
42 if (homepage == null) { 43 if (homepage == null) {
43 errors.add('pubspec.yaml is missing a "homepage" field.'); 44 errors.add('Your pubspec.yaml is missing a "homepage" field.');
44 } 45 }
45 46
46 var description = pubspec.fields['description']; 47 var description = pubspec.fields['description'];
47 if (description == null) { 48 if (description == null) {
48 errors.add('pubspec.yaml is missing a "description" field.'); 49 errors.add('Your pubspec.yaml is missing a "description" field.');
50 }
51
52 var version = pubspec.fields['version'];
53 if (version == null) {
54 errors.add('Your pubspec.yaml is missing a "version" field.');
49 } 55 }
50 56
51 return new Future.immediate(null); 57 return new Future.immediate(null);
52 } 58 }
53 } 59 }
OLDNEW
« no previous file with comments | « utils/pub/validator/name.dart ('k') | utils/tests/pub/directory_tree_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698