Skip to content

Commit

Permalink
Fix type output for unreferenced ns types
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 7, 2022
1 parent 58bd222 commit 76b0309
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function run(configuration: Configuration) {
if (include.duplicates) {
const duplicateExports = findDuplicateExportedNames(sourceFile);
duplicateExports.forEach(symbols => {
const symbol = symbols.join(',');
const symbol = symbols.join('|');
addIssue('duplicates', { filePath, symbol, symbols });
});
}
Expand Down Expand Up @@ -145,7 +145,7 @@ export async function run(configuration: Configuration) {
// No more reasons left to think this identifier is used somewhere else, report it as unreferenced
if (findReferencingNamespaceNodes(sourceFile).length > 0) {
if (type) {
addIssue('nsTypes', { filePath, symbol: identifierText });
addIssue('nsTypes', { filePath, symbol: identifierText, symbolType: type });
} else {
addIssue('nsExports', { filePath, symbol: identifierText });
}
Expand Down
5 changes: 3 additions & 2 deletions src/reporters/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import path from 'node:path';
import type { Issue, Issues, Configuration } from '../types';

const logIssueLine = ({ issue, cwd, padding }: { issue: Issue; cwd: string; padding: number }) => {
const symbols = issue.symbols ? issue.symbols.join(', ') : issue.symbol;
console.log(
`${issue.symbol.padEnd(padding + 2)}${issue.symbolType?.padEnd(11) || ''}${path.relative(cwd, issue.filePath)}`
`${symbols.padEnd(padding + 2)}${issue.symbolType?.padEnd(11) || ''}${path.relative(cwd, issue.filePath)}`
);
};

Expand Down Expand Up @@ -52,7 +53,7 @@ export default ({ issues, config, cwd }: { issues: Issues; config: Configuration
}

if (include.nsTypes) {
const unreferencedNsTypes = Object.values(issues.nsExports).map(Object.values).flat();
const unreferencedNsTypes = Object.values(issues.nsTypes).map(Object.values).flat();
logIssueGroupResults(unreferencedNsTypes, cwd, reportMultipleGroups && 'UNUSED TYPES IN NAMESPACE');
}

Expand Down
2 changes: 1 addition & 1 deletion test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ test('run', async () => {

assert(counters.duplicates === 1);
assert(Object.values(issues.duplicates).length === 1);
assert(issues.duplicates['dep.ts']['dep,default'].symbols?.[0] === 'dep');
assert(issues.duplicates['dep.ts']['dep|default'].symbols?.[0] === 'dep');
});

0 comments on commit 76b0309

Please sign in to comment.