eclipse的js校验插件

1. JSLint
JavaScript 作为一门语法灵活多变且对格式要求相对松散的语言,代码格式的混乱和某些语言特性的不正确使用,往往使得最终交付的产品中包含许多因编码风格约定造成的未 预见的行为或错误,这种习惯性的问题如果不及时指出并修改,往往会在项目的迭代过程中不断的重现,严重影响 Web 产品的稳定性与安全性。  JSLint 正是 Douglas Crockford 为解决此类问题创建的工具,JSLint 除了能指出这些不合理的约定,还能标出结构方面的问题。虽然 JSLint 不能保证代码逻辑一定正确,但却有助于发现错误并教会开发人员一些好的编码实践。值得一提的是 JSLint 工具本身也是一段 JavaScript 代码,它是检验 JavaScript 代码质量的 JavaScript 脚本。
  JSLint 对 JavaScript 脚本的质量检测主要包括以下几个方面:

  • 检测语法错误:例如大括号“{}”的配对错误。
  • 变量定义规范:例如未定义变量的检测。
  • 代码格式规范:例如句末分号的缺失。
  • 蹩脚语言特性的使用检测:如 eval 和 with 的使用限制。

  目前,与 JSLint 功能类似的 JavaScript 代码检测工具有很多,包括:YUI Test、Firebug、MS Script Debugger 、CompanionJS 等等,它们中大多数都是以浏览器插件的形式存在于客户端浏览器进行 JavaScript 运行时的检测和调试,JSLint 与这些工具的重要区别在于其更加注重静态代码格式的检测,而这也正是当前火热的敏捷开发中持续构建所需要和提倡的。
Eclipse安装JSLint插件的几种方法  笔者在安装JSLint的时候参考了网上的几种方法,现整理如下:
  方法一:

Step One: Open Eclipse up on your machine and go to ‘Help’ -> ‘Install New Software’
Step Two: Click ‘add’ and to stuff the location with the following link:


 

https://svn.codespot.com/a/eclipselabs.org/mobile-web-development-with-phonegap/tags/jslint4java1/download then click ‘ok’.
Step Three: Selecting ‘Javascript Development Tools’ and ‘jslint4java’ and click next.




  方法二:

Step One: Download jslint4java
Step Two: Put jslint4java.jar somewhere
Step Three: Add an external tool configuration in Eclipse:
                   Location: /usr/bin/java(or your path to javaw.exe)
                   Arguments: -jar /path/to/jslint4java.jar ${resource_loc}




  方法三:

1. Help -> Install new software
2. Click the 'Add' button
    Name : Rockstar Apps (or whatever you want)
    Location : http://update.rockstarapps.com/site.xml
3. expend the selection and check Rockstar JsLint
4. Click 'Next'...again
5. Accept and install
    (you'll have to hit okay when it prompts you about installing unsigned content).
6. Restart Eclipse...




资料参考  1、http://www.ibm.com/developerworks/cn/web/1105_linlin_jslint/
  2、http://stackoverflow.com/questions/2741058/jslint-eclipse-plugin
  3、http://www.andyjamesdavies.com/javascript/installing-jslint-on-eclipse-ide

转自:http://www.cnblogs.com/lhb25/archive/2012/02/20/jslint-eclipse-plugin.html


2.   JSHint

之前使用 JSlint 来校验 JavaScript 代码,发现灵活性不够,因此改用 JSHint。按照官方的说法,JSHint 是一个社区驱动(community-driven)的工具,用于检测JavaScript代码中的错误和潜在的问题,规范编码风格,确保代码的质量。 JSHint在JSLint的基础上做了很多改进,让开发人员可以自己定义校验选项。



JSHint Home: http://www.jshint.com/
JSHint Options: http://www.jshint.com/options/
JSHint For Eclipse: http://github.eclipsesource.com/jshint-eclipse/
安装方法最新稳定版本更新网址:
http://github.eclipsesource.com/jshint-eclipse/updates/

  • 在Eclipse主菜单,点击: Help > Install New Software…
  • 输入上面的URL,然后选择 JSHint Eclipse Integration
  • 后面的安装过程很简单,往下按确定就可以了

更新方法如果已经安装了,则可以更新:

  • 在Eclipse主菜单,点击: Help > Check for Updates

卸载方法按如下方式即可卸载:

  • 在Eclipse主菜单,点击: Help > About Eclipse > Installation Details
  • 选择 JSHint Eclipse Integration,点击 Uninstall

使用方法选择要启用校验的项目,右键->属性,选择JSHint 项,配置启用校验的文件和文件夹,配置文件的示例如下:



转自:http://www.cnblogs.com/lhb25/archive/2012/04/05/javascript-validation-with-jshint-eclipse.html

配置参考地址

http://zhang.zipeng.info/vimwiki/Entries/Reference/Tools/jshint.html

猜你喜欢

转载自blog.csdn.net/luo4566/article/details/84343886