eslint-plugin-compat icon indicating copy to clipboard operation
eslint-plugin-compat copied to clipboard

No warning on unsupported methods missing object name

Open gabriele-cannizzaro opened this issue 5 years ago • 7 comments

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:~~

image

~~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?~~

gabriele-cannizzaro avatar Aug 23 '20 13:08 gabriele-cannizzaro

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

diegocr avatar Nov 11 '20 13:11 diegocr

Same with @diegocr in production. So sad.

yoyo837 avatar May 04 '21 05:05 yoyo837

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.

ljharb avatar May 04 '21 05:05 ljharb

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 avatar May 10 '21 09:05 gabriele-cannizzaro

@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". Screen Shot 2022-01-11 at 7 06 42 AM

HansBrende avatar Jan 11 '22 13:01 HansBrende

@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 avatar Jan 11 '22 14:01 HansBrende

@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 :-)

gabriele-cannizzaro avatar Feb 07 '22 17:02 gabriele-cannizzaro