How to stop curly brace on new line when formatting the code - visual-studio-code

I am using VSCode and have installed phpfmt PHP formater extension. When I hit the format code option, the cruly braces of functions and classes are set to new line. I have practice of adding curly brace on the same line and I want the same to be done by the formater.
What I want is:
public function abc () {
}
What PHP formater does is:
public function abc ()
{
}

It works for me:
"phpfmt.psr2": false,
This option is enabled by default and and as written in this standard:
Opening braces for methods MUST go on the next line

"phpfmt.exclude": ["AllmanStyleBraces"]

It is coming default as you are looking for. Try to add formate extensions. Look for PHP phpcs extension.
If it is not working than reinstall your visual studio code again.

Related

customizing VSC formatting on Save

I have an existing PHP codebase where methods are formatted:
public function myIssue() {
// some code...
}
VSC changes this on save to:
public function myIssue()
{
// some code...
}
Is there some way I can turn off this specific VSC formatting rule from occurring on save and allow all the other formatting changes VSC suggests to still occur?
Not the answer you are looking for but an explanation from vscode's perspective:
Visual studio code is implementing what is called a PSR coding style and is considered to be the standard for PHP. As you can see over at the documentation at 4.1 (functions), it mentions that:
The opening brace MUST go on its own line, and the closing brace MUST
go on the next line following the body.

How to add line breaks in vs code terminal?

I Have a problem that, my vs code terminal does not have the line break after the output
please tell how to add the line break after the output
(1st image is my output and 2nd image is the expected output)
Use this in settings.json when using c++
".cpp":"echo -e",
Open VS Code, go to settings > extentions > Run code configuration open settings.json ( you must have code runner extention installed for this), you must have vscode settings json,
then white code-runner.executorMap on newline inside brackets, you must have something like this
then whatever language you code, add on the end of the String
"; echo -e"
so you must have something like this, for example I code on java
the result is this

VSCode Rust add semicolon on save

I am using the Rust extension on vscode and NOT rust-analyzer. However, when I am saving a file, vscode is using rustfmt to format my file but it doesn't automatically insert semicolons. I have a trivial function like this
fn call_me() {
let x = 5
println!(x)
}
It doesn't add the necessary semicolons. How do I make it add semicolons? Are my installations somehow messed up?
Also, I have tried rust-analyzer and it doesn't add semicolons either.
Unlike JavaScript, semicolons are not syntactically optional in Rust. Thus, leaving them out is a syntax error, not just a matter of style, and rustfmt (the standard Rust code formatting tool) doesn't ever attempt to fix any syntax errors, no matter how “obvious” they might be — if it reads a file with errors it will not make any formatting changes.
(I don't know if there's a way to get rust-analyzer, vim, or VS Code to auto-insert semicolons as a matter of editing rather than formatting.)
Maybe not what you're looking for but there are language-agnostic options to reduce the friction of semicolon insertion.
For instance the vs code extension colonize adds the shortcut alt+enter which appends a semicolon and newline, no matter where in the line the cursor is.

configure prettier to push curly braces on new lines & not clear empty lines

I am using prettier with VSCode, How can I configure it to format my code like this :
function test()
{
if()
{
MYCODE GOES HERE;
}
}
I want the { and } on new lines, and an empty line after { and before }.
Currently, it moves the curly brackets to same lines if condition or function name, and also remove the empty lines after/before { and }.
Prettier is considered an " opinionated " formatter, which means it doesn't let you choose things like that. If you want more control over the formatting, you can use a different formatter.
The built-in VS code formatter allows you to do what you're looking for, just search the settings for " function new line " and similar options.
There are of course many other formatting extensions available in the VS code marketplace as well. Whichever you choose, you will have to select it has your default formatter in your VS code settings.
As mentioned in this answer, VS Code's formatter itself works quite well, but if you want this to be part of workflow, then using ESLint might make things easier. There's a rule called brace-style.
You can then run eslint ./path/to/your/file --fix to format your code, or eslint . --fix to format code in the entire project directory.
Disclaimer: I use ESLint for code formatting most of the time and it works for me. I actually use it to find & fix problems too so it's like killing two birds with one stone, but note that ESLint is more about finding problems in the code and fixing them, so using ESLint just for code formatting might not be the best idea.

Visual Code IDE curly brace formatting

I am trying some TypeScript stuff in Visual Studio Code Editor.
When the intelligence generates a class or function, the curly brace is opening in the same line. I don't prefer that style. I needed the curly brace to be started on the new line always. Can you tell me how to make that and which settings to be turned on?
Thank you in advance
Although I do not recommend this settings you can add the following entries to your settings.json to achieve that behavior:
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": true,
"typescript.format.placeOpenBraceOnNewLineForFunctions": true
Now every time you hit Shift + Alt + F to format your code the braces will be set on a new line.