Emit the uppercase variable lint for struct fields that have names with uppercase characters
This commit is contained in:
parent
e3723dc4f1
commit
258dbd09ba
2 changed files with 26 additions and 1 deletions
|
@ -212,7 +212,7 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
|
||||||
("uppercase_variables",
|
("uppercase_variables",
|
||||||
LintSpec {
|
LintSpec {
|
||||||
lint: UppercaseVariables,
|
lint: UppercaseVariables,
|
||||||
desc: "variable names should start with a lowercase character",
|
desc: "variable and structure field names should start with a lowercase character",
|
||||||
default: warn
|
default: warn
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
@ -1201,6 +1201,23 @@ fn check_pat_uppercase_variable(cx: &Context, p: &ast::Pat) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_struct_uppercase_variable(cx: &Context, s: &ast::StructDef) {
|
||||||
|
for sf in s.fields.iter() {
|
||||||
|
match sf.node {
|
||||||
|
ast::StructField_ { kind: ast::NamedField(ident, _), .. } => {
|
||||||
|
let s = token::get_ident(ident);
|
||||||
|
if s.get().char_at(0).is_uppercase() {
|
||||||
|
cx.span_lint(
|
||||||
|
UppercaseVariables,
|
||||||
|
sf.span,
|
||||||
|
"structure field names should start with a lowercase character");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn check_unnecessary_parens_core(cx: &Context, value: &ast::Expr, msg: &str) {
|
fn check_unnecessary_parens_core(cx: &Context, value: &ast::Expr, msg: &str) {
|
||||||
match value.node {
|
match value.node {
|
||||||
ast::ExprParen(_) => {
|
ast::ExprParen(_) => {
|
||||||
|
@ -1665,6 +1682,8 @@ impl<'a> Visitor<()> for Context<'a> {
|
||||||
g: &ast::Generics,
|
g: &ast::Generics,
|
||||||
id: ast::NodeId,
|
id: ast::NodeId,
|
||||||
_: ()) {
|
_: ()) {
|
||||||
|
check_struct_uppercase_variable(self, s);
|
||||||
|
|
||||||
let old_id = self.cur_struct_def_id;
|
let old_id = self.cur_struct_def_id;
|
||||||
self.cur_struct_def_id = id;
|
self.cur_struct_def_id = id;
|
||||||
visit::walk_struct_def(self, s, i, g, id, ());
|
visit::walk_struct_def(self, s, i, g, id, ());
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
use std::io::File;
|
use std::io::File;
|
||||||
use std::io::IoError;
|
use std::io::IoError;
|
||||||
|
|
||||||
|
struct Something {
|
||||||
|
X: uint //~ ERROR structure field names should start with a lowercase character
|
||||||
|
}
|
||||||
|
|
||||||
fn test(Xx: uint) { //~ ERROR variable names should start with a lowercase character
|
fn test(Xx: uint) { //~ ERROR variable names should start with a lowercase character
|
||||||
println!("{}", Xx);
|
println!("{}", Xx);
|
||||||
}
|
}
|
||||||
|
@ -30,5 +34,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
test(1);
|
test(1);
|
||||||
|
|
||||||
|
let _ = Something { X: 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue