Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
(Note: I couldn’t find any issue template/info about feature requests, I hope this is ok! 🙏 )
Summary: Disallow.join() calls onArrays that aren’tArray<string>.
Motivation:
I had a function like this:
functionnoCommonRoot(paths:Array<string>):string{return`I could not find a common ancestor for these paths:${paths.join("\n")}Files on different drives is not supported. `.trim();}
I had trouble with using too muchstring types an mixing stuff up, so I introduced anAbsolutePath type to help me, and replacedstring withAbsolutePath in many places.
typeAbsolutePath={tag:"AbsolutePath";absolutePath:string};functionnoCommonRoot(paths:Array<AbsolutePath>):string{return`I could not find a common ancestor for these paths:${paths.join("\n")}Files on different drives is not supported. `.trim();}
When I had fixed all compile errors, I had accidentally introduced a bug!noCommonRoot now outputs:
I could not find a common ancestor for these paths:[object Object][object Object][object Object]Files on different drives is not supported.Oops!
I searched for.join in the entire project and switched to using this function instead, to avoid this problem in the future:
functionjoin(array:Array<string>,separator:string):string{returnarray.join(separator);}
That way I could fix thenoCommonRoot function:
functionnoCommonRoot(paths:Array<AbsolutePath>):string{return`I could not find a common ancestor for these paths:${join(paths.map((path)=>path.absolutePath),"\n")}Files on different drives is not supported. `.trim();}
Bonus: myjoin functionrequires the separator argument. That would be nice to lint too. The default"," is never what I want.