Skip to content

Commit

Permalink
Improve the non_snake_case lint to give better suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ftxqxd committed Oct 3, 2014
1 parent 333592e commit 4504412
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/librustc/lint/builtin.rs
Expand Up @@ -871,13 +871,17 @@ impl NonSnakeCase {
fn to_snake_case(str: &str) -> String {
let mut words = vec![];
for s in str.split('_') {
let mut last_upper = false;
let mut buf = String::new();
if s.is_empty() { continue; }
for ch in s.chars() {
if !buf.is_empty() && buf.as_slice() != "'" && ch.is_uppercase() {
if !buf.is_empty() && buf.as_slice() != "'"
&& ch.is_uppercase()
&& !last_upper {
words.push(buf);
buf = String::new();
}
last_upper = ch.is_uppercase();
buf.push_char(ch.to_lowercase());
}
words.push(buf);
Expand Down
5 changes: 4 additions & 1 deletion src/test/compile-fail/lint-non-snake-case-functions.rs
Expand Up @@ -23,11 +23,14 @@ impl Foo {

pub fn xyZ(&mut self) {}
//~^ ERROR method `xyZ` should have a snake case name such as `xy_z`

fn render_HTML() {}
//~^ ERROR method `render_HTML` should have a snake case name such as `render_html`
}

trait X {
fn ABC();
//~^ ERROR trait method `ABC` should have a snake case name such as `a_b_c`
//~^ ERROR trait method `ABC` should have a snake case name such as `abc`

fn a_b_C(&self) {}
//~^ ERROR trait method `a_b_C` should have a snake case name such as `a_b_c`
Expand Down

0 comments on commit 4504412

Please sign in to comment.