Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added rule to report if assert.rejects and assert.throws doesnt provide an AssertPredicate parameter #63

Merged
merged 4 commits into from
May 20, 2024

Conversation

jpolavar
Copy link
Contributor

@jpolavar jpolavar commented May 9, 2024

Closes #62

@jpolavar jpolavar added the PATCH label May 9, 2024
@jpolavar jpolavar requested a review from carlansley May 9, 2024 21:54
Copy link
Contributor

@carlansley carlansley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue isn't about whether or not rejects/throws has a message/string parameter, it's about the error parameter. It needs to make sure the error/2nd parameter to these functions is of type AssertPredicate. see https://nodejs.org/api/assert.html#assertthrowsfn-error-message and https://nodejs.org/api/assert.html#assertrejectsasyncfn-error-message.

package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "@checkdigit/eslint-plugin",
"version": "6.0.1",
"version": "6.0.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a rule is being added, this should be MINOR

package.json Outdated
@@ -34,7 +34,7 @@
},
"sideEffects": false,
"devDependencies": {
"@checkdigit/jest-config": "^6.0.0",
"@checkdigit/jest-config": "6.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why fixed to 6.0.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fails saying process.loadEnvFile and we don't have any env file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I created an issue for this, checkdigit/jest-config#33

@jpolavar jpolavar added MINOR and removed PATCH labels May 10, 2024
@jpolavar jpolavar requested a review from carlansley May 14, 2024 03:40
@jpolavar jpolavar self-assigned this May 14, 2024
if (
callee.type === 'MemberExpression' &&
callee.object.type === 'Identifier' &&
callee.object.name === 'assert' &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think its ok for now, but we are making an assumption that the import from node:assert will be called "assert", which may not be the case.

(assertPredicate.type !== 'FunctionExpression' &&
assertPredicate.type !== 'ArrowFunctionExpression' &&
assertPredicate.type !== 'ObjectExpression' &&
assertPredicate.type !== 'Identifier' &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, probably ok to start with, but we're assuming the identifier is of type AssertPredicate, which it may not be.

Copy link
Contributor

@carlansley carlansley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few minor things that don't necessarily need to be addressed now, but the main change is the file naming. require-assert-message-rejects-throws.spec.ts still has message in the name, should be require-assert-predicate.. etc. Also can you confirm if this has been tested against some of our larger code bases?

Copy link

Coverage after merging require-reject-throws-error into main will be

91.14%▴ +0.31%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   file-path-comment.ts100%100%100%100%
   index.ts0%0%0%0%1, 1, 10–19, 2, 20–29, 3, 30–39, 4, 40–49, 5, 50–51, 6–9
   no-card-numbers.ts95.11%89.29%100%96.03%134–139, 144–146
   no-uuid.ts95.16%85.71%100%96.23%100–101, 89–91, 99
   no-wallaby-comment.ts97.48%85%100%100%43–44, 57
   regular-expression-comment.ts95.06%88.24%100%96.77%29–31, 48
   require-assert-predicate-rejects-throws.ts100%100%100%100%
   require-strict-assert.ts98.40%92%100%100%44–45

Copy link

Beta Published - Install Command: npm install @checkdigit/eslint-plugin@6.1.0-PR.63-9cc4

@jpolavar
Copy link
Contributor Author

a few minor things that don't necessarily need to be addressed now, but the main change is the file naming. require-assert-message-rejects-throws.spec.ts still has message in the name, should be require-assert-predicate.. etc. Also can you confirm if this has been tested against some of our larger code bases?

Tested in aws-nock.
Screenshot 2024-05-14 at 10 30 26 PM

@jpolavar jpolavar requested a review from carlansley May 15, 2024 03:31
Copy link

✅ PR review status - All reviews completed and approved!

@jpolavar jpolavar merged commit e66db14 into main May 20, 2024
9 checks passed
@jpolavar jpolavar deleted the require-reject-throws-error branch May 20, 2024 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

assert.rejects and assert.throws should provide an AssertPredicate parameter
2 participants