Skip to content

Commit 396a8fa

Browse files
authored
consistent-assert: Explicitly check specifier node type (#2803)
1 parent 51fc7b9 commit 396a8fa

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

rules/consistent-assert.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ const isAssertFunction = (specifier, moduleName) =>
2222
// `import {default as assert} from 'node:assert/strict';`
2323
|| (
2424
specifier.type === 'ImportSpecifier'
25+
&& specifier.imported.type === 'Identifier'
2526
&& specifier.imported.name === 'default'
2627
)
2728
// `import {strict as assert} from 'node:assert';`
2829
|| (
2930
moduleName === 'assert'
3031
&& specifier.type === 'ImportSpecifier'
32+
&& specifier.imported.type === 'Identifier'
3133
&& specifier.imported.name === 'strict'
3234
);
3335

test/consistent-assert.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ test.snapshot({
5151
import assert from 'node:assert/strict';
5252
console.log(assert)
5353
`,
54+
// We are not checking this
55+
outdent`
56+
import {'strict' as assert} from 'assert';
57+
assert(foo)
58+
`,
5459
...[
5560
'import type assert from "node:assert/strict";',
5661
'import {type strict as assert} from "node:assert/strict";',

0 commit comments

Comments
 (0)