avajs / eslint-plugin-ava

ESLint rules for AVA
https://avajs.dev
MIT License
230 stars 49 forks source link

Prevent specifying error type in `t.notThrows()` #178

Open sindresorhus opened 7 years ago

sindresorhus commented 7 years ago

Issuehunt badges

It's an easy mistake to make if you have many t.throws() statements and then some t.notThrows() statements.

For example: https://github.com/sindresorhus/p-queue/commit/80e8e25926a6632d0429ebb526ee78a68f01d565

// Fail
t.notThrows(() => {
 t.pass();
}, TypeError);

// Ok
t.notThrows(() => {
 t.pass();
});

It should fail if it's a variable matching this regex: /^(?:[A-Z][a-z0-9]*)*Error$/


IssueHunt Summary ### Backers (Total: $60.00) - [issuehunt issuehunt](https://issuehunt.io/u/issuehunt) ($60.00) ### Submitted pull Requests - [#240 rule `prevent-errortype`](https://issuehunt.io/r/avajs/eslint-plugin-ava/pull/240) - [#326 Add `no-error-ctor-with-notthrows` rule](https://issuehunt.io/r/avajs/eslint-plugin-ava/pull/326) --- #### [Become a backer now!](https://issuehunt.io/r/avajs/eslint-plugin-ava/issues/178) #### [Or submit a pull request to get the deposits!](https://issuehunt.io/r/avajs/eslint-plugin-ava/issues/178) ### Tips - Checkout the [Issuehunt explorer](https://issuehunt.io/r/avajs/eslint-plugin-ava/) to discover more funded issues. - Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on IssueHunt to raise funds.
sindresorhus commented 7 years ago

@novemberborn In AVA, I think we should assert it's a string or undefined at runtime. What do you think?

novemberborn commented 7 years ago

@sindresorhus https://github.com/avajs/ava/issues/1125

IssueHuntBot commented 5 years ago

@issuehunt has funded $60.00 to this issue.


rahgurung commented 5 years ago

@sindresorhus @novemberborn I tried to give it a shot please review and guide further. #240