@@ -19,13 +19,12 @@ const HASH = "566513c5d83ac26e15414f2754"; // to avoid collisions with user code
1919 * location of messages in the postprocess step later.
2020 * @param {string } text text of the file
2121 * @param {string } filename filename of the file
22- * @param {(id) => string } dummyString dummy string to replace ERB tags with
23- * (this is language-specific). Should be
24- * a function that takes an id and returns
25- * a UNIQUE dummy string.
22+ * @param {(id) => string } toDummyString function that takes an id and the
23+ * matched text and returns a dummy string to replace the matched text with.
24+ * This dummy string must be unique.
2625 * @returns {Array<{ filename: string, text: string }> } source code blocks to lint
2726 */
28- function preprocess ( text , filename , dummyString ) {
27+ function preprocess ( text , filename , toDummyString ) {
2928 let lintableTextArr = text . split ( "" ) ;
3029
3130 let match ;
@@ -47,7 +46,7 @@ function preprocess(text, filename, dummyString) {
4746 numAddLines += matchLines . length - 1 ;
4847
4948 // Columns
50- const dummy = dummyString ( matchedId ) ;
49+ const dummy = toDummyString ( matchedId , matchText ) ;
5150 const coordStartIndex = indexToColumn ( text , startIndex ) ;
5251 const endColumnAfter = coordStartIndex . column + dummy . length ;
5352 const coordEndIndex = indexToColumn ( text , endIndex ) ;
@@ -88,17 +87,24 @@ function replaceTextWithDummy(lintableTextArr, startIndex, length, dummy) {
8887}
8988
9089function preprocessJs ( text , filename ) {
91- function dummyString ( id ) {
92- return `/* eslint-disable */{}/* ${ HASH } ${ id } */ /* eslint-enable */` ;
90+ function wrapInEslintDisable ( text ) {
91+ return `/* eslint-disable */${ text } /* eslint-enable */` ;
9392 }
94- return preprocess ( text , filename , dummyString ) ;
93+
94+ function toDummyString ( id , matchText ) {
95+ if ( matchText . startsWith ( "<%=" ) ) {
96+ return wrapInEslintDisable ( `{}/* eslint-plugin-erb ${ HASH } ${ id } */` ) ;
97+ }
98+ return wrapInEslintDisable ( `/* eslint-plugin-erb ${ HASH } ${ id } */` ) ;
99+ }
100+ return preprocess ( text , filename , toDummyString ) ;
95101}
96102
97103function preprocessHtml ( text , filename ) {
98- function dummyString ( id ) {
104+ function toDummyString ( id , _matchText ) {
99105 return `<!-- ${ HASH } ${ id } -->` ;
100106 }
101- return preprocess ( text , filename , dummyString ) ;
107+ return preprocess ( text , filename , toDummyString ) ;
102108}
103109
104110module . exports = {
0 commit comments