@@ -3,13 +3,13 @@ import type { Report } from "./report";
33
44export function generateNotes ( report : Report , label ?: string ) : INotesEnvelopeV3 {
55 const perLink = new Map < string , { file : string ; link : Link } [ ] > ( ) ;
6- const commonPath : Map < string , number > [ ] = [ ] ;
6+ const commonPathComponents : Map < string , number > [ ] = [ ] ;
77
88 for ( const [ file , links ] of report . detected ) {
99 const parts = file . split ( "/" ) ;
1010 for ( let i = 0 ; i < parts . length ; i ++ ) {
11- commonPath [ i ] = commonPath [ i ] || new Map ( ) ;
12- commonPath [ i ] . set ( parts [ i ] , ( commonPath [ i ] . get ( parts [ i ] ) || 0 ) + 1 ) ;
11+ commonPathComponents [ i ] = commonPathComponents [ i ] || new Map ( ) ;
12+ commonPathComponents [ i ] . set ( parts [ i ] , ( commonPathComponents [ i ] . get ( parts [ i ] ) || 0 ) + 1 ) ;
1313 }
1414
1515 for ( const link of links ) {
@@ -25,21 +25,25 @@ export function generateNotes(report: Report, label?: string): INotesEnvelopeV3
2525 }
2626
2727 const noOfFiles = report . detected . size ;
28- const path = commonPath
29- . map ( ( x ) => {
30- for ( const [ k , count ] of x . entries ( ) ) {
31- if ( count === noOfFiles ) {
32- return k ;
33- }
34- return null ;
35- }
36- } )
37- . filter ( ( x ) => x )
38- . join ( "/" ) ;
28+ // avoid stripping commonPath if we only have one file.
29+ const commonPath =
30+ noOfFiles < 2
31+ ? ""
32+ : commonPathComponents
33+ . map ( ( x ) => {
34+ for ( const [ k , count ] of x . entries ( ) ) {
35+ if ( count === noOfFiles ) {
36+ return k ;
37+ }
38+ return null ;
39+ }
40+ } )
41+ . filter ( ( x ) => x )
42+ . join ( "/" ) ;
3943
4044 const notes = [ ] ;
4145 for ( const [ _ , linkData ] of perLink ) {
42- const note = linkToNote ( linkData , path ) ;
46+ const note = linkToNote ( linkData , commonPath ) ;
4347 if ( label ) {
4448 note . labels . push ( label ) ;
4549 }
0 commit comments