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:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import '../entrypoint.dart'; | 9 import '../entrypoint.dart'; |
10 import '../io.dart'; | 10 import '../io.dart'; |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 var libDir = join(entrypoint.root.dir, "lib"); | 29 var libDir = join(entrypoint.root.dir, "lib"); |
30 return dirExists(libDir).chain((libDirExists) { | 30 return dirExists(libDir).chain((libDirExists) { |
31 if (!libDirExists) return new Future.immediate([]); | 31 if (!libDirExists) return new Future.immediate([]); |
32 return listDir(libDir, recursive: true); | 32 return listDir(libDir, recursive: true); |
33 }).transform((files) { | 33 }).transform((files) { |
34 for (var file in files) { | 34 for (var file in files) { |
35 file = relativeTo(file, libDir); | 35 file = relativeTo(file, libDir); |
36 if (splitPath(file).contains("src")) continue; | 36 if (splitPath(file).contains("src")) continue; |
37 if (path.extension(file) != '.dart') continue; | 37 if (path.extension(file) != '.dart') continue; |
38 var libName = path.filenameWithoutExtension(file); | 38 var libName = path.basenameWithoutExtension(file); |
39 _checkName(libName, 'The name of "$file", "$libName",'); | 39 _checkName(libName, 'The name of "$file", "$libName",'); |
40 } | 40 } |
41 }); | 41 }); |
42 } | 42 } |
43 | 43 |
44 void _checkName(String name, String description) { | 44 void _checkName(String name, String description) { |
45 if (name == "") { | 45 if (name == "") { |
46 errors.add("$description may not be empty."); | 46 errors.add("$description may not be empty."); |
47 } else if (!new RegExp(r"^[a-zA-Z0-9_]*$").hasMatch(name)) { | 47 } else if (!new RegExp(r"^[a-zA-Z0-9_]*$").hasMatch(name)) { |
48 errors.add("$description must be a valid Dart identifier: it may only " | 48 errors.add("$description must be a valid Dart identifier: it may only " |
(...skipping 17 matching lines...) Expand all Loading... |
66 builder | 66 builder |
67 ..add(source.substring(lastMatchEnd, match.start + 1)) | 67 ..add(source.substring(lastMatchEnd, match.start + 1)) |
68 ..add("_") | 68 ..add("_") |
69 ..add(match.group(1).toLowerCase()); | 69 ..add(match.group(1).toLowerCase()); |
70 lastMatchEnd = match.end; | 70 lastMatchEnd = match.end; |
71 } | 71 } |
72 builder.add(source.substring(lastMatchEnd)); | 72 builder.add(source.substring(lastMatchEnd)); |
73 return builder.toString().toLowerCase(); | 73 return builder.toString().toLowerCase(); |
74 } | 74 } |
75 } | 75 } |
OLD | NEW |