8000 Add a rule which disallows calling a non-void/non-never function without using its return value · Issue #1314 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content
Add a rule which disallows calling a non-void/non-never function without using its return value #1314
Closed
@dko-slapdash

Description

@dko-slapdash

In C++/gcc, there is a useful attribute which can be assigned to a function, and then swallowing the returned value of this function will be considered as an error: __attribute__((warn_unused_result)).

Is there something like that for eslint/typescript?

What code were you trying to parse?

// eslint-enable-next-line @typescript-eslint/no_unused_result <-- ???
function f() {
  return 10;
}

f();

What did you expect to happen?

It should warn that the function's return value is not consumed and is swallowed. There is also no eslint-enable-next-line (but maybe there is something instead?).

What actually happened?

Nothing, I couldn't find such a rule. Surprisingly, no-unused-expressions doesn't help here, it doesn't process function returns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0