question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal for Parser Services

See original GitHub issue

Problem

JavaScript dialects like Flow and TypeScript often have additional utilities that can be used for various purposes (i.e., a type checker). Currently, there is no way to easily expose these utilities to rules, as they sometimes require access to the state information that created the AST (the TypeScript type checker is like this). This cuts off ESLint rules from useful utilities.

Background Discussions

https://github.com/eslint/typescript-eslint-parser/issues/61#issuecomment-241567437 https://github.com/eslint/eslint/issues/5040#issuecomment-174206925

Proposal

tl;dr Allow parsers to optionally export parser services that can be retrieved through a new method on the context object.

First, allow parsers to expose a special parseForESLint() method in addition to the de facto standard parse() method. The parseForESLint() method would receive the same argument as parse(), but would return an object in this form:

{
    ast: ast,     // the AST as returned from parse()
    services: {
        serviceName: someObject     // a service to provide to rules
    }
}

If parseForESLint() is found, that will be used by ESLint, otherwise parse() is used. Doing this allows us to add additional ESLint-specific properties without needing to add them on an ESTree structure (where they don’t belong). This also opens up the possibility of adding other ESLint-specific functionality in this return object in the future.

Then, we’d add a context.getParserService() method context.parserServices object such that you can use it in a rule like this:

var service = context.parserServices.serviceName;

There would be no restrictions on the type or format of services that can be exposed through this mechanism. It’s completely free-form.


I’d love to get some feedback on this proposal from @JamesHenry @jeffmo @hzoo @alexeagle

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:26 (22 by maintainers)

github_iconTop GitHub Comments

1reaction
nzakascommented, Sep 2, 2016

@alberto the parse is present for other tools to use in an Esprima-compatible way. The parseForESLint name is specific so it signals that it’s not a appropriate for other tools to use.

1reaction
albertocommented, Aug 26, 2016

Do parsers really need to provide a different method instead of us checking for the presence of the services property?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nusii Proposals + Web Parser by Zapier Integrations
Set up the Nusii Proposals trigger, and make magic happen automatically in Web Parser by Zapier. Zapier's automation tools make it easy to...
Read more >
Parsing an RFP into a proposal outline - PropLibrary
To prepare your proposal you have to create an outline based on what they have described. You have to decide what topics should...
Read more >
Parser evaluation: a survey and a new proposal - ResearchGate
PDF | Abstract We present a critical overview of the state-of-the-art in parser evaluation methodologies and metrics. A discussion of their ...
Read more >
Zbizlink Reviews - Pros & Cons, Ratings & more | GetApp
It saves hours of work on your proposals. It helps you choose the right opportunities, partners, and resources. Cons. Sometime resume parser needs...
Read more >
Proposal Parser – Developex blog
It can take template data from different sources, including WebServices of popular Netsuite .com system. Used Technologies: PHP/MySQL. Click ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found