miniextendr_lint/rules/
fn_visibility.rs1use crate::crate_index::{CrateIndex, LintKind};
6use crate::diagnostic::Diagnostic;
7use crate::lint_code::LintCode;
8
9pub fn check(index: &CrateIndex, diagnostics: &mut Vec<Diagnostic>) {
10 for (path, data) in &index.file_data {
11 for item in &data.miniextendr_items {
12 if item.kind != LintKind::Function {
13 continue;
14 }
15
16 let is_pub = data.fn_visibility.get(&item.name).copied().unwrap_or(false);
17 let has_export_tag = data
18 .fn_doc_tags
19 .get(&item.name)
20 .is_some_and(|tags| tags.iter().any(|t| t == "export"));
21
22 if !is_pub && has_export_tag {
24 diagnostics.push(
25 Diagnostic::new(
26 LintCode::MXL106,
27 path,
28 item.line,
29 format!(
30 "function `{}` has `/// @export` but is not `pub`. \
31 The @export tag has no effect without `pub fn`.",
32 item.name,
33 ),
34 )
35 .with_help("Make the function `pub fn` to enable R export."),
36 );
37 }
38 }
39 }
40}