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

textrules Rename Rule -> SyntaxRule. #3

Closed
wants to merge 2 commits into from
Closed
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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ svlint plugin is a shared library. So crate-type of `Cargo.toml` must be `cdylib
crate-type = ["cdylib"]
```

All plugin must have `get_plugin` function to generate `Rule`.
All plugin must have `get_plugin` function to generate `SyntaxRule`.

```
#[no_mangle]
pub extern "C" fn get_plugin() -> *mut dyn Rule {
pub extern "C" fn get_plugin() -> *mut dyn SyntaxRule {
let boxed = Box::new(SamplePlugin {});
Box::into_raw(boxed)
}
```

The lint rule is defined as `Rule` trait.
The lint rule is defined as `SyntaxRule` trait.

```
pub struct SamplePlugin;

impl Rule for SamplePlugin {
fn check(&self, _syntax_tree: &SyntaxTree, node: &RefNode) -> RuleResult {
impl SyntaxRule for SamplePlugin {
fn check(&self, _syntax_tree: &SyntaxTree, node: &RefNode) -> SyntaxRuleResult {
match node {
RefNode::InitialConstruct(_) => RuleResult::Fail,
_ => RuleResult::Pass,
RefNode::InitialConstruct(_) => SyntaxRuleResult::Fail,
_ => SyntaxRuleResult::Pass,
}
}

Expand All @@ -49,7 +49,7 @@ impl Rule for SamplePlugin {
}
```

`Rule` must implement `check`, `name`, `hint` and `reason`.
`SyntaxRule` must implement `check`, `name`, `hint` and `reason`.

## Usage

Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
use sv_parser::{NodeEvent, RefNode, SyntaxTree};
use svlint::config::ConfigOption;
use svlint::linter::{Rule, RuleResult};
use svlint::linter::{SyntaxRule, SyntaxRuleResult};

#[no_mangle]
pub extern "C" fn get_plugin() -> *mut dyn Rule {
pub extern "C" fn get_plugin() -> *mut dyn SyntaxRule {
let boxed = Box::new(SamplePlugin {});
Box::into_raw(boxed)
}

pub struct SamplePlugin;

impl Rule for SamplePlugin {
impl SyntaxRule for SamplePlugin {
fn check(
&mut self,
_syntax_tree: &SyntaxTree,
event: &NodeEvent,
_config: &ConfigOption,
) -> RuleResult {
) -> SyntaxRuleResult {
match event {
NodeEvent::Enter(RefNode::InitialConstruct(_)) => RuleResult::Fail,
_ => RuleResult::Pass,
NodeEvent::Enter(RefNode::InitialConstruct(_)) => SyntaxRuleResult::Fail,
_ => SyntaxRuleResult::Pass,
}
}

Expand Down