[PATCH] D69764: [clang-format] Add East/West Const fixer capability

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 8 01:38:42 PDT 2021


MyDeveloperDay added a comment.

FYI, I'm not actually asking for this to be merged, its just I'm happy to keep rebasing it from time to time for others to use,  but to do that I have to keep pushing new reviews, but if the general opinion was to put it in then I'd go for that.

I knew it was going to be a contentious idea, and I think its very hard to do 100% correctly without semantic information (like lots of other aspects of #clang-format <https://reviews.llvm.org/tag/clang-format/>), because of that I'm a little nervous, but as its off by default I'd hope we could mitigate that.

I personally just don't want it for clang-tidy, as as much as I like clang-tidy I feel less that 1% of the people using clang-format are using clang-tidy because of the issues of setting something up to actually run it, and for something with semantic information clang-tidy -fix regularly butchers code making it incorrect,  just saying...  clang-format too is far from perfect, if you live on the edge of what I would consider to be sensible readable coding, it will mutate it into something that won't compile especially if you have an over propensity to use macros!

My feelings for this are a little mixed, when I started it only handled a few cases and I felt it was more robust, as people pushed me to support more cases I've become less happy that it won't break their code during correction.

Whilst this may not be suitable for mainstream clang-format, I think this makes for a great CI tool that is being used to "check" code rather than "correct" code, and so I build this for my CI system so I can catch people adding "east const" where I don't want them to. But for my large project I don't proactively flip back and forth between west and east to ensure I'm not making the code incorrect.

I run `clang-format -n` on my nightly & CI builds to pull out clang-format issues as build warnings in the log file, this means I can turn clang-format failures into notifications which get fixed almost immediately. People forget to run clang-format  way more often than they put in "east const", most of my developers have developed the muscle memory to not do that, but this helps bring new developers onboard without me having to crush their dreams during code review!

When it comes to "Finding" east/west const violations this does the job and I am unaware of any other tool that does that in the entire C++ ecosystem, for that point alone I think having such a tool is worth it. I wouldn't want to put this into any other tool because of the clang-format integration points being already established with editors/CI systems etc...  (the exact same reasons why I wanted C# and JSON formatting)

My 2p worth


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69764/new/

https://reviews.llvm.org/D69764



More information about the cfe-commits mailing list