@@ -6,6 +6,13 @@ import type { Entries } from 'type-fest';
6
6
export default ( { report, issues } : ReporterOptions ) => {
7
7
console . log ( '# Knip report\n' ) ;
8
8
9
+ const getFilePath = ( issue : Issue ) => {
10
+ if ( ! issue . line || ! issue . col ) return relative ( issue . filePath ) ;
11
+ return `${ relative ( issue . filePath ) } :${ issue . line } :${ issue . col } ` ;
12
+ } ;
13
+ const sortLongestSymbol = ( a : Issue , b : Issue ) => b . symbol . length - a . symbol . length ;
14
+ const sortLongestFilePath = ( a : Issue , b : Issue ) => getFilePath ( b ) . length - getFilePath ( a ) . length ;
15
+
9
16
for ( const [ reportType , isReportType ] of Object . entries ( report ) as Entries < typeof report > ) {
10
17
if ( isReportType ) {
11
18
const title = getTitle ( reportType ) ;
@@ -21,16 +28,17 @@ export default ({ report, issues }: ReporterOptions) => {
21
28
console . log ( `* ${ toRelative ( issue ) } ` ) ;
22
29
} ) ;
23
30
} else {
24
- const longestSymbol = issuesForType . sort ( ( a , b ) => b . symbol . length - a . symbol . length ) [ 0 ] . symbol . length ;
25
- const longestFilePath = relative (
26
- issuesForType . sort ( ( a , b ) => relative ( b . filePath ) . length - relative ( a . filePath ) . length ) [ 0 ] . filePath
27
- ) . length ;
28
- const sortedByFilePath = issuesForType . sort ( ( a , b ) => ( a . filePath > b . filePath ? 1 : - 1 ) ) ;
29
- console . log ( `| ${ `Name` . padEnd ( longestSymbol ) } | ${ `Location` . padEnd ( longestFilePath ) } |` ) ;
30
- console . log ( `|:${ '-' . repeat ( longestSymbol + 1 ) } |:${ '-' . repeat ( longestFilePath + 1 ) } |` ) ;
31
+ const longestSymbol = issuesForType . sort ( sortLongestSymbol ) [ 0 ] . symbol . length ;
32
+ const sortedByFilePath = issuesForType . sort ( sortLongestFilePath ) ;
33
+ const longestFilePath = getFilePath ( sortedByFilePath [ 0 ] ) . length ;
34
+
35
+ console . log ( `| ${ `Name` . padEnd ( longestSymbol ) } | ${ `Location` . padEnd ( longestFilePath ) } | Severity |` ) ;
36
+ console . log ( `| :${ '-' . repeat ( longestSymbol - 1 ) } | :${ '-' . repeat ( longestFilePath - 1 ) } | :------- |` ) ;
31
37
sortedByFilePath . forEach ( ( issue : Issue ) => {
32
38
console . log (
33
- `| ${ issue . symbol . padEnd ( longestSymbol ) } | ${ relative ( issue . filePath ) . padEnd ( longestFilePath ) } |`
39
+ `| ${ issue . symbol . padEnd ( longestSymbol ) } | ${ getFilePath ( issue ) . padEnd ( longestFilePath ) } | ${ (
40
+ issue . severity ?? ''
41
+ ) . padEnd ( 8 ) } |`
34
42
) ;
35
43
} ) ;
36
44
}
0 commit comments