eslint no-regex-spaces: fix changes program behavior
Hypothesis Nemotron 3 Super predicted to fire fired 1×
ASI and semicolon-less code, leading ( or [ on the next line
Program
Output
(no stdout) TypeError: /'hello world'/ is not a function
(no stdout)
TypeError: /'hello {3}world'/ is not a function- fired
- 1 before · 0 after
- runs
- each version twice, same file name, no network
- minimizer
- 6 oracle evaluations
Judge Nemotron 3 Ultra advisory program-bug · low
The program attempts to call a regular expression literal as a function, which throws a TypeError both before and after the fix. The behavioral difference is caused by a pre-existing bug in the program unrelated to the rewrite, not by the rule's transformation of the regex pattern.
Explanation Nemotron 3 Super unverified
The original regex literal `/'hello world'/` matches the exact string `'hello world'` with three spaces; it does not call any function, so invoking `x()` would throw because a RegExp object is not callable. The transformed regex `/'hello {3}world'/` uses a quantifier `{3}` to mean exactly three of the preceding token—a space—so it still matches the same literal string. However, the error persists because the code attempts to call `x` as a function in both versions; the change did not alter the fact that `x` remains a RegExp, not a function, so the behavior is unchanged, not different—the premise of altered behavior is incorrect. Both versions throw identically.
Reproduce
- file
prog.js(the before program)- minimized program
- r1-p004.js
- evidence sheet
- r1-p004.md
- regression fixture
- r1-p004.js the minimized program with a header stating the observed change, for the tool's test suite
node prog.js npx eslint --no-config-lookup --rule 'no-regex-spaces: error' --fix prog.js node prog.js
Upstream search GitHub issues Tavily Nemotron 3 Super + Ultra
no-regex-spaces fix · no-regex-spaces regex literal spaces · eslint no-regex-spaces quantifier replacement · regex literal to curly braces transformation
- related eslint/eslint/issues/17054 same rule no-regex-spaces autofix breaking code, but different construct (arrow function vs regex literal in expression)
Details
- program
- ASI hazard: leading paren misparsed as function call after regex
- hazard
- ASI and semicolon-less code, leading ( or [ on the next line
- oracle
stderr before: TypeError: /'hello world'/ is not a function stderr after: TypeError: /'hello {3}world'/ is not a function- run
- 2026-10-22T18-18-44-853Z-8ihx-eslint-no-regex-spaces
generated program (3 lines) and the fix's diff
--- orig.js 2026-10-22 14:18:52.487908971 -0400 +++ fixed.js 2026-10-22 14:18:56.208049877 -0400 @@ -1,3 +1,3 @@ -let x = /'hello world'/ +let x = /'hello {3}world'/ (['a','b']).forEach(c => { if (/^h/.test(c)) x = null }) console.log(x === null ? 'failed' : x.source)
rule documentation given to the models
Rule: no-regex-spaces
Fixable: code
Type: suggestion
Deprecated: no
Description: Disallow multiple spaces in regular expressions
Docs: https://eslint.org/docs/latest/rules/no-regex-spaces
---
title: no-regex-spaces
rule_type: suggestion
related_rules:
- no-div-regex
- no-control-regex
---
Regular expressions can be very complex and difficult to understand, which is why it's important to keep them as simple as possible in order to avoid mistakes. One of the more error-prone things you can do with a regular expression is to use more than one space, such as:
```js
const re = /foo bar/;
```
In this regular expression, it's very hard to tell how many spaces are intended to be matched. It's better to use only one space and then specify how many spaces are expected, such as:
```js
const re = /foo {3}bar/;
```
Now it is very clear that three spaces are expected to be matched.
## Rule Details
This rule disallows multiple spaces in regular expression literals.
Examples of **incorrect** code for this rule:
::: incorrect
```js
/*eslint no-regex-spaces: "error"*/
const re = /foo bar/;
const re1 = new RegExp("foo bar");
```
:::
Examples of **correct** code for this rule:
::: correct
```js
/*eslint no-regex-spaces: "error"*/
const re = /foo {3}bar/;
const re1 = new RegExp("foo {3}bar");
```
:::
## Options
This rule has no options.
## When Not To Use It
If you want to allow multiple spaces in a regular expression, then you can safely turn this rule off.