Reformat is compressing lines of code into a single line

It will take: 

and make it like 

Obviously, I prefer the first. This seems to happen for all `if` statements that are not bracketed, it will simply grab an `else` on the next line and move it up to the same one.

The behavior only started recently, and I can't think what change could have prompted it.

Edit: I've tried 

and that has not helped. No extra plugins enabled.

0

You can try enabling the Keep when reformatting > Line breaks in Settings | Editor | Code Style | JavaScript | Wrapping and Braces - does it work for you?

0

Unfortunately no. I did try that.

edit: and to be clear, it's not a matter of keep or not. The “reformatting” I desire is to not have two lines of code on the same line. It's very weird it would start doing this.

0

Unfortunately I failed to reproduce the issue

Could you share a complete code snippet that reproduces it plus your code style preferences (<IDE config dir>/codestyles/<scheme name>.xml) if you are using IDE-level scheme, or .idea\codeStyles\Project.xml when using a project scheme)?

0
function foo () {
  if (true)
    return;
  else
    return;
}
<code_scheme name="Project" version="173">
  <option name="OTHER_INDENT_OPTIONS">
    <value>
      <option name="USE_TAB_CHARACTER" value="true" />
    </value>
  </option>
  <HTMLCodeStyleSettings>
    <option name="HTML_UNIFORM_INDENT" value="true" />
    <option name="HTML_ALIGN_ATTRIBUTES" value="false" />
  </HTMLCodeStyleSettings>
  <JSCodeStyleSettings version="0">
    <option name="SPACE_BEFORE_GENERATOR_MULT" value="true" />
    <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
    <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
    <option name="SPACES_WITHIN_IMPORTS" value="true" />
    <option name="FUNCTION_EXPRESSION_BRACE_STYLE" value="2" />
  </JSCodeStyleSettings>
  <TypeScriptCodeStyleSettings version="0">
    <option name="JSDOC_INCLUDE_TYPES" value="true" />
  </TypeScriptCodeStyleSettings>
  <codeStyleSettings language="HTML">
    <indentOptions>
      <option name="USE_TAB_CHARACTER" value="true" />
    </indentOptions>
  </codeStyleSettings>
  <codeStyleSettings language="JavaScript">
    <option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
    <option name="BRACE_STYLE" value="2" />
    <option name="CLASS_BRACE_STYLE" value="2" />
    <option name="METHOD_BRACE_STYLE" value="2" />
    <option name="ELSE_ON_NEW_LINE" value="true" />
    <option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
    <option name="ALIGN_MULTILINE_FOR" value="false" />
    <option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
    <option name="KEEP_SIMPLE_BLOCKS_IN_ONE_LINE" value="true" />
    <option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
    <indentOptions>
      <option name="INDENT_SIZE" value="2" />
      <option name="CONTINUATION_INDENT_SIZE" value="2" />
      <option name="TAB_SIZE" value="2" />
      <option name="USE_TAB_CHARACTER" value="true" />
      <option name="SMART_TABS" value="true" />
    </indentOptions>
  </codeStyleSettings>
</code_scheme>

This is a really basic project I just set up to test, and it has the same issue as my other projects.

edit: tested again and it will do the same thing with the default xml.

<code_scheme name="Default" version="173" />

Video of doing repro here

2023-11-10 12-06-36.mp4

 

0

Sorry, my comment seems to be stuck “pending approval.”

But in a nutshell, it does it with the default profile and this snip:

function foo() {
    if (true)
        return;
    else
        return;
}
0

With your code style settings, the code is formatted as follows for me:

function foo() {
    if (true)
        return;
    else
        return;
}

As you can see, the line breaks are not removed

Please share a sample project that reproduces the issue (along with the .idea folder)

0

I got hit with “pending approval” again in my comment for sharing a link to the files on onedrive, and I can't see a way to attach a zip directly. My previous comment still has not cleared.

On one drive it's Ai1LfYkLJyBJi6M0RK6Q3S2y6ISTPg?e=w838x2

0

In your project, you are using the IDE-wide ('default') code style scheme I have no access to

When using my code style settings, formatting works as expected, line breaks are kept

Note that the second re-formatting removes the line breaks despite the option 

 

0

To be clear, I don't mind

function foo() {
    if (true) return;
    else return;
}

What I never want is

function foo() {
    if (true) return; else return;
}

When you say “the second re-formatting removes the line breaks” are you saying that it produces the first example or the second?

I don't ever want the second, and I want the IDE to fix the damage it did when it produced the second.

edit: the “project wide default” is simply this xml:

<code_scheme name="Default" version="173" />

I have set everything back to defaults that I can find!

edit: video link s!Ai1LfYkLJyBJi6MaWQgEbfKF-QCfzw?e=v4lXYp

0

When you say “the second re-formatting removes the line breaks” are you saying that it produces the first example or the second?

 

The second - it removes the manually added line breaks, overriding the Keep line breaks option

But this only happens if you hit Ctrl+Alt+L 2 times in a row, without making changes to your code in between

0

press ctrl + alt +L    2 times
then in the emergent windows click NO and select (dont ask again).

thats it..

0

请先登录再写评论。