Skip to content

💅 false positive detection on lint/complexity/noUselessEscapeInRegex in 2.0.0-beta.6 #6201

@flumm

Description

@flumm

Environment information

CLI:                                                           
  Version:                      2.0.0-beta.6                   
  Color support:                true                           
                                                               
Platform:                                                      
  CPU Architecture:             x86_64                         
  OS:                           linux                          
                                                               
Environment:                                                   
  BIOME_LOG_PATH:               unset                          
  BIOME_LOG_PREFIX_NAME:        unset                          
  BIOME_CONFIG_PATH:            unset                          
  BIOME_THREADS:                unset                          
  NO_COLOR:                     unset                          
  TERM:                         screen-256color                
  JS_RUNTIME_VERSION:           unset                          
  JS_RUNTIME_NAME:              unset                          
  NODE_PACKAGE_MANAGER:         unset                          
                                                               
Biome Configuration:                                           
  Status:                       Loaded successfully            
  Path:                         /home/dcsapak/git/biome.json   
  Formatter enabled:            true                           
  Linter enabled:               true                           
  Assist enabled:               true                           
  VCS enabled:                  false                          
                                                               
Workspace:                                                     
  Open Documents:               0                              

Rule name

noUselessEscapeInRegex

Playground link

https://next.biomejs.dev/playground/?indentStyle=space&indentWidth=4&lintRules=all&code=YwBvAG4AcwB0ACAAcgBlAGcAZQB4ACAAPQAgAC8AXgBbAFwAXAAtAF0AKwAkAC8AOwAKAAoAIgBcAFwAIgAuAG0AYQB0AGMAaAAoAHIAZQBnAGUAeAApADsA&language=js

Expected result

The following code produces a false positive:

const regex = /^[\\-]+$/;

it believes the '-' is escaped, while actually the \ is escaped.
The safe fix, removes both backslashes, which results in wrong code

it should not falsely detect the escape for '-'

Code of Conduct

  • I agree to follow Biome's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LinterArea: linterL-JavaScriptLanguage: JavaScript and super languagesS-Bug-confirmedStatus: report has been confirmed as a valid bug

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions