]>
Commit | Line | Data |
---|---|---|
416331ca | 1 | //! Tidy check to ensure that crate `edition` is '2018' |
416331ca XL |
2 | |
3 | use std::path::Path; | |
4 | ||
416331ca XL |
5 | fn is_edition_2018(mut line: &str) -> bool { |
6 | line = line.trim(); | |
7 | line == "edition = \"2018\"" || line == "edition = \'2018\'" | |
8 | } | |
9 | ||
10 | pub fn check(path: &Path, bad: &mut bool) { | |
11 | super::walk( | |
12 | path, | |
5869c6ff | 13 | &mut |path| super::filter_dirs(path) || path.ends_with("src/test"), |
416331ca XL |
14 | &mut |entry, contents| { |
15 | let file = entry.path(); | |
16 | let filename = file.file_name().unwrap(); | |
17 | if filename != "Cargo.toml" { | |
18 | return; | |
19 | } | |
20 | let has_edition = contents.lines().any(is_edition_2018); | |
21 | if !has_edition { | |
22 | tidy_error!( | |
23 | bad, | |
24 | "{} doesn't have `edition = \"2018\"` on a separate line", | |
25 | file.display() | |
26 | ); | |
27 | } | |
28 | }, | |
29 | ); | |
30 | } |