Skip to content

Parser should ignore lines with hashbangs #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
silverwind opened this issue Jun 23, 2022 · 8 comments
Closed

Parser should ignore lines with hashbangs #161

silverwind opened this issue Jun 23, 2022 · 8 comments

Comments

@silverwind
Copy link

silverwind commented Jun 23, 2022

Parsing a file with hashbang/shebang (#! in the first line) like

#!/usr/bin/env node
console.info('hello world');

results in a parser error with this parser:

Error while parsing /file.js

Line 1, column 2: Unexpected character '!'
`parseForESLint` from parser `/file.js` is invalid and will just be ignored

eslint's own parser handles this by ignoring files starting with hashbang:

https://github.com/eslint/eslint/blob/b93af98b3c417225a027cabc964c38e779adb945/lib/linter/linter.js#L779

Also, FWIW, there is a stage 3 ECMAScript proposal to make hashbangs part of the language.

@silverwind silverwind changed the title Parser should ignore files with hashbangs Parser should ignore lines with hashbangs Jun 23, 2022
@ota-meshi
Copy link
Member

I don't think it makes sense to use hashbangs in vue files.

@ota-meshi ota-meshi closed this as not planned Won't fix, can't repro, duplicate, stale Jun 23, 2022
@silverwind
Copy link
Author

silverwind commented Jun 23, 2022

It doesn't and I'd actually like to restrict the parser to just .vue files, but through the invasive way in which eslint-plugin-vue re-configures the eslint parser, this parser is used for all files including node scripts with hashbang, not just .vue and I haven't found a way yet on how to restrict this parser.

@ota-meshi
Copy link
Member

Please provide a minimal repository to reproduce the problem.

@silverwind
Copy link
Author

silverwind commented Jun 23, 2022

I already worked around the issue:

overrides:
  - files: ["**/*.vue"]
    parser: vue-eslint-parser

Arguably, this is how eslint-plugin-vue should probably do it as well, not replace the parser for all files, but only those that need it.

@silverwind
Copy link
Author

silverwind commented Jun 23, 2022

If you want to reproduce:

git clone --depth 1 https://github.com/go-gitea/gitea && cd gitea && npm install && npx eslint build/*.js

This will reproduce until go-gitea/gitea#20113 is merged.

@ota-meshi
Copy link
Member

Your problem is with eslint-module-utils (eslint-plugin-import rules).
Adding import/no-unused-modules: [0] will work.
You need to report the issue to eslint-plugin-import.

@ota-meshi
Copy link
Member

You seem to be aware of it already.

import-js/eslint-plugin-import#1369

@silverwind
Copy link
Author

Yeah, import-js/eslint-plugin-import#2431 will fix it in eslint-module-utils, but I don't see that module in the dependencies of vue-eslint-parser, so I have my doubts whether that PR will fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants