Auto merge of #47064 - kennytm:force-trailing-newlines, r=estebank
Add a tidy check for missing or too many trailing newlines. I've noticed recently there are lots of review comments requesting to fix trailing newlines. If this is going to be an official style here, it's better to let the CI do this repetitive check.
This commit is contained in:
commit
f3ca88cff7
36 changed files with 34 additions and 48 deletions
|
@ -148,4 +148,4 @@ fn check_cow_clone_from() {
|
|||
let c2: Cow<str> = Cow::Owned(s);
|
||||
c1.clone_from(&c2);
|
||||
assert!(c1.into_owned().capacity() >= 25);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,4 +67,4 @@ fn test_range_inclusive() {
|
|||
r = RangeInclusive { start: 1, end: -1 };
|
||||
assert_eq!(r.size_hint(), (0, Some(0)));
|
||||
assert_eq!(r.next(), None);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,4 +241,4 @@ impl<T: Decodable> Decodable for Arc<[T]> {
|
|||
Ok(vec.into())
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,5 +71,3 @@ pub fn check_prefetch_write_instruction(data: &[i8]) {
|
|||
prefetch_write_instruction(data.as_ptr(), 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,4 +19,4 @@ fn main() {
|
|||
match x { //~ ERROR E0004
|
||||
Terminator::TalkToMyHand => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,4 +20,4 @@ fn panic_fmt() -> ! {
|
|||
loop {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
fn main() {}
|
||||
|
|
|
@ -58,4 +58,4 @@ fn main() {
|
|||
{ const X: u32 = 4294967296. as u32; force(X); } //~ ERROR constant evaluation error
|
||||
{ const X: u128 = 1e40 as u128; force(X); } //~ ERROR constant evaluation error
|
||||
{ const X: i128 = 1e40 as i128; force(X); } //~ ERROR constant evaluation error
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,4 +20,4 @@ pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
|
|||
Foo::<'a, 'b>::xmute(u) //~ ERROR lifetime bound not satisfied
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
fn main() {}
|
||||
|
|
|
@ -16,5 +16,3 @@
|
|||
fn main() {
|
||||
let x: ! = "hello"; //~ ERROR mismatched types
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,5 +19,3 @@ pub fn main() {
|
|||
//~| ERROR core_intrinsics
|
||||
//~| ERROR core_intrinsics
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,4 +27,4 @@ fn foo() {
|
|||
|
||||
fn main() {
|
||||
foo();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -651,5 +651,3 @@ mod change_trait_bound_indirectly_where {
|
|||
Variant1(T)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -236,6 +236,3 @@ pub fn change_options(_a: i32) -> i32 {
|
|||
}
|
||||
_out
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -15,4 +15,4 @@ fn foo() -> [u8; 1024] {
|
|||
return x;
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
fn main() { }
|
||||
|
|
|
@ -18,4 +18,4 @@ macro_rules! test_macro {
|
|||
|
||||
fn main() {
|
||||
test_macro!(String,);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,5 +72,3 @@ pub fn main() {
|
|||
o!(); // not allowed in macros that output cfgs
|
||||
p!(); // not allowed in cfg'ed macros that output cfgs
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,5 +24,3 @@ fn main() {
|
|||
let x: i32 = call_another_fn(wub);
|
||||
let y: u32 = wub();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,5 +16,3 @@ pub fn foo(x: u32) { }
|
|||
|
||||
#[cfg(y)]
|
||||
pub fn foo(x: i32) { }
|
||||
|
||||
|
||||
|
|
|
@ -124,5 +124,3 @@ fn main() {
|
|||
|
||||
TupleStruct(1, 2, 3, 4).bar();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -102,4 +102,4 @@ pub fn main() {
|
|||
}
|
||||
|
||||
#[cfg(not(target_arch = "x86_64"))]
|
||||
pub fn main() {}
|
||||
pub fn main() {}
|
||||
|
|
|
@ -11,4 +11,4 @@
|
|||
#[repr(u8)]
|
||||
pub enum E {
|
||||
B = 1 as u8,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,4 +12,4 @@
|
|||
|
||||
fn main() {
|
||||
for ref mut _a in std::iter::once(true) {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,4 +16,4 @@ fn main() {
|
|||
let a = String::new();
|
||||
a.len()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,4 +27,4 @@ fn main() {
|
|||
yield;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,4 +20,4 @@ fn bar<'a>() {
|
|||
};
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
fn main() {}
|
||||
|
|
|
@ -18,4 +18,4 @@ pub trait LineFormatter<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
fn main() {}
|
||||
|
|
|
@ -15,4 +15,4 @@ struct Foo;
|
|||
|
||||
fn main() {
|
||||
let _ = Foo;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,4 +37,4 @@ pub static TEST7: bool = true;
|
|||
#[linkage = "weak_odr"]
|
||||
pub static TEST8: bool = true;
|
||||
|
||||
fn main() {}
|
||||
fn main() {}
|
||||
|
|
|
@ -48,4 +48,4 @@ pub struct Handle;
|
|||
|
||||
impl Beta for Handle {
|
||||
type Event = ();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,5 +22,3 @@ fn main() {
|
|||
+(size_of::<S2>() == 4) as usize;
|
||||
assert_eq!(optimized, 1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -44,4 +44,4 @@ pub mod unix_only {
|
|||
impl ArmOnly for super::Portable {
|
||||
fn unix_and_arm_only_function() {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,5 +46,3 @@ while [[ "$1" != "" ]]; do
|
|||
cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
|
|
|
@ -17,4 +17,4 @@ enum Bar<'x> { //~ ERROR lifetime name `'x` only used once
|
|||
Variant(&'x u32)
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
fn main() { }
|
||||
|
|
|
@ -13,4 +13,4 @@ fn deref<'x>(v: &'x u32) -> u32 { //~ ERROR lifetime name `'x` only used once
|
|||
*v
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
fn main() {}
|
||||
|
|
|
@ -46,5 +46,3 @@ while [[ "$1" != "" ]]; do
|
|||
cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
|
|
|
@ -130,6 +130,7 @@ pub fn check(path: &Path, bad: &mut bool) {
|
|||
let skip_tab = contents.contains("ignore-tidy-tab");
|
||||
let skip_length = contents.contains("ignore-tidy-linelength");
|
||||
let skip_end_whitespace = contents.contains("ignore-tidy-end-whitespace");
|
||||
let mut trailing_new_lines = 0;
|
||||
for (i, line) in contents.split("\n").enumerate() {
|
||||
let mut err = |msg: &str| {
|
||||
tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
|
||||
|
@ -161,10 +162,20 @@ pub fn check(path: &Path, bad: &mut bool) {
|
|||
if filename.ends_with(".cpp") && line.contains("llvm_unreachable") {
|
||||
err(LLVM_UNREACHABLE_INFO);
|
||||
}
|
||||
if line.is_empty() {
|
||||
trailing_new_lines += 1;
|
||||
} else {
|
||||
trailing_new_lines = 0;
|
||||
}
|
||||
}
|
||||
if !licenseck(file, &contents) {
|
||||
tidy_error!(bad, "{}: incorrect license", file.display());
|
||||
}
|
||||
match trailing_new_lines {
|
||||
0 => tidy_error!(bad, "{}: missing trailing newline", file.display()),
|
||||
1 | 2 => {}
|
||||
n => tidy_error!(bad, "{}: too many trailing newlines ({})", file.display(), n),
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue