Support RegexBuilder
This commit is contained in:
parent
4f11f84dee
commit
51d166f17a
@ -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)*
|
||||
|
@ -104,6 +104,10 @@ impl LateLintPass for RegexPass {
|
||||
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) {
|
||||
|
@ -46,7 +46,9 @@ pub const RANGE_TO_INCLUSIVE: [&'static str; 3] = ["core", "ops", "RangeToInclus
|
||||
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"];
|
||||
|
@ -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 @@ const NOT_A_REAL_REGEX : &'static str = "foobar";
|
||||
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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user