Skip to content

Commit b5cdddc

Browse files
committed
feature: @putout/plugin-labels: ImportDeclaration: assert: exclude
1 parent 9b08062 commit b5cdddc

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import a from 'a' assert {type: 'json'}

packages/plugin-labels/lib/remove-unused/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import {operator, types} from 'putout';
22

3-
const {isReturnStatement} = types;
3+
const {
4+
isReturnStatement,
5+
isIdentifier,
6+
} = types;
47
const {replaceWith} = operator;
58

69
export const report = ({name}) => `Label '${name}' is defined but never used`;
@@ -17,6 +20,9 @@ export const traverse = ({push}) => ({
1720
if (isPrevReturnWithoutArg(path))
1821
return;
1922

23+
if (isPrevImportAssert(path))
24+
return;
25+
2026
if (!usedLabel({path, name}))
2127
push({
2228
path,
@@ -57,3 +63,14 @@ function isPrevReturnWithoutArg({parentPath}) {
5763

5864
return !retPath.node.argument;
5965
}
66+
67+
function isPrevImportAssert({parentPath}) {
68+
const prev = parentPath.getPrevSibling();
69+
70+
if (!prev.isExpressionStatement())
71+
return false;
72+
73+
return isIdentifier(prev.node.expression, {
74+
name: 'assert',
75+
});
76+
}

packages/plugin-labels/lib/remove-unused/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ test('putout: remove-unused: no report: return', (t) => {
2626
t.noReport('return');
2727
t.end();
2828
});
29+
30+
test('putout: remove-unused: no report: import-assert', (t) => {
31+
t.noReport('import-assert');
32+
t.end();
33+
});

0 commit comments

Comments
 (0)