mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Check that no file contains trailing ws
rustfmt allows trailing spaces in string literals unfortunately.
This commit is contained in:
parent
089c554770
commit
de7662c852
6 changed files with 142 additions and 127 deletions
|
@ -12,8 +12,8 @@ use test_utils::covers;
|
||||||
|
|
||||||
use crate::{db::DefDatabase, nameres::*, test_db::TestDB};
|
use crate::{db::DefDatabase, nameres::*, test_db::TestDB};
|
||||||
|
|
||||||
fn def_map(fixture: &str) -> String {
|
fn def_map(ra_fixture: &str) -> String {
|
||||||
compute_crate_def_map(fixture).dump()
|
compute_crate_def_map(ra_fixture).dump()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_crate_def_map(fixture: &str) -> Arc<CrateDefMap> {
|
fn compute_crate_def_map(fixture: &str) -> Arc<CrateDefMap> {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use super::*;
|
||||||
#[test]
|
#[test]
|
||||||
fn glob_1() {
|
fn glob_1() {
|
||||||
let map = def_map(
|
let map = def_map(
|
||||||
"
|
r"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
mod foo;
|
mod foo;
|
||||||
use foo::*;
|
use foo::*;
|
||||||
|
@ -76,7 +76,7 @@ fn glob_2() {
|
||||||
#[test]
|
#[test]
|
||||||
fn glob_privacy_1() {
|
fn glob_privacy_1() {
|
||||||
let map = def_map(
|
let map = def_map(
|
||||||
"
|
r"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
mod foo;
|
mod foo;
|
||||||
use foo::*;
|
use foo::*;
|
||||||
|
@ -93,21 +93,21 @@ fn glob_privacy_1() {
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
assert_snapshot!(map, @r###"
|
assert_snapshot!(map, @r###"
|
||||||
crate
|
⋮crate
|
||||||
Baz: t v
|
⋮Baz: t v
|
||||||
bar: t
|
⋮bar: t
|
||||||
foo: t
|
⋮foo: t
|
||||||
|
⋮
|
||||||
crate::foo
|
⋮crate::foo
|
||||||
Baz: t v
|
⋮Baz: t v
|
||||||
PrivateStructFoo: t v
|
⋮PrivateStructFoo: t v
|
||||||
bar: t
|
⋮bar: t
|
||||||
|
⋮
|
||||||
crate::foo::bar
|
⋮crate::foo::bar
|
||||||
Baz: t v
|
⋮Baz: t v
|
||||||
PrivateStructBar: t v
|
⋮PrivateStructBar: t v
|
||||||
PrivateStructFoo: t v
|
⋮PrivateStructFoo: t v
|
||||||
bar: t
|
⋮bar: t
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ fn glob_privacy_1() {
|
||||||
#[test]
|
#[test]
|
||||||
fn glob_privacy_2() {
|
fn glob_privacy_2() {
|
||||||
let map = def_map(
|
let map = def_map(
|
||||||
"
|
r"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
mod foo;
|
mod foo;
|
||||||
use foo::*;
|
use foo::*;
|
||||||
|
@ -133,19 +133,19 @@ fn glob_privacy_2() {
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
assert_snapshot!(map, @r###"
|
assert_snapshot!(map, @r###"
|
||||||
crate
|
⋮crate
|
||||||
Foo: t
|
⋮Foo: t
|
||||||
PubCrateStruct: t v
|
⋮PubCrateStruct: t v
|
||||||
foo: t
|
⋮foo: t
|
||||||
|
⋮
|
||||||
crate::foo
|
⋮crate::foo
|
||||||
Foo: t v
|
⋮Foo: t v
|
||||||
bar: t
|
⋮bar: t
|
||||||
|
⋮
|
||||||
crate::foo::bar
|
⋮crate::foo::bar
|
||||||
PrivateBar: t v
|
⋮PrivateBar: t v
|
||||||
PrivateBaz: t v
|
⋮PrivateBaz: t v
|
||||||
PubCrateStruct: t v
|
⋮PubCrateStruct: t v
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ fn glob_privacy_2() {
|
||||||
fn glob_across_crates() {
|
fn glob_across_crates() {
|
||||||
covers!(glob_across_crates);
|
covers!(glob_across_crates);
|
||||||
let map = def_map(
|
let map = def_map(
|
||||||
"
|
r"
|
||||||
//- /main.rs crate:main deps:test_crate
|
//- /main.rs crate:main deps:test_crate
|
||||||
use test_crate::*;
|
use test_crate::*;
|
||||||
|
|
||||||
|
@ -163,8 +163,8 @@ fn glob_across_crates() {
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
assert_snapshot!(map, @r###"
|
assert_snapshot!(map, @r###"
|
||||||
⋮crate
|
⋮crate
|
||||||
⋮Baz: t v
|
⋮Baz: t v
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ fn glob_across_crates() {
|
||||||
fn glob_privacy_across_crates() {
|
fn glob_privacy_across_crates() {
|
||||||
covers!(glob_across_crates);
|
covers!(glob_across_crates);
|
||||||
let map = def_map(
|
let map = def_map(
|
||||||
"
|
r"
|
||||||
//- /main.rs crate:main deps:test_crate
|
//- /main.rs crate:main deps:test_crate
|
||||||
use test_crate::*;
|
use test_crate::*;
|
||||||
|
|
||||||
|
@ -183,8 +183,8 @@ fn glob_privacy_across_crates() {
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
assert_snapshot!(map, @r###"
|
assert_snapshot!(map, @r###"
|
||||||
⋮crate
|
⋮crate
|
||||||
⋮Baz: t v
|
⋮Baz: t v
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -202,10 +202,10 @@ fn glob_enum() {
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
assert_snapshot!(map, @r###"
|
assert_snapshot!(map, @r###"
|
||||||
⋮crate
|
⋮crate
|
||||||
⋮Bar: t v
|
⋮Bar: t v
|
||||||
⋮Baz: t v
|
⋮Baz: t v
|
||||||
⋮Foo: t
|
⋮Foo: t
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,7 @@ fn glob_enum() {
|
||||||
fn glob_enum_group() {
|
fn glob_enum_group() {
|
||||||
covers!(glob_enum_group);
|
covers!(glob_enum_group);
|
||||||
let map = def_map(
|
let map = def_map(
|
||||||
"
|
r"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
enum Foo {
|
enum Foo {
|
||||||
Bar, Baz
|
Bar, Baz
|
||||||
|
@ -223,10 +223,10 @@ fn glob_enum_group() {
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
assert_snapshot!(map, @r###"
|
assert_snapshot!(map, @r###"
|
||||||
⋮crate
|
⋮crate
|
||||||
⋮Bar: t v
|
⋮Bar: t v
|
||||||
⋮Baz: t v
|
⋮Baz: t v
|
||||||
⋮Foo: t
|
⋮Foo: t
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use super::*;
|
||||||
#[test]
|
#[test]
|
||||||
fn macro_rules_are_globally_visible() {
|
fn macro_rules_are_globally_visible() {
|
||||||
let map = def_map(
|
let map = def_map(
|
||||||
"
|
r"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
macro_rules! structs {
|
macro_rules! structs {
|
||||||
($($i:ident),*) => {
|
($($i:ident),*) => {
|
||||||
|
@ -31,7 +31,7 @@ fn macro_rules_are_globally_visible() {
|
||||||
#[test]
|
#[test]
|
||||||
fn macro_rules_can_define_modules() {
|
fn macro_rules_can_define_modules() {
|
||||||
let map = def_map(
|
let map = def_map(
|
||||||
"
|
r"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
macro_rules! m {
|
macro_rules! m {
|
||||||
($name:ident) => { mod $name; }
|
($name:ident) => { mod $name; }
|
||||||
|
@ -51,21 +51,21 @@ fn macro_rules_can_define_modules() {
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
assert_snapshot!(map, @r###"
|
assert_snapshot!(map, @r###"
|
||||||
crate
|
⋮crate
|
||||||
m: t
|
⋮m: t
|
||||||
n1: t
|
⋮n1: t
|
||||||
|
⋮
|
||||||
crate::m
|
⋮crate::m
|
||||||
n3: t
|
⋮n3: t
|
||||||
|
⋮
|
||||||
crate::m::n3
|
⋮crate::m::n3
|
||||||
Y: t v
|
⋮Y: t v
|
||||||
|
⋮
|
||||||
crate::n1
|
⋮crate::n1
|
||||||
n2: t
|
⋮n2: t
|
||||||
|
⋮
|
||||||
crate::n1::n2
|
⋮crate::n1::n2
|
||||||
X: t v
|
⋮X: t v
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use super::*;
|
||||||
fn name_res_works_for_broken_modules() {
|
fn name_res_works_for_broken_modules() {
|
||||||
covers!(name_res_works_for_broken_modules);
|
covers!(name_res_works_for_broken_modules);
|
||||||
let map = def_map(
|
let map = def_map(
|
||||||
"
|
r"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
mod foo // no `;`, no body
|
mod foo // no `;`, no body
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ fn name_res_works_for_broken_modules() {
|
||||||
#[test]
|
#[test]
|
||||||
fn nested_module_resolution() {
|
fn nested_module_resolution() {
|
||||||
let map = def_map(
|
let map = def_map(
|
||||||
"
|
r"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
mod n1;
|
mod n1;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ fn nested_module_resolution() {
|
||||||
#[test]
|
#[test]
|
||||||
fn nested_module_resolution_2() {
|
fn nested_module_resolution_2() {
|
||||||
let map = def_map(
|
let map = def_map(
|
||||||
"
|
r"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
mod prelude;
|
mod prelude;
|
||||||
mod iter;
|
mod iter;
|
||||||
|
@ -77,23 +77,23 @@ fn nested_module_resolution_2() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_snapshot!(map, @r###"
|
assert_snapshot!(map, @r###"
|
||||||
crate
|
⋮crate
|
||||||
iter: t
|
⋮iter: t
|
||||||
prelude: t
|
⋮prelude: t
|
||||||
|
⋮
|
||||||
crate::iter
|
⋮crate::iter
|
||||||
Iterator: t
|
⋮Iterator: t
|
||||||
traits: t
|
⋮traits: t
|
||||||
|
⋮
|
||||||
crate::iter::traits
|
⋮crate::iter::traits
|
||||||
Iterator: t
|
⋮Iterator: t
|
||||||
iterator: t
|
⋮iterator: t
|
||||||
|
⋮
|
||||||
crate::iter::traits::iterator
|
⋮crate::iter::traits::iterator
|
||||||
Iterator: t
|
⋮Iterator: t
|
||||||
|
⋮
|
||||||
crate::prelude
|
⋮crate::prelude
|
||||||
Iterator: t
|
⋮Iterator: t
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -780,17 +780,17 @@ fn nested_out_of_line_module() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_snapshot!(map, @r###"
|
assert_snapshot!(map, @r###"
|
||||||
crate
|
⋮crate
|
||||||
a: t
|
⋮a: t
|
||||||
|
⋮
|
||||||
crate::a
|
⋮crate::a
|
||||||
b: t
|
⋮b: t
|
||||||
|
⋮
|
||||||
crate::a::b
|
⋮crate::a::b
|
||||||
c: t
|
⋮c: t
|
||||||
|
⋮
|
||||||
crate::a::b::c
|
⋮crate::a::b::c
|
||||||
X: t v
|
⋮X: t v
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -812,16 +812,16 @@ fn nested_out_of_line_module_with_path() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_snapshot!(map, @r###"
|
assert_snapshot!(map, @r###"
|
||||||
crate
|
⋮crate
|
||||||
a: t
|
⋮a: t
|
||||||
|
⋮
|
||||||
crate::a
|
⋮crate::a
|
||||||
b: t
|
⋮b: t
|
||||||
|
⋮
|
||||||
crate::a::b
|
⋮crate::a::b
|
||||||
c: t
|
⋮c: t
|
||||||
|
⋮
|
||||||
crate::a::b::c
|
⋮crate::a::b::c
|
||||||
X: t v
|
⋮X: t v
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,8 +100,8 @@ mod tests {
|
||||||
|
|
||||||
use crate::mock_analysis::analysis_and_position;
|
use crate::mock_analysis::analysis_and_position;
|
||||||
|
|
||||||
fn check_goto(fixture: &str, expected: &str, expected_range: &str) {
|
fn check_goto(ra_fixture: &str, expected: &str, expected_range: &str) {
|
||||||
let (analysis, pos) = analysis_and_position(fixture);
|
let (analysis, pos) = analysis_and_position(ra_fixture);
|
||||||
|
|
||||||
let mut navs = analysis.goto_definition(pos).unwrap().unwrap().info;
|
let mut navs = analysis.goto_definition(pos).unwrap().unwrap().info;
|
||||||
assert_eq!(navs.len(), 1);
|
assert_eq!(navs.len(), 1);
|
||||||
|
@ -790,8 +790,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn goto_def_in_local_macro() {
|
fn goto_def_in_local_macro() {
|
||||||
check_goto(
|
check_goto(
|
||||||
"
|
r"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
fn bar() {
|
fn bar() {
|
||||||
macro_rules! foo { () => { () } }
|
macro_rules! foo { () => { () } }
|
||||||
<|>foo!();
|
<|>foo!();
|
||||||
|
|
|
@ -14,6 +14,7 @@ fn rust_files_are_tidy() {
|
||||||
for path in rust_files() {
|
for path in rust_files() {
|
||||||
let text = fs2::read_to_string(&path).unwrap();
|
let text = fs2::read_to_string(&path).unwrap();
|
||||||
check_todo(&path, &text);
|
check_todo(&path, &text);
|
||||||
|
check_trailing_ws(&path, &text);
|
||||||
tidy_docs.visit(&path, &text);
|
tidy_docs.visit(&path, &text);
|
||||||
}
|
}
|
||||||
tidy_docs.finish();
|
tidy_docs.finish();
|
||||||
|
@ -33,6 +34,17 @@ fn check_todo(path: &Path, text: &str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_trailing_ws(path: &Path, text: &str) {
|
||||||
|
if is_exclude_dir(path, &["test_data"]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for line in text.lines() {
|
||||||
|
if line.chars().last().map(char::is_whitespace) == Some(true) {
|
||||||
|
panic!("Trailing whitespace in {}", path.display())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct TidyDocs {
|
struct TidyDocs {
|
||||||
missing_docs: Vec<String>,
|
missing_docs: Vec<String>,
|
||||||
|
@ -41,7 +53,13 @@ struct TidyDocs {
|
||||||
|
|
||||||
impl TidyDocs {
|
impl TidyDocs {
|
||||||
fn visit(&mut self, path: &Path, text: &str) {
|
fn visit(&mut self, path: &Path, text: &str) {
|
||||||
if is_exclude_dir(path) || is_exclude_file(path) {
|
// Test hopefully don't really need comments, and for assists we already
|
||||||
|
// have special comments which are source of doc tests and user docs.
|
||||||
|
if is_exclude_dir(path, &["tests", "test_data", "handlers"]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_exclude_file(path) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,21 +76,6 @@ impl TidyDocs {
|
||||||
self.missing_docs.push(path.display().to_string());
|
self.missing_docs.push(path.display().to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_exclude_dir(p: &Path) -> bool {
|
|
||||||
// Test hopefully don't really need comments, and for assists we already
|
|
||||||
// have special comments which are source of doc tests and user docs.
|
|
||||||
let exclude_dirs = ["tests", "test_data", "handlers"];
|
|
||||||
let mut cur_path = p;
|
|
||||||
while let Some(path) = cur_path.parent() {
|
|
||||||
if exclude_dirs.iter().any(|dir| path.ends_with(dir)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
cur_path = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_exclude_file(d: &Path) -> bool {
|
fn is_exclude_file(d: &Path) -> bool {
|
||||||
let file_names = ["tests.rs"];
|
let file_names = ["tests.rs"];
|
||||||
|
|
||||||
|
@ -128,6 +131,18 @@ impl TidyDocs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_exclude_dir(p: &Path, dirs_to_exclude: &[&str]) -> bool {
|
||||||
|
let mut cur_path = p;
|
||||||
|
while let Some(path) = cur_path.parent() {
|
||||||
|
if dirs_to_exclude.iter().any(|dir| path.ends_with(dir)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
cur_path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
fn rust_files() -> impl Iterator<Item = PathBuf> {
|
fn rust_files() -> impl Iterator<Item = PathBuf> {
|
||||||
let crates = project_root().join("crates");
|
let crates = project_root().join("crates");
|
||||||
let iter = WalkDir::new(crates);
|
let iter = WalkDir::new(crates);
|
||||||
|
|
Loading…
Reference in a new issue