Skip to content

Commit

Permalink
Add support for BannedFunction issue and after_populate hook
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jun 28, 2024
1 parent d0f7414 commit 6e77061
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
3 changes: 3 additions & 0 deletions src/analyzer/custom_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ pub trait InternalHook {
) -> bool {
false
}

#[allow(unused_variables)]
fn after_populate(&self, codebase: &CodebaseInfo, interner: &Interner) {}
}

pub trait CustomHook: InternalHook + Send + Sync + core::fmt::Debug {}
49 changes: 28 additions & 21 deletions src/analyzer/function_analysis_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,27 +583,34 @@ fn get_hakana_fixmes_and_ignores(
) -> BTreeMap<u32, Vec<(IssueKind, (u32, u32, u32, u32, bool))>> {
let mut hakana_fixme_or_ignores = BTreeMap::new();
for (pos, comment) in comments {
if let Comment::CmtBlock(text) = comment {
let trimmed_text = if let Some(trimmed_text) = text.strip_prefix('*') {
trimmed_text.trim()
} else {
text.trim()
};

if let Some(Ok(issue_kind)) = get_issue_from_comment(trimmed_text, all_custom_issues) {
hakana_fixme_or_ignores
.entry(pos.line() as u32)
.or_insert_with(Vec::new)
.push((
issue_kind,
(
pos.start_offset() as u32,
pos.end_offset() as u32,
pos.to_raw_span().start.beg_of_line() as u32,
pos.end_offset() as u32,
false,
),
));
match comment {
Comment::CmtBlock(text) => {
let trimmed_text = if let Some(trimmed_text) = text.strip_prefix('*') {
trimmed_text.trim()
} else {
text.trim()
};

if let Some(Ok(issue_kind)) =
get_issue_from_comment(trimmed_text, all_custom_issues)
{
hakana_fixme_or_ignores
.entry(pos.line() as u32)
.or_insert_with(Vec::new)
.push((
issue_kind,
(
pos.start_offset() as u32,
pos.end_offset() as u32,
pos.to_raw_span().start.beg_of_line() as u32,
pos.end_offset() as u32,
false,
),
));
}
}
Comment::CmtLine(_) => {
// do nothing — if we handle issues here things are much slower
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/code_info/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
#[derive(Clone, PartialEq, Eq, Hash, Display, Debug, Serialize, Deserialize, EnumString)]
pub enum IssueKind {
AbstractInstantiation,
BannedFunction,
ExtendFinalClass,
CannotInferGenericParam,
CustomIssue(Box<String>),
Expand Down Expand Up @@ -317,6 +318,10 @@ pub fn get_issue_from_comment(
return Some(Ok(IssueKind::NoJoinInAsyncFunction));
} else if trimmed_text.starts_with("HHAST_FIXME[FinalOrAbstractClass]") {
return Some(Ok(IssueKind::MissingFinalOrAbstract));
} else if trimmed_text.starts_with("HHAST_FIXME[BannedFunctions]")
|| trimmed_text.starts_with("HHAST_IGNORE_ERROR[BannedFunctions]")
{
return Some(Ok(IssueKind::BannedFunction));
}

None
Expand Down
4 changes: 4 additions & 0 deletions src/file_scanner_analyzer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ pub fn scan_and_analyze(
cached_analysis.safe_symbol_members,
);

for hook in &config.hooks {
hook.after_populate(&codebase, &interner);
}

let populating_elapsed = populating_now.elapsed();

if logger.can_log_timing() {
Expand Down

0 comments on commit 6e77061

Please sign in to comment.