Skip to content

Commit

Permalink
Auto merge of #47064 - kennytm:force-trailing-newlines, r=estebank
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jan 1, 2018
2 parents 037bc65 + 4577a70 commit f3ca88c
Show file tree
Hide file tree
Showing 36 changed files with 34 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/liballoc/tests/cow_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/libcore/tests/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/libserialize/collection_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,4 @@ impl<T: Decodable> Decodable for Arc<[T]> {
Ok(vec.into())
})
}
}
}
2 changes: 0 additions & 2 deletions src/test/codegen/prefetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,3 @@ pub fn check_prefetch_write_instruction(data: &[i8]) {
prefetch_write_instruction(data.as_ptr(), 3);
}
}


2 changes: 1 addition & 1 deletion src/test/compile-fail/E0004.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ fn main() {
match x { //~ ERROR E0004
Terminator::TalkToMyHand => {}
}
}
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/duplicate_entry_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ fn panic_fmt() -> ! {
loop {}
}

fn main() {}
fn main() {}
2 changes: 1 addition & 1 deletion src/test/compile-fail/float-int-invalid-const-cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-28848.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
2 changes: 0 additions & 2 deletions src/test/compile-fail/never-assign-wrong-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@
fn main() {
let x: ! = "hello"; //~ ERROR mismatched types
}


2 changes: 0 additions & 2 deletions src/test/compile-fail/range_inclusive_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ pub fn main() {
//~| ERROR core_intrinsics
//~| ERROR core_intrinsics
}


2 changes: 1 addition & 1 deletion src/test/compile-fail/useless_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ fn foo() {

fn main() {
foo();
}
}
2 changes: 0 additions & 2 deletions src/test/incremental/hashes/enum_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,5 +651,3 @@ mod change_trait_bound_indirectly_where {
Variant1(T)
}
}


3 changes: 0 additions & 3 deletions src/test/incremental/hashes/inline_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,3 @@ pub fn change_options(_a: i32) -> i32 {
}
_out
}



2 changes: 1 addition & 1 deletion src/test/mir-opt/return_an_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ fn foo() -> [u8; 1024] {
return x;
}

fn main() { }
fn main() { }
2 changes: 1 addition & 1 deletion src/test/parse-fail/issue-37113.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ macro_rules! test_macro {

fn main() {
test_macro!(String,);
}
}
2 changes: 0 additions & 2 deletions src/test/parse-fail/range_inclusive_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


2 changes: 0 additions & 2 deletions src/test/run-fail/return-never-coerce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,3 @@ fn main() {
let x: i32 = call_another_fn(wub);
let y: u32 = wub();
}


2 changes: 0 additions & 2 deletions src/test/run-make/a-b-a-linker-guard/a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@ pub fn foo(x: u32) { }

#[cfg(y)]
pub fn foo(x: i32) { }


2 changes: 0 additions & 2 deletions src/test/run-make/reproducible-build/reproducible-build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,3 @@ fn main() {

TupleStruct(1, 2, 3, 4).bar();
}


2 changes: 1 addition & 1 deletion src/test/run-pass/abi-sysv64-register-usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ pub fn main() {
}

#[cfg(not(target_arch = "x86_64"))]
pub fn main() {}
pub fn main() {}
2 changes: 1 addition & 1 deletion src/test/run-pass/auxiliary/issue_42007_s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#[repr(u8)]
pub enum E {
B = 1 as u8,
}
}
2 changes: 1 addition & 1 deletion src/test/run-pass/for-loop-mut-ref-element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

fn main() {
for ref mut _a in std::iter::once(true) {}
}
}
2 changes: 1 addition & 1 deletion src/test/run-pass/generator/borrow-in-tail-expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ fn main() {
let a = String::new();
a.len()
};
}
}
2 changes: 1 addition & 1 deletion src/test/run-pass/generator/match-bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ fn main() {
yield;
}
};
}
}
2 changes: 1 addition & 1 deletion src/test/run-pass/generator/yield-subtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ fn bar<'a>() {
};
}

fn main() {}
fn main() {}
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-22066.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ pub trait LineFormatter<'a> {
}
}

fn main() {}
fn main() {}
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-32292.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ struct Foo;

fn main() {
let _ = Foo;
}
}
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-33992.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ pub static TEST7: bool = true;
#[linkage = "weak_odr"]
pub static TEST8: bool = true;

fn main() {}
fn main() {}
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-35376.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ pub struct Handle;

impl Beta for Handle {
type Event = ();
}
}
2 changes: 0 additions & 2 deletions src/test/run-pass/optimization-fuel-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ fn main() {
+(size_of::<S2>() == 4) as usize;
assert_eq!(optimized, 1);
}


2 changes: 1 addition & 1 deletion src/test/rustdoc/doc-cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ pub mod unix_only {
impl ArmOnly for super::Portable {
fn unix_and_arm_only_function() {}
}
}
}
2 changes: 0 additions & 2 deletions src/test/ui-fulldeps/update-references.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,3 @@ while [[ "$1" != "" ]]; do
cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME
fi
done


2 changes: 1 addition & 1 deletion src/test/ui/in-band-lifetimes/single_use_lifetimes-4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ enum Bar<'x> { //~ ERROR lifetime name `'x` only used once
Variant(&'x u32)
}

fn main() { }
fn main() { }
2 changes: 1 addition & 1 deletion src/test/ui/in-band-lifetimes/single_use_lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ fn deref<'x>(v: &'x u32) -> u32 { //~ ERROR lifetime name `'x` only used once
*v
}

fn main() {}
fn main() {}
2 changes: 0 additions & 2 deletions src/test/ui/update-references.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,3 @@ while [[ "$1" != "" ]]; do
cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME
fi
done


11 changes: 11 additions & 0 deletions src/tools/tidy/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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),
};
})
}

Expand Down

0 comments on commit f3ca88c

Please sign in to comment.