ba326cd770
Now that we have pkg/path, we can ditch the old methods in io.dart that do the same thing. Review URL: https://codereview.chromium.org//12255016 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@18500 260f80e4-7a28-3924-810f-c04153c831b5
49 lines
1.6 KiB
Dart
49 lines
1.6 KiB
Dart
// 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 'dart:async';
|
|
|
|
import '../../../pkg/path/lib/path.dart' as path;
|
|
|
|
import '../entrypoint.dart';
|
|
import '../io.dart';
|
|
import '../utils.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).then((dirs) {
|
|
for (var dir in dirs) {
|
|
if (!dirExists(dir)) continue;
|
|
|
|
dir = path.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.');
|
|
}
|
|
|
|
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');
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|