Skip to content

Documentation for creating custom rules #262

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
erindepew opened this issue Nov 28, 2017 · 8 comments
Closed

Documentation for creating custom rules #262

erindepew opened this issue Nov 28, 2017 · 8 comments

Comments

@erindepew
Copy link
Contributor

Thanks for all your work on this!
I would like to write a custom rule just for our use, but can't seem to find any documentation on how to do so. If it already exists can someone point me in the right direction, otherwise I'd be happy to help create some docs!

@mysticatea
Copy link
Member

Thank you for this issue!

Sure, it will be great if some docs exist.

The way to make custom rules is the same as core essentially, but it has additional AST types. The spec of the AST types is here: https://github.com/mysticatea/vue-eslint-parser/blob/master/docs/ast.md

There are some parserServices to traverse the additional AST and to access the tokens of template.

  • context.parserServices.defineTemplateBodyVisitor(visitor, scriptVisitor)
  • context.parserServices.getTemplateBodyTokenStore()

Please see https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/mustache-interpolation-spacing.js as an example.

@danielbastos11
Copy link

ESLint also has a extremely useful page on the subject: https://eslint.org/docs/developer-guide/working-with-rules

@michalsnik
Copy link
Member

I guess the most valuable thing would be to mention how to easily inspect this custom AST @mysticatea. For regular JavaScript there is an excellent http://astexplorer.net but it's not that obvious how to inspect AST generated by vue-eslint-parser. The rest is well described in eslint documentation.

@mysticatea
Copy link
Member

I hope that we can add vue-eslint-parser to http://astexplorer.net after fkling/astexplorer#285.

@michalsnik
Copy link
Member

That would be cool! 💪

@kindy
Copy link

kindy commented Dec 24, 2017

@mysticatea
I think we don't need to wait that PR (that I created for a long time)
but just add vue-eslint-parser in astexplorer now.
you can start the work based on my fork, and send PR latter.

@kindy
Copy link

kindy commented Feb 14, 2018

Hi guys, I just add 'vue-eslint-parser' to my own ast playground, maybe you want to have a look:

https://ast.js.org

then click button "+vue/vue-eslint-parser".

P.S. this tool is at very early stage, feedbacks are welcome.

@michalsnik
Copy link
Member

This is really cool @kindy we might even put it in our documentation. It's really helpful 💪

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

No branches or pull requests

5 participants