return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - How to prevent Prettier from breaking test code from 1 line to multiple lines - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to prevent Prettier from breaking test code from 1 line to multiple lines - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question asked Sep 24, 2019 at 16:50 Leon GabanLeon Gaban 39k122 gold badges349 silver badges550 bronze badges 1
  • if you don't use multi-line template strings, a simple RegExp can clean that up for you. – dandavis Commented Sep 24, 2019 at 16:59
Add a ment  | 

3 Answers 3

Reset to default 4

To prevent Prettier from formatting your code, use this ment 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

Would love to see them add the ability to ignore specific functions, in Javascript, like 'console.log'. Had to change my snippets to add the //prettier-ignore at the end of every line.

If this is something that will happen regularly in your codebase, and you don't want to have ignore statements all over your code, and you want to enable going past 80 characters (which Prettier remends not doing), you could increase the width by adding

"printWidth": <whatever you want your max column length to be>

to your prettierrc.json

Print Width in the docs

Alternatively, if you don't want the ments in the code, you can create a .prettierignore file and add your file to that.

发布评论

评论列表(0)

  1. 暂无评论