Skip to content

Commit

Permalink
fix: use proper location, add missing disable checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mds1 committed Sep 13, 2023
1 parent 0c62464 commit 2dcc7ad
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/check/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ impl Report {
/// Returns true if no issues were found.
#[must_use]
pub fn is_valid(&self) -> bool {
self.invalid_items.is_empty()
!self.invalid_items.iter().any(|item| !item.is_disabled)
}
}
16 changes: 11 additions & 5 deletions src/check/validators/constant_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,19 @@ fn validate_name(parsed: &Parsed, v: &VariableDefinition) -> Option<InvalidItem>
.attrs
.iter()
.any(|a| matches!(a, VariableAttribute::Constant(_) | VariableAttribute::Immutable(_)));
let name = &v.name.as_ref().unwrap().name;

if is_constant && !is_valid_constant_name(name) {
Some(InvalidItem::new(ValidatorKind::Constant, parsed, v.loc, name.clone()))
} else {
None
if !is_constant {
return None
}

v.name.as_ref().and_then(|name| {
let name_string = &name.name;
if is_valid_constant_name(name_string) {
None
} else {
Some(InvalidItem::new(ValidatorKind::Constant, parsed, name.loc, name_string.clone()))
}
})
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/check/validators/src_names_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn is_valid_internal_or_private_name(name: &str) -> bool {
fn validate_name(parsed: &Parsed, f: &FunctionDefinition) -> Option<InvalidItem> {
let name = f.name();
if f.is_internal_or_private() && !is_valid_internal_or_private_name(&name) {
Some(InvalidItem::new(ValidatorKind::Src, parsed, f.loc, name))
Some(InvalidItem::new(ValidatorKind::Src, parsed, f.name_loc, name))
} else {
None
}
Expand Down
2 changes: 1 addition & 1 deletion src/check/validators/test_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn is_test_function(f: &FunctionDefinition) -> bool {
fn validate_name(parsed: &Parsed, f: &FunctionDefinition) -> Option<InvalidItem> {
let name = f.name();
if is_test_function(f) && !is_valid_test_name(&name) {
Some(InvalidItem::new(ValidatorKind::Test, parsed, f.loc, name))
Some(InvalidItem::new(ValidatorKind::Test, parsed, f.name_loc, name))
} else {
None
}
Expand Down
1 change: 1 addition & 0 deletions tests/check-proj1-AllFindings/src/Counter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ contract Counter {
}

// scopelint: this directive is invalid
// Extra line break at the bottom is intention to ensure formatting fails.

21 changes: 20 additions & 1 deletion tests/check-proj1-AllFindings/src/CounterIgnored3.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// This file is identical to `Counter.sol` except it has ignore statements.
// This file is identical to `Counter.sol` except it has ignore statements and adds multiline
// function declaration tests.

pragma solidity ^0.8.17;

Expand Down Expand Up @@ -32,4 +33,22 @@ contract CounterIgnored1 {
function _privateHasLeadingUnderscore() private {
number += 1000;
}

// -------- Multiline function declaration tests --------
function prettyLongMethodName( // scopelint: disable-line
address someImportantUser,
uint256 someImportantNumber,
bytes32 someImportantData
) internal {
// do something
}

// scopelint: disable-next-line
function prettyLongMethodName2(
address someImportantUser,
uint256 someImportantNumber,
bytes32 someImportantData
) internal {
// do something
}
}

0 comments on commit 2dcc7ad

Please sign in to comment.