Skip to content

Commit

Permalink
Fix a whole bunch more clippy complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jan 6, 2024
1 parent 29cf05f commit 0332cf7
Show file tree
Hide file tree
Showing 86 changed files with 839 additions and 1,001 deletions.
16 changes: 8 additions & 8 deletions src/aast_utils/name_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl NameContext<'_> {
&mut self,
interner: &mut ThreadedInterner,
name: &str,
alias_name: &String,
alias_name: &str,
alias_kind: &NsKind,
) {
let current_context = self.name_resolution_contexts.last_mut().unwrap();
Expand Down Expand Up @@ -159,13 +159,13 @@ impl NameContext<'_> {
uses: &mut Vec<(StrId, StrId)>,
) -> StrId {
// fully qualified names are already resolved
if name.starts_with('\\') {
return interner.intern_str(&name[1..]);
if let Some(stripped) = name.strip_prefix('\\') {
return interner.intern_str(stripped);
}

// XHP names preceded by : are already resolved
if name.starts_with(':') {
return interner.intern_str(&name[1..].replace(':', "\\"));
if let Some(stripped) = name.strip_prefix(':') {
return interner.intern(stripped.replace(':', "\\"));
}

match name.as_str() {
Expand Down Expand Up @@ -222,7 +222,7 @@ impl NameContext<'_> {
fn resolve_alias(
&mut self,
interner: &mut ThreadedInterner,
name: &String,
name: &str,
alias_kind: NsKind,
uses: &mut Vec<(StrId, StrId)>,
) -> Option<StrId> {
Expand Down Expand Up @@ -278,7 +278,7 @@ impl NameContext<'_> {
None
}

pub fn is_reserved(name: &String) -> bool {
pub fn is_reserved(name: &str) -> bool {
let reserved_types = [
"mixed",
"vec",
Expand All @@ -303,7 +303,7 @@ impl NameContext<'_> {
"nonnull",
];

reserved_types.contains(&name.as_str())
reserved_types.contains(&name)
}
}

Expand Down
48 changes: 21 additions & 27 deletions src/aast_utils/naming_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,9 @@ impl<'ast> Visitor<'ast> for Scanner<'_> {
nc: &mut NameContext<'ast>,
p: &'ast oxidized::tast::ShapeFieldInfo,
) -> Result<(), ()> {
match &p.name {
oxidized::nast::ShapeFieldName::SFclassConst(_, member_name) => {
let p = self.interner.intern(member_name.1.clone());
self.resolved_names.insert(member_name.0.start_offset(), p);
}
_ => {}
if let oxidized::nast::ShapeFieldName::SFclassConst(_, member_name) = &p.name {
let p = self.interner.intern(member_name.1.clone());
self.resolved_names.insert(member_name.0.start_offset(), p);
}
p.recurse(nc, self)
}
Expand Down Expand Up @@ -223,29 +220,26 @@ impl<'ast> Visitor<'ast> for Scanner<'_> {
nc: &mut NameContext<'ast>,
p: &'ast oxidized::nast::ShapeFieldName,
) -> Result<(), ()> {
match p {
oxidized::nast::ShapeFieldName::SFclassConst(id, _) => {
let resolved_name = nc.get_resolved_name(
self.interner,
&id.1,
aast::NsKind::NSClass,
if let Some(symbol_name) = nc.symbol_name {
if let Some(member_name) = nc.member_name {
self.symbol_member_uses
.entry((symbol_name, member_name))
.or_default()
} else {
self.symbol_uses.entry(symbol_name).or_default()
}
if let oxidized::nast::ShapeFieldName::SFclassConst(id, _) = p {
let resolved_name = nc.get_resolved_name(
self.interner,
&id.1,
aast::NsKind::NSClass,
if let Some(symbol_name) = nc.symbol_name {
if let Some(member_name) = nc.member_name {
self.symbol_member_uses
.entry((symbol_name, member_name))
.or_default()
} else {
&mut self.file_uses
},
);
self.symbol_uses.entry(symbol_name).or_default()
}
} else {
&mut self.file_uses
},
);

self.resolved_names
.insert(id.0.start_offset(), resolved_name);
}
_ => {}
self.resolved_names
.insert(id.0.start_offset(), resolved_name);
};

p.recurse(nc, self)
Expand Down
5 changes: 4 additions & 1 deletion src/algebra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ hakana-type = { path = "../ttype" }
rustc-hash = "1.1.0"

[lib]
path = "lib.rs"
path = "lib.rs"

[lints.clippy]
type_complexity = "allow"
2 changes: 0 additions & 2 deletions src/algebra/clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ fn get_hash(
+ Wrapping(creating_object_id.1)
+ Wrapping(if wedge { 100000 } else { 0 }))
.0
.try_into()
.unwrap()
} else {
let mut hasher = rustc_hash::FxHasher::default();

Expand Down
4 changes: 4 additions & 0 deletions src/analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ regex = "1.6.0"

[lib]
path = "lib.rs"

[lints.clippy]
too_many_arguments = "allow"
type_complexity = "allow"
2 changes: 1 addition & 1 deletion src/analyzer/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl Config {
true
}

pub fn allow_taints_in_file(&self, file: &String) -> bool {
pub fn allow_taints_in_file(&self, file: &str) -> bool {
for ignore_file_path in &self.security_config.ignore_files {
if glob::Pattern::new(ignore_file_path).unwrap().matches(file) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/custom_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub trait InternalHook {
inferred_return_type: &mut Option<TUnion>,
codebase: &CodebaseInfo,
statements_analyzer: &StatementsAnalyzer,
fb_ast: &Vec<aast::Stmt<(), ()>>,
fb_ast: &[aast::Stmt<(), ()>],
) -> bool {
false
}
Expand Down
75 changes: 36 additions & 39 deletions src/analyzer/dataflow/program_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,46 +390,43 @@ fn get_child_nodes(

if match_sinks {
if let Some(sink) = graph.sinks.get(to_id) {
match &sink.kind {
DataFlowNodeKind::TaintSink { types, .. } => {
let mut matching_sinks = types.clone();
matching_sinks.retain(|t| new_taints.contains(t));

if !matching_sinks.is_empty() {
if let Some(issue_pos) = &generated_source.pos {
let taint_sources = generated_source.get_taint_sources();
for taint_source in taint_sources {
for matching_sink in &matching_sinks {
if !config.allow_data_from_source_in_file(
taint_source,
matching_sink,
&new_destination,
interner,
) {
continue;
}

new_destination.taint_sinks.remove(matching_sink);

let message = format!(
"Data from {} found its way to {} using path {}",
taint_source.get_error_message(),
matching_sink.get_error_message(),
new_destination
.get_trace(interner, &config.root_dir)
);
new_issues.push(Issue::new(
IssueKind::TaintedData(matching_sink.clone()),
message,
**issue_pos,
&None,
));
if let DataFlowNodeKind::TaintSink { types, .. } = &sink.kind {
let mut matching_sinks = types.clone();
matching_sinks.retain(|t| new_taints.contains(t));

if !matching_sinks.is_empty() {
if let Some(issue_pos) = &generated_source.pos {
let taint_sources = generated_source.get_taint_sources();
for taint_source in taint_sources {
for matching_sink in &matching_sinks {
if !config.allow_data_from_source_in_file(
taint_source,
matching_sink,
&new_destination,
interner,
) {
continue;
}

new_destination.taint_sinks.remove(matching_sink);

let message = format!(
"Data from {} found its way to {} using path {}",
taint_source.get_error_message(),
matching_sink.get_error_message(),
new_destination
.get_trace(interner, &config.root_dir)
);
new_issues.push(Issue::new(
IssueKind::TaintedData(matching_sink.clone()),
message,
**issue_pos,
&None,
));
}
}
}
}
_ => {}
}
}
}
Expand All @@ -456,7 +453,7 @@ fn get_child_nodes(
new_child_nodes
}

fn has_recent_assignment(generated_path_types: &Vec<PathKind>) -> bool {
fn has_recent_assignment(generated_path_types: &[PathKind]) -> bool {
let filtered_paths = generated_path_types
.iter()
.rev()
Expand Down Expand Up @@ -492,7 +489,7 @@ fn has_recent_assignment(generated_path_types: &Vec<PathKind>) -> bool {
false
}

fn has_unmatched_property_assignment(symbol: &StrId, generated_path_types: &Vec<PathKind>) -> bool {
fn has_unmatched_property_assignment(symbol: &StrId, generated_path_types: &[PathKind]) -> bool {
let filtered_paths = generated_path_types
.iter()
.rev()
Expand Down Expand Up @@ -539,7 +536,7 @@ fn has_unmatched_property_assignment(symbol: &StrId, generated_path_types: &Vec<
pub(crate) fn should_ignore_array_fetch(
path_type: &PathKind,
match_type: &ArrayDataKind,
previous_path_types: &Vec<PathKind>,
previous_path_types: &[PathKind],
) -> bool {
// arraykey-fetch requires a matching arraykey-assignment at the same level
// otherwise the tainting is not valid
Expand Down Expand Up @@ -609,7 +606,7 @@ pub(crate) fn should_ignore_array_fetch(

pub(crate) fn should_ignore_property_fetch(
path_type: &PathKind,
previous_path_types: &Vec<PathKind>,
previous_path_types: &[PathKind],
) -> bool {
// arraykey-fetch requires a matching arraykey-assignment at the same level
// otherwise the tainting is not valid
Expand Down
56 changes: 25 additions & 31 deletions src/analyzer/dataflow/unused_variable_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,41 +334,35 @@ impl<'a> Scanner<'a> {
) {
for (comment_pos, comment) in self.comments {
if comment_pos.line() == stmt.0.line() {
match comment {
Comment::CmtBlock(block) => {
if block.trim() == "HHAST_FIXME[UnusedVariable]" {
analysis_data.add_replacement(
(comment_pos.start_offset() as u32, limit as u32),
Replacement::TrimPrecedingWhitespace(
comment_pos.to_raw_span().start.beg_of_line() as u32,
),
);

return;
}
if let Comment::CmtBlock(block) = comment {
if block.trim() == "HHAST_FIXME[UnusedVariable]" {
analysis_data.add_replacement(
(comment_pos.start_offset() as u32, limit as u32),
Replacement::TrimPrecedingWhitespace(
comment_pos.to_raw_span().start.beg_of_line() as u32,
),
);

return;
}
_ => {}
}
} else if comment_pos.line() == stmt.0.line() - 1 {
match comment {
Comment::CmtBlock(block) => {
if let "HAKANA_FIXME[UnusedAssignment]"
| "HAKANA_FIXME[UnusedAssignmentStatement]" = block.trim()
{
let stmt_start = stmt.0.to_raw_span().start;
analysis_data.add_replacement(
(
comment_pos.start_offset() as u32,
(stmt_start.beg_of_line() as u32) - 1,
),
Replacement::TrimPrecedingWhitespace(
comment_pos.to_raw_span().start.beg_of_line() as u32,
),
);
return;
}
if let Comment::CmtBlock(block) = comment {
if let "HAKANA_FIXME[UnusedAssignment]"
| "HAKANA_FIXME[UnusedAssignmentStatement]" = block.trim()
{
let stmt_start = stmt.0.to_raw_span().start;
analysis_data.add_replacement(
(
comment_pos.start_offset() as u32,
(stmt_start.beg_of_line() as u32) - 1,
),
Replacement::TrimPrecedingWhitespace(
comment_pos.to_raw_span().start.beg_of_line() as u32,
),
);
return;
}
_ => {}
}
}
}
Expand Down
Loading

0 comments on commit 0332cf7

Please sign in to comment.