-1

I am using VS Code as my editor. I have installed the 'EditorConfig for VS Code' extension. I have added an .editorconfig file to my root project. This is the code in the .editorconfig file:

root = true

[*.c]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
brace_style = attach

The following is the C-file (called main.c) that I want to format by using designated shortcut to apply formatting to the C-file:

#include <stdio.h>
#include <math.h>

double fun(double x, double n)
{
    return pow(x, n);
}

int main()
{
    printf("Please write a base number:\n");
    double base, exponent;
    scanf("%lf", &base);
    printf("Write a exponent number:\n");
    scanf("%lf", &exponent);
    printf("The numbers %lf and %lf gives: %lf \n", base, exponent, fun(base, exponent));
}

The C-file (called main.c) is located within the root-folder as .editorconfig file. Thus,

Root
|-- .editorconfig
|-- Project A
    |-- main.c

I want to be able to make opening brackets be positioned on same line. The property brace_style should ensure brackets being positioned on same line. Unfortunately they keep being moved to new line. I can change property of indent_size to say 8, and these changes will then be formatted in the main.c file. Thus, there is "connection" between the main.c file and the .editorconfig file. It just don't want to format the brackets to same line.

starball
  • 20,030
  • 7
  • 43
  • 238
morten
  • 35
  • 4

1 Answers1

0

I'm not aware of VS Code's EditorConfig extension supporting a brace_style property. EditorConfig.EditorConfig documents that it uses the editorconfig npm package, (at the time of this writing), its only supported properties are indent_style, indent_size, tab_width end_of_line (on save), insert_final_newline (on save), and trim_trailing_whitespace (on save).

I tried googling for the brace_style property and found this JetBrains documentation, so I wonder if you got it from a JetBrains IDE and assumed it was something you could use with any editor, when in fact- it's a editor extension. See also https://github.com/editorconfig/editorconfig/issues/199#issuecomment-72388652.

If the EditorConfig extension for VS Code is adding those newlines, that's weird. If you just want it to get rid of them if they're already there, since the VS Code extension you're using comes from the EditorConfig maintainers, you'll either need to find a different extension, ask them to implement something that they've already said doesn't make sense to be universal, or wait for their idea for a proposed domain specific property "curly_bracket_next_line" to get decided upon (you may find issue tickets related to that here).

starball
  • 20,030
  • 7
  • 43
  • 238