This function has too many statements. (41)
Solution 1
It doesn't mean poorly managed code as @pankajparkar says before, it could be because you have something like this, lets say this from one of my projects:
$scope.betLoader = false;
$scope.showIfbetAlerts = true;
$scope.displayStraight = true;
$scope.displayParlay = true;
$scope.displayIfBet = true;
$scope.displayTeaser = true;
$scope.displayPleaser = true;
$scope.displayReverse = true;
$scope.unavailableBet = false;
$scope.subAccordion = false;
$scope.betTypeShow = false;
$scope.showStraight = true;
you can do this:
$scope.setInitialState = function() {
$scope.betLoader = false;
$scope.showIfbetAlerts = true;
$scope.displayStraight = true;
$scope.displayParlay = true;
$scope.displayIfBet = true;
$scope.displayTeaser = true;
$scope.displayPleaser = true;
$scope.displayReverse = true;
$scope.unavailableBet = false;
$scope.subAccordion = false;
$scope.betTypeShow = false;
};
$scope.setInitialState();
that will fix it.
UPDATE
Let me explain:
it is not only related with the dependencies, jslint throws this error when there are too many statements, he says before on line ten which is where the controller begins, so parting from there, he should have too many statements, if you put all those statements in 1 function, those statements will be reduce to 1 :)
Solution 2
The best way to get rid of the error would be to edit your jshint
settings to not display it.
http://jshint.com/docs/options/#maxstatements
That's a very wishy-washy jshint
warning that doesn't really mean anything.
Normally, a function that requires more than 4 or 5 parameters is a bad idea for a lot of reasons, but isn't technically wrong. In this case those params are Angular's way of defining dependencies, so shouldn't be a problem. If the code works, I wouldn't worry about it.
Solution 3
If the controller wants more statements and you don't have any other method to remove it then go to your .jshintrc file and edit it like
"maxstatements": 80, // or whatever number you want'
thanks
Comments
-
Non over 3 years
I have this controller
.controller('ctrl', function($scope, $rootScope, $timeout, $alert, $location, $tooltip, $popover, BetSlipFactory, AccordionsFactory, AuthFactory, RiskWinCalculations) {...});
and, I am getting this error due to
jshint
:line 10 col 44 This function has too many statements. (41)
so, what should I do to avoid it ?
-
Pankaj Parkar almost 9 yearsthat mean your code code is poorly managed..you should make it modular it..Then your code will also having more than 1000 lines..am correct?
-
user2357112 almost 9 yearsSplit it up into meaningful pieces with less statements? Or if the code is repetitive, make it less repetitive.
-
Pankaj Parkar almost 9 years@NietzscheProgrammer oh thats really cool. Cant believe such case.could you remove the unused first and then check what is the number...
-
-
Reacting almost 9 yearsit is not only with dependencies, jslint throws this error when there are too many statements, he says before on line ten which is where the controller begins, so parting from there, he should have too many statements, if you put all those statements in 1 function, those statements will be reduce to 1 :)
-
Non almost 9 yearsGenius, I put all those statements together and wrapped in a function and boila :)
-
Pradep over 8 yearsThis fixed the problem for me too. I thought jshint was worried about lots of lines of code. Apparently it is worried more about lots of assignment statements. Thanks for the answer :)
-
Andrew Craswell over 7 yearsHow would yo solve this problem if you use controllerAs syntax rather than $scope?
-
Kandy almost 7 yearsI think this is the best to do since this limit controls only the readability. :)