[clang-format] Add Left/Right Const fixer capability
authormydeveloperday <mydeveloperday@gmail.com>
Thu, 23 Sep 2021 19:00:33 +0000 (20:00 +0100)
committermydeveloperday <mydeveloperday@gmail.com>
Thu, 23 Sep 2021 19:00:33 +0000 (20:00 +0100)
commita44ab1702539c9ef3aea292e23cfbff17897bdbd
tree8c90acccdbfed78567149eee6fb3155e5c7f3992
parent52272f294ffc28691ec3d77582c3678273d25411
[clang-format] Add Left/Right Const fixer capability

Developers these days seem to argue over east vs west const like they used to argue over tabs vs whitespace or the various bracing style. These previous arguments were mainly eliminated with tools like `clang-format` that allowed those rules to become part of your style guide. Anyone who has been using clang-format in a large team over the last couple of years knows that we don't have those religious arguments any more, and code reviews are more productive.

https://www.youtube.com/watch?v=fv--IKZFVO8
https://mariusbancila.ro/blog/2018/11/23/join-the-east-const-revolution/
https://www.youtube.com/watch?v=z6s6bacI424

The purpose of this revision is to try to do the same for the East/West const discussion. Move the debate into the style guide and leave it there!

In addition to the new `ConstStyle: Right` or `ConstStyle: Left` there is an additional command-line argument `--const-style=left/right` which would allow an individual developer to switch the source back and forth to their own style for editing, and back to the committed style before commit. (you could imagine an IDE might offer such a switch)

The revision works by implementing a separate pass of the Annotated lines much like the SortIncludes and then create replacements for constant type declarations.

Differential Revision: https://reviews.llvm.org/D69764
12 files changed:
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/docs/tools/dump_format_style.py
clang/include/clang/Format/Format.h
clang/lib/Format/CMakeLists.txt
clang/lib/Format/Format.cpp
clang/lib/Format/QualifierAlignmentFixer.cpp [new file with mode: 0644]
clang/lib/Format/QualifierAlignmentFixer.h [new file with mode: 0644]
clang/tools/clang-format/ClangFormat.cpp
clang/unittests/Format/CMakeLists.txt
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/QualifierFixerTest.cpp [new file with mode: 0755]