eslint-plugin-es5
eslint-plugin-es5 copied to clipboard
no-es6-methods a bit too strict
an innocent file like this:
var x
x.values()
Will fail eslint with this error:
ES6 methods not allowed: values es5/no-es6-methods
This is my .eslintrc
file:
{
"extends": [
"plugin:es5/no-es2015"
]
}
In short, I think there's no easy way to tell if x
(in the example above) is an array or something that really does have .values()
- so I propose that we drop these rules... WDYT?
I am having the same problem with .find
The following will fail even though we are using the jQuery API and not Array.find
.
var jqueryObject = $('.example').find('.child-element');
https://api.jquery.com/find/
I ended up just setting "es5/no-es6-methods": "warn",
I'm seeing the same thing for chained lodash methods
eg.
_.chain(
.get(arr)
.find('prop')
)
These are false positives.
This seems like a very difficult thing to detect with ESLint and seems like a type checker like Flow or TypeScript, since it would be hard to analyze the variable to scope to know if you're calling .find()
on a jQuery element or an array without the help of a type system.
I tried to introduce this rule into a large codebase using jQuery and had to disable it. I'm wondering if there should be an option to ignore certain function names (like .find()
), or maybe that's overkill? Thoughts?
I'm also experiencing the same issue, and ended up using the same solution that @bzmw recommended.
Same problem here with jQuery's find method on forms:
var form = jQuery('#myForm');
var val = form.find('#myfield').val();
Same as above.
One thing I started doing, which is far from perfect, is running something like grep '\.find(' *.js|grep -v '\$'
, which at least let's me find potential cases of non-jquery .find
after using the plugin. Most are likely to be variables (i.e., x.find(y)
where previously var x = $(y)
) but it's a quick sanity check.
While there's no simple and complete solution to this, in the case that brought me here, the ability to exempt specific methods would suffice, and would make a good addition to this plugin.
#36 (and thus v1.5.0) made this much better, especially if naming jQuery variables with $
.
https://github.com/nkt/eslint-plugin-es5/pull/39 adds an ability to skip methods that still don't work correctly. For example, in my project, there are a lot of jQuery variables with names without a $ sign and it could take a long time to fix and check thousands of lines (the previous PR doesn't fix it).
And, I've noticed that some es6 methods aren't banned.
I've added also the ability to add extra methods listed in MDN (Array methods, String methods ) to be highlighted by this plugin.