Skip to content

if statements – one line vs. one expression #445

@tomek-he-him

Description

@tomek-he-him

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

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

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

But ESLint does:

$ 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:

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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions