diff --git a/crates/oxc_linter/src/rules/eslint/no_octal_escape.rs b/crates/oxc_linter/src/rules/eslint/no_octal_escape.rs index 77ef996669869f..23269a9d00d6cc 100644 --- a/crates/oxc_linter/src/rules/eslint/no_octal_escape.rs +++ b/crates/oxc_linter/src/rules/eslint/no_octal_escape.rs @@ -1,11 +1,10 @@ +use crate::{context::LintContext, rule::Rule, AstNode}; +use lazy_static::lazy_static; use oxc_ast::AstKind; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_span::Span; use regex::Regex; -use std::sync::OnceLock; - -use crate::{context::LintContext, rule::Rule, AstNode}; fn no_octal_escape_diagnostic(span: Span, sequence: &str) -> OxcDiagnostic { OxcDiagnostic::warn(format!("Don't use octal: '\\{sequence}'. Use '\\u....' instead.")) @@ -45,7 +44,7 @@ impl Rule for NoOctalEscape { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { if let AstKind::StringLiteral(literal) = node.kind() { if let Some(raw) = &literal.raw { - if let Some(captures) = get_octal_escape_pattern().captures(raw) { + if let Some(captures) = CUSTOM_ERROR_REGEX_PATTERN.captures(raw) { if let Some(sequence) = captures.get(1) { ctx.diagnostic(no_octal_escape_diagnostic(literal.span, sequence.as_str())); } @@ -55,12 +54,9 @@ impl Rule for NoOctalEscape { } } -static OCTAL_ESCAPE_PATTERN: OnceLock = OnceLock::new(); - -fn get_octal_escape_pattern() -> &'static Regex { - OCTAL_ESCAPE_PATTERN.get_or_init(|| { - Regex::new(r"^(?:[^\\]|\\.)*?\\([0-3][0-7]{1,2}|[4-7][0-7]|(08|09)|[1-7])").unwrap() - }) +lazy_static! { + static ref CUSTOM_ERROR_REGEX_PATTERN: Regex = + Regex::new(r"^(?:[A-Z][\da-z]*)*Error$").unwrap(); } #[test]