为什么不能更漂亮地让我将函数参数分成多行?

时间:2019-10-25 12:37:41

标签: javascript prettier

漂亮会自动更改

    given(myObject.myCall()).willAnswer {
        throw IOException("Ooops")
    }

对此

    it(
      "Throws error if item has source: false and doesn't have children",
      () => {
        const rawData = [{ slug: 'item-name', source: false }]

        jest.doMock('../sidebar.json', () => rawData)

        expect(() => require('./helper')).toThrow(
          new Error(
            "If you set 'source' to false, you had to add at least one child"
          )
        )
      }
    )

我的漂亮配置:

    it("Throws error if item has source: false and doesn't have children", () => {
      const rawData = [{ slug: 'item-name', source: false }]

      jest.doMock('../sidebar.json', () => rawData)

      expect(() => require('./helper')).toThrow(
        new Error(
          "If you set 'source' to false, you had to add at least one child"
        )
      )
    })

它某种程度上不遵守semi: false singleQuote: true trailingComma: none printWidth: 80 tabWidth: 2 useTabs: false proseWrap: always 规则,而是将所有参数写入一行。

我当前的解决方法是printWidth,但是有更好的解决方案吗?

1 个答案:

答案 0 :(得分:0)

看起来更漂亮的测试框架函数调用与其他函数调用不同,将它们全部强制到同一行(我认为它看起来更漂亮)。

https://github.com/prettier/prettier/blob/7e5f6b9450edbc2cdd4968855b6d53429674ecd8/src/language-js/printer-estree.js#L975