javascriptlintprettier

How to prevent Prettier from breaking test code from 1 line to multiple lines


Code in question

it('will display No Policy Found after fist submit attempt.', () => {
    const policyDetails = {
        partyID: null,
        agreementID: null,
        isValidPolicy: false,
    };
    wrapper.setProps({policyDetails});
    wrapper.setState({submitCount: 1});
    const result = wrapper.instance().displayUserNotices();
    const render = shallow(result)
        .find('UserNotice')
        .find('p');

    expect(render.text()).toEqual(NO_POLICY_USER_NOTICE);
});

I keep writing

const render = shallow(result)
  .find('UserNotice')
  .find('p');

as the desired following 1-liner:

const render = shallow(result).find('UserNotice').find('p');

But prettier keeps reverting it.

I tried adding

noUnexpectedMultiline: true in the .prettierrc.yml but that didn't work.

Ideas?


Solution

  • To prevent Prettier from formatting your code, use this comment before the variable/function/etc.

    // prettier-ignore
    

    Alternatively, if you're in Markdown, you can ignore multiple lines, like this:

    <!-- prettier-ignore-start -->
    # Headline
    
    ```js
    const foo      =         'hey';
    console.log      (foo);
    ```
    <!-- prettier-ignore-end -->
    

    For more information: https://prettier.io/docs/en/ignore.html