mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-08 01:28:18 +03:00
Improve the non_snake_case lint to give better suggestions
This commit is contained in:
@@ -871,13 +871,17 @@ fn is_snake_case(ident: ast::Ident) -> bool {
|
||||
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 @@ fn foo__method(&self) {}
|
||||
|
||||
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`
|
||||
|
||||
Reference in New Issue
Block a user