-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor issue counters & introduce (custom) reporters
- Loading branch information
Showing
10 changed files
with
276 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import path from 'node:path'; | ||
import type { Issues, Configuration } from '../types'; | ||
|
||
const logIssueLine = (cwd: string, filePath: string, symbols: string[]) => { | ||
console.log(`${path.relative(cwd, filePath)}: ${symbols.join(', ')}`); | ||
}; | ||
|
||
const logIssueGroupResult = (issues: string[], cwd: string, title: false | string) => { | ||
title && console.log(`--- ${title} (${issues.length})`); | ||
if (issues.length) { | ||
const sortedByFilePath = issues.sort(); | ||
sortedByFilePath.forEach(filePath => console.log(path.relative(cwd, filePath))); | ||
} else { | ||
console.log('N/A'); | ||
} | ||
}; | ||
|
||
const logIssueGroupResults = ( | ||
issues: { filePath: string; symbols: string[] }[], | ||
cwd: string, | ||
title: false | string | ||
) => { | ||
title && console.log(`--- ${title} (${issues.length})`); | ||
if (issues.length) { | ||
const sortedByFilePath = issues.sort((a, b) => (a.filePath > b.filePath ? 1 : -1)); | ||
sortedByFilePath.forEach(({ filePath, symbols }) => logIssueLine(cwd, filePath, symbols)); | ||
} else { | ||
console.log('N/A'); | ||
} | ||
}; | ||
|
||
export default ({ issues, config, cwd }: { issues: Issues; config: Configuration; cwd: string }) => { | ||
const { | ||
isOnlyFiles, | ||
isOnlyExports, | ||
isOnlyTypes, | ||
isOnlyDuplicates, | ||
isFindUnusedFiles, | ||
isFindUnusedExports, | ||
isFindUnusedTypes, | ||
isFindDuplicateExports | ||
} = config; | ||
|
||
if (isFindUnusedFiles) { | ||
const unusedFiles = Array.from(issues.file); | ||
logIssueGroupResult(unusedFiles, cwd, !isOnlyFiles && 'UNUSED FILES'); | ||
} | ||
|
||
if (isFindUnusedExports) { | ||
const unusedExports = Object.values(issues.export).map(issues => { | ||
const items = Object.values(issues); | ||
return { | ||
filePath: items[0].filePath, | ||
symbols: items.map(i => i.symbol) | ||
}; | ||
}); | ||
logIssueGroupResults(unusedExports, cwd, !isOnlyExports && 'UNUSED EXPORTS'); | ||
} | ||
|
||
if (isFindUnusedTypes) { | ||
const unusedTypes = Object.values(issues.type).map(issues => { | ||
const items = Object.values(issues); | ||
return { | ||
filePath: items[0].filePath, | ||
symbols: items.map(i => i.symbol) | ||
}; | ||
}); | ||
logIssueGroupResults(unusedTypes, cwd, !isOnlyTypes && 'UNUSED TYPES'); | ||
} | ||
|
||
if (isFindDuplicateExports) { | ||
const unusedDuplicates = Object.values(issues.duplicate).map(issues => { | ||
const items = Object.values(issues); | ||
return { | ||
filePath: items[0].filePath, | ||
symbols: items.map(i => i.symbols ?? []).flat() | ||
}; | ||
}); | ||
logIssueGroupResults(unusedDuplicates, cwd, !isOnlyDuplicates && 'DUPLICATE EXPORTS'); | ||
} | ||
}; |
Oops, something went wrong.