Skip to content

Commit

Permalink
bugfix257 Change textrules API to pass line: Option<&str>.
Browse files Browse the repository at this point in the history
- Same issue as <dalance/svlint#257>
- Matches <dalance/svlint#261>.
  • Loading branch information
DaveMcEwan committed Jul 3, 2023
1 parent 3b1d72d commit a1bb2e3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ crate-type = ["cdylib"]

[dependencies]
#svlint = { path = "../svlint" }
svlint = "0.8.0"
#svlint = "0.8.0" TODO: Update svlint dependency pin before PR review.
svlint = { git = "https://github.com/DaveMcEwan/svlint.git", rev = "7a4f5eb" }
sv-parser = "0.13.1"
regex = "1" # Only used for the rule "forbidden_regex".
8 changes: 7 additions & 1 deletion src/forbidden_regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ pub struct ForbiddenRegex {
impl TextRule for ForbiddenRegex {
fn check(
&mut self,
line: &str,
line: Option<&str>,
_option: &ConfigOption,
) -> TextRuleResult {
let line: &str = if line.is_none() {
return TextRuleResult::Pass;
} else {
line.unwrap()
};

if self.re.is_none() {
let r = format!(r"XXX");
self.re = Some(Regex::new(&r).unwrap());
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ mod tests {

let mut pass = true;

// Signal beginning of file to all TextRules.
// None *may* be used by rules to reset their internal state.
let _ = linter.textrules_check(None, &sv, &0);

// Iterate over lines in the file, applying each textrule to each
// line in turn.
let text: String = read_to_string(&sv).unwrap();
let mut beg: usize = 0;
for line in text.lines() {
for _failed in linter.textrules_check(&line, &sv, &beg) {
for _failed in linter.textrules_check(Some(&line), &sv, &beg) {
pass = false;
}

Expand Down

0 comments on commit a1bb2e3

Please sign in to comment.