Skip to content

Parser should ignore lines with hashbangs #161

Not planned
@silverwind

Description

@silverwind

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.

Activity

changed the title [-]Parser should ignore files with hashbangs[/-] [+]Parser should ignore lines with hashbangs[/+] on Jun 23, 2022
ota-meshi

ota-meshi commented on Jun 23, 2022

@ota-meshi
Member

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

silverwind

silverwind commented on Jun 23, 2022

@silverwind
Author

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

ota-meshi commented on Jun 23, 2022

@ota-meshi
Member

Please provide a minimal repository to reproduce the problem.

silverwind

silverwind commented on Jun 23, 2022

@silverwind
Author

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

silverwind commented on Jun 23, 2022

@silverwind
Author

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

ota-meshi commented on Jun 24, 2022

@ota-meshi
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

ota-meshi commented on Jun 24, 2022

@ota-meshi
Member

You seem to be aware of it already.

import-js/eslint-plugin-import#1369

silverwind

silverwind commented on Jul 11, 2022

@silverwind
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @silverwind@ota-meshi

        Issue actions

          Parser should ignore lines with hashbangs · Issue #161 · vuejs/vue-eslint-parser