clang format export not respecting settings?

I created a C++ code formatting style I use with my unreal engine project.

I use the “Write current style to .clang format” and set it to use Rider Formatter and Read Code Style from .clang-format files.

However it then says there are things in the Clang Format that are overriding the settings.  If I uncheck the read code style from .clang format files option, my settings work.  Could it be that the .clang-format file export isn't working right, or are the settings I want not possible to store in a .clang-format file?  I'd want to export these settings and save them to share with the team and restore them when needed. I don't see other export formats. This ends up as a file I can commit to our git repo which is nice, once I get it working.

I also verified the clang-format file it's trying to use is the correct one I just exported by using this. https://www.jetbrains.com/help/rider/Configure_Code_Formatting_Rules.html#troubleshoot-formatting-settings

I didn't exactly read through the format file in detail either to find whether or not my settings exported out correctly since it's a gigantic file and I'm not familiar with this format.

0
3 comments

Hello Ilya,

Thank you for contacting Rider support.

The yellow bar with a message means, that the code style settings from .clang-format are red and values there intersects with those you can see in Rider UI. The settings from .clang-format file takes priority over Riders own settings, so that, such a settings are marked in yellow.

Would you mind sharing additional information as described below, so that I can take a closer look at the issue?

  • Go to Settings | Manage Layers. Select every layer one by one and select Export to File. Please, share the resulting files;
  • Share the .clang-format file generated by Rider;
  • Point out sample setting that you feel doesn't work;

Have a nice day!

0

Not sure if there's a way to attach files, so here are the contents of the .clang-format file and a link to the layer files. https://github.com/ill/FileShare/blob/main/SettingsLayers.zip

I have the files for the exported DotSettings layers but I'm not sure how to attach them in this forum.

Sample settings that don't work are spacing before pointer and after pointer.  I have it set so it should look like this:

Type* VarName;

But it does this based on the clang-format file.

Type *VarName;
 

---

Language: Cpp

BasedOnStyle: LLVM

AccessModifierOffset: -4

AlignAfterOpenBracket: DontAlign

AlignConsecutiveAssignments: false

AlignConsecutiveDeclarations: false

AlignOperands: false

AlignTrailingComments: false

AllowShortIfStatementsOnASingleLine: false

AlwaysBreakAfterDefinitionReturnType: false

AlwaysBreakTemplateDeclarations: Yes

BinPackArguments: false

BinPackParameters: false

BraceWrapping:

  AfterCaseLabel: true

  AfterClass: true

  AfterControlStatement: true

  AfterEnum: true

  AfterFunction: true

  AfterNamespace: true

  AfterStruct: true

  AfterUnion: true

  AfterExternBlock: false

  BeforeCatch: true

  BeforeElse: true

  BeforeLambdaBody: true

  BeforeWhile: true

  SplitEmptyFunction: true

  SplitEmptyRecord: true

  SplitEmptyNamespace: true

BreakBeforeBraces: Custom

BreakConstructorInitializersBeforeComma: false

ColumnLimit: 0

ConstructorInitializerAllOnOneLineOrOnePerLine: true

IncludeCategories:

  - Regex: '^<.*'

    Priority: 1

  - Regex: '^".*'

    Priority: 2

  - Regex: '.*'

    Priority: 3

IncludeIsMainRegex: '([-_](test|unittest))?$'

IndentCaseBlocks: true

IndentWidth: 4

InsertNewlineAtEOF: true

MacroBlockBegin: ''

MacroBlockEnd: ''

MaxEmptyLinesToKeep: 2

SpaceInEmptyParentheses: false

SpacesInAngles: false

SpacesInConditionalStatement: false

SpacesInCStyleCastParentheses: false

SpacesInParentheses: false

TabWidth: 4

UseTab: Always

...


 

0

Hello Ilya,

Thank you for the details shared.

The LLVM style you use in clang-format predefines the PointerAlignment: Right rule. If there is no PointerAlignment: Left (or Middle) explicitly specified in the config file, the alignment to Right is used. Since clang-format formatting settings have higher priority over Rider's own settings, the alignment to the right is used in this case.

As I understand, the problem occurred in this scenario:

  • You configured your code style settings in Rider UI. The style configured is Type* VarName. Reformatting works as expected until you export settings to .clang-format;
  • After you exported settings to .clang-format, the resulting format is different: Type *VarName.

I registered this issue on our tracker: RSCPP-36053 PointerAlignment is not exported to .clang-format.

To workaround it, please add PointerAlignment: Left manually to the .clang-format file.

Hope that helps.

If there is anything else I can assist you with, please tell me.

Have a nice day!

0

Please sign in to leave a comment.