From 3352acd4b1c0c74e0189efc092cb9399a5515f91 Mon Sep 17 00:00:00 2001 From: scagood <2230835+scagood@users.noreply.github.com> Date: Tue, 6 Feb 2024 18:20:11 +0000 Subject: [PATCH] chore(shebang): Only report the first line #85 --- lib/rules/shebang.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/rules/shebang.js b/lib/rules/shebang.js index 6bb9c6fa..c4f9d4ef 100644 --- a/lib/rules/shebang.js +++ b/lib/rules/shebang.js @@ -69,6 +69,7 @@ function getShebangInfo(sourceCode) { } } +/** @type {import('eslint').Rule.RuleModule} */ module.exports = { meta: { docs: { @@ -150,7 +151,12 @@ module.exports = { const info = getShebangInfo(sourceCode) return { - Program(node) { + Program() { + const loc = { + start: { line: 1, column: 0 }, + end: { line: 1, column: sourceCode.lines.at(0).length }, + } + if ( needsShebang ? NODE_SHEBANG_PATTERN.test(info.shebang) @@ -160,7 +166,7 @@ module.exports = { // Checks BOM and \r. if (needsShebang && info.bom) { context.report({ - node, + loc, messageId: "unexpectedBOM", fix(fixer) { return fixer.removeRange([-1, 0]) @@ -169,7 +175,7 @@ module.exports = { } if (needsShebang && info.cr) { context.report({ - node, + loc, messageId: "expectedLF", fix(fixer) { const index = sourceCode.text.indexOf("\r") @@ -180,7 +186,7 @@ module.exports = { } else if (needsShebang) { // Shebang is lacking. context.report({ - node, + loc, messageId: "expectedHashbangNode", fix(fixer) { return fixer.replaceTextRange( @@ -192,7 +198,7 @@ module.exports = { } else { // Shebang is extra. context.report({ - node, + loc, messageId: "expectedHashbang", fix(fixer) { return fixer.removeRange([0, info.length])