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

javascript - Why does jshint complain about linebreak within expression? - Stack Overflow

programmeradmin2浏览0评论

When passing the following code to jshint, it considers the linebreak in the if-condition to be bad, saying "Bad line breaking before '&&'."

if (1 == 1 
        && true) {
    console.log("hello world");
}

However, having the linebreak after '&&' is fine.

if (1 == 1 && 
        true) {
    console.log("hello world");
}

Why does jshint consider the first to be wrong and the latter to be right?

When passing the following code to jshint, it considers the linebreak in the if-condition to be bad, saying "Bad line breaking before '&&'."

if (1 == 1 
        && true) {
    console.log("hello world");
}

However, having the linebreak after '&&' is fine.

if (1 == 1 && 
        true) {
    console.log("hello world");
}

Why does jshint consider the first to be wrong and the latter to be right?

Share Improve this question edited Jan 8, 2013 at 11:58 chtenb asked Jan 8, 2013 at 11:40 chtenbchtenb 16.2k14 gold badges83 silver badges118 bronze badges 1
  • 3 Maybe because it's ugly ;) – ThiefMaster Commented Jan 8, 2013 at 11:42
Add a comment  | 

2 Answers 2

Reset to default 14

According to a discussion on GitHub:

This may cause problems like semi colon insertion and old javascript parsers breaking. Please check a large range of browsers.

This check can be disabled with laxbreak:true.

The laxbreak option is on its way to deprecation, but I'm not sure if the default jshint behavior will change.

The creator of JSHint probably doesn't like this kind of wrapping and prefers the && in the first line which seems to be much more common:

The primary reasoning behind this convention is that the operator makes it clear that the line is a continuation of the preceding line. With the operator before the line break, this is much harder to spot.

Actually there's an issue about exactly what you are asking about on Github: https://github.com/jshint/jshint/issues/557

发布评论

评论列表(0)

  1. 暂无评论