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.

Add eslint `must-use` flag.

See original GitHub issue

While reading through the docs of Rust’s Result type, I learned that they annotate Result with a compiler attribute that enforces a user to “do something” with the result.

It might be nice to introduce an eslint rule that does this for neverthrow.

It would prevent situations like this:

const doSomethingThatMayFail = async () => {
  await changeUserPassword() // Returns a `Result<null, DbError>`
}

Note that we haven’t checked to see if changeUserPassword actually succeeded.


Edit:

Learning Resources:

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:20 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
mdbetancourtcommented, Nov 11, 2021

publish eslint-plugin-neverthrow to npm

@supermacro is already published since yesterday, the reported issue was a misconfiguration in the package.json file

I will try out the plugin in our Caribou codebase and test that things are good (hopefully no more tweaks and changes)

perfect i hope hear good news from you soon

send over a well-deserved bounty 😃

thank you 😃 I wrote you on twitter, when you finished we can talk about the payment there

1reaction
mdbetancourtcommented, Oct 27, 2021

The eslint-rule must work similarly to how it works in Rust (details here). Basically, the developer must ensure that the Result is not an Err variant, or explicitly do something with an Err variant … you can see examples in the linked Rust document.

Yup i get the idea of create the lib and build the eslint plugin from rust 😃

  • call the .match method
  • call the .unwrapOr method
  • call the ._unsafeUnwrap method

so as long as any of these methods is called eslint should be happy?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started with ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Basic Features: ESLint - Next.js
If you include any ESLint rules that depend on more than the contents of a single source file and need to disable the...
Read more >
Enabling the fix flag for stdio · Issue #9076 · eslint/eslint - GitHub
Add a new flag like --fix-dry-run that can be used with --stdin ... and the fixed output at the same time, I'd need...
Read more >
Grunt-eslint & enabling `--fix` flag to auto fix violations
For the --fix flag, you only have to add an options: { fix: true } to your gruntfile. Here is an example of...
Read more >
How To Lint and Format Code with ESLint in Visual Studio Code
It's important to include the --save-dev flag because this saves the package as a dependency for development usage only. In this case, eslint...
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