Skip to content

Commit e42d161

Browse files
committed
Fix: shebang should allow CLI flags (fixes #51)
1 parent 06231d4 commit e42d161

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/rules/shebang.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var getPackageJson = require("../util/get-package-json")
2020

2121
var NODE_SHEBANG = "#!/usr/bin/env node\n"
2222
var SHEBANG_PATTERN = /^(#!.+?)?(\r)?\n/
23+
var NODE_SHEBANG_PATTERN = /#!\/usr\/bin\/env node(?: [^\r\n]+?)?\n/
2324

2425
/**
2526
* Checks whether or not a given path is a `bin` file.
@@ -88,7 +89,7 @@ module.exports = function(context) {
8889

8990
return {
9091
Program: function(node) {
91-
if (needsShebang ? info.shebang === NODE_SHEBANG : !info.shebang) {
92+
if (needsShebang ? NODE_SHEBANG_PATTERN.test(info.shebang) : !info.shebang) {
9293
// Good the shebang target.
9394
// Checks BOM and \r.
9495
if (needsShebang && info.bom) {

tests/lib/rules/shebang.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ ruleTester.run("shebang", rule, {
126126
filename: fixture("string-bin/lib/test.js"),
127127
code: "\n\n\nhello();",
128128
},
129+
130+
// https://github.com/mysticatea/eslint-plugin-node/issues/51
131+
{
132+
filename: fixture("string-bin/bin/test.js"),
133+
code: "#!/usr/bin/env node --harmony\nhello();",
134+
},
129135
],
130136
invalid: [
131137
{
@@ -303,5 +309,13 @@ ruleTester.run("shebang", rule, {
303309
"This file must have Unix linebreaks (LF).",
304310
],
305311
},
312+
313+
// https://github.com/mysticatea/eslint-plugin-node/issues/51
314+
{
315+
filename: fixture("string-bin/lib/test.js"),
316+
code: "#!/usr/bin/env node --harmony\nhello();",
317+
output: "hello();",
318+
errors: ["This file needs no shebang."],
319+
},
306320
],
307321
})

0 commit comments

Comments
 (0)