zoukankan      html  css  js  c++  java
  • 用JSLint+Ant检验HTML代码

    文章转自:hikejun.com/blog/?p=31

    JSLint真是一个强大的工具。之前只是关注它对Javascript的作用方面,其实它同样可以检验HTML代码以及内联的Javascript代码。

    JSlint应该说跟WDG HTML Validator(http://htmlhelp.com/tools/validator/)的作用不完全一样。JSLint不仅作语法检查,还做写法上的检查。JSLint的出发点是为了保证代码的品质。

    比如在链接里写脚本会报错,如下:
    [apply] Lint 在行 23 字符 14: Script URL.
    [apply]

    ????????

    JSlint在语法检查上不会那么严格,但都是最重要的,比如标签是否对称嵌套,标签是否闭合。(详情见http://www.jslint.com/lint.html

    将检验HTML代码这个任务加入到前端开发Build环节中。但在实践中,我遇到了编码问题,如果源文件是UTF-8的就会有麻烦。迫不得以采取一个笨方法,通过ant的copy任务先将源文件备分为ISO-8859-1编码(ant不支持GBK的转换)的文件,再对它进行校验。之后再统一删除备分文件。

    关于编码问题,文章下面评论有人写到,不知道是否可行?

    slint.js 文件中有个 readFile( 方法(在文件尾部),
    给他加个参数:
    readFile(f,'utf-8')
    即可指定文件编码。

    还有一篇文章:《用 Ant 构建组件

    它的build.xml如下,有涉及编码的问题,可以看一下:

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="Smart Queue" default="compress" basedir=".">
        <description>Build file for Ant</description>
        <property name="src" location="src" />
        <property name="build" location="build" />
            <property name="lib" location="lib"/>
            <property name="inputencoding" value="utf-8"/>
            <property name="outputencoding" value="gbk"/>
    
            <target name="init">
                    <mkdir dir="${build}"/>
            </target>
    
            <target name="concat" depends="init">
                    <concat destfile="${build}/smart-queue.source.js" encoding="${inputencoding}" outputencoding="${outputencoding}">
                            <filelist dir="${src}" files="intro.js, lang.js, smart-queue.js" />
                    </concat>
            </target>
    
            <target name="compress" depends="concat">
                    <java jar="${lib}/yuicompressor.jar" fork="true">
                            <arg line="--type js --charset utf-8 -o ${build}/smart-queue.js ${build}/smart-queue.js"/>
                    </java>
            </target>
    
            <target name="clean">
                    <delete dir="${build}"/>
            </target>
    </project>
  • 相关阅读:
    css3
    css3
    npm 安装包无法继续下载? 卡住
    tcp/ip协议中的SYN, ACK的数值变化
    【转】6 Reasons Why JavaScript’s Async/Await Blows Promises Away (Tutorial)
    ES6 中 Symbol.split的用法
    Why does Typescript use the keyword “export” to make classes and interfaces public?
    es6中的import,export浏览器已经支持
    Understanding the JavaScript Engine—— two phase
    【转】js-ES6学习笔记-Symbol
  • 原文地址:https://www.cnblogs.com/meteoric_cry/p/1821199.html
Copyright © 2011-2022 走看看