Skip to content

Commit

Permalink
Disallow specifying rule conditions multiple times (fixes #40)
Browse files Browse the repository at this point in the history
  • Loading branch information
AMDmi3 committed Feb 22, 2024
1 parent 6124404 commit 95b447e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,34 @@ fn parse_rule(
rule.title = title.to_string();
}
}
Rule::rule_directive_tags => rule.tags = parse_tags(item.into_inner().next().unwrap()),
Rule::rule_directive_tags => {
if !rule.tags.is_empty() {
panic!("tags specified multiple times");
}
rule.tags = parse_tags(item.into_inner().next().unwrap())
}
Rule::rule_directive_files => {
if rule.files.is_some() {
panic!("files condition specified multiple times");
}
rule.files = Some(parse_globs_condition(item.into_inner().next().unwrap()));
}
Rule::rule_directive_nofiles => {
if rule.nofiles.is_some() {
panic!("nofiles condition specified multiple times");
}
rule.nofiles = Some(parse_globs_condition(item.into_inner().next().unwrap()));
}
Rule::rule_directive_match => {
if rule.match_.is_some() {
panic!("match condition specified multiple times");
}
rule.match_ = Some(parse_regexes_condition(item.into_inner().next().unwrap()));
}
Rule::rule_directive_nomatch => {
if rule.nomatch.is_some() {
panic!("nomatch condition specified multiple times");
}
rule.nomatch = Some(parse_regexes_condition(item.into_inner().next().unwrap()));
}
_ => unreachable!("unexpected parser rule type in parse_rule {:#?}", item),
Expand Down
12 changes: 12 additions & 0 deletions tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@ mod stdout {
.assert_stdout_contains("a.py:2");
}
}

mod parsing {
use super::*;

#[test]
fn multiple_conditions() {
TestCase::new_for_stdout_tests()
.add_rule("files *.py\nfiles *.py")
.run()
.assert_failure();
}
}

0 comments on commit 95b447e

Please sign in to comment.