Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use updated textrules API with TextRulesEvent #8

Merged
merged 3 commits into from
Oct 13, 2023
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ crate-type = ["cdylib"]

[dependencies]
#svlint = { path = "../svlint" }
svlint = "0.8.0"
svlint = "0.9.0"
sv-parser = "0.13.1"
regex = "1" # Only used for the rule "forbidden_regex".
11 changes: 9 additions & 2 deletions src/forbidden_regex.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use svlint::config::ConfigOption;
use svlint::linter::{TextRule, TextRuleResult};
use svlint::linter::{TextRule, TextRuleEvent, TextRuleResult};
use regex::Regex;

#[derive(Default)]
Expand All @@ -10,9 +10,16 @@ pub struct ForbiddenRegex {
impl TextRule for ForbiddenRegex {
fn check(
&mut self,
line: &str,
event: TextRuleEvent,
_option: &ConfigOption,
) -> TextRuleResult {
let line: &str = match event {
TextRuleEvent::StartOfFile => {
return TextRuleResult::Pass;
}
TextRuleEvent::Line(x) => x,
};

if self.re.is_none() {
let r = format!(r"XXX");
self.re = Some(Regex::new(&r).unwrap());
Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod tests {
use std::fs::read_to_string;
use std::path::{Path, PathBuf};
use svlint::config::Config;
use svlint::linter::Linter;
use svlint::linter::{Linter, TextRuleEvent};
use sv_parser::parse_sv_str;

fn so_path() -> String {
Expand Down Expand Up @@ -77,12 +77,16 @@ mod tests {

let mut pass = true;

// Signal beginning of file to all TextRules, which *may* be used
// by textrules to reset their internal state.
let _ = linter.textrules_check(TextRuleEvent::StartOfFile, &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(TextRuleEvent::Line(&line), &sv, &beg) {
pass = false;
}

Expand Down