feat: add require-assert-message rule - #565
Open
electrohyun wants to merge 2 commits into
Open
Conversation
aladdin-add
requested review from
aladdin-add
and
a balanced review from Copilot
August 25, 2026 19:42
There was a problem hiding this comment.
Pull request overview
Adds n/require-assert-message to enforce meaningful messages for supported Node.js assertion APIs.
Changes:
- Implements assertion reference tracking and message validation.
- Adds comprehensive rule tests and documentation.
- Registers the rule and updates the generated rule list.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
lib/rules/require-assert-message.js |
Implements the new rule. |
lib/all-rules.js |
Registers the rule. |
tests/lib/rules/require-assert-message.js |
Adds rule test cases. |
docs/rules/require-assert-message.md |
Documents behavior and scope. |
README.md |
Adds the rule to the rule list. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+139
to
+142
| } else if ( | ||
| isUndefined(message, context) || | ||
| isEmptyString(message) | ||
| ) { |
| continue | ||
| } | ||
|
|
||
| const message = node.arguments[messageIndex] |
Author
|
Applied the Copilot review feedback and renamed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Disclosure: I'm a participant of open source contribution program OSSCA
Important
This PR currently supports only
node:assertandnode:assert/strict; bareassertandassert/strictspecifiers are not supported.I would appreciate feedback on whether this scope is appropriate before merging.
To avoid false positives, the rule conservatively skips all calls through a CommonJS assertion binding if that binding is reassigned after initialization. This can also skip calls that appear before the reassignment. It does not currently exclude property mutations such as
assert.ok = mock.What is the purpose of this pull request?
This PR adds
n/require-assert-message, a rule that requires messages for Node.jsassertcalls.Without a message, assertion failures fall back to Node.js's default
AssertionErrormessage, which can make the reason for a failure harder to identify. The rule reports missing or obviously empty messages for assertion APIs whose message position can be determined statically.What changes did you make? (Give an overview)
n/require-assert-message.node:assert,node:assert/strict, and thestrictexport fromnode:assert.assert(),assert.ok(), equality assertions,match(),doesNotMatch(), andpartialDeepStrictEqual().undefined, avoidexpression, an empty string, and an empty template literal.throws,doesNotThrow,rejects, anddoesNotRejectbecause their optionalerrorargument makes the message position ambiguous.ifError, which has no message parameter, andfail, which is commonly used to mark unreachable code.Related Issues
refs #322
Is there anything you'd like reviewers to focus on?
node:assertandnode:assert/strict. Should it also support bareassertandassert/strictspecifiers to align with existing plugin rules?Reassigned bindings are excluded:
The current binding-reassignment policy is intentionally conservative and may also create false negatives for calls before the reassignment.
However, property mutations are not currently excluded:
This is an uncommon case. Please let me know whether it should also be excluded, or whether limiting the rule to binding reassignment is the right scope.