1//! Doc links into R packages the package does not declare.
2//!
3//! - MXL204: roxygen2 reads ``[`Type::method`]``, `[Type::method]` and
4//! `[text][pkg::topic]` as a link into the R package named before the last
5//! `::`, and warns "refers to un-installed package" when there is none. The
6//! link was usually written for rustdoc. This rule warns on each `pkg::`
7//! link in `#[miniextendr]` docs whose `pkg` is not the package itself, not
8//! in `Depends` / `Imports` / `Suggests` / `Enhances` / `LinkingTo`, and not
9//! shipped with R. Leading prose counts only under
10//! `roxygen_prose_links = "keep"`: the default strips its links. A block
11//! that renders no help page (`@noRd`, `noexport`) does not count at all:
12//! the macro strips every link there (#1818). The rule reports and never
13//! rewrites. It skips when there is no `DESCRIPTION`.
1415use crate::crate_index::CrateIndex;
16use crate::diagnostic::Diagnostic;
17use crate::lint_code::LintCode;
1819pub fn check(index: &CrateIndex, diagnostics: &mut Vec<Diagnostic>) {
20let Some(description) = &index.description else {
21return;
22 };
23for (path, data) in &index.file_data {
24for link in &data.doc_pkg_links {
25if (link.leading_prose && !index.prose_links_keep) || description.resolves(&link.pkg) {
26continue;
27 }
28 diagnostics.push(
29 Diagnostic::new(
30 LintCode::MXL204,
31 path,
32 link.line,
33::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}` reaches roxygen2 as a link into the R package `{1}`, which is not this package, not in DESCRIPTION (Depends, Imports, Suggests, Enhances, LinkingTo) and not shipped with R.",
link.written, link.pkg))
})format!(
34"`{}` reaches roxygen2 as a link into the R package `{}`, which is not \
35 this package, not in DESCRIPTION (Depends, Imports, Suggests, Enhances, \
36 LinkingTo) and not shipped with R.",
37 link.written, link.pkg,
38 ),
39 )
40 .with_help(
41"If it names a Rust item, root the target at the crate with the \
42 `[text][crate::path]` spelling (`[`Type::method`][crate::Type::method]`); \
43 it is a link in rustdoc and plain text on the R page. If it is an R \
44 package, add it to DESCRIPTION.",
45 ),
46 );
47 }
48 }
49}