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

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 13 00:19:14 PDT 2021


MyDeveloperDay added a comment.

If this is something we think we wouldn't want in clang-format, what about the idea of building a new binary which did allow the modification of the tokens, This comes up from time to time and I kind of feel its a weak argument for those that don't want to use it enforcing their will on those that do.

I feel we have D69764: [clang-format] Add East/West Const fixer capability <https://reviews.llvm.org/D69764> and D95168: [clang-format] Add InsertBraces option <https://reviews.llvm.org/D95168> both of which seem to break the fundamental belief that some feel that we shouldn't change anything other than whitespace (A fact that has already been broken 3 times already).

But really these are just separate passes, so why couldn't clang-format allow custom passes to be added much like any compiler does.

If the objection is that this isn't clang-format's role then what if we build something new whose purpose IS to allow these kinds of changes?

I'm pretty rubbish with names but what about:

  clang-format++
  clang-modifier
  clang-rewriter

I think it still has some value to those that want to use it, and I'd like to find an elegant way to deliver it.

  if (Style.Language == FormatStyle::LK_Cpp) {
    if (Style.FixNamespaceComments)
      Passes.emplace_back([&](const Environment &Env) {
        return NamespaceEndCommentsFixer(Env, Expanded).process();
      });
  
    if (Style.SortUsingDeclarations)
      Passes.emplace_back([&](const Environment &Env) {
        return UsingDeclarationsSorter(Env, Expanded).process();
      });
  
    if (Style.InsertBraces != FormatStyle::BIS_Never)
      Passes.emplace_back([&](const Environment &Env) {
        return BracesInserter(Env, Expanded).process();
      });
  
    if (Style.isCpp() && Style.ConstPlacement != FormatStyle::CS_Leave)
    Passes.emplace_back([&](const Environment &Env) {
      return EastWestConstFixer(Env, Expanded).process();
    });
  }
  
  if (Style.Language == FormatStyle::LK_JavaScript &&
      Style.JavaScriptQuotes != FormatStyle::JSQS_Leave)
    Passes.emplace_back([&](const Environment &Env) {
      return JavaScriptRequoter(Env, Expanded).process();
    });
  
  Passes.emplace_back([&](const Environment &Env) {
    return Formatter(Env, Expanded, Status).process();
  });
  
  if (Style.Language == FormatStyle::LK_JavaScript &&
      Style.InsertTrailingCommas == FormatStyle::TCS_Wrapped)
    Passes.emplace_back([&](const Environment &Env) {
      return TrailingCommaInserter(Env, Expanded).process();
    });


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

https://reviews.llvm.org/D69764



More information about the cfe-commits mailing list