Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions rust-code-analysis-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ fn act_on_file(path: PathBuf, cfg: &Config) -> std::io::Result<()> {
};
action::<Count>(&language, source, &path, pr, cfg)
} else if cfg.preproc_lock.is_some() {
if let Some(language) = guess_language(&source, &path).0 {
if language == LANG::Cpp {
let mut results = cfg.preproc_lock.as_ref().unwrap().lock().unwrap();
preprocess(
&PreprocParser::new(source, &path, None),
&path,
&mut results,
);
}
if let Some(language) = guess_language(&source, &path).0
&& language == LANG::Cpp
{
let mut results = cfg.preproc_lock.as_ref().unwrap().lock().unwrap();
preprocess(
&PreprocParser::new(source, &path, None),
&path,
&mut results,
);
}
Ok(())
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/alterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ impl Alterator for CppCode {
AstNode::new(node.kind(), text, span, Vec::new())
}
Cpp::PreprocDef | Cpp::PreprocFunctionDef | Cpp::PreprocCall => {
if let Some(last) = children.last() {
if last.r#type == "\n" {
children.pop();
}
if let Some(last) = children.last()
&& last.r#type == "\n"
{
children.pop();
}
Self::get_default(node, code, span, children)
}
Expand Down
10 changes: 5 additions & 5 deletions src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,11 @@ impl Checker for RustCode {
}

fn is_useful_comment(node: &Node, code: &[u8]) -> bool {
if let Some(parent) = node.parent() {
if parent.kind_id() == Rust::TokenTree {
// A comment could be a macro token
return true;
}
if let Some(parent) = node.parent()
&& parent.kind_id() == Rust::TokenTree
{
// A comment could be a macro token
return true;
}
let code = &code[node.start_byte()..node.end_byte()];
code.starts_with(b"/// cbindgen:")
Expand Down
14 changes: 7 additions & 7 deletions src/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ impl Callback for Find {
type Cfg = FindCfg;

fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
if let Some(good) = find(parser, &cfg.filters) {
if !good.is_empty() {
println!("In file {}", cfg.path.to_str().unwrap());
for node in good {
dump_node(parser.get_code(), &node, 1, cfg.line_start, cfg.line_end)?;
}
println!();
if let Some(good) = find(parser, &cfg.filters)
&& !good.is_empty()
{
println!("In file {}", cfg.path.to_str().unwrap());
for node in good {
dump_node(parser.get_code(), &node, 1, cfg.line_start, cfg.line_end)?;
}
println!();
}
Ok(())
}
Expand Down
48 changes: 24 additions & 24 deletions src/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ impl Getter for PythonCode {
String => {
let mut operator = HalsteadType::Unknown;
// check if we've a documentation string or a multiline comment
if let Some(parent) = node.parent() {
if parent.kind_id() != ExpressionStatement || parent.child_count() != 1 {
operator = HalsteadType::Operand;
};
}
if let Some(parent) = node.parent()
&& (parent.kind_id() != ExpressionStatement || parent.child_count() != 1)
{
operator = HalsteadType::Operand;
};
operator
}
_ => HalsteadType::Unknown,
Expand Down Expand Up @@ -444,28 +444,28 @@ impl Getter for CppCode {
Cpp::FunctionDeclarator == id
|| Cpp::FunctionDeclarator2 == id
|| Cpp::FunctionDeclarator3 == id
}) {
if let Some(first) = fd.child(0) {
match first.kind_id().into() {
Cpp::TypeIdentifier
| Cpp::Identifier
| Cpp::FieldIdentifier
| Cpp::DestructorName
| Cpp::OperatorName
| Cpp::QualifiedIdentifier
| Cpp::QualifiedIdentifier2
| Cpp::QualifiedIdentifier3
| Cpp::QualifiedIdentifier4
| Cpp::TemplateFunction
| Cpp::TemplateMethod => {
let code = &code[first.start_byte()..first.end_byte()];
return std::str::from_utf8(code).ok();
}
_ => {}
}
})
&& let Some(first) = fd.child(0)
{
match first.kind_id().into() {
Cpp::TypeIdentifier
| Cpp::Identifier
| Cpp::FieldIdentifier
| Cpp::DestructorName
| Cpp::OperatorName
| Cpp::QualifiedIdentifier
| Cpp::QualifiedIdentifier2
| Cpp::QualifiedIdentifier3
| Cpp::QualifiedIdentifier4
| Cpp::TemplateFunction
| Cpp::TemplateMethod => {
let code = &code[first.start_byte()..first.end_byte()];
return std::str::from_utf8(code).ok();
}
_ => {}
}
}
}
Comment thread
marlon-costa-dc marked this conversation as resolved.
Outdated
}
_ => {
if let Some(name) = node.child_by_field_name("name") {
Expand Down
Loading