eslint-plugin-angular this.variable cause没有方法' findIndex'

时间:2016-07-05 05:19:00

标签: angularjs eslint

我注意到如果我在这里完成了步骤https://github.com/Gillespie59/eslint-plugin-angular并且运行eslint它在大多数文件上运行良好,但它会导致在其中包含this变量的文件出现以下问题。

例如,如果我有以下文件:

function profileCtrl($scope, dataFactory) {
    $scope.buttonDisabled = false;
    $scope.loading = false;

    $scope.user = {};

    function readUser(userId) {
        $scope.buttonDisabled = true;
        $scope.loading = true;
        dataFactory.readUser(userId).then(function(res){
            $scope.user = res.data;
            $scope.buttonDisabled = false;
            $scope.loading = false;
        });
    };    
}

然后eslint会吐出来:

/home/ubuntu/sample/app/components/profile/profile.js
   1:10  error  'dataFactory' is defined but never used                                                      no-unused-vars
   1:21  error  Missing space before function parentheses                                                    space-before-function-paren
   2:5   error  Expected indentation of 2 space characters but found 4                                       indent
   2:25  error  Extra semicolon                                                                              semi
   4:5   error  Expected indentation of 2 space characters but found 4                                       indent
   5:9   error  Expected indentation of 6 space characters but found 8                                       indent
   5:57  error  Extra semicolon                                                                              semi
   6:6   error  Extra semicolon                                                                              semi
   7:5   error  Expected indentation of 2 space characters but found 4                                       indent
   7:54  error  Identifier 'first_name' is not in camel case                                                 camelcase
   7:66  error  Identifier 'last_name' is not in camel case                                                  camelcase
   8:9   error  Expected indentation of 6 space characters but found 8                                       indent
   8:9   error  You should use the "log" method of the AngularJS Service $log instead of the console object  angular/log
   8:86  error  Extra semicolon                                                                              semi
   9:9   error  Expected indentation of 6 space characters but found 8                                       indent
  10:13  error  Expected indentation of 10 space characters but found 12                                     indent
  11:13  error  Expected indentation of 10 space characters but found 12                                     indent
  12:13  error  Expected indentation of 10 space characters but found 12                                     indent
  13:13  error  Expected indentation of 10 space characters but found 12                                     indent
  14:10  error  Extra semicolon                                                                              semi
  15:9   error  Expected indentation of 6 space characters but found 8                                       indent
  15:26  error  Extra semicolon                                                                              semi
  16:9   error  Expected space or tab after '/*' in comment                                                  spaced-comment
  22:6   error  Extra semicolon                                                                              semi
  23:5   error  Expected indentation of 2 space characters but found 4                                       indent
  23:23  error  Extra semicolon                                                                              semi
  26:10  error  'profileCtrl' is defined but never used                                                      no-unused-vars
  26:21  error  Missing space before function parentheses                                                    space-before-function-paren
  27:5   error  Expected indentation of 2 space characters but found 4                                       indent
  27:34  error  Extra semicolon                                                                              semi
  28:5   error  Expected indentation of 2 space characters but found 4                                       indent
  28:27  error  Extra semicolon                                                                              semi
  30:5   error  Expected indentation of 2 space characters but found 4                                       indent
  30:21  error  Extra semicolon                                                                              semi
  32:5   error  Expected indentation of 2 space characters but found 4                                       indent
  32:14  error  'readUser' is defined but never used                                                         no-unused-vars
  32:22  error  Missing space before function parentheses                                                    space-before-function-paren
  33:9   error  Expected indentation of 6 space characters but found 8                                       indent
  33:37  error  Extra semicolon                                                                              semi
  34:9   error  Expected indentation of 6 space characters but found 8                                       indent
  34:30  error  Extra semicolon                                                                              semi
  35:9   error  Expected indentation of 6 space characters but found 8                                       indent
  35:51  error  Missing space before function parentheses                                                    space-before-function-paren
  35:56  error  Missing space before opening brace                                                           space-before-blocks
  36:13  error  Expected indentation of 10 space characters but found 12                                     indent
  36:35  error  Extra semicolon                                                                              semi
  37:13  error  Expected indentation of 10 space characters but found 12                                     indent
  37:42  error  Extra semicolon                                                                              semi
  38:13  error  Expected indentation of 10 space characters but found 12                                     indent
  38:35  error  Extra semicolon                                                                              semi
  39:11  error  Extra semicolon                                                                              semi

✖ 51 problems (51 errors, 0 warnings)

注意它甚至进行角度检查。但是,如果文件是这样的:

function profileCtrl($scope, dataFactory) {
    $scope.buttonDisabled = false;
    $scope.loading = false;

    $scope.user = {};

    function readUser(userId) {
        $scope.buttonDisabled = true;
        $scope.loading = true;
        dataFactory.readUser(userId).then(function(res){
            $scope.user = res.data;
            $scope.buttonDisabled = false;
            $scope.loading = false;
        });
    };


    this.updateUser = null;

}

然后,我收到以下错误:

ubuntu@ip-172-31-30-67:~/sample/app$ /home/ubuntu/node_modules/eslint/bin/eslint.js components/profile/profile.js 
Object [object Object],[object Object],[object Object],[object Object],[object Object],[object Object] has no method 'findIndex'
TypeError: Object [object Object],[object Object],[object Object],[object Object],[object Object],[object Object] has no method 'findIndex'
    at isClassDeclaration (/home/ubuntu/node_modules/eslint-plugin-angular/rules/controller-as-vm.js:65:26)
    at EventEmitter.ThisExpression (/home/ubuntu/node_modules/eslint-plugin-angular/rules/controller-as-vm.js:80:18)
    at EventEmitter.emit (events.js:117:20)
    at NodeEventGenerator.enterNode (/home/ubuntu/node_modules/eslint/lib/util/node-event-generator.js:40:22)
    at CodePathAnalyzer.enterNode (/home/ubuntu/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:607:23)
    at CommentEventGenerator.enterNode (/home/ubuntu/node_modules/eslint/lib/util/comment-event-generator.js:97:23)
    at Controller.traverser.traverse.enter (/home/ubuntu/node_modules/eslint/lib/eslint.js:905:36)
    at Controller.__execute (/home/ubuntu/node_modules/eslint/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (/home/ubuntu/node_modules/eslint/node_modules/estraverse/estraverse.js:501:28)
    at Controller.Traverser.controller.traverse (/home/ubuntu/node_modules/eslint/lib/util/traverser.js:36:33)

如何解决此问题。

1 个答案:

答案 0 :(得分:2)

对我来说,特拉维斯失败了。从this comment我发现它可能是节点版本问题。尝试更新节点。它似乎适用于6.3