Skip to content

Commit 51d166f

Browse files
committed
Support RegexBuilder
1 parent 4f11f84 commit 51d166f

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
All notable changes to this project will be documented in this file.
33

44
## 0.0.70 — TBD
5-
* [`invalid_regex`] and [`trivial_regex`] can now warn on `RegexSet::new` and
6-
byte regexes
5+
* [`invalid_regex`] and [`trivial_regex`] can now warn on `RegexSet::new`,
6+
`RegexBuilder::new` and byte regexes
77

88
## 0.0.69 — 2016-05-20
99
* Rustup to *rustc 1.10.0-nightly (476fe6eef 2016-05-21)*

src/regex.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ impl LateLintPass for RegexPass {
104104
check_regex(cx, &args[0], true);
105105
} else if match_def_path(cx, def_id, &paths::REGEX_BYTES_NEW) {
106106
check_regex(cx, &args[0], false);
107+
} else if match_def_path(cx, def_id, &paths::REGEX_BUILDER_NEW) {
108+
check_regex(cx, &args[0], true);
109+
} else if match_def_path(cx, def_id, &paths::REGEX_BYTES_BUILDER_NEW) {
110+
check_regex(cx, &args[0], false);
107111
} else if match_def_path(cx, def_id, &paths::REGEX_SET_NEW) {
108112
check_set(cx, &args[0], true);
109113
} else if match_def_path(cx, def_id, &paths::REGEX_BYTES_SET_NEW) {

src/utils/paths.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ pub const RANGE_TO_INCLUSIVE: [&'static str; 3] = ["core", "ops", "RangeToInclus
4646
pub const RANGE_TO_INCLUSIVE_STD: [&'static str; 3] = ["std", "ops", "RangeToInclusive"];
4747
pub const RANGE_TO_STD: [&'static str; 3] = ["std", "ops", "RangeTo"];
4848
pub const REGEX: [&'static str; 3] = ["regex", "re_unicode", "Regex"];
49+
pub const REGEX_BUILDER_NEW: [&'static str; 5] = ["regex", "re_builder", "unicode", "RegexBuilder", "new"];
4950
pub const REGEX_BYTES: [&'static str; 3] = ["regex", "re_bytes", "Regex"];
51+
pub const REGEX_BYTES_BUILDER_NEW: [&'static str; 5] = ["regex", "re_builder", "bytes", "RegexBuilder", "new"];
5052
pub const REGEX_BYTES_NEW: [&'static str; 4] = ["regex", "re_bytes", "Regex", "new"];
5153
pub const REGEX_BYTES_SET_NEW: [&'static str; 5] = ["regex", "re_set", "bytes", "RegexSet", "new"];
5254
pub const REGEX_NEW: [&'static str; 4] = ["regex", "re_unicode", "Regex", "new"];

tests/compile-fail/regex.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66

77
extern crate regex;
88

9-
use regex::{Regex, RegexSet};
10-
use regex::bytes::{Regex as BRegex, RegexSet as BRegexSet};
9+
use regex::{Regex, RegexSet, RegexBuilder};
10+
use regex::bytes::{Regex as BRegex, RegexSet as BRegexSet, RegexBuilder as BRegexBuilder};
1111

1212
const OPENING_PAREN : &'static str = "(";
1313
const NOT_A_REAL_REGEX : &'static str = "foobar";
1414

1515
fn syntax_error() {
1616
let pipe_in_wrong_position = Regex::new("|");
1717
//~^ERROR: regex syntax error: empty alternate
18+
let pipe_in_wrong_position_builder = RegexBuilder::new("|");
19+
//~^ERROR: regex syntax error: empty alternate
1820
let wrong_char_ranice = Regex::new("[z-a]");
1921
//~^ERROR: regex syntax error: invalid character class range
2022
let some_unicode = Regex::new("[é-è]");
@@ -27,6 +29,8 @@ fn syntax_error() {
2729
//~^ERROR: regex syntax error: empty alternate
2830
let some_binary_regex = BRegex::new(OPENING_PAREN);
2931
//~^ERROR: regex syntax error on position 0: unclosed
32+
let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN);
33+
//~^ERROR: regex syntax error on position 0: unclosed
3034

3135
let closing_paren = ")";
3236
let not_linted = Regex::new(closing_paren);
@@ -57,6 +61,10 @@ fn trivial_regex() {
5761
//~^ERROR: trivial regex
5862
//~|HELP consider using `==` on `str`s
5963

64+
let trivial_eq_builder = RegexBuilder::new("^foobar$");
65+
//~^ERROR: trivial regex
66+
//~|HELP consider using `==` on `str`s
67+
6068
let trivial_starts_with = Regex::new("^foobar");
6169
//~^ERROR: trivial regex
6270
//~|HELP consider using `str::starts_with`
@@ -96,11 +104,13 @@ fn trivial_regex() {
96104

97105
// non-trivial regexes
98106
let non_trivial_dot = Regex::new("a.b");
107+
let non_trivial_dot_builder = RegexBuilder::new("a.b");
99108
let non_trivial_eq = Regex::new("^foo|bar$");
100109
let non_trivial_starts_with = Regex::new("^foo|bar");
101110
let non_trivial_ends_with = Regex::new("^foo|bar");
102111
let non_trivial_ends_with = Regex::new("foo|bar");
103112
let non_trivial_binary = BRegex::new("foo|bar");
113+
let non_trivial_binary_builder = BRegexBuilder::new("foo|bar");
104114
}
105115

106116
fn main() {

0 commit comments

Comments
 (0)