Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions rust-code-analysis-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn mk_globset(elems: Vec<String>) -> GlobSet {
globset.add(glob);
}
});
globset.build().map_or(GlobSet::empty(), |globset| globset)
globset.build().unwrap_or(GlobSet::empty())
}

fn act_on_file(path: PathBuf, cfg: &Config) -> std::io::Result<()> {
Expand Down Expand Up @@ -132,17 +132,17 @@ fn act_on_file(path: PathBuf, cfg: &Config) -> std::io::Result<()> {
line_end: cfg.line_end,
};
action::<Find>(&language, source, &path, pr, cfg)
} else if cfg.count_lock.is_some() {
} else if let Some(count_lock) = &cfg.count_lock {
let cfg = CountCfg {
filters: cfg.count_filter.clone(),
stats: cfg.count_lock.as_ref().unwrap().clone(),
stats: count_lock.clone(),
};
action::<Count>(&language, source, &path, pr, cfg)
} else if cfg.preproc_lock.is_some() {
} else if let Some(preproc_lock) = &cfg.preproc_lock {
if let Some(language) = guess_language(&source, &path).0
&& language == LANG::Cpp
{
let mut results = cfg.preproc_lock.as_ref().unwrap().lock().unwrap();
let mut results = preproc_lock.lock().unwrap();
preprocess(
&PreprocParser::new(source, &path, None),
&path,
Expand Down
13 changes: 6 additions & 7 deletions src/metrics/cyclomatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,12 @@ impl Cyclomatic for PythonCode {
If | Elif | For | While | Except | With | Assert | And | Or => {
stats.cyclomatic += 1.;
}
Else => {
if node.has_ancestors(
|node| matches!(node.kind_id().into(), ForStatement | WhileStatement),
|node| node.kind_id() == ElseClause,
) {
stats.cyclomatic += 1.;
}
Else if node.has_ancestors(
|node| matches!(node.kind_id().into(), ForStatement | WhileStatement),
|node| node.kind_id() == ElseClause,
) =>
{
stats.cyclomatic += 1.;
}
_ => {}
}
Expand Down
6 changes: 1 addition & 5 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,7 @@ impl<'a> Node<'a> {
let mut level = level;
let mut node = *self;
while level != 0 {
if let Some(parent) = node.parent() {
node = parent;
} else {
return None;
}
node = node.parent()?;
level -= 1;
}

Expand Down
4 changes: 2 additions & 2 deletions src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ pub fn read_file_with_eol(path: &Path) -> std::io::Result<Option<Vec<u8>>> {
let mut start = vec![0; 64.min(file_size)];
let start = if file.read_exact(&mut start).is_ok() {
// Skip the bom if one
if start[..2] == [b'\xFE', b'\xFF'] || start[..2] == [b'\xFF', b'\xFE'] {
if start[..2] == *b"\xFE\xFF" || start[..2] == *b"\xFF\xFE" {
&start[2..]
} else if start[..3] == [b'\xEF', b'\xBB', b'\xBF'] {
} else if start[..3] == *b"\xEF\xBB\xBF" {
&start[3..]
} else {
&start
Expand Down