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
19 changes: 19 additions & 0 deletions src/check/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ pub enum FileKind {
Src,
/// Contracts with test methods live in the `test` directory and end with `.t.sol`.
Test,
/// Contracts with handler methods live in the `test` directory and end with `.handler.sol`.
Handler,
}

/// Provides a method to check if a file is of a given kind.
Expand All @@ -124,6 +126,7 @@ impl IsFileKind for Path {
FileKind::Script => path.starts_with("./script") && path.ends_with(".s.sol"),
FileKind::Src => path.starts_with("./src") && path.ends_with(".sol"),
FileKind::Test => path.starts_with("./test") && path.ends_with(".t.sol"),
FileKind::Handler => path.starts_with("./test") && path.ends_with(".handler.sol"),
}
}
}
Expand Down Expand Up @@ -218,6 +221,8 @@ pub struct ExpectedFindings {
pub test_helper: usize,
/// The number of expected findings for test contracts.
pub test: usize,
/// The number of expected findings for handler contracts.
pub handler: usize,
}

impl ExpectedFindings {
Expand All @@ -233,6 +238,7 @@ impl ExpectedFindings {
src: expected_findings,
test_helper: expected_findings,
test: expected_findings,
handler: expected_findings,
}
}

Expand Down Expand Up @@ -321,6 +327,18 @@ impl ExpectedFindings {
let invalid_items_test = validate(&to_parsed(
"./test/MyContract.t.sol",
src,
pt.clone(),
comments.clone(),
inline_config,
invalid_inline_config_items,
));

let (inline_config_items, invalid_inline_config_items): (Vec<_>, Vec<_>) =
comments.parse_inline_config_items().partition_result();
let inline_config = InlineConfig::new(inline_config_items, src);
let invalid_items_handler = validate(&to_parsed(
"./test/MyContract.handler.sol",
src,
pt,
comments,
inline_config,
Expand All @@ -333,5 +351,6 @@ impl ExpectedFindings {
assert_eq!(invalid_items_src.len(), self.src);
assert_eq!(invalid_items_test_helper.len(), self.test_helper);
assert_eq!(invalid_items_test.len(), self.test);
assert_eq!(invalid_items_handler.len(), self.handler);
}
}
7 changes: 5 additions & 2 deletions src/check/validators/error_prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ pub fn validate(parsed: &Parsed) -> Vec<InvalidItem> {
}

fn is_matching_file(file: &Path) -> bool {
file.is_file_kind(FileKind::Src) || file.is_file_kind(FileKind::Test)
file.is_file_kind(FileKind::Src) ||
file.is_file_kind(FileKind::Test) ||
file.is_file_kind(FileKind::Handler)
}

fn validate_name(
Expand Down Expand Up @@ -84,7 +86,8 @@ mod tests {
}
";

let expected_findings = ExpectedFindings { src: 2, test: 2, ..ExpectedFindings::default() };
let expected_findings =
ExpectedFindings { src: 2, test: 2, handler: 2, ..ExpectedFindings::default() };
expected_findings.assert_eq(content, &validate);
}
}
46 changes: 36 additions & 10 deletions src/check/validators/variable_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::path::Path;
fn is_matching_file(file: &Path) -> bool {
file.is_file_kind(FileKind::Src) ||
file.is_file_kind(FileKind::Test) ||
file.is_file_kind(FileKind::Handler) ||
file.is_file_kind(FileKind::Script)
}

Expand Down Expand Up @@ -230,8 +231,13 @@ mod tests {
}
";

let expected_findings =
ExpectedFindings { src: 1, test: 1, script: 1, ..ExpectedFindings::default() };
let expected_findings = ExpectedFindings {
src: 1,
test: 1,
handler: 1,
script: 1,
..ExpectedFindings::default()
};
expected_findings.assert_eq(content, &validate);
}

Expand All @@ -245,8 +251,13 @@ mod tests {
}
";

let expected_findings =
ExpectedFindings { src: 1, test: 1, script: 1, ..ExpectedFindings::default() };
let expected_findings = ExpectedFindings {
src: 1,
test: 1,
handler: 1,
script: 1,
..ExpectedFindings::default()
};
expected_findings.assert_eq(content, &validate);
}

Expand All @@ -260,8 +271,13 @@ mod tests {
}
";

let expected_findings =
ExpectedFindings { src: 2, test: 2, script: 2, ..ExpectedFindings::default() };
let expected_findings = ExpectedFindings {
src: 2,
test: 2,
handler: 2,
script: 2,
..ExpectedFindings::default()
};
expected_findings.assert_eq(content, &validate);
}

Expand All @@ -276,8 +292,13 @@ mod tests {
}
";

let expected_findings =
ExpectedFindings { src: 2, test: 2, script: 2, ..ExpectedFindings::default() };
let expected_findings = ExpectedFindings {
src: 2,
test: 2,
handler: 2,
script: 2,
..ExpectedFindings::default()
};
expected_findings.assert_eq(content, &validate);
}

Expand All @@ -291,8 +312,13 @@ mod tests {
}
";

let expected_findings =
ExpectedFindings { src: 1, test: 1, script: 1, ..ExpectedFindings::default() };
let expected_findings = ExpectedFindings {
src: 1,
test: 1,
handler: 1,
script: 1,
..ExpectedFindings::default()
};
expected_findings.assert_eq(content, &validate);
}
}
Loading