我应该使用JSLint或JSHint JavaScript验证吗? [英] Should I use JSLint or JSHint JavaScript validation?

查看:108
本文介绍了我应该使用JSLint或JSHint JavaScript验证吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在针对JSLint验证我的JavaScript并取得进展,它正在帮助我编写更好的JavaScript - 特别是在使用Jquery库时。

I am currently validating my JavaScript against JSLint and making progress on, it's assisting me to write better JavaScript - in particular in working with the Jquery library.

我有现在遇到 JSHint ,一个 JSLint 的分支。

所以我想知道是非常多的JavaScript驱动的Web应用程序,这是更好或最适用的验证工具:

I have now come across JSHint, a fork of JSLint.
So I am wondering for web applications, which are very much JavaScript was driven, which is the better or most applicable validation tool to work against:


  • JSLint或JSHint?

我想现在决定验证机制并继续前进,将其用于客户端验证。

I want to decide now on a validation mechanism and moving forward, use this for client side validation.

和jshint和jslint之间的区别?请在单个javascript示例中解释。

And Difference between jshint and jslint? Please explain in single javascript example.

链接:


  1. jshint - http://www.jshint.com/

jslint - http://jslint.com/


推荐答案



这个答案有已被编辑。我将离开下面的原始答案以获取上下文(否则评论没有意义)。


This answer has been edited. I'm leaving the original answer below for context (otherwise the comments wouldn't make sense).

当最初询问此问题时,JSLint是主要的linting工具JavaScript的。 JSHint是JSLint的一个新分支,但还没有与原来的分歧很多。

When this question was originally asked, JSLint was the main linting tool for JavaScript. JSHint was a new fork of JSLint, but had not yet diverged much from the original.

从那以后,JSLint一直保持静态,而JSHint已经改变了很多 - 它抛弃了许多JSLint更多的对抗规则,增加了一大堆新规则,并且通常变得更加灵活。此外,另一个工具ESLint现在可用,它更灵活,有更多规则选项。

Since then, JSLint has remained pretty much static, while JSHint has changed a great deal - it has thrown away many of JSLint's more antagonistic rules, has added a whole load of new rules, and has generally become more flexible. Also, another tool ESLint is now available, which is even more flexible and has more rule options.

在我的原始答案中,我说你不应强迫自己坚持JSLint的规则;只要你理解为什么它会发出警告,你就可以自己判断是否要改变代码来解决警告。

In my original answer, I said that you should not force yourself to stick to JSLint's rules; as long as you understood why it was throwing a warning, you could make a judgement for yourself about whether to change the code to resolve the warning or not.

用超从2011开始的JSLint的严格规则集,这是合理的建议 - 我看到很少有JavaScript代码集可以通过JSLint测试。然而,在今天的JSHint和ESLint工具中提供了更实用的规则,尝试让代码通过零警告是一个更现实的主张。

With the ultra-strict ruleset of JSLint from 2011, this was reasonable advice -- I've seen very few JavaScript codesets that could pass a JSLint test. However with the more pragmatic rules available in today's JSHint and ESLint tools, it is a much more realistic proposition to try to get your code passing through them with zero warnings.

那里可能仍然偶尔会出现这样的情况,即linter会抱怨你有意做过的事情 - 例如,你知道你应该总是使用 === 但只是这一个你有充分的理由使用 == 。但即便如此,使用ESLint,您可以选择在相关行周围指定 eslint-disable ,这样您仍然可以通过零警告进行通过lint测试,其余的你的代码遵守规则。 (只是不经常这样做!)

There may still occasionally be cases where a linter will complain about something that you've done intentionally -- for example, you know that you should always use === but just this one time you have a good reason to use ==. But even then, with ESLint you have the option to specify eslint-disable around the line in question so you can still have a passing lint test with zero warnings, with the rest of your code obeying the rule. (just don't do that kind of thing too often!)

[原始答案]

一定要使用JSLint。但是不要挂在结果上并修复它所警告的一切。它将帮助您改进代码,它将帮助您找到潜在的错误,但不是JSLint抱怨的所有内容都证明是一个真正的问题,所以不要觉得您必须在零警告的情况下完成该过程。

By all means use JSLint. But don't get hung up on the results and on fixing everything that it warns about. It will help you improve your code, and it will help you find potential bugs, but not everything that JSLint complains about turns out to be a real problem, so don't feel like you have to complete the process with zero warnings.

几乎所有具有任何显着长度或复杂性的Javascript代码都会在JSLint中产生警告,无论它写得多好。如果您不相信我,请尝试通过它运行一些流行的库,如JQuery。

Pretty much any Javascript code with any significant length or complexity will produce warnings in JSLint, no matter how well written it is. If you don't believe me, try running some popular libraries like JQuery through it.

有些JSLint警告比其他更有价值:了解哪些值得注意,哪些不太重要。应该考虑每个警告,但不要觉得有必要修改你的代码以清除任何给定的警告;看完代码并决定你对它感到满意是完全可以的;有时JSlint不喜欢的东西实际上是正确的。

Some JSLint warnings are more valuable than others: learn which ones to watch out for, and which ones are less important. Every warning should be considered, but don't feel obliged to fix your code to clear any given warning; it's perfectly okay to look at the code and decide you're happy with it; there are times when things that JSlint doesn't like are actually the right thing to do.

这篇关于我应该使用JSLint或JSHint JavaScript验证吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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