我正在使用angular,并且想使用JSHint.但是,我收到了很多警告,例如'$' is not defined.,这在角度上是正确的,但JSHint不知道这一点.
是否有一种方法可以忽略某些特定的错误(因为这种$错误经常发生),或者对于Angular的JS有更好的选择吗?
解决方案JsHint允许您跨源代码和每个文件定义全局变量.
您可以添加.jshintrc文件并放入以下代码段,这将影响您的整个代码
{"predef": [ "$" ]}第二种选择是添加 /* global $ */作为有问题文件顶部的注释.
请参见 jshint/docs/#inline-configuration
总的来说,我更喜欢 eslint .它具有与jshint相同的功能,但也具有非常可扩展的优点.有很多现有的eslint软件包可用于处理特定于角度的掉毛错误,您可以选择编写自己的规则
I am using angular and would like to use JSHint. However, I get a lot of warnings like '$' is not defined., which would be correct in angular but JSHint does not know this.
Is there a way to ignore some certain errors (as this $-error occurs rather often) or is there a better linter for the JS of angular?
解决方案JsHint allows you define globals variables across your source code and a per file basis.
You can add a .jshintrc file and put the following snippet which will effect your entire code
{"predef": [ "$" ]}A second option is to add /* global $ */ as a comment at the top of offending files.
See jshint/docs/#inline-configuration
Over all, I prefer eslint. It has functional parity with jshint, but also has the advantage of being very extensible. There are many existing eslint packages out there for handling angular specific linting errors and you have the option of writing your own rules
更多推荐
将JsHint与Angular一起使用时,忽略角度样式
发布评论