OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library pubspec_field_validator; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 import '../entrypoint.dart'; | |
10 import '../system_cache.dart'; | |
11 import '../validator.dart'; | |
12 import '../version.dart'; | |
13 | |
14 /// A validator that checks that the pubspec has valid "author" and "homepage" | |
15 /// fields. | |
16 class PubspecFieldValidator extends Validator { | |
17 PubspecFieldValidator(Entrypoint entrypoint) | |
18 : super(entrypoint); | |
19 | |
20 Future validate() { | |
21 // The types of all fields are validated when the pubspec is parsed. | |
22 var pubspec = entrypoint.root.pubspec; | |
23 var author = pubspec.fields['author']; | |
24 var authors = pubspec.fields['authors']; | |
25 if (author == null && authors == null) { | |
26 errors.add('Your pubspec.yaml must have an "author" or "authors" field.'); | |
27 } else { | |
28 if (authors == null) authors = [author]; | |
29 | |
30 var hasName = new RegExp(r"^ *[^< ]"); | |
31 var hasEmail = new RegExp(r"<[^>]+> *$"); | |
32 for (var authorName in authors) { | |
33 if (!hasName.hasMatch(authorName)) { | |
34 warnings.add('Author "$authorName" in pubspec.yaml should have a ' | |
35 'name.'); | |
36 } | |
37 if (!hasEmail.hasMatch(authorName)) { | |
38 warnings.add('Author "$authorName" in pubspec.yaml should have an ' | |
39 'email address\n(e.g. "name <email>").'); | |
40 } | |
41 } | |
42 } | |
43 | |
44 var homepage = pubspec.fields['homepage']; | |
45 if (homepage == null) { | |
46 errors.add('Your pubspec.yaml is missing a "homepage" field.'); | |
47 } | |
48 | |
49 var description = pubspec.fields['description']; | |
50 if (description == null) { | |
51 errors.add('Your pubspec.yaml is missing a "description" field.'); | |
52 } | |
53 | |
54 var version = pubspec.fields['version']; | |
55 if (version == null) { | |
56 errors.add('Your pubspec.yaml is missing a "version" field.'); | |
57 } | |
58 | |
59 return new Future.value(); | |
60 } | |
61 } | |
OLD | NEW |