简体   繁体   English

JSHint链接方法调用

[英]JSHint chaining method calls

I have the following code in an Angular app: 我在Angular应用中有以下代码:

'use strict';

angular.module('fooApp')
    .controller('FooCtrl', function ($scope) {

    });

When I run JSHint (with indent set to 4) on this code, I get the following error: 当我在此代码上运行JSHint(缩进设置为4)时,出现以下错误:

[L6:C5] W015: Expected '}' to have an indentation at 1 instead at 5.
    });

How do I get JSHint to allow me to keep my chaining indentation? 如何获得JSHint以允许我保留链接缩进?

Update 更新资料

I found that if I add a body to the FooCtrl function like this: 我发现,如果我将主体添加到FooCtrl函数中,如下所示:

'use strict';

angular.module('fooApp')
    .controller('FooCtrl', function ($scope) {
        $scope.foo = {};
    });

Then it does pass JSHint. 然后它确实通过了JSHint。 Anyone know why? 有人知道为什么吗?

I don't believe there is a way to do it. 我不相信有办法。 The whitespace checking in JSHint is fairly static, you get on or off, no configuration. JSHint中的空白检查是相当静态的,您可以打开或关闭,无需进行配置。 There's an open bounty to add some configuration, but nothing seems to be in the works (at least for your situation). 有一个开放的赏金来添加一些配置,但是似乎没有任何进展(至少针对您的情况)。

https://github.com/jshint/jshint/issues/28 https://github.com/jshint/jshint/issues/28

You'll either have to just ignore it or turn off the whitespace check. 您要么只是忽略它,要么关闭空白检查。

simply said: you don't. 简单地说:你没有。 Either you remove all indentation checking from your config file, or you match the crockford's recommandation. 您可以从配置文件中删除所有缩进检查,或者与crockford的要求匹配。 There's an open bug about giving more flexible rules, but it has to be implemented. 给出更灵活的规则存在一个开放的错误 ,但是必须实现。

Having submitted code to JSHint, it would not be hard to implement a more flexible way to check whitespaces. 将代码提交给JSHint之后,将不难实现一种更灵活的方法来检查空白。 Except that there are a lot of cases where it has to be checked... The main problem is to find an intelligent way to fine tune your indentation preferences. 除了在很多情况下需要检查它以外,主要的问题是找到一种智能的方式来微调您的缩进首选项。

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

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