如何使用静态代码分析显示所有JavaScript全局变量? [英] How to display all JavaScript global variables with static code analysis?

查看:74
本文介绍了如何使用静态代码分析显示所有JavaScript全局变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以在Chrome或FF中键入以下命令:

I know that I can type into Chrome or FF the following command:

Object.keys(window);

但这会显示DHTMLX的内容以及我不感兴趣的函数名称。并且它不显示尚未执行的函数中的变量。我们有超过20,000行的JavaScript代码库,所以我更喜欢静态代码分析。我找到了 JavsScript Lint 。这是一个很棒的工具,但我不知道如何使用它来显示全局变量。

but this displays DHTMLX stuff and also function names in which I'm not interested in. And it doesn't display variables in functions that have not been executed yet. We have more than 20,000 lines of JavaScript codebase, so I would prefer static code analyis. I found JavsScript Lint. It is a great tool but I don't know how to use it for displaying global vars.

所以我正在寻找内存泄漏,遗忘 var 关键字等等......

So I'm searching for memory leaks, forgotten var keywords, and so on...

推荐答案

我找到了一个非常好的解决方案列表使用 jsl 命令行工具的所有全局变量:

I found a very good solution to list all the global variables with the jsl command line tool:

这是文档

我只需要输入 / * jsl:选项显式* / 到我要检查的每个文件中。然后就足以运行 ./ jsl -process< someFile> | grep'未声明的标识符'

I just have to put /*jsl:option explicit*/ into each file that I want to check. Then it is enough to run ./jsl -process <someFile> | grep 'undeclared identifier'

也可以使用包含一些的 referenceFile 故意全局变量 / * jsl:import< referenceFile> * / 因此不会列出这些变量。

It is also possible to use referenceFile that contains some intentional global variables /*jsl:import <referenceFile>*/ so these variables will not be listed.

这篇关于如何使用静态代码分析显示所有JavaScript全局变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆