From a2c39925bb4b49b5a45ad03694d8c577113b45d4 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 3 Aug 2024 21:39:43 +0800 Subject: [PATCH] fix(`no-hashbang-comment`): error on files without comments (#35) --- lib/rules/no-hashbang-comment.js | 2 +- test/no-hashbang-comment.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/rules/no-hashbang-comment.js b/lib/rules/no-hashbang-comment.js index 5d14a0b..0b6b165 100644 --- a/lib/rules/no-hashbang-comment.js +++ b/lib/rules/no-hashbang-comment.js @@ -5,7 +5,7 @@ module.exports = (context, badBrowser) => { return { 'Program:exit' (node) { const [comment] = sourceCode.getAllComments(); - if (comment.type === 'Shebang') { + if (comment && comment.type === 'Shebang') { context.report(node, `Hashbang comments are not supported in ${badBrowser}`) } } diff --git a/test/no-hashbang-comment.js b/test/no-hashbang-comment.js index 3abd76a..302437b 100644 --- a/test/no-hashbang-comment.js +++ b/test/no-hashbang-comment.js @@ -9,6 +9,7 @@ ruleTester.run('no-hashbang-comment', rule, { valid: [ {code: '// Regular comment'}, {code: '/* Regular comment */'}, + {code: 'noComment;'}, ], invalid: [ {