Skip to content
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

[Feature Request] Allow specifying parser per file extension #8543

Closed
weikinhuang opened this issue May 4, 2017 · 9 comments
Closed

[Feature Request] Allow specifying parser per file extension #8543

weikinhuang opened this issue May 4, 2017 · 9 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion

Comments

@weikinhuang
Copy link

Tell us about your environment

  • ESLint Version: ^3.x.x
  • Node Version: latest
  • npm Version: latest

What parser (default, Babel-ESLint, etc.) are you using?
babel-eslint & typescript-eslint

Proposal
It would be beneficial to include the ability for eslint to determine which parser to use based on file extension so that eslint can be run against a multi-language codebase in a single pass. By extension this would also benefit text editors that can't currently specify multiple configs so that a single config can be used to check the entire project.

Right now, I am running eslint once for JS(X), and again for Typescript each using a different parser since the ts-parser doesn't support most stage-X ecma features and the babel-parser doesn't support TS syntax.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label May 4, 2017
@kaicataldo kaicataldo added core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels May 4, 2017
@kaicataldo
Copy link
Member

kaicataldo commented May 4, 2017

This does seem useful to me now that we're actively supporting more parsers (TypeScript, Babel, and now Vue!).

One idea: the parser option could accept an object that maps the parser to a filetype and its parser options:

{
  "parser": {
    "typescript-eslint-parser": {
      "filetypes": [".ts"],
      "parserOptions": {}
    },
    "vue-eslint-parser": {
      "filetypes": [".vue", ".js"],
      "parserOptions": {}
    }
  }
}

Curious what other team members think!

@platinumazure
Copy link
Member

@kaicataldo What happens if multiple parsers are listed as supporting the same file type(s)?

@kaicataldo
Copy link
Member

kaicataldo commented May 4, 2017

What do you think the most expected behavior would be? Seems to me like it should throw an error.

@platinumazure
Copy link
Member

platinumazure commented May 5, 2017 via email

@kaicataldo
Copy link
Member

@platinumazure To be honest, I don't quite know what means! Mind sharing some examples?

@platinumazure
Copy link
Member

platinumazure commented May 5, 2017

@kaicataldo Sorry, see #3611. Basically #3611 feels like a generalization of my file-extension-based proposal.

Example of what I meant for parsers:

"parser": {
    "js": {
        "parser": "espree",
        "parserOptions": {}
    },
    "ts": {
        "parser": "typescript-eslint-parser",
        "parserOptions": {}
    }
}

Where that proposal falls apart is if you have multiple file types that need the same parser. Then a glob-based config approach might work better since you just specify config overrides for uncommon cases:

{
    "parser": "espree",
    "parserOptions": {},
    "overrides": {
        "*.ts": {
            "parser": "typescript-eslint-parser",
            // For this example we'll assume no parserOptions need to change
            "rules": {} // Override rules as well for TS files. Basically any config option can be modified here
        }
    }
}

But I'm not 100% sure what the glob-based config proposal actually looks like.

@mightyiam
Copy link

I have just released a package that should provide this feature. Please try! Bug reports, feature requests and pull requests are warmly welcomed!
https://www.npmjs.com/package/eslint-multiple-parsers

@kaicataldo
Copy link
Member

I believe this is now supported with glob configuration!

@mightyiam
Copy link

Great. Now I know how to deprecate an npm package.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Apr 2, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion
Projects
None yet
Development

No branches or pull requests

5 participants