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

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

Issue 12313014: Make some name validation errors warnings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make using a reserved word as a package name an error. Created 7 years, 10 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 | « no previous file | 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/name.dart
diff --git a/utils/pub/validator/name.dart b/utils/pub/validator/name.dart
index 249a0c9ee76e2907d4c700d9e2424c0e296d9066..a0ca81ad65f03139533d42a8ecb0957071142d97 100644
--- a/utils/pub/validator/name.dart
+++ b/utils/pub/validator/name.dart
@@ -28,12 +28,14 @@ class NameValidator extends Validator {
: super(entrypoint);
Future validate() {
- _checkName(entrypoint.root.name, 'Package name "${entrypoint.root.name}"');
+ _checkName(entrypoint.root.name, 'Package name "${entrypoint.root.name}"',
+ isPackage: true);
return _libraries.then((libraries) {
for (var library in libraries) {
var libName = path.basenameWithoutExtension(library);
- _checkName(libName, 'The name of "$library", "$libName",');
+ _checkName(libName, 'The name of "$library", "$libName",',
+ isPackage: false);
}
if (libraries.length == 1) {
@@ -62,18 +64,19 @@ class NameValidator extends Validator {
});
}
- void _checkName(String name, String description) {
+ void _checkName(String name, String description, {bool isPackage}) {
if (name == "") {
errors.add("$description may not be empty.");
} else if (!new RegExp(r"^[a-zA-Z0-9_]*$").hasMatch(name)) {
- errors.add("$description may only contain letters, numbers, and "
+ warnings.add("$description may only contain letters, numbers, and "
"underscores.\n"
"Using a valid Dart identifier makes the name usable in Dart code.");
} else if (!new RegExp(r"^[a-zA-Z]").hasMatch(name)) {
- errors.add("$description must begin with letter.\n"
+ warnings.add("$description must begin with letter.\n"
"Using a valid Dart identifier makes the name usable in Dart code.");
} else if (_RESERVED_WORDS.contains(name.toLowerCase())) {
- errors.add("$description may not be a reserved word in Dart.\n"
+ var messages = isPackage ? errors : warnings;
+ messages.add("$description may not be a reserved word in Dart.\n"
"Using a valid Dart identifier makes the name usable in Dart code.");
} else if (new RegExp(r"[A-Z]").hasMatch(name)) {
warnings.add('$description should be lower-case. Maybe use '
« no previous file with comments | « no previous file | utils/tests/pub/validator_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698