Skip to content

Commit

Permalink
chore(shebang): Only report the first line eslint-community#85
Browse files Browse the repository at this point in the history
  • Loading branch information
scagood committed Feb 6, 2024
1 parent 3b74a71 commit 3352acd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/rules/shebang.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function getShebangInfo(sourceCode) {
}
}

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
docs: {
Expand Down Expand Up @@ -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)
Expand All @@ -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])
Expand All @@ -169,7 +175,7 @@ module.exports = {
}
if (needsShebang && info.cr) {
context.report({
node,
loc,
messageId: "expectedLF",
fix(fixer) {
const index = sourceCode.text.indexOf("\r")
Expand All @@ -180,7 +186,7 @@ module.exports = {
} else if (needsShebang) {
// Shebang is lacking.
context.report({
node,
loc,
messageId: "expectedHashbangNode",
fix(fixer) {
return fixer.replaceTextRange(
Expand All @@ -192,7 +198,7 @@ module.exports = {
} else {
// Shebang is extra.
context.report({
node,
loc,
messageId: "expectedHashbang",
fix(fixer) {
return fixer.removeRange([0, info.length])
Expand Down

0 comments on commit 3352acd

Please sign in to comment.