eslint-plugin-compat
eslint-plugin-compat copied to clipboard
No warning on unsupported methods missing object name
It looks like the plugin can't identify the unsupported use of a method call that doesn't include the class name:
'string'.repeat(5); // false negative
new String().repeat(5); // ! ESLint: String.repeat() is not supported in IE 11 (compat/compat)
In this case the first use of repeat() is not flagged as incompatible with IE, while the second one is. Is there a way to flag any use of incompatible methods on string literals?
EDIT: changed the above to reflect the much clearer rewrite by @HansBrende in the comment below. Original:
~~It looks like the plugin can't identify the unsupported use of a method call that doesn't include the object name:~~

~~In this case the first use of repeat() is not flagged as incompatible with IE, while the second one is. Is there a way to flag any use of incompatible methods?~~
Same here...someone at my team used the es2021's replaceAll() method and there was no warning thrown from ESLint, the code ended up in production and disaster happened...
Moreover, i have just tried that String.repeat(5) here and i am not even getting a warning, nothing, which is very odd...using latest public releases of every npm package at time of writing. 🤔
May i ask what's your config @gabriele-cannizzaro ? Here's my browserlist and config
Same with @diegocr in production. So sad.
String.repeat is not a thing that exists, so it would be just as weird for something to lint against it as to lint against String.yogurt.
Sorry @ljharb, I might have misunderstood your comment, but what do you mean by "String.repeat is not a thing that exists"?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
@gabriele-cannizzaro hmm, I'm gonna go out on a limb here and guess that by "String.repeat is not a thing that exists", he means "String.repeat is not a thing that exists".

@ljharb for clarity, let's pretend OP said:
It looks like the plugin can't identify the unsupported use of a method call that doesn't include the class name:
'string'.repeat(5); // false negative
new String().repeat(5); // ! ESLint: String.repeat() is not supported in IE 11(compat/compat)
In this case the first use of repeat() is not flagged as incompatible with IE, while the second one is. Is there a way to flag any use of incompatible methods on string literals?
Now the issue at hand is clear.
@HansBrende thank you for the rewrite, that makes it indeed much clearer. Re-reading my original post and the thread I was obviously confusing things :-)