llvm / llvm-project

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

clang format namepace versus namespace alias #53390

Open davidhunter22 opened 2 years ago

davidhunter22 commented 2 years ago

clang format does not seem to differentiate between introducing a namespace and a name space alias. If I have the code

namespace Foo
{
  namespace Bar = Baz;
}

If I have "NamespaceIndentation: None" the namespace Bar = Baz; will have it's indentation removed.

namespace Foo
{
namespace Bar = Baz;
}

It would be nice to control this separately. In particular to treat the indetation of namespace aliases as distinct from introducting a new namespace. So in the above to leave the namespace alias indented even with "NamespaceIndentation: None"

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-format

phyBrackets commented 2 years ago

I would like to work on this issue.

davidhunter22 commented 2 years ago

phyBrackets great I look forward to trying it. I did notice that the issue also effects lines like using namespace Foo; Maybe the code just sees the keyword namespace and always does the same thing.

rajkumarananthu commented 1 year ago

Hi Team,

I am interested to work on this issue, can someone help me assigning this to me. I don't have permissions to assign it to myself.

Thanks

rajkumarananthu commented 1 year ago

Hi,

I am planning to add a new option 'IndentNamespaceAliases' which can be a boolean value to control the indentation of Aliases, as per NamespaceIndentation.

does this sound good? or any suggestions?

thanks rajkumar

davidhunter22 commented 10 months ago

Sounds good to me. Maybe consider doing something like IndentUsingNamespace as well. I assume if IndentNamespaceAliases is not present the behavior be exactly as it is now to avoid modifying existing code.

rajkumarananthu commented 10 months ago

Cool, thanks for the confirmation, I will try to work on this week.

-Rajkumar Ananthu

mydeveloperday commented 3 months ago

I'm wondering why we need the option?

what large c++ project has this style?

Sorry I don't get it, surely NamespaceIndentation is the style?

namespace Foo
{
  namespace Bar = Baz;
int i;
double d;
}