Skip to content

Commit ba9676c

Browse files
committed
Format style checker
Signed-off-by: Yuki Okushi <[email protected]>
1 parent 9a193b0 commit ba9676c

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

ci/style.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ use std::io::prelude::*;
3434
use std::path::Path;
3535

3636
macro_rules! t {
37-
($e:expr) => (match $e {
38-
Ok(e) => e,
39-
Err(e) => panic!("{} failed with {}", stringify!($e), e),
40-
})
37+
($e:expr) => {
38+
match $e {
39+
Ok(e) => e,
40+
Err(e) => panic!("{} failed with {}", stringify!($e), e),
41+
}
42+
};
4143
}
4244

4345
fn main() {
@@ -58,15 +60,14 @@ fn walk(path: &Path, err: &mut Errors) {
5860
let path = entry.path();
5961
if t!(entry.file_type()).is_dir() {
6062
walk(&path, err);
61-
continue
63+
continue;
6264
}
6365

6466
let name = entry.file_name().into_string().unwrap();
6567
match &name[..] {
6668
n if !n.ends_with(".rs") => continue,
6769

68-
"lib.rs" |
69-
"macros.rs" => continue,
70+
"lib.rs" | "macros.rs" => continue,
7071

7172
_ => {}
7273
}
@@ -101,13 +102,13 @@ fn check_style(file: &str, path: &Path, err: &mut Errors) {
101102
let mut in_impl = false;
102103

103104
for (i, line) in file.lines().enumerate() {
104-
if line.contains("#[cfg(") && line.contains(']') && !line.contains(" if ")
105-
&& !(line.contains("target_endian") ||
106-
line.contains("target_arch"))
105+
if line.contains("#[cfg(")
106+
&& line.contains(']')
107+
&& !line.contains(" if ")
108+
&& !(line.contains("target_endian") || line.contains("target_arch"))
107109
{
108110
if state != State::Structs {
109-
err.error(path, i, "use cfg_if! and submodules \
110-
instead of #[cfg]");
111+
err.error(path, i, "use cfg_if! and submodules instead of #[cfg]");
111112
}
112113
}
113114
if line.contains("#[derive(") && (line.contains("Copy") || line.contains("Clone")) {
@@ -123,7 +124,7 @@ fn check_style(file: &str, path: &Path, err: &mut Errors) {
123124
let orig_line = line;
124125
let line = line.trim_start();
125126
let is_pub = line.starts_with("pub ");
126-
let line = if is_pub {&line[4..]} else {line};
127+
let line = if is_pub { &line[4..] } else { line };
127128

128129
let line_state = if line.starts_with("use ") {
129130
if line.contains("c_void") {
@@ -149,13 +150,19 @@ fn check_style(file: &str, path: &Path, err: &mut Errors) {
149150
} else if line.starts_with("mod ") {
150151
State::Modules
151152
} else {
152-
continue
153+
continue;
153154
};
154155

155156
if state as usize > line_state as usize {
156-
err.error(path, i, &format!("{} found after {} when \
157-
it belongs before",
158-
line_state.desc(), state.desc()));
157+
err.error(
158+
path,
159+
i,
160+
&format!(
161+
"{} found after {} when it belongs before",
162+
line_state.desc(),
163+
state.desc()
164+
),
165+
);
159166
}
160167

161168
if f_macros == 2 {

0 commit comments

Comments
 (0)