Skip to content

Unexpected newline between object and [ of property access #1313

Closed

Description

@Amwam

Running a snippet similar to the one below results in an eslint error of no-unexpected-multiline.

const data = {};
[].forEach(key => {
  data[key]('foo')
    .then(() => console.log('bar'))
    .catch(() => console.log('baz'));
});

Prettifies to:

const data = {};
[].forEach(key => {
  data
    [key]('foo')
    .then(() => console.log('bar'))
    .catch(() => console.log('baz'));
});

I would have expected the first snippet to be untouched, but I'm not sure if that should be the correct behaviour or not.

Activity

  1. ASudri commented on Aug 25, 2017

    @ASudri

    I have so:

    const core = require('./corelib');
    core[maker][q](oid, session)
             .then();
    

    Prettifies to:

    const core = require('./corelib');
    core[maker]
          [q](oid, session)
          .then();
    
  2. azz commented on Aug 26, 2017

    @azz
    Member

    @ASudri That's working as intended. It's the same with non-computed member expressions:

    data.prop1.func(arg1, arg2)
      .then(() => console.log('foo'))
      .catch(() => console.log('bar'));

    is formatted as:

    data.prop1
      .func(arg1, arg2)
      .then(() => console.log('foo'))
      .catch(() => console.log('bar'));
  3. added
    locked-due-to-inactivity
    on Jul 6, 2018
  4. locked as resolved and limited conversation to collaborators on Jul 6, 2018
  5. added theissue type on Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    locked-due-to-inactivity

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions