diff --git a/lib/rules/header.js b/lib/rules/header.js index 3504b6fc59b780674e652ad1ca944cb3577b8fed..d86dc0b490845c22f54ae83dbc52efcf448e628b 100644 --- a/lib/rules/header.js +++ b/lib/rules/header.js @@ -27,6 +27,9 @@ function excludeShebangs(comments) { // check if they are at the start of the file since that is already checked by // hasHeader(). function getLeadingComments(context, node) { + if (!node.body) { + return context.getSourceCode().ast.comments; + } var all = excludeShebangs(context.getSourceCode().getAllComments(node.body.length ? node.body[0] : node)); if (all[0].type.toLowerCase() === "block") { return [all[0]]; @@ -44,6 +47,8 @@ function genCommentBody(commentType, textArray, eol, numNewlines) { var eols = eol.repeat(numNewlines); if (commentType === "block") { return "/*" + textArray.join(eol) + "*/" + eols; + } else if (commentType === "block-html") { + return "" + eols; } else { return "//" + textArray.join(eol + "//") + eols; } @@ -103,7 +108,7 @@ function hasHeader(src) { src = src.slice(m.index + m[0].length); } } - return src.substr(0, 2) === "/*" || src.substr(0, 2) === "//"; + return src.substr(0, 2) === "/*" || src.substr(0, 2) === "//" || src.substr(0, 4) === "