MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / justified

Function justified

atomic-audit/src/substantive/rust.rs:114–141  ·  view source on GitHub ↗
(mut node: Node<'_>, context: &Context<'_>, safety: bool)

Source from the content-addressed store, hash-verified

112}
113
114fn justified(mut node: Node<'_>, context: &Context<'_>, safety: bool) -> bool {
115 let explains = |node| {
116 let text = tokens::text(node, context.source);
117 let marker = if safety { "SAFETY:" } else { "Reason:" };
118 tokens::comment(node)
119 && text
120 .split_once(marker)
121 .is_some_and(|(_, reason)| reason.trim().len() >= 8)
122 };
123 // Support a comment inside the unsafe block or immediately before its
124 // enclosing statement. Strings containing SAFETY are never comments.
125 if code_comment_inside(node, &explains) {
126 return true;
127 }
128 for _ in 0..4 {
129 if node.prev_named_sibling().is_some_and(explains) {
130 return true;
131 }
132 let Some(parent) = node.parent() else {
133 break;
134 };
135 if matches!(parent.kind(), "function_item" | "source_file" | "block") {
136 break;
137 }
138 node = parent;
139 }
140 false
141}
142
143fn code_comment_inside<'tree>(node: Node<'tree>, explains: &impl Fn(Node<'tree>) -> bool) -> bool {
144 // Only direct comments in the unsafe body count, not a nested operation's

Callers 1

inspectFunction · 0.85

Calls 5

commentFunction · 0.85
code_comment_insideFunction · 0.85
parentMethod · 0.80
textFunction · 0.50
lenMethod · 0.45

Tested by

no test coverage detected