基于Javascript的HTML/CSS代码检查工具

5
有没有像JSLINT一样基于JavaScript的html/css检查器?

3
为什么要使用基于JavaScript的检查器?W3C验证器或CSS Tidy有什么问题吗? - questzen
只是为了个人项目,但我想没有问题。 - Corey Hart
5个回答

6

本来想找基于JS的,但是既然没有,我猜这个就只能用了。 - Corey Hart
有一个NPM包可以调用W3C验证服务:https://github.com/nikestep/html-angular-validate - 它专门用于验证使用AngularJS的HTML,但如果需要,您可以设置angular:false。它也可作为grunt插件gulp插件使用。 - FiniteLooper

2

更新信息

以下是后者的一个示例错误信息:

C:\dev\html>cscript //E:JScript c:\users\dino\bin\csslint-wsh.js --format=compiler style\basic.css

CSSLINT
style\basic.css(5,1) CSSLINT: warning: Heading (h1) has already been defined.
h1           { font-size: 20pt }
style\basic.css(6,1) CSSLINT: warning: Heading (h2) has already been defined.
h2           { font-size: 18pt; font-weight:bold; color: navy }
style\basic.css(7,1) CSSLINT: warning: Heading (h3) has already been defined.
h3           { font-size: 16pt; font-weight:bold; color: #483d8b;}
style\basic.css(8,1) CSSLINT: warning: Heading (h4) has already been defined.
h4           { font-size: 14pt; font-weight:bold; color:#C71585; margin-bottom:2px; }
style\basic.css(9,1) CSSLINT: warning: Heading (h5) has already been defined.
h5           { font-size: 12pt; font-weight:bold; color:#6495ED; margin-bottom:2px; }
style\basic.css(10,1) CSSLINT: warning: Heading (h6) has already been defined.
h6           { font-size: 10pt; font-weight:bold; color:navy }
style\basic.css(12,1) CSSLINT: warning: Element (td.head) is overqualified, just use .head without element name.
td.head      { font-size: 12pt; color: #c71585;   font-weight: bold; }
style\basic.css(39,4) CSSLINT: warning: Broken box model: using width with padding.
   width: 48%;
style\basic.css(44,4) CSSLINT: warning: Broken box model: using width with border.
   margin: 0.2em 0 0.2em 0;

在使用带有flymake的Emacs时的示例:

在此输入图片描述


我再怎么感谢你提供的可以在Windows上轻松使用的CSSLint版本的链接都不为过!我曾经尝试了一段时间的Node.js,但是在解析一个80k的*.css文件时因为内存不足而放弃了。 - Michael12345

2

1

0

最近我开始使用grunt-html,经过几个小时的调试后才发现我漏掉了一个闭合括号>,导致我的html-minifier挂起。

我不确定它是否完美,也不指望它能百分之百符合W3C标准。但它确实有助于捕捉语法/简单错误。

我还发现了一个W3C变体grunt-html-validation


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接