mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
33 lines
976 B
Rust
33 lines
976 B
Rust
#[allow(clippy::wildcard_imports)]
|
|
use oxc_ast::{ast::*, AstKind, Span};
|
|
use oxc_diagnostics::{
|
|
miette::{self, Diagnostic},
|
|
thiserror::Error,
|
|
};
|
|
|
|
use crate::{context::LintContext, rule::Rule, AstNode};
|
|
|
|
#[derive(Debug, Default, Clone)]
|
|
pub struct EarlyErrorJavaScript;
|
|
|
|
impl Rule for EarlyErrorJavaScript {
|
|
#[allow(clippy::single_match)]
|
|
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
|
match node.get().kind() {
|
|
AstKind::RegExpLiteral(lit) => check_regexp_literal(lit, ctx),
|
|
_ => {}
|
|
}
|
|
}
|
|
}
|
|
|
|
fn check_regexp_literal(lit: &RegExpLiteral, ctx: &LintContext) {
|
|
#[derive(Debug, Error, Diagnostic)]
|
|
#[error("The 'u' and 'v' regular expression flags cannot be enabled at the same time")]
|
|
#[diagnostic()]
|
|
struct RegExpFlagUAndV(#[label] Span);
|
|
|
|
let flags = lit.regex.flags;
|
|
if flags.contains(RegExpFlags::U | RegExpFlags::V) {
|
|
ctx.diagnostic(RegExpFlagUAndV(lit.span));
|
|
}
|
|
}
|