nodejs 前端工具总结

htmlhint

https://github.com/yaniswang/HTMLHint

使用

var HTMLHint  = require("htmlhint").HTMLHint;
var messages = HTMLHint.verify(code, options);

选项

{
    'tagname-lowercase': true,
    'attr-lowercase': true,
    'attr-value-double-quotes': true,
    'doctype-first': true,
    'tag-pair': true,
    'spec-char-escape': true,
    'id-unique': true
}

返回

[{
    type: 'error',
    message: 'Id redefinition of [ row ].',
    raw: ' id="row"',
    evidence: '<div id="row" class="clearfix">',
    line: 114,
    col: 5,
    rule:
    {
        id: 'id-unique',
        description: 'Id must be unique.',
        link: 'https://github.com/yaniswang/HTMLHint/wiki/id-unique'
    }   
}]

csslint

https://github.com/stubbornella/csslint

使用

var csslint = require('csslint').CSSLint;
var result = csslint.verify(code, rules);

选项

...

返回

{
    messages:
        [{ type: 'warning',
            line: 1,
            col: 1,
            message: 'The universal selector (*) is known to be slow.',
            evidence: '*{}',
            rule: [Object]
        }],
    stats: [ floats: 0, 'font-sizes': 0, important: 0, 'rule-count': 1 ],
    ruleset: {}
}

jslint

https://github.com/reid/node-jslint

使用

var jslint = require('jslint');
var result = jslint(code);
var data = jslint.data();

选项

anon :true  //匿名函数声明中function关键字与()之间的空白可以被省略
bitwise : true  //允许按位运算
browser : true  //浏览器(标准)是预定义的全局
cap : true  //允许大写的HTML
continue : true  //容忍continuation语句
css : true  //允许检查CSS
debug : true  //允许debuger语句
devel : true  //允许控制台语句console、alert语句
eqeq : true  //允许==和!=运算符
es5 : true  //允许ECMAScript 5 的语法
evil : true  //允许使用eval
forin : true  //for in声明的中的key不需要使用hasOwnProperty过滤
fragment : true  //允许检查HTML片段
indent : 空白缩进的数量,默认建议4个空格
maxerr :  允许做大的错误数,默认是50
maxlen : 允许单行的最大长度
newcap : true  //构造函数的首字母大小写可以被忽略
node : true  //node.js是预定义的全局
nomen : true  //允许标识符以_开头
on : true  //允许在HTML使用类似onclick这样的事件处理
passfail : true  //应该在扫描到第一个错误时停止
plusplus : true  //允许++递增 或 --递减
properties : true  //由于 JavaScript 是松散类型、动态对象的语言,在编译时不可能确定,如果希望检查属性名称拼写,所有内置的属性名称必须写在 /*properties*/中
regexp : true  //允许正则表达式文本中含有.
rhino : true  //假设是在rhino环境中
undef : true  //变量的定义顺序可以是混乱的,比如var a = b.name, b = {name: "b"};
unparam : true  //允许忽略未使用的参数
sloppy : true  //'use strict'标注是可选的
sub : true  //容忍所有的下标表示法,如果属性名是一个合法的标识符,建议用.表示法
vars : true  //允许每个函数有多个var声明
white : true  //容忍多余的空白
widget : true  //假设是在Yahoo Widgets环境中
windows : true  //MS Windows的特定全局应该是预定义的

返回

{
    errors: [
        {
            { id: '(error)',
              raw: 'Unexpected dangling \'_\' in \'{a}\'.',
              evidence: '    environment.bind("touchstart", _onTouchStart);
              line: 25,
              character: 36,
              a: '_onTouchStart',
              b: undefined,
              c: undefined,
              d: undefined,
              reason: 'Unexpected dangling \'_\' in \'_onTouchStart\'.' },
        }
    ]
}

jshint

使用

var JSHINT = require("jshint").JSHINT;
var result = jshint(js);

选项

asi         : true, // if automatic semicolon insertion should be tolerated
bitwise     : true, // if bitwise operators should not be allowed
boss        : true, // if advanced usage of assignments should be allowed
browser     : true, // if the standard browser globals should be predefined
camelcase   : true, // if identifiers should be required in camel case
couch       : true, // if CouchDB globals should be predefined
curly       : true, // if curly braces around all blocks should be required
debug       : true, // if debugger statements should be allowed
devel       : true, // if logging globals should be predefined (console, alert, etc.)
dojo        : true, // if Dojo Toolkit globals should be predefined
eqeqeq      : true, // if === should be required
eqnull      : true, // if == null comparisons should be tolerated
es5         : true, // if ES5 syntax should be allowed
esnext      : true, // if es.next specific syntax should be allowed
evil        : true, // if eval should be allowed
expr        : true, // if ExpressionStatement should be allowed as Programs
forin       : true, // if for in statements must filter
funcscope   : true, // if only function scope should be used for scope tests
gcl         : true, // if JSHint should be compatible with Google Closure Linter
globalstrict: true, // if global "use strict"; should be allowed (also enables 'strict')
immed       : true, // if immediate invocations must be wrapped in parens
iterator    : true, // if the `__iterator__` property should be allowed
jquery      : true, // if jQuery globals should be predefined
lastsemic   : true, // if semicolons may be ommitted for the trailing
                    // statements inside of a one-line blocks.
latedef     : true, // if the use before definition should not be tolerated
laxbreak    : true, // if line breaks should not be checked
laxcomma    : true, // if line breaks should not be checked around commas
loopfunc    : true, // if functions should be allowed to be defined within
                    // loops
mootools    : true, // if MooTools globals should be predefined
multistr    : true, // allow multiline strings
newcap      : true, // if constructor names must be capitalized
noarg       : true, // if arguments.caller and arguments.callee should be
                    // disallowed
node        : true, // if the Node.js environment globals should be
                    // predefined
noempty     : true, // if empty blocks should be disallowed
nonew       : true, // if using `new` for side-effects should be disallowed
nonstandard : true, // if non-standard (but widely adopted) globals should
                    // be predefined
nomen       : true, // if names should be checked
onevar      : true, // if only one var statement per function should be
                    // allowed
passfail    : true, // if the scan should stop on first error
phantom     : true, // if PhantomJS symbols should be allowed
plusplus    : true, // if increment/decrement should not be allowed
proto       : true, // if the `__proto__` property should be allowed
prototypejs : true, // if Prototype and Scriptaculous globals should be
                    // predefined
rhino       : true, // if the Rhino environment globals should be predefined
undef       : true, // if variables should be declared before used
scripturl   : true, // if script-targeted URLs should be tolerated
shadow      : true, // if variable shadowing should be tolerated
smarttabs   : true, // if smarttabs should be tolerated
                    // (http://www.emacswiki.org/emacs/SmartTabs)
strict      : true, // require the "use strict"; pragma
sub         : true, // if all forms of subscript notation are tolerated
supernew    : true, // if `new function () { ... };` and `new Object;`
                    // should be tolerated
trailing    : true, // if trailing whitespace rules apply
validthis   : true, // if 'this' inside a non-constructor function is valid.
                    // This is a function scoped option only.
withstmt    : true, // if with statements should be allowed
white       : true, // if strict whitespace rules apply
worker      : true, // if Web Worker script symbols should be allowed
wsh         : true, // if the Windows Scripting Host environment globals
                    // should be predefined
yui         : true, // YUI variables should be predefined

// Obsolete options
onecase     : true, // if one case switch statements should be allowed
regexp      : true, // if the . should not be allowed in regexp literals
regexdash   : true  // if unescaped first/last dash (-) inside brackets
                    // should be tolerated
// These are the JSHint options that can take any value
// (we use this object to detect invalid options)
maxlen       : false,
indent       : false,
maxerr       : false,
predef       : false,
quotmark     : false, //'single'|'double'|true
scope        : false,
maxstatements: false, // {int} max statements per function
maxdepth     : false, // {int} max nested block depth per function
maxparams    : false, // {int} max params per function
maxcomplexity: false, // {int} max cyclomatic complexity per function
unused       : true  // warn if variables are unused. Available options:
                     //   false    - don't check for unused variables
                     //   true     - "vars" + check last function param
                     //   "vars"   - skip checking unused function params
                     //   "strict" - "vars" + check all function params

返回

{
    errors: [
        {
            { id: '(error)',
              raw: 'Unexpected dangling \'_\' in \'{a}\'.',
              evidence: '    environment.bind("touchstart", _onTouchStart);
              line: 25,
              character: 36,
              a: '_onTouchStart',
              b: undefined,
              c: undefined,
              d: undefined,
              reason: 'Unexpected dangling \'_\' in \'_onTouchStart\'.' },
        }
    ]
}
posted @ 2013-04-10 16:50 Elementstorm 阅读(...) 评论(...) 编辑 收藏