Skip to content

Commit

Permalink
Revert "Revert to see benchmark"
Browse files Browse the repository at this point in the history
This reverts commit 213468e.
  • Loading branch information
leaysgur authored and Boshen committed Sep 7, 2024
1 parent c05b5be commit bd91c1a
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions crates/oxc_linter/src/rules/eslint/no_invalid_regexp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use oxc_allocator::Allocator;
use oxc_ast::{ast::Argument, AstKind};
use oxc_diagnostics::OxcDiagnostic;
use oxc_diagnostics::{LabeledSpan, OxcDiagnostic};
use oxc_macros::declare_oxc_lint;
use oxc_regular_expression::{FlagsParser, ParserOptions, PatternParser};
use oxc_span::Span;
Expand Down Expand Up @@ -81,17 +81,27 @@ impl Rule for NoInvalidRegexp {
// For compatibility with ESLint, we need to check "user-defined duplicated" flags here
// "valid duplicated" flags are also checked
let mut unique_flags = FxHashSet::default();
let mut violations = vec![];
for (idx, ch) in flags_text.char_indices() {
if !unique_flags.insert(ch) {
#[allow(clippy::cast_possible_truncation)]
let span_start = flags_span_start + idx as u32;
return ctx.diagnostic(
// Use the same prefix with `oxc_regular_expression`
OxcDiagnostic::warn("Invalid regular expression: Duplicated flag")
.with_label(Span::new(span_start, span_start)),
);
violations.push(idx);
}
}
if !violations.is_empty() {
return ctx.diagnostic(
// Use the same prefix with `oxc_regular_expression`
OxcDiagnostic::warn("Invalid regular expression: Duplicated flag").with_labels(
violations
.iter()
.map(|&start| {
#[allow(clippy::cast_possible_truncation)]
let start = flags_span_start + start as u32;
LabeledSpan::new_with_span(None, Span::new(start, start))
})
.collect::<Vec<_>>(),
),
);
}

// Omit user defined invalid flags
for flag in &self.0.allow_constructor_flags {
Expand Down

0 comments on commit bd91c1a

Please sign in to comment.