【问题标题】:WebStorm, empty code blocks, and curly bracesWebStorm、空代码块和花括号
【发布时间】:2017-04-07 16:33:50
【问题描述】:

每次我“重新格式化代码”时,WebStorm 都会在任何空花括号之间放置一个换行符。例如,如果我有这个代码:

export class Example {}

我重新格式化代码(Command + Option + L 在 mac 上),我最终得到了这个:

export class Example { }

如何阻止我的编辑器插入新行? WebStorm 版本为 2016.2

【问题讨论】:

    标签: typescript webstorm


    【解决方案1】:

    使用这些设置,它似乎可以工作——IDE 不会将此类代码分成多行,而是保持原样。

    1. Settings/Preferences | Editor | Code Style | TypeScript --> Wrapping and Braces
    2. Keep when reformatting | Simple block in one line -- 勾选
    3. Braces placement | In class declaration -- "行尾"

    PhpStorm 2016.3 的屏幕截图...但在 2016.2 中应该是相同的。

    【讨论】:

    • 所以这段代码:export class Example {}无论如何都会变成export class Example {[NEW_LINE]}。但是如果我打开Simple methods in one line,这段代码:constructor() {} 将保持不变。这非常接近(因为无论如何我不应该有太多的空课程),所以我会接受这个作为答案。谢谢。
    • 类示例与我的设置保持一致——上面的这 2 个更改是我所做的唯一事情。
    【解决方案2】:

    根据WebStorm在线帮助:

    Braces Placement OptionsBraces placement style 设置为 Next line if wrapped

    【讨论】:

    • 如果我转到 Webstorm -> Preferences -> Editor -> Code Style -> TypeScript -> Wrapping and Braces 并为 Braces placement -> In class declaration 选择 Next line if wrapped,则 OPENING 大括号被移动,而不是右大括号。
    • @exk0730 可以尝试将其设置为End of line吗?
    • 是的,这就是它的默认设置,我相信。它似乎只控制开始大括号:/
    【解决方案3】:

    其实是Simple methods in one line选项

    【讨论】:

      猜你喜欢
      • 2018-04-29
      • 2011-04-07
      • 2010-12-13
      • 2012-01-18
      • 2015-12-19
      • 1970-01-01
      • 2014-07-28
      • 1970-01-01
      相关资源
      最近更新 更多