沉默的JSLint警告括号内 [英] Silencing JSLint warnings in brackets

查看:233
本文介绍了沉默的JSLint警告括号内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始一饮而尽角约曼项目,并在括号中打开它,几乎无处不在我得到'东西'它被定义之前,具体使用<它被定义之前使用code>'角'。我搞砸与周围扩展和其他解决方法,但我真的不知道我在做什么,我一直没能找到任何好的文档。

I just started a gulp-angular Yeoman project and opened it in brackets, and nearly everywhere I'm getting 'something' was used before it was defined, specifically 'angular' was used before it was defined. I've messed around with extensions and other fixes, but I honestly don't know what I'm doing and I haven't been able to find any good documentation.

我能做些什么沉默在整个项目中的这些警告?换句话说,我怎么能避免使用 / *全球角* / $ p中$ ptty多在我的项目中的每个文件?

What can I do to silence these warnings across the entire project? In other words, how can I avoid using /*global angular*/ in pretty much every file in my project?

下面是我的控制器声明一个一个简单的例子:

Here's a quick example of one of my controller declarations:

/*global console*/

(function () {
    'use strict';

    angular
        .module('sbk')
        .controller('MainController', MainController);

    /** @ngInject */
    function MainController() {
        console.log('Woo!');
    }
})();

这导致了以下的JSLint警告:

Which results in the following JSLint warnings:

'angular' was used before it was defined.
'MainController' was used before it was defined.
'MainController' was used before it was defined.
Move the invocation into the parens that contain the function.

编辑:更新,以使我的问题更清楚一点。

updated to make my issue a little clearer

推荐答案

好了,所以请记住,JSLint的仅仅是一个JavaScript文件,大多数的JSLint插件我用在安装某个地方猛的来源(尽管在Visual Studio插件嵌入它变成一个dll!),这样你就可以的总是的得到它做你想要的[在合理范围内。

Okay, so remember that JSLint is just a JavaScript file, and most JSLint plugins I've used has the source shoved in the install somewhere (though the Visual Studio plugin embeds it into a dll!), so you can always get it to do what you want [within reason].

在你的情况,绝对最坏的情况是,你初始化你想要的JSLint承担的命名空间predefined变量列表是的总是的认为是在范围内。我要告诉你如何设置,全球范围内支架,这可能并不总是做的最好的事情,你需要记住,如果你掉毛另一个项目的有角,好了,你搞砸了JSLint的。

In your case, the absolute worst case is that you initialize the list of predefined variables with the namespaces you want JSLint to assume are always considered to be in scope. I'm going to show you how to set that globally within Brackets, which might not always be the best thing to do, and you need to keep in mind if you're linting another project that doesn't have Angular, well, you've screwed up JSLint.

(老实说,我很失望,支架不具有全球作为其preferences.json文件中的全局性的。我想我应该提交一个补丁。 )

(Honestly, I'm disappointed that Brackets doesn't have global as a global in its preferences.json file. Guess I should submit a patch.)

有很多方法,我们可以做到这一点。我要去一个命名空间添加到标准对象。您还可以通过(在我的支架安装的JSLint的文件行497)增加了浏览器全局集合限制其曝光。我们也可以创建一个新的JSLint指令选项,类似于浏览器。这不是快'N'肮脏的,但可能是正确的方式做到这一点无需提交支架补丁。但现在,我们只是做了快速'N'肮脏的修复。

There are lots of ways we could do this. I'm going to add a namespace to the standard object. You could also limit its exposure by adding to the browser collection of globals (line 497 in my Bracket install's jslint file). We could also create a new JSLint directive option, similar to browser. That's not quick 'n' dirty, but is probably The Right Way to do this without submitting a Brackets patch. But for now, let's just do the quick 'n' dirty fix.

我使用Windows。如果你不是,YMWV。我不是每天都使用的支架,所以我还没有在生产的编码环境测试这一点。如果有什么不工作,我很有兴趣听到它,但是,我会看到,如果我能找到什么是错的。

I'm using Windows. If you're not, YMWV. I do not use Brackets daily, so I haven't tested this in a production coding environment. If anything doesn't work, I'd be interested to hear it, however, and I'll see if I can find what's wrong.

该jslint.js文件,你要的是这里,如果你使用默认安装了位置:结果
C:\\ Program Files文件(x86)的\\支架\\ WWW \\分机\\ DEFAULT \\ JSLint的\\第三方\\ JSLint的

The jslint.js file you want is here, if you went with the default install location:
C:\Program Files (x86)\Brackets\www\extensions\default\JSLint\thirdparty\jslint

(只是为了好玩,请注意,我们使用的JSLint的版本是从2011年!?!来吧,支架的家伙!)

(Just for fun, notice that the version of JSLint we're using is from 2011!!?! Come on, Brackets guys!)

标准是,在我的文件上线974下面是它原本:

standard is, in my file, on line 974. Here's what it had originally:

// standard contains the global names that are provided by the
// ECMAScript standard.

    standard = array_to_object([
        'Array', 'Boolean', 'Date', 'decodeURI', 'decodeURIComponent',
        'encodeURI', 'encodeURIComponent', 'Error', 'eval', 'EvalError',
        'Function', 'isFinite', 'isNaN', 'JSON', 'Math', 'Number', 'Object',
        'parseInt', 'parseFloat', 'RangeError', 'ReferenceError', 'RegExp',
        'String', 'SyntaxError', 'TypeError', 'URIError'
    ], false),

下面是一个测试JavaScript片段我想皮棉使用我的全局对象, UTIL

Here's a test JavaScript snippet I want to lint that uses my global object, util:

/*jslint sloppy:true, white:true */
utils.spam();
utils.spammySpam();

smutils.spam();

所有我们需要做的是添加,utils的标准,我们就大功告成了。

All we need to do is to add , 'utils' to standard, and we're done.

    standard = array_to_object([
        'Array', 'Boolean', 'Date', 'decodeURI', 'decodeURIComponent',
        'encodeURI', 'encodeURIComponent', 'Error', 'eval', 'EvalError',
        'Function', 'isFinite', 'isNaN', 'JSON', 'Math', 'Number', 'Object',
        'parseInt', 'parseFloat', 'RangeError', 'ReferenceError', 'RegExp',
        'String', 'SyntaxError', 'TypeError', 'URIError', 'utils'
    ], false),

要过于清楚,你会'角''MainController 添加到您的代替标准对象utils的

To be overly clear, you'd add 'angular' and 'MainController' to your standard object in place of 'utils'.

顺便说一句,克罗克福德(JSLint的的创建者和维护者)会恨我们这样做。我不知道的真正的责怪他。

Btw, Crockford (JSLint's creator and maintainer) would hate that we did that. I don't really blame him.

现在我得到 smutils 的错误,而不是 utils的。幸运的是,全局指令仍然工作在此设置:

Now I get an error for smutils, but not utils. Luckily, the global directive still works with this setup:

/*jslint sloppy:true, white:true */
/*global smutils */
utils.spam();
utils.spammySpam();

smutils.spam();

和我们再次JSLint的友好。

And we're JSLint friendly again.

黑客JSLint的直接可能没有最被看好的选项状态,但它的作品。

Hacking JSLint directly might not have most favored option status, but it works.

顺便说一下,回复:戴夫的评论,IMO的JSLint一直赞成JSHint或JSCS的pcated普遍德$ P $,我不那么肯定。只是作为一个例子,它并不支架使用现成的?有关JSLint的最好的部分是多大的的主观讨论发生在得到大的团队在同一页上。相信我,Crockford的不会告诉你做的东西的indefensibly的错误的。

Btw, re: Dave's comment, "IMO JSLint has been popularly deprecated in favor of JSHint or JSCS," I'm not so sure. Just as an example, which does Brackets use out of the box? The best part about JSLint is how much less subjective discussion has to happen to get a large team on the same page. And trust me, Crockford's not going to tell you to do something that's indefensibly wrong.

他可能会伤害你的感情,他可能会问你做一些事情,伤害了在第一,但我真的觉得JSLint的可以教团队的很多的关于JavaScript的最佳实践。这是值得居住的JSLint一会儿跳到JSHint之前。

He might hurt your feelings, and he might ask you to do something that hurts at first, but I really think JSLint can teach a team a lot about JavaScript best practices. It's worth living in JSLint for a while before jumping to JSHint.

这篇关于沉默的JSLint警告括号内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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