简体   繁体   English

jslint4java 容忍未使用的变量

[英]jslint4java tolerates unused variables

I have downloaded and set up jslint4java.我已经下载并设置了 jslint4java。 When I use the following command:当我使用以下命令时:

java -jar C:\...\jslint4java-2.0.0.jar --encoding UTF-8 --indent 4 --browser *.js

Although there are some unused variables in the file, jsLint does not complain about them.虽然文件中有一些未使用的变量,但 jsLint 并没有抱怨它们。 I want it to.我想要它。 But I did not find any appropriate option in the command line docu .但是我在命令行文档中没有找到任何合适的选项。

Any advice on what setting I am missing there?关于我在那里缺少什么设置的任何建议?

Note: This is about variables not method parameters.注意:这是关于变量而不是方法参数。 I found the --unparam option, but it is about parameters, and it is for dis -abling rather than for en -abling the check.我找到了--unparam选项,但它是关于参数的它是用于禁用而不是用于启用检查。 I do not use this option, so the check is supposed to work.我不使用此选项,因此检查应该有效。

The jslint for Visual Studio plug-in does complain about the unused variables. Visual Studio 插件的 jslint确实抱怨未使用的变量。

Simple code example:简单的代码示例:

$(document).ready(function() {
    var a = 0,
        b = 1;

    alert(b);
});

In this example, the jslint for Visual Studio plug-in correctly complains about variable a not being used, whilst jslint4java doesn't.在这个例子中,用于 Visual Studio 插件的 jslint 正确地抱怨变量a没有被使用,而 jslint4java 没有。

Do you have a code sample where it complains?您是否有抱怨的代码示例? If the result is different to jslint.com with the same options selected, it's a bug in jslint4java (though please bear in mind that jslint4java may be running a slightly older version of JSLint).如果结果与选择相同选项的 jslint.com 不同,则这是 jslint4java 中的错误(但请记住,jslint4java 可能运行的是稍旧版本的 JSLint)。


I've figured out what's up.我已经弄清楚是怎么回事了。 It's not necessarily a bug in jslint4java.这不一定是 jslint4java 中的错误。 You do see the "unused variable" warning if you specify --report report on the command line.如果您在命令行上指定--report report ,您确实会看到“未使用的变量”警告。 JSLint produces an optional HTML report on your code in addition to any warnings.除了任何警告之外,JSLint 还会针对您的代码生成可选的 HTML 报告。 That must be what the VS plugin is using.那一定是VS插件正在使用的。 I've got no idea why they're not surfaced as regular JSLint warnings.我不知道为什么它们没有作为常规的 JSLint 警告出现。

You're not the only one to notice this: http://tech.groups.yahoo.com/group/jslint_com/message/2526您不是唯一一个注意到这一点的人: http://tech.groups.yahoo.com/group/jslint_com/message/2526

The unparam option controls unused parameters. unparam选项控制未使用的参数。 Default is that it will complain.默认是它会抱怨。 If jslint4java doesn't, it's probably a bug.如果 jslint4java 没有,那可能是一个错误。 Internally to jslint, unused parameters are passed in a separate field after the analysis, jslint4java might have missed it.在 jslint 内部,未使用的参数在分析后在单独的字段中传递,jslint4java 可能会错过它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM