Questions tagged [code-formatting]
Code formatting is the way to format the source code of programs, such as using spaces and tabs, improving legibility.
1,604
questions
-1
votes
0
answers
27
views
Why is VS Code inserting more indentation than there is for the previous line or than should be correct for regular nesting context?
Tab key indents 4 tabs at a time in vs code. I don't know which settings I've triggered but it was working fine earlier. The file is in php format and coding is html and php mixed.
I remember I didn't ...
0
votes
1
answer
81
views
How to add custom separator between functions using clang format?
I have a C and C++ code base which I format using clang format. I'd like to make my code easy to read by placing separators between functions in the following way:
//-----------------------------------...
0
votes
0
answers
34
views
how to setup a jsconfig.json for node.js
So I started to learning Node.js recently so far the gatherings all are good but I came across the concept of setup with jsconfig.json which largely helps to free the clutters made in mentioning the ...
-1
votes
1
answer
19
views
No proper formatting in React App.js in VS Code
Working on React got this improper formatting of code
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header ...
0
votes
1
answer
39
views
How to make clang-format not break after = signs and not BinPackArguments
I'm using clang-format with a small configuration file, based on the Microsoft style.
---
BasedOnStyle: Microsoft
BinPackParameters: 'false'
BinPackArguments: 'false'
ColumnLimit: '120'
#Other options....
0
votes
1
answer
27
views
How to reverse the effect of code style "Chop down if long"?
I have a big multi-dimensions array like this (the ouput of a PhpUnit provider) :
return [
'my first test case' => [
$variable1,
$variable2,
$variable3,
$...
0
votes
0
answers
16
views
Squiggly AND double line to highlight errors/warnings in Visual Studio Code
After using the Extensions Bisect feature of VSCode (which is a pretty handy tool imo), I figured out that the extension causing the ugly squiggly AND double line to highlight errors/warnings (shown ...
0
votes
1
answer
25
views
Intellij - how to force split on operator rather than on max size
How to tell intellij to split lines like Eclipse does:
private static final boolean VERY_VERBOSE = !(System.getProperty( "veryverbose" ) == null
|| System.getProperty( "...
1
vote
1
answer
21
views
Rider - place curly bracket with offset based on the begining of the parent level, not the parent declaration
I use JetBrains Rider 2022.2.3 Build #RD-222.4167.23, built on September 9, 2022
I want curly braces to be positioned based on the beginning of the level, not the declaration.
For example, I want
var ...
0
votes
0
answers
12
views
jupyterlab_code_formatter: multi-line list in code, specify items/characters per line?
jupyterlab_code_formatter installed for Jupyter lab
Black, isort, YAPF, Autopep8 added for jupyterlab_code_formatter
Question: which config should I twist if I want the auto-formatted list to not be ...
0
votes
1
answer
44
views
Intellij IDEA Java code formatting: can I force a newline after public and before a method return type?
I would like my java method declarations to look like:
static public
boolean method1(int arg1) {
...
}
where there is a newline after public and before boolean. Is there a way to do that in IntelliJ ...
0
votes
1
answer
59
views
Rider/ReSharper - Wrap chained method calls before first method
I have set Line Brakes and Wrapping -> Arrangement of Members Access Expression -> Wrap chained method calls to Chop always
Rider is formatting chained method calls this was:
var numbers = ...
0
votes
0
answers
18
views
PDB and line length formatting
Some collaborators on a project are encouraging the use of the automatic code formatting tool black. Unfortunately, some of its decisions clash with my aesthetic intuitions, but more importantly, the ...
0
votes
1
answer
70
views
May I vertically-align YAML values?
YAML code can get difficult to read and maintain, so like in other languages, I'd like to vertically-align "scalars".
For example, instead of this:
breakfast:
spam: 1
hamHamHamHam: 2
...
1
vote
0
answers
22
views
How to force empty line between code blocks in Prettier
I'm using Prettier to format my codebase and I want to add a space between code blocks like loops, if/case statements, functions, etc.
So right now Prettier leaves the following alone:
// ----- ...
0
votes
1
answer
56
views
Configuration file for checkpatch.pl tool
According to the explanation from this source, the .checkpatch.conf file that specifies the configuration options for checkpatch.pl tool must be in the top-level directory of the project.
Would it be ...
0
votes
0
answers
22
views
Xcode: Any way to change how hot-key comments are formatted?
Right now, if you hit CMD + /, the current or selected line(s) of code is(are) prepended with "//" turning it into a comment. No surprises.
However, it always puts the "//" at the ...
0
votes
1
answer
31
views
Ansible module and tags on single line
Consider these ansible tasks:
- import_tasks: foo/spam.yml
tags: foo, spam
- import_tasks: foo/ham.yml
tags: foo, ham
- import_tasks: foo/eggs.yml
tags: foo, eggs
Is it possible to write those ...
0
votes
1
answer
50
views
Is it possible to format the tuples aligned by arrows in IntellIJ for scala?
In PyCharm there is an option to align dict items on colon for Python:
dct = {
'one' : 1,
'two' : 2,
'three': 3,
}
And I want a similar way to format the dict items on arrow for Scala ...
0
votes
0
answers
38
views
How to make VSCode break long lines of JavaScript down without resorting to Prettier or Standard?
I'm trying to transition from JetBrains IDEs to Visual Studio Code, but I'm running into an issue with formatting JavaScript. When an assignment statement is over the line length limit, the VSCode ...
0
votes
2
answers
45
views
My prettier format breaking vue code (ref<number>(0)) with typescript
Before Format:
const activeIndex = ref<number>(0)
After Format:
const activeIndex = ref < number > 0
Prettier Output:
enter image description here
Prettier Config:
{
"$schema"...
1
vote
1
answer
204
views
Android Studio formats Dart code differently than the dart format tool
Android Studio settings in Editor -> Code Style -> Dart state that:
Code is formatted using the dart format tool included with the Dart SDK. See FAQ.
But in some cases, it seems to be behave ...
0
votes
1
answer
61
views
IntelliJ Java formatter align when multiline at asignment
how can I force IntelliJ Java formatter to keep code like this:
boolean betweenKingLeftAndRookEmpty =
board.getSquareAtPosition(59).isEmpty() &&
board....
0
votes
2
answers
44
views
How can I sort the JS variables in a single file alphabetically?
I have a JS file with about 1,000 variables that looks like this:
export const FruitOrange: React.FC = () => (
<Trans id="fruit.orange">Orange</Trans>
);
export const ...
1
vote
1
answer
160
views
How can I force the 'this' keyword on local fields and methods with the Spotless Java code formatter?
I want to enforce the use of the 'this' keyword using Spotless. For example: getTowerData().recordMap would be this.getTowerData().recordMap.
I'm running Spotless with Gradle with the current ...
0
votes
0
answers
39
views
Delphi JCF Formatter: how to preserve spaces in declaration?
how can I keep the spaces in this declarations, so the : kept aligned.
Var1 : string;
MyVar1 : integer;
MyOtherVar : boolean;
May somewhere in Clarify - Align, but I have not ...
0
votes
0
answers
14
views
Is there a more proper way to code this so razor formats it correctly?
Visual Studio improperly formats the code below as shown. I would think that if this were the way Microsoft employees were taught to code these kinds of scenarios that Microsoft would probably fix ...
0
votes
1
answer
162
views
clang-format always indent struct initiallizers
i have a very strange behavior with my current .clang-format file.
here is the file:
---
BasedOnStyle: LLVM
ColumnLimit: 200
IndentWidth: 4
UseTab: Always
TabWidth: 4
BreakBeforeBraces: Linux
...
1
vote
1
answer
172
views
Style .arb files in android studio
I'm starting to work with .arb files in Android Studio and I find them quite difficult to read as only plain text.
Is there any way to color or format the structures more readeable?
no style code for ....
0
votes
0
answers
65
views
JetBrains PhpStorm - comments have a lot of extra space?
I just moved from VSCode to PhpStorm. A small annoying thing is that when commenting a section (in a Blade file) PhpStorm adds a lot of (unneeded) space, which I have to go over and manually trim. ...
3
votes
0
answers
541
views
How to configure Prettier to format Cypress code with chained calls?
I'm using Prettier to format my Cypress code, but it's breaking lines in a way that I don't like. Specifically, it's formatting lines like this:
cy.contains("div[role='alert']", "Status ...
1
vote
1
answer
200
views
Tools to lint and format Python code in Quarto (`.qmd`)/R Markdown (`Rmd`) files
I search for Python linters/formatters for Quarto .qmd and R Markdown (.Rmd) files. Are there any tools that work out of the box to:
a) either lint and/or format Python code in Python code cells of ...
0
votes
1
answer
78
views
keyword "public" not indented correctly using vscode in c/c++
i'm using the default visual studio formatter for c/c++, yet it seems to be formatting the word "public" different, its adding 2 white spaces (refer to image) which as far as i know isn't ...
0
votes
1
answer
199
views
Visual Studio: how to format each input parameter in a line in function declaration and function definition?
I have a function like this void my func(int a, int b, int c);
Is there any tool, any way or any VS extension to format (convert) my function as
void myfunc(
int a,
int b,
int c);
void ...
0
votes
2
answers
389
views
Format Kotlin with minimal indent for code blocks in constructor parameters, like Foo({ bar })
When formatting this code block (from the Kotest documentation), Jetbrains Intellij or Android Studio adds a lot of unnecessary white space.
Original code:
class MyTests : FreeSpec({
"String....
1
vote
0
answers
36
views
clang format space before parens in function call except for short names like gettext helpers?
An example of a common style pattern is:
return g_strdup (_("24-hour"));
label = g_strdup_printf (C_("timezone desc", "%s (%s)"), ...
I.e. space between function name ...
1
vote
1
answer
692
views
How to prevent VSCode from reordering python imports across statements?
This is the correct way to import Gtk3 into python:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GObject
When I save such code in VSCode with "editor....
0
votes
1
answer
351
views
Black make function arguments formatting without new lines around barackets
I'd like to format function argumetns in a way similar to the PyCharm default formatting - see image. Meaning no new line after '(' and before ) so it does NOT look like in the second image. It looks ...
0
votes
1
answer
53
views
Format SQL code: function closed parenthese under the name of function
I'm working on PhpStorm (the same as for any other IDEA product) and there is a possibility to manage SQL auto-formatting in it.
I'm playing with settings to unify our SQL formatting standard. I've ...
5
votes
0
answers
185
views
How to format C++ code in Visual Studio using my own rules?
I am using Visual Studio 2019.
I want to create a setting file for Visual Studio which consists of my own formatting rules and anyone can import those settings for their Visual Studio. (I think this ...
0
votes
1
answer
20
views
How to stop from alignment with space in WebStorm
When I use "Optimize imports" all imports are aligned with spaces like in the screenshot below.
How can I disable this?
0
votes
0
answers
31
views
how can i prevent uncrustify removing space between namespace "static class" and formatting it to staticclass?
i am using qt beautifier uncrustify. Withouth namespace it doesnt remove space between "static class" but when i use it under namespace it removes space between formatting it to staticclass
...
0
votes
0
answers
80
views
Require 'this' keyword in VS2022 while formatting and compiling
I upgraded to Visual Studio 2022 (17.4.4) and see that the formatting options have changed significantly.
I have tried experimenting and searching but cannot figure out how to force the required use ...
0
votes
0
answers
33
views
IntelliJ IDEs - Wrap line different depending on finalising comma existence
Hey I want different styles how my objects or arrays are formatted. The difference should only make the syntax and the code formatter from IntelliJ. I wonder if there is any setting in the IDE for ...
0
votes
0
answers
84
views
How do I properly configure Uncrustify indentation for nested designated initializers in an array?
I am trying to use Uncrustify version [Uncrustify-0.72.0_f] (on Windows 10) (https://github.com/uncrustify/uncrustify/releases/tag/uncrustify-0.72.0) to format a nested array (an array of structs) ...
0
votes
0
answers
37
views
Making “Reformat code” on request block - it has other layout I need
Laravel 9 app in PhpStorm 2021.1.4
When I make “Reformat code” on a block of code I got :
$totalVotesCount = Vote::getByName($filterName, true)
->getByStatus($filterStatus)
...
0
votes
0
answers
20
views
PhpStorm reformat array [duplicate]
I lost my previous settings from PhpStorm for formatting an array like this:
$array = [
'short_key' => 'value1',
'a_much_longer_key' => 'value2',
'another_long_key' => 'value3',
];...
0
votes
1
answer
65
views
How do I prevent the Reformat Code action for Markdown files from putting a full stop on a line of its own?
I find that the "Reformat Code" action in IntelliJ (and, by extension, Android Studio) will put a full stop on a new line in Markdown files if the full stop is the character at the "...
0
votes
1
answer
350
views
How to change tab size in Visual Studio 2022 for Mac?
I am using Visual Studio 2022 for Mac (currently v17.4). I want to change tab size as they are too big. I cannot see such option anywhere and even in the documentation it says it doesn't apply to ...
1
vote
1
answer
463
views
How to prevent AndroidStudio from formatting custom line breaks?
Problem
AndroidStudio formats custom line breaks.
Version: Dolphin | 2021.3.1
What I've tried
I tried to disable this function like below:
AndroidStudio> Preferences> Editor> Code Style> ...