about summary refs log tree commit diff
path: root/clippy_dev
diff options
context:
space:
mode:
authorflip1995 <hello@philkrones.com>2020-02-11 11:10:54 +0100
committerflip1995 <hello@philkrones.com>2020-02-14 14:37:56 +0100
commit3da2c9183a19c6f11e8bd61f16d03b6830eb3eec (patch)
tree97c36ee8a8b13adc3a8e297628ec90f150a2c30e /clippy_dev
parent560559bafe1d61bca3d815ce80c53ae2d48e1829 (diff)
downloadrust-3da2c9183a19c6f11e8bd61f16d03b6830eb3eec.tar.gz
rust-3da2c9183a19c6f11e8bd61f16d03b6830eb3eec.zip
Save Lint::module as full path of module
Diffstat (limited to 'clippy_dev')
-rw-r--r--clippy_dev/src/lib.rs31
1 files changed, 18 insertions, 13 deletions
diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs
index 67a9abd29d6..042ce9bc009 100644
--- a/clippy_dev/src/lib.rs
+++ b/clippy_dev/src/lib.rs
@@ -170,29 +170,34 @@ pub fn gather_all() -> impl Iterator<Item = Lint> {
 
 fn gather_from_file(dir_entry: &walkdir::DirEntry) -> impl Iterator<Item = Lint> {
     let content = fs::read_to_string(dir_entry.path()).unwrap();
-    let mut filename = dir_entry.path().file_stem().unwrap().to_str().unwrap();
+    let path = dir_entry.path();
+    let filename = path.file_stem().unwrap();
+    let path_buf = path.with_file_name(filename);
+    let mut rel_path = path_buf
+        .strip_prefix(clippy_project_root().join("clippy_lints/src"))
+        .expect("only files in `clippy_lints/src` should be looked at");
     // If the lints are stored in mod.rs, we get the module name from
     // the containing directory:
     if filename == "mod" {
-        filename = dir_entry
-            .path()
-            .parent()
-            .unwrap()
-            .file_stem()
-            .unwrap()
-            .to_str()
-            .unwrap()
+        rel_path = rel_path.parent().unwrap();
     }
-    parse_contents(&content, filename)
+
+    let module = rel_path
+        .components()
+        .map(|c| c.as_os_str().to_str().unwrap())
+        .collect::<Vec<_>>()
+        .join("::");
+
+    parse_contents(&content, &module)
 }
 
-fn parse_contents(content: &str, filename: &str) -> impl Iterator<Item = Lint> {
+fn parse_contents(content: &str, module: &str) -> impl Iterator<Item = Lint> {
     let lints = DEC_CLIPPY_LINT_RE
         .captures_iter(content)
-        .map(|m| Lint::new(&m["name"], &m["cat"], &m["desc"], None, filename));
+        .map(|m| Lint::new(&m["name"], &m["cat"], &m["desc"], None, module));
     let deprecated = DEC_DEPRECATED_LINT_RE
         .captures_iter(content)
-        .map(|m| Lint::new(&m["name"], "Deprecated", &m["desc"], Some(&m["desc"]), filename));
+        .map(|m| Lint::new(&m["name"], "Deprecated", &m["desc"], Some(&m["desc"]), module));
     // Removing the `.collect::<Vec<Lint>>().into_iter()` causes some lifetime issues due to the map
     lints.chain(deprecated).collect::<Vec<Lint>>().into_iter()
 }