Skip to main content

miniextendr_lint/rules/
doc_attr_interleave.rs

1//! MXL302: non-doc attribute interrupts a doc-comment stream on a `#[miniextendr]` item.
2//!
3//! When `#[cfg(...)]`, `#[deprecated]`, or another non-doc attribute appears *between*
4//! two `///` comment blocks on a `#[miniextendr]` item, trailing prose can be incorrectly
5//! concatenated into the preceding `@examples` / `@details` / `@return` block, producing
6//! corrupted `.Rd` output.
7//!
8//! The macro now resets multiline-continuation context at the interruption point so the
9//! generated output is well-formed, but this warning guides users toward the idiomatic
10//! pattern: all `///` comments placed above all non-doc attributes.
11
12use crate::crate_index::CrateIndex;
13use crate::diagnostic::Diagnostic;
14use crate::lint_code::LintCode;
15
16pub fn check(index: &CrateIndex, diagnostics: &mut Vec<Diagnostic>) {
17    for (path, data) in &index.file_data {
18        for (item_name, line) in &data.interleaved_doc_attrs {
19            diagnostics.push(
20                Diagnostic::new(
21                    LintCode::MXL302,
22                    path,
23                    *line,
24                    format!(
25                        "`{item_name}`: non-doc attribute interrupts a `///` doc-comment stream; \
26                         trailing doc content will not continue the preceding roxygen tag",
27                    ),
28                )
29                .with_help(
30                    "Move all `///` doc comments above non-doc attributes (`#[cfg(...)]`, \
31                     `#[deprecated]`, etc.) to keep the doc-comment stream contiguous. \
32                     The macro recovers automatically but tag-continuation is reset at the \
33                     interruption point.",
34                ),
35            );
36        }
37    }
38}