将JsHint与Angular一起使用时,忽略角度样式

编程入门 行业动态 更新时间:2024-10-25 14:27:47
本文介绍了将JsHint与Angular一起使用时,忽略角度样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用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一起使用时,忽略角度样式

本文发布于:2023-11-24 05:38:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624128.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:样式   角度   JsHint   Angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!