Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit 3830afc

Browse files
Fix no-unused-collection: should not fire if collection is exported (#244)
Co-authored-by: Dmytro Pustovit <[email protected]>
1 parent 3d632f7 commit 3830afc

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/rules/no-unused-collection.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ function collectUnusedCollections(
6161
});
6262
}
6363

64+
function isExported(variable: TSESLint.Scope.Variable) {
65+
const definition = variable.defs[0];
66+
return definition && definition.node.parent?.parent?.type.startsWith('Export');
67+
}
68+
6469
function isUnusedCollection(variable: TSESLint.Scope.Variable) {
70+
if (isExported(variable)) {
71+
return false;
72+
}
6573
if (variable.references.length <= 1) {
6674
return false;
6775
}

tests/rules/no-unused-collection.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ ruleTester.run('Primitive return types should be used.', rule, {
160160
console.log(i);
161161
}`,
162162
},
163+
{
164+
code: `
165+
export const array = [];
166+
167+
array.push(1);
168+
`,
169+
},
170+
{
171+
code: `export const collection = new Map()`,
172+
},
163173
],
164174
invalid: [
165175
{

0 commit comments

Comments
 (0)