在这篇blog之前写过同类的校验JS代码工具:JavaScript Lint 的在 Notepad++ 中如何使用,google 提供的 Closure Linter 给了我们更多的工具选择。

Closure Linter是在Python上运行的,所以先在系统中配置安装Python的运行环境:

  1. 安装 Python。本人安装的版本为 Python 2.5.4
  2. 安装 Easy Install 模块。也就是要安装 setuptools windows下本人安装的为: setuptools-0.6c11.win32-py2.5.exe
  3. 确保 Easy Install 配置到Path环境变量。

然后,在命令行中执行如下命令:

easy_install E:\closure_linter\closure_linter-2-1.2.6.tar.gz

如果出现啪啦啪啦如下的截图画面:

则说明Closure Linter 安装成功!OK,在Notepad++ 的NppExec执行如下命令:

gjslint --strict $(FULL_CURRENT_PATH)

可以将这个命令保存为 Closure Linter。点击“OK”试试,如果在控制台窗口输出如下结果:

gjslint –-strict D:\work\js\WOYO\event.js
Process started >>>
----- FILE  :  D:\work\js\WOYO\event.js -----
Line 3, E:0217: Missing @return JsDoc in function with non-trivial return
Line 4, E:0002: Missing space before "{"
Line 5, E:0005: Illegal tab in whitespace before "if"
Line 5, E:0002: Missing space before "("
Line 6, E:0005: Illegal tab in whitespace before "return"
Line 7, E:0005: Illegal tab in whitespace before "}"
Line 8, E:0005: Illegal tab in whitespace before "else"
Line 8, E:0002: Missing space before "("
Line 9, E:0005: Illegal tab in whitespace before "var"
Line 9, E:0002: Missing space before "="
Line 9, E:0002: Missing space before "["
Line 9, E:0131: Single-quoted string preferred over double-quoted string.
Line 9, E:0131: Single-quoted string preferred over double-quoted string.
Line 9, E:0131: Single-quoted string preferred over double-quoted string.
Line 10, E:0005: Illegal tab in whitespace before "        "
Line 10, E:0001: Extra space at end of line
Line 11, E:0005: Illegal tab in whitespace before "for"
Line 11, E:0002: Missing space before "("
Line 11, E:0002: Missing space before "="
Line 11, E:0002: Missing space after "="
Line 11, E:0002: Missing space before "<"
Line 11, E:0002: Missing space after "<"
Line 12, E:0005: Illegal tab in whitespace before "try"
Line 13, E:0005: Illegal tab in whitespace before "var"
Line 14, E:0005: Illegal tab in whitespace before "return"
Line 15, E:0005: Illegal tab in whitespace before "}"
Line 16, E:0005: Illegal tab in whitespace before "catch"
Line 16, E:0002: Missing space before "("
Line 16, E:0002: Missing space before "{"
Line 17, E:0005: Illegal tab in whitespace before "//"
Line 18, E:0005: Illegal tab in whitespace before "}"
Line 19, E:0005: Illegal tab in whitespace before "}"
Line 20, E:0005: Illegal tab in whitespace before "}"
Line 21, E:0005: Illegal tab in whitespace before "throw"
Line 21, E:0131: Single-quoted string preferred over double-quoted string.
Line 24, E:0220: No docs found for member 'Ajax.Request'
Line 24, E:0002: Missing space before "{"
Line 25, E:0005: Illegal tab in whitespace before "var"
Line 26, E:0005: Illegal tab in whitespace before "var"
Line 27, E:0005: Illegal tab in whitespace before "if"
Line 27, E:0002: Missing space before "("
Line 28, E:0005: Illegal tab in whitespace before "var"
Line 28, E:0001: Extra space at end of line
Line 29, E:0005: Illegal tab in whitespace before "if"
Line 29, E:0002: Missing space before "("
Line 30, E:0005: Illegal tab in whitespace before "requestType"
Line 31, E:0005: Illegal tab in whitespace before "}"
Line 32, E:0005: Illegal tab in whitespace before "var"
Line 33, E:0005: Illegal tab in whitespace before "req.open"
Line 34, E:0005: Illegal tab in whitespace before "req.onreadystatechange"
Line 35, E:0005: Illegal tab in whitespace before "if"
Line 36, E:0005: Illegal tab in whitespace before "callbackData"
Line 36, E:0002: Missing space after "+"
Line 36, E:0002: Missing space before "+"
Line 37, E:0005: Illegal tab in whitespace before "}"
Line 38, E:0005: Illegal tab in whitespace before "}"
Line 39, E:0005: Illegal tab in whitespace before "this.onSuccess"
Line 39, E:0002: Missing space before "{"
Line 41, E:0002: Missing space before "{"
Line 42, E:0005: Illegal tab in whitespace before "$"
Line 42, E:0002: Missing space before "{"
Line 43, E:0005: Illegal tab in whitespace before "var"
Line 44, E:0005: Illegal tab in whitespace before "url"
Line 45, E:0005: Illegal tab in whitespace before "dataType"
Line 46, E:0005: Illegal tab in whitespace before "}"
Line 47, E:0005: Illegal tab in whitespace before "req.onSuccess"
Line 47, E:0002: Missing space before "{"
Line 48, E:0005: Illegal tab in whitespace before "        "
Line 48, E:0001: Extra space at end of line
Line 49, E:0005: Illegal tab in whitespace before "}"
Line 50, E:0005: Illegal tab in whitespace before "$.ajax"
Line 51, E:0005: Illegal tab in whitespace before "url"
Line 52, E:0005: Illegal tab in whitespace before "dataType"
Line 53, E:0005: Illegal tab in whitespace before "success"
Line 54, E:0005: Illegal tab in whitespace before "$"
Line 55, E:0005: Illegal tab in whitespace before "}"
Line 56, E:0005: Illegal tab in whitespace before "}"
Line 57, E:0005: Illegal tab in whitespace before "return"
Line 58, E:0005: Illegal tab in whitespace before "}"
Line 66, E:0210: Missing docs for parameter: "file"
Line 66, E:0210: Missing docs for parameter: "postData"
Line 67, E:0005: Illegal tab in whitespace before "var"
Line 68, E:0005: Illegal tab in whitespace before "if"
Line 68, E:0002: Missing space before "("
Line 69, E:0005: Illegal tab in whitespace before "req.onreadystatechange"
Line 70, E:0005: Illegal tab in whitespace before "if"
Line 71, E:0005: Illegal tab in whitespace before "if"
Line 72, E:0005: Illegal tab in whitespace before "alert"
Line 73, E:0005: Illegal tab in whitespace before "return"
Line 74, E:0005: Illegal tab in whitespace before "}"
Line 75, E:0005: Illegal tab in whitespace before "        "
Line 75, E:0001: Extra space at end of line
Line 76, E:0005: Illegal tab in whitespace before "updateobj"
Line 76, E:0110: Line too long (94 characters).
Line 77, E:0005: Illegal tab in whitespace before "}"
Line 78, E:0005: Illegal tab in whitespace before "req.open"
Line 79, E:0005: Illegal tab in whitespace before "req.setRequestHeader"
Line 79, E:0002: Missing space after ","
Line 80, E:0005: Illegal tab in whitespace before "if"
Line 81, E:0005: Illegal tab in whitespace before "req.send"
Line 84, E:0005: Illegal tab in whitespace before "document.getElementsByTagName"
Line 88, E:0005: Illegal tab in whitespace before "function"
Line 89, E:0005: Illegal tab in whitespace before "function"
Line 89, E:0001: Extra space after "function"
Line 89, E:0131: Single-quoted string preferred over double-quoted string.
Line 90, E:0005: Illegal tab in whitespace before "function"
Line 90, E:0001: Extra space after "function"
Line 90, E:0131: Single-quoted string preferred over double-quoted string.
Line 91, E:0005: Illegal tab in whitespace before "function"
Line 91, E:0001: Extra space after "function"
Line 91, E:0131: Single-quoted string preferred over double-quoted string.
Line 95, E:0005: Illegal tab in whitespace before "var"
Line 96, E:0005: Illegal tab in whitespace before "for"
Line 96, E:0002: Missing space before "("
Line 96, E:0002: Missing space before "="
Line 96, E:0002: Missing space after "="
Line 96, E:0002: Missing space before "<"
Line 96, E:0002: Missing space after "<"
Line 97, E:0005: Illegal tab in whitespace before "try"
Line 98, E:0005: Illegal tab in whitespace before "xmlhttp"
Line 99, E:0005: Illegal tab in whitespace before "}"
Line 100, E:0005: Illegal tab in whitespace before "catch"
Line 100, E:0002: Missing space before "("
Line 101, E:0005: Illegal tab in whitespace before "continue"
Line 102, E:0005: Illegal tab in whitespace before "}"
Line 103, E:0005: Illegal tab in whitespace before "break"
Line 104, E:0005: Illegal tab in whitespace before "}"
Line 105, E:0005: Illegal tab in whitespace before "return"
Line 106, E:0300: File does not end with new line.  (})
Found 129 errors, including 0 new errors, in 1 files (0 files OK).Some of the errors reported by GJsLint may be auto-fixable using the script
fixjsstyle. Please double check any changes it makes and report any bugs. The
script can be run by executing:fixjsstyle –-strict D:\work\js\WOYO\event.js<<< Process finished.
================ READY ================

则说明JS代码已经被 Closure Linter工具校验。居然这么多 bug!不过,修复 bug 也可以利用工具来完成,哈哈!执行如下的命令即可:

fixjsstyle –-strict $(FULL_CURRENT_PATH)

在Console窗口中显示的结果:

fixjsstyle –-strict D:\work\js\WOYO\event.js
Process started >>>
Fixed 44 errors in D:\work\js\WOYO\event.js
<<< Process finished.
================ READY ================

129个bug修复了44个!因为选择了strict参数,果然很严苛!哈哈!

(完)

转载于:https://www.cnblogs.com/georgewing/archive/2010/11/27/1889594.html

在 Notepad++ 运行 Closure Linter 来校验JS代码相关推荐

  1. 前端身份证号码校验js代码

    今天把项目前端的身份证号码从最初的只是校验长度改为只允许正规的号码,具体内容如下 功能主要校验  年月日 地址  格式  以及最后一位的校验 var code="123132132121&q ...

  2. 在线运行代码 html js,在线运行HTML/JS代码

    很早以前论坛里贴出来的代码不仅能够修改而且能够在线运行,我也没有定这篇文章,因为本站中有这种运行的功能,为了方便大家学习,本人再记下来,大家可以借鉴. 本实例能运行HTML/js代码兼容IE/FF/C ...

  3. 一行js代码识别Selenium+Webdriver及其应对方案

    有不少朋友在开发爬虫的过程中喜欢使用Selenium + Chromedriver,以为这样就能做到不被网站的反爬虫机制发现. 先不说淘宝这种基于用户行为的反爬虫策略,仅仅是一个普通的小网站,使用一行 ...

  4. 一行js代码识别Selenium+Webdriver及其应对方案 1

    有不少朋友在开发爬虫的过程中喜欢使用Selenium + Chromedriver,以为这样就能做到不被网站的反爬虫机制发现. 先不说淘宝这种基于用户行为的反爬虫策略,仅仅是一个普通的小网站,使用一行 ...

  5. (26)ESLint一JS代码格式校验

    一.什么是代码格式 代码格式即为代码风格,每个程序员再开发的时候,书写代码的风格都是不一样的,比如说,有的人喜欢书写字符串时用双引号,有的喜欢用单引号,有的再书写标签代码缩进时,喜欢用2个空格,有的喜 ...

  6. Android中使用WebView加载本地html并支持运行JS代码和支持缩放

    场景 Openlayers中使用Image的rotation实现车辆定位导航带转角(判断车辆图片旋转角度): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/art ...

  7. 如何使用notepad运行python程序

    关于使用notepad运行python程序 首先要确保python解释器已经安装成功,查看方法,windows可以在命令提示符中查看,通过按下win+R键,调出运行窗口,在输入框中输入cmd回车,然后 ...

  8. (5)通过Node.js 运行JS代码

    一.使用快捷键ctrl+`键打开终端,也可以手动选择菜单栏中的终端,然后编写一个hello.js文件 二.输入命令node .\node_demo\hello.js 三.得到JS文件的内容 如果没有显 ...

  9. ie运行不了java脚本界面_IE浏览器不能运行js JS代码失效不能运行了如何解决

    IE浏览器不能运行js JS代码失效不能运行了如何解决 发布时间:2012-02-20 16:39:23   作者:佚名   我要评论 IE不能运行js,在IE浏览器js代码失效,js不能运行了怎么办 ...

最新文章

  1. css超过两行显示为..._使用这些不太常用的CSS属性,布局效率上又提高了一个层次...
  2. Java -cp 使用
  3. php管理员登录文件,使用PHP文件重置管理员密码(Drupal 8)
  4. 浅析关键词与搜索引擎之间不得不说的关系
  5. linux终端信息读取,linux系统 如何通过终端查看信息
  6. leetcode算法题--调整数组顺序使奇数位于偶数前面
  7. 【CSS】一侧定宽,另一侧自适应的布局该如何去做
  8. docker部署nessus+awvs
  9. gnome硬盘分析_解决八种Linux硬盘问题的技巧
  10. Centos7中安装ElasticSearch7.2_亲测可用_坑很多---ElasticSearch工作笔记026
  11. java集合之列表:ArrayList、Vector、LinkedList
  12. [转载] Python程序将十进制转换为二进制,八进制和十六进制
  13. #脚本实现宠物动作行为_短视频剧情创作方法有哪些?爆款短视频的标配,只需88个脚本模板...
  14. 网络收包流程-报文从网卡驱动到网络层(或者网桥)的流程(非NAPI、NAPI)(一)
  15. Redis 入门指南
  16. PostgreSQL 修改数据库用户的密码
  17. 有一个包含 10 亿个搜索关键词的日志文件,如何快速获取到 Top 10 最热门的搜索关键词呢?
  18. 看两宋风云,搞清了4个之前对两宋历史认识错误的地方
  19. vue省市区 下拉框实现
  20. 面试官问你Java线程池--怎么样回答才能让面试官知道你真的懂了!

热门文章

  1. 1.17 设置工作簿的页眉和页脚 [原创Excel教程]
  2. 何时是PNE(纯策略纳什均衡)?何时是MNE(混合策略纳什均衡)?
  3. 八进制在计算机系统中的应用场景,二进制、八进制、十进制、十六进制都能干什么? 十六进制计算器使用场景...
  4. 如何使用 OpenTracing 和 Jaeger 追踪 Pulsar 消息
  5. C和C++中的struct
  6. pca百分比取多少比较好_主成分分析(PCA)的详细解释
  7. CPU后面的字母注解
  8. [图像] 金字塔模型
  9. 抓包工具以及如何看抓包信息
  10. MySQL——插入数据