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 directory_validator; | |
6 | |
7 import '../entrypoint.dart'; | |
8 import '../io.dart'; | |
9 import '../validator.dart'; | |
10 | |
11 /// A validator that validates a package's top-level directories. | |
12 class DirectoryValidator extends Validator { | |
13 DirectoryValidator(Entrypoint entrypoint) | |
14 : super(entrypoint); | |
15 | |
16 static final _PLURAL_NAMES = ["tools", "tests", "docs", "examples"]; | |
17 | |
18 Future validate() { | |
19 return listDir(entrypoint.root.dir).chain((dirs) { | |
20 return Futures.wait(dirs.map((dir) { | |
21 return dirExists(dir).transform((exists) { | |
22 if (!exists) return; | |
23 | |
24 dir = basename(dir); | |
25 if (_PLURAL_NAMES.contains(dir)) { | |
26 // Cut off the "s" | |
27 var singularName = dir.substring(0, dir.length - 1); | |
28 warnings.add('Rename the top-level "$dir" directory to ' | |
29 '"$singularName".\n' | |
30 'The Pub layout convention is to use singular directory ' | |
31 'names.\n' | |
32 'Plural names won\'t be correctly identified by Pub and other ' | |
33 'tools.'); | |
Bob Nystrom
2013/01/03 23:18:54
How about:
''Rename the top-level "$dir" director
nweiz
2013/01/04 00:25:15
That doesn't really make sense for "doc", and I th
| |
34 } | |
35 | |
36 if (dir.contains(new RegExp(r"^samples?$"))) { | |
37 warnings.add('Rename the top-level "$dir" directory to "example".\n' | |
38 'This allows Pub to find your examples and create "packages" ' | |
39 'directories for them.\n'); | |
40 } | |
41 }); | |
42 })); | |
43 }); | |
44 } | |
45 } | |
OLD | NEW |