Skip to content

Add consistent-assert rule #2535

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

Merged
merged 21 commits into from
Jan 24, 2025
Merged

Conversation

axetroy
Copy link
Contributor

@axetroy axetroy commented Jan 21, 2025

Close #1806

<!-- end auto-generated rule header -->
<!-- Do not manually modify this header. Run: `npm run fix:eslint-docs` -->

Enforce consistent assertion styles with `node:assert`.
Copy link
Owner

Choose a reason for hiding this comment

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

This is just repeating the title.

assert(true);

// ✅
assert.ok(true);
Copy link
Owner

Choose a reason for hiding this comment

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

It's not clear from the examples why assert.ok is better than assert.

Comment on lines 53 to 56
const variable = scope.variables.find(variable => variable.name === specifier.local.name);
if (!variable) {
continue;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const variable = scope.variables.find(variable => variable.name === specifier.local.name);
if (!variable) {
continue;
}
const variable = sourceCode.getDeclaredVariables(specifier);


// Skip if the identifier is not part of a call expression
// Skip if the identifier is the object of a member expression
if (!isFunctionCall() || isMemberExpression()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we only check function call?

@axetroy axetroy requested a review from sindresorhus January 22, 2025 09:56
@fisker
Copy link
Collaborator

fisker commented Jan 23, 2025

@axetroy Pushed some changes, mainly 0bcf6f4 (#2535) should improve readability. Please take a look.

```

```js
import assert from 'node:assert/strict';
Copy link
Collaborator

@fisker fisker Jan 23, 2025

Choose a reason for hiding this comment

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

The node:assert/strict module should be encouraged to use, let's move this one to top.

meta: {
type: 'problem',
docs: {
description: 'Enforce consistent assertion styles with `node:assert`',
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
description: 'Enforce consistent assertion styles with `node:assert`',
description: 'Enforce consistent assertion styles with `node:assert`.',

@@ -0,0 +1,51 @@
# Enforce consistent assertion styles with `node:assert`
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
# Enforce consistent assertion styles with `node:assert`
# Enforce consistent assertion style with `node:assert`

@sindresorhus sindresorhus merged commit f3fc973 into sindresorhus:main Jan 24, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule proposal: Prefer assert() or assert.ok()
3 participants