question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[no-array-method-this-argument] Ignore usages with method references

See original GitHub issue

The no-array-method-this-argument is useful and makes sense, however in some cases I believe it should not warn. For example:

value.map(x.someMethod, x);

Imagine that someMethod uses this so it should be correct when invoking it.

The rule complains about this usage but 1) removing the thisArg is wrong and 2) changing the code to value.map(v => x.someMethod(v)) is uglier (and is not as “functional-style” as the other).

So I propose in this case the rule to not warn for such code - where a method reference is used as the first argument to map.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sindresorhuscommented, Jun 30, 2021

I’m not neutral on adding such option, but if added, it should be false by default.

0reactions
boris-petrovcommented, Jun 30, 2021

@sindresorhus - you’re right that it’s subjective. That’s why I prefer the other one. I’m also not sure about the performance - I could only guess that creating a bound function is slower than passing this explicitly.

Anyway, that’s my opinion and preference. An option to skip such cases where the first argument is a method reference (perhaps also a function name but I could argue that in that case a bind is better) would be nice. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Find Usages. Method Options | IntelliJ IDEA Documentation
This section describes the controls for specifying Method Usage Search ... search is performed for all references of the method by its name....
Read more >
Method References (The Java™ Tutorials > Learning the Java ...
Method References. You use lambda expressions to create anonymous methods. Sometimes, however, a lambda expression does nothing but call an existing method.
Read more >
Intellij - can be replaced with method reference - Stack Overflow
I get the following statement: "Non-static method cannot be referenced from a static context". Why Idea suggests me I should use method ......
Read more >
Java 8 Method Reference: How to Use it | Codementor
In Java, we can use references to objects, either by creating new ... So to use a method reference, you first need a...
Read more >
Method References in Java with examples - GeeksforGeeks
A code is more clear and short if one uses a lambda expression rather than using an anonymous class and one can use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found