[cfe-dev] [C/C++][clang-format] Exempt Specific Function-Like Symbols From The One-Line Rule
Jacob Faibussowitsch via cfe-dev
cfe-dev at lists.llvm.org
Fri Oct 1 10:14:42 PDT 2021
Dear Clang Community,
TL:DR; If at all possible, how can I wrangle clang-format to give me:
1. The following as one line
ierr = FunctionCall();CHKERRQ(ierr);
And not
ierr = FunctionCall();
CHKERRQ(ierr);
2. Function parameters without spaces:
FunctionCall(a,b,c);
And not
FunctionCall(a, b, c);
No holds barred here, modifying clang-format internals/providing patches is not off the table.
————————————
I am a contributor to the Portable Extensible Toolkit for Scientific Computation (PETSc), and have been trying to modernize the tooling workflow within PETSc using clang-tooling. I’ve had great success implementing a linter using the libclang python interface so style enforcement was next on the chopping block.
Like any established code-base we have an opinionated code-style (https://petsc.org/release/developers/style/ <https://petsc.org/release/developers/style/>) which is absolutely powerless against the developer that doesn’t read it. So far we’ve painstakingly enforced it by judicious grep-based checkers (or by hand in code-review :( ). We’d love to use clang-format to automate this but have 2 main sticking points:
1. An error-code checking macro:
#define CHKERRQ(ierr) do { \
if (ierr) { \
handleError(ierr); \
} \
} while (0)
Which is appended to every line, and *must* be on the same line as the call:
ierr = LibraryFunctionCall();CHKERRQ(ierr);
However clang-format will put these on separate lines:
ierr = LibraryFunctionCall();
CHKERRQ(ierr);
2. While this is somewhat more relaxed we don’t use spaces between parameters in function calls:
LibraryFunctionCall(arg1,arg2,arg3);
Which clang-format will change to:
LibraryFunctionCall(arg1, arg2, arg3);
Is there any way around either of these two? We’ve gone through the listed style-options (https://clang.llvm.org/docs/ClangFormatStyleOptions.html <https://clang.llvm.org/docs/ClangFormatStyleOptions.html>) but there doesn’t seem to be a publicly accessible option for the above. With this in mind, how feasible is it for clang to provide this? How feasible is it to implement these ourselves (perhaps as a clang-tidy-style plugin for clang-format or modifications to clang-format itself)?
Best regards,
Jacob Faibussowitsch
(Jacob Fai - booss - oh - vitch)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20211001/ae26461f/attachment-0001.html>
More information about the cfe-dev
mailing list