Skip to content

Commit 14bd40b

Browse files
committed
Save Lint::module as full path of module
1 parent 1b76818 commit 14bd40b

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

clippy_dev/src/lib.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,29 +170,34 @@ pub fn gather_all() -> impl Iterator<Item = Lint> {
170170

171171
fn gather_from_file(dir_entry: &walkdir::DirEntry) -> impl Iterator<Item = Lint> {
172172
let content = fs::read_to_string(dir_entry.path()).unwrap();
173-
let mut filename = dir_entry.path().file_stem().unwrap().to_str().unwrap();
173+
let path = dir_entry.path();
174+
let filename = path.file_stem().unwrap();
175+
let path_buf = path.with_file_name(filename);
176+
let mut rel_path = path_buf
177+
.strip_prefix(clippy_project_root().join("clippy_lints/src"))
178+
.expect("only files in `clippy_lints/src` should be looked at");
174179
// If the lints are stored in mod.rs, we get the module name from
175180
// the containing directory:
176181
if filename == "mod" {
177-
filename = dir_entry
178-
.path()
179-
.parent()
180-
.unwrap()
181-
.file_stem()
182-
.unwrap()
183-
.to_str()
184-
.unwrap()
182+
rel_path = rel_path.parent().unwrap();
185183
}
186-
parse_contents(&content, filename)
184+
185+
let module = rel_path
186+
.components()
187+
.map(|c| c.as_os_str().to_str().unwrap())
188+
.collect::<Vec<_>>()
189+
.join("::");
190+
191+
parse_contents(&content, &module)
187192
}
188193

189-
fn parse_contents(content: &str, filename: &str) -> impl Iterator<Item = Lint> {
194+
fn parse_contents(content: &str, module: &str) -> impl Iterator<Item = Lint> {
190195
let lints = DEC_CLIPPY_LINT_RE
191196
.captures_iter(content)
192-
.map(|m| Lint::new(&m["name"], &m["cat"], &m["desc"], None, filename));
197+
.map(|m| Lint::new(&m["name"], &m["cat"], &m["desc"], None, module));
193198
let deprecated = DEC_DEPRECATED_LINT_RE
194199
.captures_iter(content)
195-
.map(|m| Lint::new(&m["name"], "Deprecated", &m["desc"], Some(&m["desc"]), filename));
200+
.map(|m| Lint::new(&m["name"], "Deprecated", &m["desc"], Some(&m["desc"]), module));
196201
// Removing the `.collect::<Vec<Lint>>().into_iter()` causes some lifetime issues due to the map
197202
lints.chain(deprecated).collect::<Vec<Lint>>().into_iter()
198203
}

0 commit comments

Comments
 (0)