llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.33k stars 11.7k forks source link

.editorconfig #50445

Open 96fca67a-c7e4-47a5-b9c7-b7489d0c6f76 opened 3 years ago

96fca67a-c7e4-47a5-b9c7-b7489d0c6f76 commented 3 years ago
Bugzilla Link 51101
Version trunk
OS Windows NT
CC @dwblaikie,@mydeveloperday

Extended Description

.editorconfig ( https://editorconfig.org/ ) is the standard way to define code formatting and analysis rules.

The main advantage of editorconfig file is filtering options which are unavailable in Clang Format YAML.

The conversion from YAML to editorconfig can be done straight-forward, for example:

.clang-format:

Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align

.editorconfig:

[*.cpp]
clang_format_cpp_access_modifier_offset = -4
clang_format_cpp_align_after_open_bracket = align

# Can specify different rule for a different filter
[tests/*.cpp]
clang_format_cpp_access_modifier_offset = 8
mydeveloperday commented 3 years ago

I think generally as an idea this is pretty good, I guess perhaps to begin with it might be nice to have a .editorconfig to .clang-format converter

That is something that could be developed as a standalone. (great little starter project for someone!)

There are likely aspects of .editorconfig which clang-format doesn't support

But probably it would be good to take a deeper look at where these is overlap and where there isn't

its might open up new avenues for new functionality to be added to clang-format.

96fca67a-c7e4-47a5-b9c7-b7489d0c6f76 commented 3 years ago

Yes. It solves few issues with the current approach: Well known file. All editors today understand editorconfig but not clang-format. By understand I mean highlighting or visual editing.

Filtering rules: Today you must do it externally by calling or not calling clang-format for needed files.

Forward compatibility: Today if you specify option from future clang-format fails. Editorconfig format requires you to not fail in such case.

dwblaikie commented 3 years ago

To be clear, the feature request is that you would like clang-format to support parsing .editorconfig files directly as an alternative to .clang-format files?

96fca67a-c7e4-47a5-b9c7-b7489d0c6f76 commented 3 years ago

Here are C++ formatting rules understood by ReSharper C++:

https://www.jetbrains.com/help/resharper/EditorConfig_CPP_CppBlankLinesPageScheme.html

96fca67a-c7e4-47a5-b9c7-b7489d0c6f76 commented 3 years ago

Here are C++ formatting rules that Visual Studio understands: https://docs.microsoft.com/en-us/visualstudio/ide/cpp-editorconfig-properties?view=vs-2019