-
-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule proposal: No this
argument in array methods when using arrow functions
#974
Comments
I've never seen anyone use this. |
I have seen it in the wild many times before, but I don't remember any specific place now. It's most likely to happen when you migrate from a function to arrow function. |
What do you think forbid use of I don't think it's useful. |
Do you mean to forbid |
Forbid 2nd argument in
call, It's never useful, why would someone use foo.map(function() {}, bar) instead of foo.map(function() {}.bind(bar)) or foo.map(() => use(this)) |
I agree. |
|
How about |
A more generic solution, enfore array method arguments length, takes a number or range. {
slice: [1], // At least one argument, forbid `.slice()` to copy array
reduce: 2, // Enfore inital value for `.reduce()`
map: 1, // For the example in the topic, forbid use this argument
concat: [0, 5], // Allow concat at most 5 arrays (just an example)
} This rule may not only work for array, we can also make it work for any method. For example: // eslint-xxx {"is": 2, "parserInt": 2}
Object.is(foo) // Fail, missing the second value to compare
parseInt(foo) // Fail, missing the radix |
I don't really see the use-case for this. I wouldn't use any of those.
There's already a built-in rule for this. |
Have you ever use Another case, I don't like |
Ok. Yeah, I can see how that could be useful. I'm just concerned that the general solution will have many more possible false-positives. |
Your proposal would have been ideal if we had type information, but as I commented earlier, I fear a generic solution would have a lot of false-positives. The rule proposed here is much more focused. I think they both could exist. |
@fisker Can you open a separate proposal for your idea about a generic arguments rule? |
This is now accepted. |
This triggers some false positive with React.Children, what is your recommendation for this? Should I try to fix the code enforcing the rule? Should I disable the rule each time I use |
Prevent specifying the
this
argument to array methods when using an arrow function, since it has no effect.Applies to the following instance methods:
And also
Array.from
.Only
Array.from
can be safely auto-fixed. The others should use suggestions.Fail
Pass
The text was updated successfully, but these errors were encountered: