@@ -96,22 +96,23 @@ type NeedleContentInsertion = Pick<NeedleInsertion, 'needle' | 'autoIndent'> & {
9696 */
9797export const convertToPrettierExpressions = ( str : string ) : string =>
9898 str
99- . replace ( / ( < | \\ \( ) (? ! ) / g, ' $1\\ n?[\\ s]*' )
100- . replace ( / (? ! ) ( > | \\ \) ) / g, ' ,?\\ n?[\\ s]*$1' )
101- . replace ( / \s + / g, '[\\s\\ n]*' ) ;
99+ . replace ( / ( < | \\ \( ) (? ! ) / g, String . raw ` $1\n?[\s]*` )
100+ . replace ( / (? ! ) ( > | \\ \) ) / g, String . raw ` ,?\n?[\s]*$1` )
101+ . replace ( / \s + / g, String . raw `[\s\ n]*` ) ;
102102
103103const isArrayOfContentToAdd = ( value : unknown ) : value is ContentToAdd [ ] => {
104104 return Array . isArray ( value ) && value . every ( item => typeof item === 'object' && 'content' in item ) ;
105105} ;
106106
107- export const createNeedleRegexp = ( needle : string ) : RegExp => new RegExp ( `(?://|<!--|\\{?/\\*|#) ${ needle } (?: [^$\\n]*)?(?:$|\\n)` , 'g' ) ;
107+ export const createNeedleRegexp = ( needle : string ) : RegExp =>
108+ new RegExp ( String . raw `(?://|<!--|\{?/\*|#) ${ needle } (?: [^$\n]*)?(?:$|\n)` , 'g' ) ;
108109
109110type NeedleLinePosition = {
110111 start : number ;
111112 end : number ;
112113} ;
113114
114- export const getNeedlesPositions = ( content : string , needle = ' jhipster-needle-(?:[-\\ w]*)' ) : NeedleLinePosition [ ] => {
115+ export const getNeedlesPositions = ( content : string , needle = String . raw ` jhipster-needle-(?:[-\w]*)` ) : NeedleLinePosition [ ] => {
115116 const regexp = createNeedleRegexp ( needle ) ;
116117 const positions : NeedleLinePosition [ ] = [ ] ;
117118 let match : RegExpExecArray | null ;
@@ -142,7 +143,7 @@ export const checkContentIn = (contentToCheck: string | RegExp, content: string,
142143 ? convertToPrettierExpressions ( escapeRegExp ( contentToCheck ) )
143144 : contentToCheck
144145 . split ( '\n' )
145- . map ( line => `\ \s*${ escapeRegExp ( line ) } `)
146+ . map ( line => String . raw ` \s*${ escapeRegExp ( line ) } `)
146147 . join ( '\n' ) ;
147148 re = new RegExp ( pattern ) ;
148149 } else {
0 commit comments