oxc/no-optional-chaining Restriction
What it does
Disallow optional chaining.
Why is this bad?
Optional chaining is a relatively new JavaScript feature that may not be supported in older environments. In some cases, transpiling optional chaining can result in verbose helper code that impacts bundle size or performance. This rule is useful when you need to maintain compatibility with older JavaScript targets or want to avoid the overhead of transpiled optional chaining.
Examples
Examples of incorrect code for this rule:
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"
}
}