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.

new cap: option capIsNewExceptionPattern is not behaving as documented

See original GitHub issue

Documentation for capIsNewExceptionPattern says the following:

allows any uppercase-started function names that match the specified regex pattern to be called without the new operator.

However, the actual behaviour seems to be that entire call expression is matched against the pattern, not just the function name.

Either capIsNewExceptionPattern should match only function name, or the documentation should reflect the actual behaviour.

I believe matching code with regex is fundamentally wrong and the first option is more sane solution. So, the documentation should stay as is, behaviour corrected and example updated, but that might be a breaking change.

Additionally, the example given as “correct code for this rule” is actually producing warnings (see demo), the reason being the regex configured does not match anything in the code at all.

Also other options of this rule may be poorly documented as well, for example capIsNewExceptions also states that it matches names, while actually it can match either name or full expression.

Tell us about your environment

Node version: v12.10.0 npm version: v6.10.3 Local ESLint version: v6.8.0 (Currently used) Global ESLint version: Not found

Also same result on whatever version is currently deployed as demo.

Please show your full configuration:

Demo links

Expected no warnings: https://eslint.org/demo#eyJ0ZXh0IjoiLyplc2xpbnQgbmV3LWNhcDogW1wiZXJyb3JcIiwgeyBcImNhcElzTmV3RXhjZXB0aW9uUGF0dGVyblwiOiBcIl5CYXIkXCIgfV0qL1xuXG5mb28uQmFyKCk7Iiwib3B0aW9ucyI6eyJwYXJzZXJPcHRpb25zIjp7ImVjbWFWZXJzaW9uIjoxMCwic291cmNlVHlwZSI6Im1vZHVsZSIsImVjbWFGZWF0dXJlcyI6e319LCJydWxlcyI6e30sImVudiI6e319fQ==

Not expected to ignore: https://eslint.org/demo#eyJ0ZXh0IjoiLyplc2xpbnQgbmV3LWNhcDogW1wiZXJyb3JcIiwgeyBcImNhcElzTmV3RXhjZXB0aW9uUGF0dGVyblwiOiBcIl5mb29cXC5CYXIkXCIgfV0qL1xuXG5mb28uQmFyKCk7Iiwib3B0aW9ucyI6eyJwYXJzZXJPcHRpb25zIjp7ImVjbWFWZXJzaW9uIjoxMCwic291cmNlVHlwZSI6Im1vZHVsZSIsImVjbWFGZWF0dXJlcyI6e319LCJydWxlcyI6e30sImVudiI6e319fQ==

Documentation example, wrong on several accounts: https://eslint.org/demo#eyJ0ZXh0IjoiLyplc2xpbnQgbmV3LWNhcDogW1wiZXJyb3JcIiwgeyBcImNhcElzTmV3RXhjZXB0aW9uUGF0dGVyblwiOiBcIl5QZXJzb25cXC4uXCIgfV0qL1xuXG52YXIgZnJpZW5kID0gcGVyc29uLkFjcXVhaW50YW5jZSgpO1xudmFyIGJlc3RGcmllbmQgPSBwZXJzb24uRnJpZW5kKCk7Iiwib3B0aW9ucyI6eyJwYXJzZXJPcHRpb25zIjp7ImVjbWFWZXJzaW9uIjoxMCwic291cmNlVHlwZSI6Im1vZHVsZSIsImVjbWFGZWF0dXJlcyI6e319LCJydWxlcyI6e30sImVudiI6e319fQ==

What did you do?

Configuration:

eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Bar$" }]

Code:

foo.Bar();

What did you expect to happen?

No warnings as function named Bar should be ignored.

What actually happened? Please include the actual, raw output from ESLint.

A warning against function Bar.

Are you willing to submit a pull request to fix this bug?

Only if it’s as trivial as pattern.test(calleeName), but then it’s probably trivial for anyone else as well.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Mar 12, 2020

I’m not sure if this issue has already been addressed but just not closed yet, but if not, may I tackle the issue of improving the documentation?

@jordanmoore753 there is no PR yet, and it doesn’t look like anyone is working on this at the moment, so feel free to claim this 😃

1reaction
mdjermanoviccommented, Feb 24, 2020

Of course, PR is welcome 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

new-cap - ESLint - Pluggable JavaScript Linter
"capIsNewExceptionPattern" allows any uppercase-started function names that match the specified regex pattern to be called without the new operator.
Read more >
ESLint: How to set "new-cap" rule's "capIsNewExceptions ...
I'm too lazy to check, but I assume that the rest of the array is passed to the rule itself as an options...
Read more >
Capped Option:Definition, How It Works, Benefits - Investopedia
A capped option limits, or caps, the maximum profit for the holder by automatically exercising when the underlying asset reaches a specified price....
Read more >
html menu and bootstrap infor deisplay panel (ed9f58ce) · 提交
`feature` - Issues asking for a new feature to be added, or an existing one to be ... "Core" is normally the right...
Read more >
initial commit · 03ea124eae - chronos - Forge de Cliss XXI
Option de Diff ... not dead. Chrome >= 45. Firefox >= 38. Edge >= 12. Explorer >= 10 ... All notable changes to...
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