Skip to content

Commit

Permalink
Report unused members of re-exports (fixes #140)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jun 17, 2023
1 parent f2d787e commit f911062
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {
}

const isStar = Boolean(importedModule?.isStar);
const isReExportedByEntryFile = isStar && isExportedInEntryFile(importedModule);
const isReExportedByEntryFile = !isIncludeEntryExports && isStar && isExportedInEntryFile(importedModule);

if (!isReExportedByEntryFile && !isExportedItemReferenced(exportedItem, filePath)) {
if (['enum', 'type', 'interface'].includes(exportedItem.type)) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions tests/fixtures/include-entry-reexports/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/fixtures/include-entry-reexports/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@fixtures/include-entry-reexports",
"version": "1.0.0",
"private": true,
"type": "module",
"workspaces": [
"packages/*"
]
}
3 changes: 3 additions & 0 deletions tests/fixtures/include-entry-reexports/packages/app/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { foo } from '@kp/shared'

console.log(foo())
10 changes: 10 additions & 0 deletions tests/fixtures/include-entry-reexports/packages/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@kp/app",
"version": "0.0.0",
"private": true,
"main": "index.mjs",
"type": "module",
"dependencies": {
"@kp/shared": "*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const bar = () => 'bar'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = () => 'foo'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './foo.mjs'
export * from './bar.mjs'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kp/shared",
"version": "0.0.0",
"private": true,
"main": "index.mjs",
"type": "module"
}
39 changes: 39 additions & 0 deletions tests/include-entry-reexports.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { main } from '../src/index.js';
import { resolve } from '../src/util/path.js';
import baseArguments from './helpers/baseArguments.js';
import baseCounters from './helpers/baseCounters.js';

const cwd = resolve('tests/fixtures/include-entry-reexports');

test('Skip unused nsExports in entry source files', async () => {
const { counters } = await main({
...baseArguments,
cwd,
isIncludeEntryExports: false,
});

assert.deepEqual(counters, {
...baseCounters,
processed: 4,
total: 4,
});
});

test('Report unused nsExports in entry source files', async () => {
const { issues, counters } = await main({
...baseArguments,
cwd,
isIncludeEntryExports: true,
});

assert(issues.nsExports['packages/shared/bar.mjs']['bar']);

assert.deepEqual(counters, {
...baseCounters,
nsExports: 1,
processed: 4,
total: 4,
});
});

0 comments on commit f911062

Please sign in to comment.