mdbetancourt / eslint-plugin-neverthrow

MIT License
44 stars 4 forks source link

Allow _unsafeUnwrapErr #12

Closed yageb-ikea closed 1 year ago

yageb-ikea commented 1 year ago

This change will allow _unsafeUnwrapErr to be a valid way of consuming the result. The rule already allows _unsafeUnwrap.

This change is needed because currently there is no simple way to assert an error message in a unit test for example. When using _unsafeUnwrapErr, the linter shows this message:

Result must be handled with either of match, unwrapOr or _unsafeUnwrap. eslint:neverthrow/must-use-result

To avoid this, I had to do this in unit tests:

let error: Error = new Error();
result.match(
  () => {},
  (e) => {
     error = e;
});
expect(error.message).toBe("The object is missing");

Which is a lot of boilerplate for a small assertion.

Using _unsafeUnwrap will obviously not work with an Err.

Other changes:

yageb-ikea commented 1 year ago

@mdbetancourt Please take a look at this change 😃

yageb-ikea commented 1 year ago

On a second thought, I don't think it is needed right now.