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

Unified Diff: utils/pub/validator/directory.dart

Issue 11741026: Add a validator for top-level directory names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 12 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/validator.dart ('k') | utils/tests/pub/validator_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/validator/directory.dart
diff --git a/utils/pub/validator/directory.dart b/utils/pub/validator/directory.dart
new file mode 100644
index 0000000000000000000000000000000000000000..07ad933ce56b2ee4af3e2826ced8fa78854e094d
--- /dev/null
+++ b/utils/pub/validator/directory.dart
@@ -0,0 +1,45 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library directory_validator;
+
+import '../entrypoint.dart';
+import '../io.dart';
+import '../validator.dart';
+
+/// A validator that validates a package's top-level directories.
+class DirectoryValidator extends Validator {
+ DirectoryValidator(Entrypoint entrypoint)
+ : super(entrypoint);
+
+ static final _PLURAL_NAMES = ["tools", "tests", "docs", "examples"];
+
+ Future validate() {
+ return listDir(entrypoint.root.dir).chain((dirs) {
+ return Futures.wait(dirs.map((dir) {
+ return dirExists(dir).transform((exists) {
+ if (!exists) return;
+
+ dir = basename(dir);
+ if (_PLURAL_NAMES.contains(dir)) {
+ // Cut off the "s"
+ var singularName = dir.substring(0, dir.length - 1);
+ warnings.add('Rename the top-level "$dir" directory to '
+ '"$singularName".\n'
+ 'The Pub layout convention is to use singular directory '
+ 'names.\n'
+ 'Plural names won\'t be correctly identified by Pub and other '
+ '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
+ }
+
+ if (dir.contains(new RegExp(r"^samples?$"))) {
+ warnings.add('Rename the top-level "$dir" directory to "example".\n'
+ 'This allows Pub to find your examples and create "packages" '
+ 'directories for them.\n');
+ }
+ });
+ }));
+ });
+ }
+}
« no previous file with comments | « utils/pub/validator.dart ('k') | utils/tests/pub/validator_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698