Skip to content
← Back to rules

eslint/no-irregular-whitespace Correctness

✅ This rule is turned on by default.

What it does ​

Disallows the use of irregular whitespace characters in the code.

Why is this bad? ​

Irregular whitespace characters are invisible to most editors and can cause unexpected behavior, making code harder to debug and maintain. They can also cause issues with code formatting and parsing.

Examples ​

Examples of incorrect code for this rule:

javascript
// Contains irregular whitespace characters (invisible)
function example() {
  var foo = "bar"; // irregular whitespace before 'bar'
}

Examples of correct code for this rule:

javascript
function example() {
  var foo = "bar"; // regular spaces only
}

Configuration ​

This rule accepts a configuration object with the following properties:

skipComments ​

type: boolean

default: false

Whether to skip irregular whitespace in comments.

skipJSXText ​

type: boolean

default: true

Whether to skip irregular whitespace in JSX text.

skipRegExps ​

type: boolean

default: true

Whether to skip irregular whitespace in regular expression literals.

skipStrings ​

type: boolean

default: true

Whether to skip irregular whitespace in string literals.

skipTemplates ​

type: boolean

default: true

Whether to skip irregular whitespace in template literals.

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "no-irregular-whitespace": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "no-irregular-whitespace": "error",
  },
});
bash
oxlint --deny no-irregular-whitespace

Version ​

This rule was added in v0.1.1.

References ​