complex macros generating doc comments not clustered correctly
ssokolow opened this issue · comments
Describe the bug
As requested in #227, this is a more complex example of macro-generated doctests that still trip cargo-spellcheck 0.9.2 up into reporting code inside doctests as typos.
Sorry for taking so long.
I've tried to minimize it as much as is possible without reducing the set of false positives it generates and I even managed to make it see more while I was minimizing.
To Reproduce
Put the following in lib.rs
in a fresh project and run cargo spellcheck check
:
#[macro_export]
macro_rules! from_str_variant_reduced {
($from_str_name:ident) => {
/// ```no_run
#[doc = concat!("use cli_validators::path::", stringify!($from_str_name), ";")]
/// #[derive(argh::FromArgs)]
/// #[argh(description = "Example program")]
/// struct CliArgs {
/// path: Vec<String>,
/// }
/// fn main() { let matches: CliArgs = argh::from_env(); }
/// ```
/// ```no_run
/// #[derive(gumdrop::Options)]
/// struct CliArgs {
#[doc = concat!(" #[options(free, parse(try_from_str = \"",
stringify!($from_str_name), "\"))]")]
/// path: Vec<String>,
/// }
/// fn main() { let matches = CliArgs::parse_args_default_or_exit(); }
/// ```
pub fn $from_str_name(_value: &str) -> Result<(), String> {
Ok(())
}
};
}
Expected behavior
There should be no spelling errors found.
Screenshots
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:6
|
6 | #[derive(argh::FromArgs)]
| ^^^^
| - arch or aright
|
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:6
|
6 | #[derive(argh::FromArgs)]
| ^^^^^^^^
| - Frogmarch
|
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:7
|
7 | #[argh(description = "Example program")]
| ^^^^
| - arch or aright
|
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:7
|
7 | #[argh(description = "Example program")]
| ^
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:8
|
8 | struct CliArgs {
| ^^^^^^
| - strict, strut, struck, structure, destruct, instruct, obstruct, or one of 1 others
|
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:8
|
8 | struct CliArgs {
| ^^^^^^^
| - Clings
|
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:9
|
9 | path: Vec<String>,
| ^^^
| - Sec, Vic, Rec, Dec, Vex, Vac, Vet, or one of 3 others
|
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:11
|
11 | fn main() { let matches: CliArgs = argh::from_env(); }
| ^^
| - fen, fin, fan, fun, en, in, fa, or one of 7 others
|
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:11
|
11 | fn main() { let matches: CliArgs = argh::from_env(); }
| ^^^^^^^
| - Clings
|
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:11
|
11 | fn main() { let matches: CliArgs = argh::from_env(); }
| ^
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:11
|
11 | fn main() { let matches: CliArgs = argh::from_env(); }
| ^^^^
| - arch or aright
|
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:11
|
11 | fn main() { let matches: CliArgs = argh::from_env(); }
| ^^^^^^^^
| - frogmen
|
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:20
|
20 | fn main() { let matches = CliArgs::parse_args_default_or_exit(); }
| ^^
| - fen, fin, fan, fun, en, in, fa, or one of 7 others
|
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:20
|
20 | fn main() { let matches = CliArgs::parse_args_default_or_exit(); }
| ^
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:20
|
20 | fn main() { let matches = CliArgs::parse_args_default_or_exit(); }
| ^^^^^^^
| - Clings
|
| Possible spelling mistake found.
error: spellcheck(Hunspell)
--> /home/ssokolow/rust_test/src/lib.rs:20
|
20 | fn main() { let matches = CliArgs::parse_args_default_or_exit(); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| Possible spelling mistake found.
Please complete the following information:
- System: Kubuntu Linux 20.04.3 LTS
- Obtained: cargo
- Version: cargo-spellcheck 0.9.2
Additional context
It would require being able to detect macro_rules
that are included in doc comments and - at the very least - skip them. It's a non goal to become a rust-preprocessor and be able to eval them.
The issue why this is not skipped, is caused by the fact, that currently only strings are expected as prefix and postfix, others are skipped.
With \
``` not being closed. The next detect block of comments starts with what one would expect to be considered code, but is not, which causes all the trailing issues.
Thanks for creating the detailed test case, it's now clear what's required to resolve this use case.
Why would it require that?
Shouldn't it be possible to implement a compromise where unrecognized #[doc = ...]
attributes are skipped, preserving the parser state rather than resetting it? ...possibly as an option in the config file?
My #[doc = ...]
hackery isn't equivalent to document.write('<div>')
... it's entirely self-contained, as far as well-formedness goes.
Not saying that it is a requirement in principle, it's just that current implementation requires it :) - an impl detail.
And yes, continued clustering for #[doc = foo!(..)]
is the planned solution, while omitting its content.
Should be solved, after all :)