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.

Rule proposal: `no-unused-return-value`

See original GitHub issue

Please describe what the rule should do:

Detect unused return values of built-in object methods where it never makes sense not to use the return value.

What category of rule is this? (place an “X” next to just one item)

[x] Suggests an alternate way of doing something (suggestion)

Provide 2-3 code examples that this rule will warn about:

const arr = [{name: 'eslint'}];
arr.map(item => item.name); // error: Unused Array.prototype.map return value
const arr = [{name: 'eslint'}];
arr.filter(item => item.name === 'eslint'); // error: Unused Array.prototype.filter return value
let i = 0;
const arr = [1,2,3];
arr.map((item) => {  // error: Unused Array.prototype.map return value
  i += 1;
});
Object.create(null); // error: Unused Object.create return value

Why should this rule be included in ESLint (instead of a plugin)?

It is useful to anyone using built-in JS objects and especially for iteration methods that return a value like Array.prototype.map . If its return value is unused, it would be better to refactor such cases to Array.prototype.forEach to make the intend clear.

I could see the rule being especially useful to beginners who might not have memorized yet that Array.prototype.filter or Array.prototype.map do not modify the array.

The concept can be applied to any built-in static or prototype method that either returns a value or does iteration only. It can be extended to other built-ins like String, Number, Map, Set and more.

For Array and Object, I see these suitable methods:

Array.isArray
Array.of
Array.prototype.concat
Array.prototype.filter
Array.prototype.includes
Array.prototype.indexOf
Array.prototype.join
Array.prototype.lastIndexOf
Array.prototype.slice
Array.prototype.toSource
Array.prototype.toString
Array.prototype.toLocaleString
Array.prototype.entries
Array.prototype.every
Array.prototype.find
Array.prototype.findIndex
Array.prototype.keys
Array.prototype.map
Array.prototype.some
Array.prototype.values

Object.create
Object.entries
Object.fromEntries
Object.getOwnPropertyDescriptor
Object.getOwnPropertyDescriptors
Object.getOwnPropertyNames
Object.getOwnPropertySymbols
Object.getPrototypeOf
Object.is
Object.isExtensible
Object.isFrozen
Object.isSealed
Object.keys
Object.values
Object.prototype.hasOwnProperty
Object.prototype.isPrototypeOf
Object.prototype.propertyIsEnumerable
Object.prototype.toLocaleString
Object.prototype.toString

Related previous discussion: https://github.com/eslint/eslint/issues/12269

Are you willing to submit a pull request to implement this rule?

No

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
ljharbcommented, Mar 1, 2020

Array.from(iterableOrArraylike, forEachFunction)

0reactions
eslint-deprecated[bot]commented, Apr 4, 2020

Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expressions of Quantity: Special Cases of Subject-Verb ...
Subject-verb agreement is generally quite straightforward in English. ... take plural verbs when they are used as indefinite quantifiers (see rule 1 above):....
Read more >
spec: require return values to be explicitly used or ignored (Go ...
I propose that Go should reject unused return-values by default. If we do so, we may also want to consider an ignore built-in...
Read more >
Grammar: Main Parts of Speech - Academic Guides
Noun. The name of something, like a person, animal, place, thing, or concept. Nouns are typically used as subjects, objects, objects of prepositions, ......
Read more >
Propositional Logic | Internet Encyclopedia of Philosophy
The term proposition is sometimes used synonymously with statement. However, it is sometimes used to name something abstract that two different statements with ......
Read more >
How to Write Doc Comments for the Javadoc Tool - Oracle
However, if the Javadoc tool is being used to generate documentation for a particular ... Whenever possible, supply return values for special cases...
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