Add check for errant {{produces}} marker.
If a lint example has an `ignore` tag, but the lint author also includes the {{produces}} marker, then the output will just contain the text `{{produces}}`. This adds a check for this mistake and provides help on how the lint docs should be written.
This commit is contained in:
parent
31f858d9a5
commit
c6cba68c16
1 changed files with 34 additions and 4 deletions
|
@ -45,6 +45,36 @@ impl Lint {
|
||||||
fn check_style(&self) -> Result<(), Box<dyn Error>> {
|
fn check_style(&self) -> Result<(), Box<dyn Error>> {
|
||||||
for &expected in &["### Example", "### Explanation", "{{produces}}"] {
|
for &expected in &["### Example", "### Explanation", "{{produces}}"] {
|
||||||
if expected == "{{produces}}" && self.is_ignored() {
|
if expected == "{{produces}}" && self.is_ignored() {
|
||||||
|
if self.doc_contains("{{produces}}") {
|
||||||
|
return Err(format!(
|
||||||
|
"the lint example has `ignore`, but also contains the {{{{produces}}}} marker\n\
|
||||||
|
\n\
|
||||||
|
The documentation generator cannot generate the example output when the \
|
||||||
|
example is ignored.\n\
|
||||||
|
Manually include the sample output below the example. For example:\n\
|
||||||
|
\n\
|
||||||
|
/// ```rust,ignore (needs command line option)\n\
|
||||||
|
/// #[cfg(widnows)]\n\
|
||||||
|
/// fn foo() {{}}\n\
|
||||||
|
/// ```\n\
|
||||||
|
///\n\
|
||||||
|
/// This will produce:\n\
|
||||||
|
/// \n\
|
||||||
|
/// ```text\n\
|
||||||
|
/// warning: unknown condition name used\n\
|
||||||
|
/// --> lint_example.rs:1:7\n\
|
||||||
|
/// |\n\
|
||||||
|
/// 1 | #[cfg(widnows)]\n\
|
||||||
|
/// | ^^^^^^^\n\
|
||||||
|
/// |\n\
|
||||||
|
/// = note: `#[warn(unexpected_cfgs)]` on by default\n\
|
||||||
|
/// ```\n\
|
||||||
|
\n\
|
||||||
|
Replacing the output with the text of the example you \
|
||||||
|
compiled manually yourself.\n\
|
||||||
|
"
|
||||||
|
).into());
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if !self.doc_contains(expected) {
|
if !self.doc_contains(expected) {
|
||||||
|
@ -317,10 +347,10 @@ impl<'a> LintExtractor<'a> {
|
||||||
..,
|
..,
|
||||||
&format!(
|
&format!(
|
||||||
"This will produce:\n\
|
"This will produce:\n\
|
||||||
\n\
|
\n\
|
||||||
```text\n\
|
```text\n\
|
||||||
{}\
|
{}\
|
||||||
```",
|
```",
|
||||||
output
|
output
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue