]> git.lizzy.rs Git - rust.git/commitdiff
Support `RegexBuilder`
authormcarton <cartonmartin+git@gmail.com>
Wed, 25 May 2016 19:36:51 +0000 (21:36 +0200)
committermcarton <cartonmartin+git@gmail.com>
Wed, 25 May 2016 19:36:51 +0000 (21:36 +0200)
CHANGELOG.md
src/regex.rs
src/utils/paths.rs
tests/compile-fail/regex.rs

index f17b1dd083748583940844a1378d613ea8ce579d..928fac7412e9d9107ea0280d0c4b7309c8de93e3 100644 (file)
@@ -2,8 +2,8 @@
 All notable changes to this project will be documented in this file.
 
 ## 0.0.70 — TBD
-* [`invalid_regex`] and [`trivial_regex`] can now warn on `RegexSet::new` and
-  byte regexes
+* [`invalid_regex`] and [`trivial_regex`] can now warn on `RegexSet::new`,
+  `RegexBuilder::new` and byte regexes
 
 ## 0.0.69 — 2016-05-20
 * Rustup to *rustc 1.10.0-nightly (476fe6eef 2016-05-21)*
index 8876a649e5d9d403d5124132e83a14d2f279f0ce..b335bf993b5fc34fd8b947a4fc424bbb196d0b56 100644 (file)
@@ -104,6 +104,10 @@ fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
                 check_regex(cx, &args[0], true);
             } else if match_def_path(cx, def_id, &paths::REGEX_BYTES_NEW) {
                 check_regex(cx, &args[0], false);
+            } else if match_def_path(cx, def_id, &paths::REGEX_BUILDER_NEW) {
+                check_regex(cx, &args[0], true);
+            } else if match_def_path(cx, def_id, &paths::REGEX_BYTES_BUILDER_NEW) {
+                check_regex(cx, &args[0], false);
             } else if match_def_path(cx, def_id, &paths::REGEX_SET_NEW) {
                 check_set(cx, &args[0], true);
             } else if match_def_path(cx, def_id, &paths::REGEX_BYTES_SET_NEW) {
index b0ce8b4a2339881c532fbc25d0024bfcf4091d04..3c91578abd091b1d84c3fb7b7446005fea5d8e1d 100644 (file)
@@ -46,7 +46,9 @@
 pub const RANGE_TO_INCLUSIVE_STD: [&'static str; 3] = ["std", "ops", "RangeToInclusive"];
 pub const RANGE_TO_STD: [&'static str; 3] = ["std", "ops", "RangeTo"];
 pub const REGEX: [&'static str; 3] = ["regex", "re_unicode", "Regex"];
+pub const REGEX_BUILDER_NEW: [&'static str; 5] = ["regex", "re_builder", "unicode", "RegexBuilder", "new"];
 pub const REGEX_BYTES: [&'static str; 3] = ["regex", "re_bytes", "Regex"];
+pub const REGEX_BYTES_BUILDER_NEW: [&'static str; 5] = ["regex", "re_builder", "bytes", "RegexBuilder", "new"];
 pub const REGEX_BYTES_NEW: [&'static str; 4] = ["regex", "re_bytes", "Regex", "new"];
 pub const REGEX_BYTES_SET_NEW: [&'static str; 5] = ["regex", "re_set", "bytes", "RegexSet", "new"];
 pub const REGEX_NEW: [&'static str; 4] = ["regex", "re_unicode", "Regex", "new"];
index d9f262fb045a0639f169108fcb1d692b5eefe3ca..d6287b881a19334222210dc43fefedc078db0a2c 100644 (file)
@@ -6,8 +6,8 @@
 
 extern crate regex;
 
-use regex::{Regex, RegexSet};
-use regex::bytes::{Regex as BRegex, RegexSet as BRegexSet};
+use regex::{Regex, RegexSet, RegexBuilder};
+use regex::bytes::{Regex as BRegex, RegexSet as BRegexSet, RegexBuilder as BRegexBuilder};
 
 const OPENING_PAREN : &'static str = "(";
 const NOT_A_REAL_REGEX : &'static str = "foobar";
@@ -15,6 +15,8 @@
 fn syntax_error() {
     let pipe_in_wrong_position = Regex::new("|");
     //~^ERROR: regex syntax error: empty alternate
+    let pipe_in_wrong_position_builder = RegexBuilder::new("|");
+    //~^ERROR: regex syntax error: empty alternate
     let wrong_char_ranice = Regex::new("[z-a]");
     //~^ERROR: regex syntax error: invalid character class range
     let some_unicode = Regex::new("[é-è]");
@@ -27,6 +29,8 @@ fn syntax_error() {
     //~^ERROR: regex syntax error: empty alternate
     let some_binary_regex = BRegex::new(OPENING_PAREN);
     //~^ERROR: regex syntax error on position 0: unclosed
+    let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN);
+    //~^ERROR: regex syntax error on position 0: unclosed
 
     let closing_paren = ")";
     let not_linted = Regex::new(closing_paren);
@@ -57,6 +61,10 @@ fn trivial_regex() {
     //~^ERROR: trivial regex
     //~|HELP consider using `==` on `str`s
 
+    let trivial_eq_builder = RegexBuilder::new("^foobar$");
+    //~^ERROR: trivial regex
+    //~|HELP consider using `==` on `str`s
+
     let trivial_starts_with = Regex::new("^foobar");
     //~^ERROR: trivial regex
     //~|HELP consider using `str::starts_with`
@@ -96,11 +104,13 @@ fn trivial_regex() {
 
     // non-trivial regexes
     let non_trivial_dot = Regex::new("a.b");
+    let non_trivial_dot_builder = RegexBuilder::new("a.b");
     let non_trivial_eq = Regex::new("^foo|bar$");
     let non_trivial_starts_with = Regex::new("^foo|bar");
     let non_trivial_ends_with = Regex::new("^foo|bar");
     let non_trivial_ends_with = Regex::new("foo|bar");
     let non_trivial_binary = BRegex::new("foo|bar");
+    let non_trivial_binary_builder = BRegexBuilder::new("foo|bar");
 }
 
 fn main() {