-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ES2023
no-hashbang-comment
(#29)
- Loading branch information
Showing
6 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# no-hashbang-comment | ||
|
||
This prevents use of ES2023 hashang comments: | ||
|
||
```js | ||
#!/usr/bin/env node | ||
``` | ||
|
||
These will not be allowed because they are not supported in the following browsers: | ||
|
||
- Edge < 79 | ||
- Safari < 13.1 | ||
- Firefox < 67 | ||
- Chrome < 74 | ||
|
||
|
||
## What is the Fix? | ||
|
||
You have to omit the comment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
module.exports = (context, badBrowser) => { | ||
const { sourceCode = context.getSourceCode() } = context; | ||
return { | ||
'Program:exit' (node) { | ||
const [comment] = sourceCode.getAllComments(); | ||
if (comment.type === 'Shebang') { | ||
context.report(node, `Hashbang comments are not supported in ${badBrowser}`) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
const rule = require('../lib/index').rules['no-hashbang-comment'] | ||
const RuleTester = require('eslint').RuleTester | ||
|
||
const ruleTester = new RuleTester({languageOptions: {ecmaVersion: 2018}}) | ||
|
||
ruleTester.run('no-hashbang-comment', rule, { | ||
valid: [ | ||
{code: '// Regular comment'}, | ||
{code: '/* Regular comment */'}, | ||
], | ||
invalid: [ | ||
{ | ||
code: '#!/usr/bin/env node', | ||
errors: [ | ||
{ | ||
message: | ||
'Hashbang comments are not supported in undefined' | ||
} | ||
] | ||
} | ||
] | ||
}) |