简体   繁体   English

linter和验证器有什么区别?

[英]What is the difference between a linter and a validator?

I'm working on organizing some things and wanted to combined these two sets. 我正在组织一些事情,并希望将这两组结合起来。 In fact I don't know of any other validator besides the W3 - http://validator.w3.org/ 实际上除了W3之外我不知道任何其他验证器 - http://validator.w3.org/

Linters - jslint | jshint | eslint
Validators - w3

Is there any difference between these 2 types of tools. 这两种工具之间有什么区别吗? Both just look at the code statically and test it against a set syntax correct ? 两者只是静态地查看代码并根据设置语法对其进行测试?

A lint program checks for suspicious or dangerous code, and checks the code against styling guidelines. lint程序检查可疑或危险的代码,并根据样式指南检查代码。 A linter must be able to parse the code, so it also validates against a language spec. linter必须能够解析代码,因此它还可以根据语言规范进行验证。 Therefore, to a degree, a linter is a validator plus extra stuff. 因此,在某种程度上,linter是验证器加上额外的东西。

A validator program verifies the code adheres to language specifications. 验证程序验证代码是否符合语言规范。 It doesn't care about style or logic. 它不关心风格或逻辑。

Examples of things caught by a linter, but not by a validator: 由linter捕获但不是由验证器捕获的事物的示例:

  • Division by zero (its valid syntax, so it passes the validator). 除以零(其有效语法,因此它传递验证器)。
  • Using a variable before its been declared or populated (again, valid syntax). 在声明或填充之前使用变量(再次,有效语法)。
  • Detecting out-of-bounds problems with array indexing (again, valid syntax). 使用数组索引检测越界问题(同样,有效语法)。
  • Style issues (same thing) 风格问题(同样的事情)
  • Code like if (x = 3) { } is valid syntax in many languages, and will pass a validator. if (x = 3) { }是许多语言中的有效语法,并且将传递验证器。 A linter will say "hey, what are you doing, bro? this doesn't look right to me." 一个linter会说“嘿,你在做什么,兄弟?这对我来说不合适。” (an example of suspicious code) (可疑代码示例)

A lint looks for syntax and other problems. lint寻找语法和其他问题。 Validators look for compliance with particular specifications. 验证器寻求符合特定规范。

Linters make sure that code is properly formed and syntaxed as to prevent bugs - usually in realtime or upon save/compile. Linters确保代码正确形成并进行语法化以防止错误 - 通常是实时或保存/编译。

Validators (in the case of W3) make sure that the markup adheres to the rules defined for that specific doctype. 验证器(在W3的情况下)确保标记符合为该特定doctype定义的规则。

There is overlap between the two (as they are both intended to help preempt bugs, but a Linter is typically far more exhaustive.) 两者之间存在重叠(因为它们都旨在帮助预防错误,但是Linter通常更为详尽。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM