最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get rid of blocks nested too deeply while using jshint with grunt? - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 10

just add following sentence before function starts.

// jshint maxdepth:5

发布评论

评论列表(0)

  1. 暂无评论