|
1 |
| -# Nonexistent Path in Comment Lint |
| 1 | +# nonexistent_path_in_comment |
2 | 2 |
|
3 | 3 | ### What it does
|
4 |
| - |
5 |
| -This lint checks comments in the code for file path references and verifies that the referenced files actually do exist. It processes both line comments (using `//`) and block comments (`/* ... */`) by using regex to extract potential file paths. When the lint finds a file path that does not exist on the filesystem it emits a warning. |
| 4 | +This lint checks code comments, including both line comments (using `//`) and block comments |
| 5 | +(`/*...*/`) for file path references. It then validates that the referenced files exist either |
| 6 | +relative to the source file's directory or relative to the workspace root. When a file path |
| 7 | +reference does not point to an existing file, the lint emits a warning. |
6 | 8 |
|
7 | 9 | ### Why is this bad?
|
8 |
| - |
9 |
| -References to nonexistent files in comments can be misleading: |
10 |
| -- They clutter the code with outdated or inaccurate references. |
11 |
| -- They may cause confusion among developers who are trying to trace implementation details or documentation. |
| 10 | +References to nonexistent files in comments can be misleading: |
| 11 | +- They clutter the code with outdated or inaccurate references. |
| 12 | +- They may cause confusion among developers who are trying to trace implementation details |
| 13 | +or documentation. |
12 | 14 |
|
13 | 15 | ### Known problems
|
14 |
| -- Can only check for absolute path or path relative to commented file. |
15 |
| -- [This example from the issue](https://github.com/trailofbits/dylint/issues/1225#issue-2315607396) would get flaged even if it did exist, as this lint doesn't check for project root. |
| 16 | +- This example: |
| 17 | +```rust |
| 18 | +// dylint/dylint/build.rs (it exists) |
| 19 | +``` |
| 20 | +would get flagged here because the workspace root is `supplementary` |
| 21 | +it did exist, as this lint doesn't check for project root. |
16 | 22 |
|
17 | 23 | ### Example
|
18 |
| - |
19 |
| -The lint issues a warning when a comment refers to a file that does not exist: |
20 |
| - |
21 | 24 | ```
|
22 |
| -// See ../nonexistent/path/file.rs for further details |
| 25 | +// See ../nonexistent/path/file.rs for implementation details |
23 | 26 | fn main() {}
|
24 | 27 | ```
|
25 |
| - |
26 |
| -Use this approach instead, referring to a file that exists: |
27 |
| - |
| 28 | +Use instead: |
28 | 29 | ```
|
29 |
| -// See ../existing/file.rs for actual implementation details |
| 30 | +// See ../actual/path/file.rs for implementation details |
30 | 31 | fn main() {}
|
31 |
| -``` |
| 32 | +``` |
0 commit comments