OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library name_validator; | 5 library name_validator; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import '../../../pkg/path/lib/path.dart' as path; | 10 import '../../../pkg/path/lib/path.dart' as path; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 .where((file) => !path.split(file).contains("src") && | 59 .where((file) => !path.split(file).contains("src") && |
60 path.extension(file) == '.dart') | 60 path.extension(file) == '.dart') |
61 .toList(); | 61 .toList(); |
62 }); | 62 }); |
63 } | 63 } |
64 | 64 |
65 void _checkName(String name, String description) { | 65 void _checkName(String name, String description) { |
66 if (name == "") { | 66 if (name == "") { |
67 errors.add("$description may not be empty."); | 67 errors.add("$description may not be empty."); |
68 } else if (!new RegExp(r"^[a-zA-Z0-9_]*$").hasMatch(name)) { | 68 } else if (!new RegExp(r"^[a-zA-Z0-9_]*$").hasMatch(name)) { |
69 errors.add("$description may only contain letters, numbers, and " | 69 warnings.add("$description may only contain letters, numbers, and " |
70 "underscores.\n" | 70 "underscores.\n" |
71 "Using a valid Dart identifier makes the name usable in Dart code."); | 71 "Using a valid Dart identifier makes the name usable in Dart code."); |
72 } else if (!new RegExp(r"^[a-zA-Z]").hasMatch(name)) { | 72 } else if (!new RegExp(r"^[a-zA-Z]").hasMatch(name)) { |
73 errors.add("$description must begin with letter.\n" | 73 warnings.add("$description must begin with letter.\n" |
74 "Using a valid Dart identifier makes the name usable in Dart code."); | 74 "Using a valid Dart identifier makes the name usable in Dart code."); |
75 } else if (_RESERVED_WORDS.contains(name.toLowerCase())) { | 75 } else if (_RESERVED_WORDS.contains(name.toLowerCase())) { |
76 errors.add("$description may not be a reserved word in Dart.\n" | 76 warnings.add("$description may not be a reserved word in Dart.\n" |
nweiz
2013/02/20 19:41:02
These should still be errors for package names.
Bob Nystrom
2013/02/20 21:13:40
Done.
nweiz
2013/02/20 21:25:02
I meant all of the newly-warning'd errors, not jus
| |
77 "Using a valid Dart identifier makes the name usable in Dart code."); | 77 "Using a valid Dart identifier makes the name usable in Dart code."); |
78 } else if (new RegExp(r"[A-Z]").hasMatch(name)) { | 78 } else if (new RegExp(r"[A-Z]").hasMatch(name)) { |
79 warnings.add('$description should be lower-case. Maybe use ' | 79 warnings.add('$description should be lower-case. Maybe use ' |
80 '"${_unCamelCase(name)}"?'); | 80 '"${_unCamelCase(name)}"?'); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 String _unCamelCase(String source) { | 84 String _unCamelCase(String source) { |
85 var builder = new StringBuffer(); | 85 var builder = new StringBuffer(); |
86 var lastMatchEnd = 0; | 86 var lastMatchEnd = 0; |
87 for (var match in new RegExp(r"[a-z]([A-Z])").allMatches(source)) { | 87 for (var match in new RegExp(r"[a-z]([A-Z])").allMatches(source)) { |
88 builder | 88 builder |
89 ..add(source.substring(lastMatchEnd, match.start + 1)) | 89 ..add(source.substring(lastMatchEnd, match.start + 1)) |
90 ..add("_") | 90 ..add("_") |
91 ..add(match.group(1).toLowerCase()); | 91 ..add(match.group(1).toLowerCase()); |
92 lastMatchEnd = match.end; | 92 lastMatchEnd = match.end; |
93 } | 93 } |
94 builder.add(source.substring(lastMatchEnd)); | 94 builder.add(source.substring(lastMatchEnd)); |
95 return builder.toString().toLowerCase(); | 95 return builder.toString().toLowerCase(); |
96 } | 96 } |
97 } | 97 } |
OLD | NEW |