question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Detected not working optional chaining on global variables / optional DOM APIs

See original GitHub issue

Please describe what the rule should do:

eslint should warn me that a browser (without a secure context) can throw and the optional chaining will not save the day:

// Throws an exception in runtime with insecure origin
> caches?.has('anything');
VM262:1 Uncaught ReferenceError: caches is not defined

// Runs without exception in runtime (with secure and insecure origin)
window.caches?.has('anything');

What new ECMAScript feature does this rule relate to? Same for all new APIs which are on the global object.

What category of rule is this? (place an “X” next to just one item)

[x] Warns about a potential error (problem)

Why should this rule be included in ESLint (instead of a plugin)? I dont know. Are you willing to submit a pull request to implement this rule? No, sorry.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
nzakascommented, Aug 28, 2021

We aren’t moving forward with this, so closing.

0reactions
nzakascommented, Mar 23, 2021

Gotcha. I’m not sold on the need for this being a core rule, though. It doesn’t really seem to rise to the level of must-have for us.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optional chaining (?.) - JavaScript - MDN Web Docs - Mozilla
The optional chaining ( ?. ) operator accesses an object's property or calls a function. If the object accessed or function called is ......
Read more >
Optional chaining '?.' - The Modern JavaScript Tutorial
The optional chaining ?. is a safe way to access nested object properties, even if an intermediate property doesn't exist.
Read more >
Documentation - TypeScript 3.7
Optional chaining is issue #16 on our issue tracker. For context, there have been over 23,000 issues on the TypeScript issue tracker since...
Read more >
How To Enable Optional Chaining Within Your Javascript ...
The best way to describe optional chaining is to show a useful problem that it solves, dealing with JSON returned from an external...
Read more >
Optional chaining, but for a variable? [duplicate] - Stack Overflow
Is it possible to do something where it prints undefined or something if the variable is not there instead of throwing an error?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found