jshint/jshint — Issue #428: Potential indentation bug when it comes to key-value objects
Author: biggeleben
Created: 2012-01-27 14:09:01+00:00
State: open

Hi.

We integrated JSHint into our build systems which really is a great help to avoid common JS traps. Since we collaborate in teams, it's also a nice tool to get some discipline in terms of code formatting (they hate me for it). So, we use a **indentation level of 4 and white-space checks are turned on**. Unfortunately, there is just one tiny problem. When we come to **complex jQuery chains**, JSHint rarely reports an error. This error is always about the indentation level of keys in key/value objects. I try to nail that pattern down with a simplified example.

Steps to reproduce:

We start with a simple jQuery chain. This passes JSHint.

```javascript
$().append(
$().css({
key: 'value'
})
);
```

Sometimes we need to store that in a variable. No problem for JSHint.

```javascript
var foo = $().append(
$().css({
key: 'value'
})
);
```

Now we add another variable. However, we don't indent that block yet to illustrate the transition - this still passes JSHint!

```javascript
var foo = $().append(
$().css({
key: 'value'
})
),
andThis = 'works_but_looks_strange';
```

Finally, we indent that block. This is actually how it guarantees readability. But this does **NOT** pass JSHint.

```javascript
var foo = $().append(
$().css({
key: 'value'
})
),
andThis = 'fails';
```

**Actual result**: *Expected 'key' to have an indentation at 5 instead at 13.*

**Expected result**: This passes JSHint as well.

**Note**:

We even found (and use) a workaround whenever this issue occurs:

```javascript
var foo = $().append(
$().css(
{ key: 'value'
})
),
andThis = 'is_a_workaround';
```

I played around with the latest JSHint code in order to provide a patch but I could not isolate the specific reason for this behavior. It seems that chained function calls do not change - i.e. increase - the indentation level. Actually, they seem not to be checked at all in this case - thus allowing indentation levels that are not multiples of 4.

Any help on this would be awesome.