How to format C# "else" onto one line in Rider - rider

How can I get else to be on one line as it should be? (meaning } else { instead of the version shown below).
I am already using K&R style which fixes all other uses of braces (as shown below), but it does not fix the else.

There is a toggle in the "Editor" > "Code Style" > "C#" settings under the "Line Breaks and Wrapping" tab called "Place 'else' on new line":
Disabling this will achieve what you want.

Related

Autoformat code CTRL+SHIFT+L add a space, between ending quote and parenthesis of string

For example when my code says:
System.out.println("Printing demo features");
I use CTRL+SHIFT+L and Intellij make this:
System.out.println("Printing demo features" );
Thanks for your help.
It looks like you have custom code styling in place for Java, thus the auto format function tries to match it:
Check Settings > Editor > Code Style > Java > Spaces and look for "Within" grouping. See if you have some options marked like "Method call parentheses". If you don't have any custom style in place, simple reset the Java style to default and it should be "fixed".
Obs.: I am on Intellij14, options might be different.
Check off Settings > Editor > Code Style > Java > Spaces > Within > Method call parentheses
If above didn't help: "File" -> "Invalidate Caches / Restart..." (sounds unrelated, but in my case actually solved it)

How do I change the way syntax warnings for a missing semi-colon (red squiggly lines) are generated?

I love the fact that IntelliJ evaluates my code for syntax errors, but I don't like that it shows common errors on the current line as I'm typing.
There are several examples of this, but the most common one is the red error line (squiggly underline) for a missing semi-colon. I don't want the editor to check for this error until after I've finished typing the line and have pressed return. In fact, I really don't want the editor to evaluate the current line for ANY syntax errors until after I've completed it. The constant changing of the error indicators on the current line as I type is getting annoying.
I've looked around in the various options, but I can't seem to even find the name of squiggle line feature. It isn't code analysis, as that applies to the red and yellow indicators in the right margin. What is the name of this feature, and where can I find the options for it?
Example ( '|' is the current carrot position, '~~' are the red error lines)
System.Out = |
~~
The issue isn't limited to just the semi-colon, but for all sorts of other common syntax issues that I know I know about and will fix before moving on to the next line.
Update: I think the name of the feature is "error highlighting". But I still can't find any way to disable it for the current line. The closest I found was Setting --> Editor --> General --> Error Highlighting --> Reparse Delay, but that changed it globally with no option for just the current line.
There is no option in IntelliJ IDEA to disable error highlighting for the current line.
You can change the Settings -> Editor -> General -> Error Highlighting -> Auto reparse delay (ms) to something more comfortable, e.g. 3000 ms.
It will still highlight the error, but not immediately.

IntelliJ, Java formatting: force empty blocks to be on one line

Is it possible to tell IntelliJ to put empty block on one line when formatting Java files.
I'd like this:
#Override
public void onClickPositive(int tag, Object payload) {
}
To automatically become this:
#Override
public void onClickPositive(int tag, Object payload) {}
There is no way to do it for reformatting code.
This can only be done manually.
Check your Code Style settings, under "Alignment and Braces" to preserve your formatting.
You should find a "Simple methods in one line" option there. Check it and clear the "Line breaks" check box.
Enable following Simple blocks in one line code style in settings.
Settings > Editor > Code Style > Java > Wrapping and Braces > Keep when reformatting > Simple blocks in one line
You can remove the unnecessary line breaks more universally throughout a project than just remove the newline before curly braces.
First go to the following setting and set a larger value for hard wrap:
Settings > Editor > Code Style
The default is 120. Change it to 250 or any other large value.
Next, navigate to the following setting:
Settings > Editor > Code Style > Java > Wrapping and Braces > Keep when reformatting > Line breaks
Uncheck "line breaks"
Finally, go back to your file and try to reformat the code.
This removes all the unnecessary line breaks that have been put into the code.

Extra space after Join Lines in IntelliJ

IntelliJ IDEA 13.0.1, 13.0.2 (but probably applies to earlier/later versions too)
Consider the following:
Collections.addAll(
new ArrayList<Object>(),
new Object());
I do "Join Lines" since it will fit on one line:
Collections.addAll( new ArrayList<Object>(), new Object());
// ^ space is annoying ^ space is nice
"Join Line" adds an extra space between the current and next line. It makes sense for some lines, but the space before the first parameter has always bugged me.
My workaround is to select and "Reformat Code", but I don't want to do the extra step if I don't have to.
Is there a better way to make "Join Line" not add that first space?
Notes:
Edit > Join Lines
Mac OS X: ⌃⇧J
Windows: Ctrl+Shift+J
Code > Reformat Code
Mac OS X: ⌥⌘L
Windows: Ctrl+Alt+L
I suspect you have a non default formatting set. Try:
File -> Settings -> Code Style -> Java -> Spaces and uncheck Method call parantheses.
This appears to be a bug in the Code Style settings.
The bug appears—for both method declarations and calls—if you modify the Default Scheme and check the following settings:
Code Style > Java > Wrapping and Braces
+- Method declaration parameters
| \- New line after '('
\- Method call arguments
\- New line after '('
Also, there needs to be more than one parameter in the method declaration or call.
Here is the issue in JetBrains' YouTrack.

How can I configure removing space between line comment slasles and text in Intellij IDEA?

If I want to comment line I use "Ctrl+/" and get the "//" at start of line
Then I use auto formatting with "Ctrl+alt+L" keys and get
At the end I must remove space between "//" and text manually every time...
Can I do all of these steps in one time? I didn't find any settings for this...
An alternative, not perfect though, is:
Editor -> Code Style -> Java -> Code Generation
Uncheck Line Comment at first column
The menu hierarchy is the one in Intellij IDEA 14.
I suggest you can use a setting to avoid the further indentation of your comment (the effect of the second screenshot).
Your comments will look like this:
// Bundle b = new Bundle();
That might not be quite exactly what you want, but at least you will be able to use "Ctrl+/" after the reformatting to return the line to a properly aligned state.
Here is the setting:
Go to Settings -> Project Settings -> Code Style -> Java
On the Wrapping and Braces tab, find the tree item at the top: Keep when reformatting and tick: Comment at first column
This works for Scala.
Preferences -> Editor -> Code Style -> Scala -> Other -> Comment Code
Uncheck Line comment at first column and Block comment at first column.
Example:
def regexTest(): Unit = {
Comment
When press comment shortcut in line 2, the above code becomes
def regexTest(): Unit = {
//Comment
Version 2020.2