Some one please help me to fix a warning in grunt. I am using fallowing condition in my project and i am getting a warning, Blocks are nested too deeply<5>.
var chartGuideLines = function() {
var chartid = $scope.chart.panel.id;
var chartTitle = $scope.confdata.prop.chartsarray;
for(var i = 0; i< chartTitle.length; i++) {
var chartslength = chartTitle[i];
var chartsId = chartslength.id;
if(chartsId === chartid){
for(var j = 0; j < chartslength.charts.length; j++) {
var chartsdata = chartslength.charts[j];
var guidlines = chartsdata.guideliney;
if( typeof guidlines !== 'undefined') {
var guidlineY = $scope.chart.targetNode.getElementsByClassName('guideline-y');
for (var ii=0; ii<guidlineY.length; ii++) {
guidlineY[ii].style.strokeDasharray = guidlines.stroke;
}
}
}
}
}
};
Thanks in advance.
Some one please help me to fix a warning in grunt. I am using fallowing condition in my project and i am getting a warning, Blocks are nested too deeply<5>.
var chartGuideLines = function() {
var chartid = $scope.chart.panel.id;
var chartTitle = $scope.confdata.prop.chartsarray;
for(var i = 0; i< chartTitle.length; i++) {
var chartslength = chartTitle[i];
var chartsId = chartslength.id;
if(chartsId === chartid){
for(var j = 0; j < chartslength.charts.length; j++) {
var chartsdata = chartslength.charts[j];
var guidlines = chartsdata.guideliney;
if( typeof guidlines !== 'undefined') {
var guidlineY = $scope.chart.targetNode.getElementsByClassName('guideline-y');
for (var ii=0; ii<guidlineY.length; ii++) {
guidlineY[ii].style.strokeDasharray = guidlines.stroke;
}
}
}
}
}
};
Thanks in advance.
Share Improve this question asked Oct 8, 2014 at 16:23 kumarkkumark 911 silver badge6 bronze badges 3- It's just a warning. Is this really a problem for you? While certainly there is a "code smell" when you have things nested this deeply to hint that some refactoring may be in order, in your case and without understanding what the code it intended to do, it would seem difficult to refactor the triple-nested loop in a logical way. – Mike Brant Commented Oct 8, 2014 at 16:30
- @Mike Brant, It's not a problem i can do --force but just to know any option to use reduce loops . – kumark Commented Oct 8, 2014 at 16:44
- You could do something like break each level of those loops into a separate function call, but again, in your case I think that would actually make the code harder to understand/maintain. – Mike Brant Commented Oct 8, 2014 at 17:16
1 Answer
Reset to default 10just add following sentence before function starts.
// jshint maxdepth:5