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

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

Issue 11543006: Add a validator that checks that the lib directory is not empty. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/validator.dart ('k') | utils/tests/pub/oauth2_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/validator/lib.dart
diff --git a/utils/pub/validator/lib.dart b/utils/pub/validator/lib.dart
new file mode 100644
index 0000000000000000000000000000000000000000..64f44c6365f5694c8468c8b73d513a0a171a7416
--- /dev/null
+++ b/utils/pub/validator/lib.dart
@@ -0,0 +1,43 @@
+// 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 lib_validator;
+
+import 'dart:io';
+
+import '../entrypoint.dart';
+import '../io.dart';
+import '../system_cache.dart';
+import '../utils.dart';
+import '../validator.dart';
+
+// TODO(nweiz): When issue 7196 is fixed, complain about non-Dart files in lib.
+/// A validator that checks that libraries in "lib/" (and not "lib/src/") exist
+/// and are well-formed.
+class LibValidator extends Validator {
+ LibValidator(Entrypoint entrypoint)
+ : super(entrypoint);
+
+ Future validate() {
+ var libDir = join(entrypoint.root.dir, "lib");
+ return dirExists(libDir).chain((libDirExists) {
+ if (!libDirExists) {
+ errors.add('Your package must have a "lib/" directory so users have '
Bob Nystrom 2012/12/12 00:11:51 In pub install, it's only a warning if you depend
nweiz 2012/12/12 00:53:34 We decided to make this an error because there's n
+ 'something to import.');
+ return new Future.immediate(null);
+ }
+
+ return listDir(libDir).transform((files) {
+ files = files.map((file) => relativeTo(file, libDir));
+ if (files.isEmpty) {
+ errors.add('The "lib/" directory may not be empty so users have '
+ 'something to import');
+ } else if (files.length == 1 && files.first == "src") {
+ errors.add('The "lib/" directory must contain something other than '
+ '"src/" so users have something to import');
+ }
+ });
+ });
+ }
+}
« no previous file with comments | « utils/pub/validator.dart ('k') | utils/tests/pub/oauth2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698