JSCS错误:X和Y在它们之间最多应有2行

时间:2015-07-08 16:10:23

标签: javascript jscs

  

和$ rootScope在app / scripts / services / betslipfactory.js之间最多应该有2行:

  131 |            }
   132 |            $rootScope.copyLineStatus += '</div>';
   133 |          });
---------------------^
   134 |
   135 |
     

找到1个代码样式错误!

这是我来到这里的错误

_.each(status.selections, function(selection) {
            $rootScope.copyLineStatus += '<div class="well">';
            $rootScope.copyLineStatus += '<strong>' + selection.teamName  + ' </strong>';
            if (selection.lineChange) {
              $rootScope.copyLineStatus += '<div class="row">';
              $rootScope.copyLineStatus += '<div class="col-md-12">';
              $rootScope.copyLineStatus += '<strong>Lines:</strong>';
              $rootScope.copyLineStatus += '</div>';
              $rootScope.copyLineStatus += '</div>';
              $rootScope.copyLineStatus += '<div class="row">';
              $rootScope.copyLineStatus += '<div class="col-md-6">';
              $rootScope.copyLineStatus += '<strong>Before</strong>';
              $rootScope.copyLineStatus += '<div>' + selection.oldSpread + '(' + selection.oldMoneyLine + ')';
              $rootScope.copyLineStatus += '</div>';
              $rootScope.copyLineStatus += '</div>';
              $rootScope.copyLineStatus += '<div class="col-md-6">';
              $rootScope.copyLineStatus += '<strong>Current</strong>';
              $rootScope.copyLineStatus += '<div>' + selection.newSpread + '(' + selection.newMoneyLine + ')';
              $rootScope.copyLineStatus += '</div>';
              $rootScope.copyLineStatus += '</div>';
              $rootScope.copyLineStatus += '</div>';
            }

            if (selection.timeChange) {
              $rootScope.copyLineStatus += '<div class="row">';
              $rootScope.copyLineStatus += '<div class="col-md-6">';
              $rootScope.copyLineStatus += '<strong>Previous Time:</strong>';
              $rootScope.copyLineStatus += '<div>' + selection.oldDate + '</div>';
              $rootScope.copyLineStatus += '</div>';
              $rootScope.copyLineStatus += '<div class="col-md-6">';
              $rootScope.copyLineStatus += '<strong>Current Time:</strong>';
              $rootScope.copyLineStatus += '<div>' + selection.newDate + '</div>';
              $rootScope.copyLineStatus += '</div>';
              $rootScope.copyLineStatus += '</div>';
            }

            if (selection.statusChange) {
              $rootScope.copyLineStatus += '<div class="row">';
              $rootScope.copyLineStatus += '<div class="col-md-6">';
              $rootScope.copyLineStatus += '<strong>Old Status:</strong>';
              $rootScope.copyLineStatus += '<div>' + selection.oldStatus + '</div>';
              $rootScope.copyLineStatus += '</div>';
              $rootScope.copyLineStatus += '<div class="col-md-6">';
              $rootScope.copyLineStatus += '<strong>New Status:</strong>';
              $rootScope.copyLineStatus += '<div>' + selection.newStatus + '</div>';
              $rootScope.copyLineStatus += '</div>';
              $rootScope.copyLineStatus += '</div>';
            }

            if (selection.pitchingChangeThis) {
              $rootScope.copyLineStatus += '<div class="row">';
              $rootScope.copyLineStatus += '<div class="col-md-12">';
              $rootScope.copyLineStatus += '<strong>New Pitcher On Your Team:</strong>';
              $rootScope.copyLineStatus += '<div>' + selection.newPlayerNameThis + '</div>';
              $rootScope.copyLineStatus += '</div>';
            }

            if (selection.pitchingChangeOther) {
              $rootScope.copyLineStatus += '<div class="row">';
              $rootScope.copyLineStatus += '<div class="col-md-12">';
              $rootScope.copyLineStatus += '<strong>New Pitcher On The Other Team:</strong>';
              $rootScope.copyLineStatus += '<div>' + selection.newPlayerNameOther + '</div>';
              $rootScope.copyLineStatus += '</div>';
            }
            $rootScope.copyLineStatus += '</div>'; //closing the '<div .well>' tag...       
          });
             //HERE IS THE ERROR ^

2 个答案:

答案 0 :(得分:3)

这与OP之后的情况略有不同,但可能会为寻找此错误的其他人提供服务:

如果您希望能够使用多个换行符来隔离代码以提高可读性,则可以从 .jscsrc 文件中删除此行。请注意,您无法将其设置为false,因为它为true或需要删除。

"disallowMultipleLineBreaks": true

虽然这为您提供了更大的灵活性,但这也意味着您可能需要在整个开发团队中应用通用方法以保持一致。

答案 1 :(得分:1)

好吧,你之间可能有两行空白:

  $rootScope.copyLineStatus += '</div>'; //closing the '<div .well>' tag...       
});

和下一行代码。

自动修复代码

仅限JSCS

在控制台中运行:

jscs "myfile.js" --fix

您还可以将其指向目录或文件列表。查看documentation for more info

在Sublime中

有一个叫SublimeJSCSFormatter的普格林应该为你做这件事。从来没有用过它。

WebStorm / PHPStorm

只需按CTRL+ALT+LCMD+ALT+L(在mac中)