Improve the non_snake_case
lint to give better suggestions
This commit is contained in:
parent
333592edde
commit
45044124e4
2 changed files with 9 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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`
|
||||
|
|
Loading…
Add table
Reference in a new issue