eslint: wrap-iife doesn't catch .call / .apply. JSCS does
Tell us about your environment
- ESLint Version: 3.5.0
- Node Version: N/A
- npm Version: N/A
What parser (default, Babel-ESLint, etc.) are you using? Default
Please show your full configuration:
/* global window */
/* eslint wrap-iife: ["error", "inside"] */
window.foo = (function() { return 1; })();
window.bar = function() { return 3; }.call(this, arg1);
window.baz = function() { return d; }.apply(this, args);
The following passes. window.foo is fine because it is wrapped in parens, but the others don’t require it.
I’d expect that the functions that are called using .call and .apply should also be wrapped in parens. That is the behavior of the corresponding rule in JSCS and I’d like to keep that behavior while converting: http://jscs.info/rule/requireParenthesesAroundIIFE
Proposal
The current proposal is to add a new boolean option called functionPrototypeMethods that will lint call and apply using the same inside or outside value. For example:
/* eslint wrap-iife: [2, "outside", { functionPrototypeMethods: true }] */
(function(){ foo(); }()) // ok
(function(){ foo(); }.call(bar)) // ok
(function(){ foo(); }).call(bar) // error, expected parens to be outside but they were inside
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 3
- Comments: 21 (21 by maintainers)
Commits related to this issue
- Adding tests to cover #7212 — committed to TheSavior/eslint by TheSavior 8 years ago
- Update: Adding tests to cover #7212 — committed to TheSavior/eslint by TheSavior 8 years ago
@TheSavior This issue is accepted now, so feel free to start implementing this (assuming you’re still interested in doing so).
Updated the initial post with the current proposal