Skip to content

oxc/no-optional-chaining Restriction

What it does

Disallow optional chaining.

Example

javascript
const foo = obj?.foo;
obj.fn?.();

Options

json
{
  "rules": {
    "no-optional-chaining": [
        "error",
        {
            "message": "Our output target is ES2016, and optional chaining results in verbose
            helpers and should be avoided.",
        }
    ]
  }
}
  • message: A custom help message to display when optional chaining is found.

How to use

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

bash
oxlint --deny oxc/no-optional-chaining
json
{
  "rules": {
    "oxc/no-optional-chaining": "error"
  }
}

References

Released under the MIT License.