Extending jshint with custom checks

眉间皱痕 提交于 2019-12-12 08:24:28

问题


In the Python world there are multiple static code analysis tools that can be easily extended with custom checks via writing plugins or extensions, for example:

  • pylint
  • flake8

In the JavaScript world, as far as I understand, jshint is the number one tool for static code analysis. I've been using it for a while and it definitely helps to find lots of code style violations, but, recently, I've encountered the need to extend jshint with a custom check. How can I do that? Is it extendable?


I've looked through the documentation and the only thing I've found is how to write a custom reporter which is not what I'm looking for.

As a workaround, I guess I can fork the jshint repo, implement the check, and use the fork in the project maintaining updates from the upstream.


回答1:


The ability to create custom JSHint rules has been discussed on the JSHint Google group, but that thread has had no activity in 17 months. Your only at this time is to use ESLint. ESLint was created with the explicit purpose of making each of the JSHint rules pluggable, and I think at this time, every JSHint rules is available in ESLint.




回答2:


If I were you I would try to use something like ESLint. The ES stands for ECMAScript, which is where the rules for the JS language come from. Every single rule in ESLint is standalone (so you can use what you like), and you can use the default rules as a guideline or skeleton to create your own rule and plug it in.

Try ESLint.



来源:https://stackoverflow.com/questions/27278003/extending-jshint-with-custom-checks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!