airbnb / airbnb/javascript

`if` statements – one line vs. one expression

Open
#445 5 comments 0 reactions 0 assignees View on GitHub
needs eslint rule change/addition question
Dominant language
JavaScript
Stars
148k
Forks
26.6k
PR merge metrics
No merged PRs in 30d

Description

Until I started using ESLint with your configuration I saw nothing against the rules in this:

``` js
$ cat if.js
const [one, two] = [1, 2];

if (one !== two) throw new Error(
'One does not equal two'
);
```

But ESLint does:

``` sh
$ eslint if.js

if.js
3:0 error Expected { after 'if' condition curly

✖ 1 problem (1 error, 0 warnings)
```

Is this intended? In my opinion the pattern I’ve been using is explicit – and more readable than this:

``` js
if (one !== two) {
throw new Error(
'One does not equal two'
);
}
```

The parens form a visual brace-like block much like in #438.

Contributor guide

No contributing guide indexed for this repository

Research direction

The report identifies ESLint's `curly` rule and the project's configuration, with a comparison to the braced form and a reference to #438. Start by checking how `curly` is configured and how the style guide addresses one-line `if` statements; done means deciding whether the current rule is intended and documenting or changing that guidance accordingly.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript
Domain
documentation, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.