wpilibsuite / styleguide

Style guides for wpilibsuite projects
Other
5 stars 16 forks source link

Improper handling of C++ namespace comments in macros #279

Open KangarooKoala opened 4 months ago

KangarooKoala commented 4 months ago

Given this input .cpp file:

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#define TEST(namespaceName, name, ...)\
  namespace namespaceName {\
  using name = __VA_ARGS__;\
  }  /* namespace namespacename */\
  using name = namespaceName::name;

Running wpiformat on the file results in this:

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#define TEST(namespaceName, name, ...) \
  namespace namespaceName {            \
  using name = __VA_ARGS__;            \
  }  // namespace namespaceName
using name = namespaceName::name;

It also happens on .h and .inc files (as long as there's an include guard or #pragma once) and with object-like macros.

It seems that in the BraceComment pipeline, wpiformat unconditionally uses a // comment to close a namespace, even though /* */ comments are also supposed to be clean for cpplint (for this very reason). Additionally, since there are no checks for NOLINT or NOLINTNEXTLINE in the pipeline, there is no way to suppress the format that I'm aware of.

calcmogul commented 4 months ago

We force // for style reasons. /* */ should only be used when absolutely necessary. Detecting those cases properly may be difficult.