JSLint for eclipse 安装以及setting 说明

来源:互联网 发布:怎么注册多个淘宝账号 编辑:程序博客网 时间:2024/05/20 06:26

JSLint is a JavaScript program that looks for problems in JavaScript programs. It is acode quality tool

how to use JSLintfor  Eclipse

Installation

Step One:Open Eclipse up on your machine and go to‘Help’ -> ‘Install New Software’


Step Two: Click ‘add’ on the popup and youwill have the screen as below. 

With that screen where it says location add the following link:

https://svn.codespot.com/a/eclipselabs.org/mobile-web-development-with-

phonegap/tags/jslint4java1/download 

then click ‘ok’.




Step Three: Once the information has loadedchoose the options as shown

 on the next screen below selecting ‘jslint4java’

 and click next. If have not install ‘Javascript Development Tools’, selected it too.



Step Four: Keep clicking next, you may have toaccept any license terms 

and during installation you will get the screen

 below,don’t worry, just click ‘ok’.




StepFive: OpenEclipseup on your machine and go to‘window’->‘preferences’,

click the item ‘jslint4java’

Checked some checkbox and input forsetting 





StepFix: choosea project ,clicktheenablejslint4java,check the eclipse head  menu, 

clickproject ->clean… ,then click project->Build project . 

If you have many builder, you can chooseonly one builder by 

right click projectname ->  properties ->Builders



If you only need one builder ,you canedit the .project file of one project

Edit the file content as follow 

<?xml version="1.0" encoding="UTF-8"?><projectDescription><name>mr</name><comment></comment><projects></projects><buildSpec><buildCommand><name>com.googlecode.jslint4java.eclipse.jsLintBuilder</name><arguments></arguments></buildCommand></buildSpec><natures><nature>com.googlecode.jslint4java.eclipse.jsLintNature</nature></natures></projectDescription>


JSLint Setting

Filter code

describe

other

adsafe

If adsafe rules should be enforced

是否Verify第三方的JS库Adsafe。

bitwise

If bitwise operators should be allowed

如果为真,SHint会禁用位运算符 Javascript允许位运算,但是他却没有整型,位运算符要把参与运算的数字从浮点数变为整数,并在运算后再转换回来。这样他们的效率就不如在别的语言中那么高。

browser

If the standard browser globals should be predefined

是否标准的浏览器全局变量应该预先定义。

cap

If upper case html should be allowed

是否允许大写html标签。

confusion

If types can be used inconsistently

是否变量使用类型一致。

continue

If the continuation statement should be tolerated

是否允许连续的声明。

css

If css workarounds should be tolerated

是否允许Css域。

debug

If debugger statements should be allowed

是否允许调试器声明。

devel

If logging should be allowed (console, alert, etc.)

是否允许调试js。

eqeqeq

If === should be allowed

如果为真,JSLint会看你在代码中是否都用了===或者是!==,而不是使用==和!=。


Filter code

describe

other

es5

If es5 syntax should be allowed

是否允许ECMAScript 5语法

evil

If eval should be allowed

如果为真,JSLint会允许使用eval eval提供了访问Javascript编译器的途径,这有时很有用,但是同时也对你的代码形成了注入攻击的危险,并且会对debug造成一些困难。 记住,Function构造函数也是另一个‘eval’,另外,当传入的参数是字符串的时候,setTimeout和setInterval也会类似于eval。

forin

If for in statements need not filter

如果为真,那么,JSHint允许在for in 循环里面不出现hasOwnProperty, for in循环一般用来遍历一个对象的属性,这其中也包括他继承自原型链的属性,而hasOwnProperty可以来判断一个属性是否是对象本身的属性而不是继承得来的。

immed

If immediate invocations must be wrapped  in parens

如果为真,JSLint要求匿名函数的调用如下:

(function(){ // }());而不是

(function(){ //bla bla })();

laxbreak

if statement breaks should not be checked

如果为真,JSLint则不会检查换行。 Javascript会通过自动补充分号来修正一些错误,因此这个选项可以检查一些潜在的问题。

newcap

If constructor names capitalization is ignored

如果为真,JSLint会要求每一个构造函数名都要大写字母开头。


Filter code

describe

other

nomen

If names may have dangling _

如果为真,JSHint会禁用下划线的变量名。 很多人使用_name的方式来命名他们的变量,以说明这是一个私有变量,但实际上,并不是,下划线只是做了一个标识。 如果要使用私有变量,可以使用闭包来实现。

on

If html event handlers should be allowed

是否允许html事件处理程序。

onevar

if only one var statement per function is allowed.

如果为真,JSLint期望函数只被var的形式声明一遍。

passfail

If the scan should stop on first error

如果为真,JSHint会在发现首个错误后停止检查。

plusplus

If increment/decrement should be allowed

如果为真,JSHint会禁用自增运算和自减运算 ++和--可能会带来一些代码的阅读上的困惑。

regexp

If the . should be allowed in regexp literals

如果为真,JSHint会不允许使用.和[^...]的正则, 因为这样的正则往往会匹配到你不期望的内容,并可能会应用造成一些危害。

rhino

If the rhino environment globals should be predefined

是否Rhino的环境全局变量应该预先定义。

safe

If use of some browser features should be restricted

如果使用一些浏览器特性应该被限制。

strict

If the 'use strict'; pragma is optional

如果为真,JSHint会要求你使用use strict;语法。 Strict 模式是ES5里面的一个新特性,他允许你把一个程序或者函数放在一个“严格”的作用域中。ECMAScript 5


Other setting

describe

the mumber of spaces used for indentation

规定代码之间的空格数

The maximum number  of warnings reported

最大显示错误数

Maximum line length

每行最大字符数

The names of predefined global variables

预先定义的全局变量


references


Jlint 官网 http://www.jslint.com/lint.html

google 代码规范 http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml

jquery 代码规范http://contribute.jquery.org/style-guide/js/




原创粉丝点击