[all-commits] [llvm/llvm-project] a44ab1: [clang-format] Add Left/Right Const fixer capability

MyDeveloperDay via All-commits all-commits at lists.llvm.org
Thu Sep 23 12:01:24 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a44ab1702539c9ef3aea292e23cfbff17897bdbd
      https://github.com/llvm/llvm-project/commit/a44ab1702539c9ef3aea292e23cfbff17897bdbd
  Author: mydeveloperday <mydeveloperday at gmail.com>
  Date:   2021-09-23 (Thu, 23 Sep 2021)

  Changed paths:
    M clang/docs/ClangFormatStyleOptions.rst
    M clang/docs/ReleaseNotes.rst
    M clang/docs/tools/dump_format_style.py
    M clang/include/clang/Format/Format.h
    M clang/lib/Format/CMakeLists.txt
    M clang/lib/Format/Format.cpp
    A clang/lib/Format/QualifierAlignmentFixer.cpp
    A clang/lib/Format/QualifierAlignmentFixer.h
    M clang/tools/clang-format/ClangFormat.cpp
    M clang/unittests/Format/CMakeLists.txt
    M clang/unittests/Format/FormatTest.cpp
    A clang/unittests/Format/QualifierFixerTest.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list