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

Docs: Add doc on parser services (fixes #8390) #8795

Merged
merged 5 commits into from Jun 26, 2017

Conversation

VictorHom
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[X] Documentation update

What changes did you make? (Give an overview)
Added documentation on parser services. The associated issue can be found at #8390

Is there anything you'd like reviewers to focus on?
Any details to add

@mention-bot
Copy link

@VictorHom, thanks for your PR! By analyzing the history of the files in this pull request, we identified @nzakas, @lo1tuma and @ilyavolodin to be potential reviewers.

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM


### Working with Custom Parsers

If you want to use your own parser and provide additional capabilities for your rules, you can specify your own customer parser. By default, the ESLint parser will use its parse method that takes in the source code as a first parameter and additional optional parameters as a second parameter to create an AST. You can specify a `parse` configuration to use your own custom parser. The parse configuration expects a `parseForESLint` method to be exposed. `parseForESLint` behaves like `parse` and takes in the the source code and optional ESLint configurations. When `parseForESLint` is called, the method should return an object that contains the required property `ast` and an optional `services` property. `ast` should contain the AST. The `services` property contains the parser-dependent services. The value of the service property is available to rules as `context.parserServices`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's correct to say "parse configration expects a parseForESLint method to be exposed." If it's exposed - we'll use it, if not, we'll fall back to parse method as explained below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be nice to provide an example of what might be in the parser services. For example, typescript parser exposes methods to get native errors (I think).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmm I looked for services in https://github.com/eslint/typescript-eslint-parser and didn't see sign of the project adding a services value. I don't have a good example elsewhere.

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

Copy link
Member

@ilyavolodin ilyavolodin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for PR.

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: s/customer parser/custom parser

Apologies for putting this here rather than inline: the mobile GitHub review interface seems to be buggy right now.

@@ -221,7 +221,7 @@ Add these keywords into your `package.json` file to make it easy for others to f

### Working with Custom Parsers

If you want to use your own parser and provide additional capabilities for your rules, you can specify your own customer parser. By default, the ESLint parser will use its parse method that takes in the source code as a first parameter and additional optional parameters as a second parameter to create an AST. You can specify a `parse` configuration to use your own custom parser. The parse configuration expects a `parseForESLint` method to be exposed. `parseForESLint` behaves like `parse` and takes in the the source code and optional ESLint configurations. When `parseForESLint` is called, the method should return an object that contains the required property `ast` and an optional `services` property. `ast` should contain the AST. The `services` property contains the parser-dependent services. The value of the service property is available to rules as `context.parserServices`
If you want to use your own parser and provide additional capabilities for your rules, you can specify your own customer parser. By default, the ESLint parser will use its parse method that takes in the source code as a first parameter and additional optional parameters as a second parameter to create an AST. You can specify a `parse` configuration to use your own custom parser. If a `parseForESLint` method is exposed, this method will be used to parse. Otherwise, the parser will use the parse method. `parseForESLint` behaves like `parse` and takes in the the source code and optional ESLint configurations. When `parseForESLint` is called, the method should return an object that contains the required property `ast` and an optional `services` property. `ast` should contain the AST. The `services` property contains the parser-dependent services. The value of the service property is available to rules as `context.parserServices`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: s/customer parser/custom parser

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

@eslintbot
Copy link

LGTM

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants