File tree 4 files changed +35
-12
lines changed
4 files changed +35
-12
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ version = "0.0.0"
6
6
[lib ]
7
7
name = " rustc_lint"
8
8
path = " lib.rs"
9
- crate-type = [" dylib" ]
9
+ crate-types = [" rlib " , " dylib" ]
10
10
test = false
11
11
12
12
[dependencies ]
@@ -15,3 +15,5 @@ rustc = { path = "../librustc" }
15
15
rustc_const_eval = { path = " ../librustc_const_eval" }
16
16
syntax = { path = " ../libsyntax" }
17
17
syntax_pos = { path = " ../libsyntax_pos" }
18
+ lazy_static = " 1.0"
19
+ regex = " 0.2.3"
Original file line number Diff line number Diff line change @@ -21,6 +21,12 @@ use syntax_pos::Span;
21
21
use rustc:: hir:: { self , PatKind } ;
22
22
use rustc:: hir:: intravisit:: FnKind ;
23
23
24
+ use regex:: Regex ;
25
+
26
+ lazy_static ! {
27
+ static ref ALPHABETIC_UNDERSCORE : Regex = Regex :: new( "([[:alpha:]])_([[:alpha:]])" ) . unwrap( ) ;
28
+ }
29
+
24
30
#[ derive( PartialEq ) ]
25
31
pub enum MethodLateContext {
26
32
TraitAutoImpl ,
@@ -62,20 +68,24 @@ impl NonCamelCaseTypes {
62
68
63
69
// start with a non-lowercase letter rather than non-uppercase
64
70
// ones (some scripts don't have a concept of upper/lowercase)
65
- !name. is_empty ( ) && !name. chars ( ) . next ( ) . unwrap ( ) . is_lowercase ( ) && !name. contains ( '_' )
71
+ !name. is_empty ( ) && !name. chars ( ) . next ( ) . unwrap ( ) . is_lowercase ( ) &&
72
+ !ALPHABETIC_UNDERSCORE . is_match ( name)
66
73
}
67
74
68
75
fn to_camel_case ( s : & str ) -> String {
69
- s. split ( '_' )
70
- . flat_map ( |word| {
71
- word. chars ( ) . enumerate ( ) . map ( |( i, c) | if i == 0 {
72
- c. to_uppercase ( ) . collect :: < String > ( )
73
- } else {
74
- c. to_lowercase ( ) . collect ( )
75
- } )
76
- } )
77
- . collect :: < Vec < _ > > ( )
78
- . concat ( )
76
+ let s = s. split ( '_' )
77
+ . map ( |word| {
78
+ word. chars ( ) . enumerate ( ) . map ( |( i, c) | if i == 0 {
79
+ c. to_uppercase ( ) . collect :: < String > ( )
80
+ } else {
81
+ c. to_lowercase ( ) . collect ( )
82
+ } )
83
+ . collect :: < Vec < _ > > ( )
84
+ . concat ( )
85
+ } )
86
+ . collect :: < Vec < _ > > ( )
87
+ . join ( "_" ) ;
88
+ ALPHABETIC_UNDERSCORE . replace_all ( s. as_str ( ) , "$1$2" ) . to_string ( )
79
89
}
80
90
81
91
if !is_camel_case ( name) {
Original file line number Diff line number Diff line change @@ -41,6 +41,9 @@ extern crate rustc;
41
41
extern crate log;
42
42
extern crate rustc_const_eval;
43
43
extern crate syntax_pos;
44
+ #[ macro_use]
45
+ extern crate lazy_static;
46
+ extern crate regex;
44
47
45
48
use rustc:: lint;
46
49
use rustc:: middle;
You can’t perform that action at this time.
0 commit comments