将JsHint与Angular一起使用时,忽略角度样式 [英] Using JsHint with Angular, ignore angular styles

查看:63
本文介绍了将JsHint与Angular一起使用时,忽略角度样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用angular,并且想使用JSHint.但是,我收到了很多警告,例如'$' is not defined.,这在角度上是正确的,但JSHint不知道这一点.

是否有一种方法可以忽略某些特定的错误(因为这种$错误经常发生),或者对于Angular的JS有更好的选择吗?

解决方案

JsHint允许您跨源代码和每个文件定义全局变量.

您可以添加.jshintrc文件并放入以下代码段,这将影响您的整个代码

{"predef": [ "$" ]}

第二种选择是添加 /* global $ */作为有问题文件顶部的注释.

请参见 http://jshint.com/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 http://jshint.com/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一起使用时,忽略角度样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆