eslint-plugin-html-erb
Version:
Ignore Rails code in ERB template
25 lines (20 loc) • 575 B
JavaScript
/**
* @fileoverview Ignore Rails code in ERB template
* @author Pierre-Michel Brown
*/
;
module.exports.processors = {
'.erb': {
preprocess: function(text) {
var scriptRegex = /(<script[^>]*>)(((?!<\/script>)[\s\S])+)<\/script>/g;
text = text.replace(scriptRegex, function(match, openingTag, jsCode) {
jsCode = jsCode.replace(/<%=?((?!%>)[\s\S])*%>/g, 'window');
return openingTag + jsCode + '</script>';
});
return [text];
},
postprocess: function(messages) {
return messages[0];
},
},
};