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 new rule require-assert-message rule #45

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jpolavar
Copy link
Contributor

@jpolavar jpolavar commented Nov 7, 2023

Closes #30

Added rule to report for missing message argument to always be supplied to node:assert methods.

@jpolavar jpolavar added the MINOR label Nov 7, 2023
@jpolavar jpolavar self-assigned this Nov 7, 2023
Copy link

github-actions bot commented Nov 7, 2023

Coverage after merging require-assert-message into main will be

94.90%▴ +0.45%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   file-path-comment.ts100%100%100%100%
   no-card-numbers.ts92.59%89.29%100%93.18%134–135, 137–138, 144–145
   no-uuid.ts92.31%87.50%100%93.55%100, 89–90, 99
   require-assert-message.ts100%100%100%100%

Copy link

github-actions bot commented Nov 7, 2023

Beta Published - Install Command: npm install @checkdigit/[email protected]

@jpolavar jpolavar requested a review from carlansley November 7, 2023 18:21

import rule from './require-assert-message';

describe('no-uuid', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

update description

valid: [
{
code: `import { strict as assert } from 'node:assert';
assert.ok(statusCode === StatusCodes.OK, 'Failed to get data.');`,
Copy link
Contributor

Choose a reason for hiding this comment

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

the indenting in the test code is weird, should be two spaces and line up correctly.

const methodName = node.callee.property.name;

if (objectName === 'assert' && methodName !== 'ifError') {
const expectedMessageArgIndex = methodName === 'ok' || methodName === 'strict' ? 1 : 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

i am not convinced this logic is correct. e.g. don't think the assert(value) form is accounted for? Maybe a better approach is to see if the argument named "message" is provided. (all the assert type definitions use message as the argument name). that should be available somehow.

Error,
);`,
errors: [{ message: 'Missing message argument in doesNotReject() method.' }],
},
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 we need a pass/fail test for every method https://nodejs.org/api/assert.html.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was using @typescript-eslint/utils; somehow all the arguments are of type: 'Literal' argument and argument named ‘message’ is not available. Should we follow approach to load all assert methods in runtime from node:assert and get all the arguments length and then report back if arguments length are less than expected?

Copy link

github-actions bot commented Nov 8, 2023

❌ PR review status - reviewer has not approved

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.

Add require-assert-message rule
2 participants