Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add pre-commit configuration file to run clang-format #4651

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 4 additions & 5 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
# clang 9.0 AllowAllArgumentsOnNextLine: true
# clang 9.0 AllowAllConstructorInitializersOnNextLine: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
# clang 9.0 AllowShortLambdasOnASingleLine: All
# clang 9.0 features AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
Expand All @@ -42,7 +41,7 @@ BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom
BraceWrapping:
# clang 9.0 feature AfterCaseLabel: false
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: true
AfterEnum: true
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fail_fast: true
default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.5
hooks:
- id: clang-format
args: ['--style=file']
files: '\.(c|cc|h|cxx|hxx)$'
exclude: '^Modules/ThirdParty'
12 changes: 4 additions & 8 deletions Examples/DataRepresentation/Mesh/MeshCellsIteration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -272,32 +272,28 @@ main(int, char *[])
CellType * cell = cellIterator.Value();
switch (cell->GetType())
{
case itk::CellGeometryEnum::VERTEX_CELL:
{
case itk::CellGeometryEnum::VERTEX_CELL: {
std::cout << "VertexCell : " << std::endl;
auto * line = dynamic_cast<VertexType *>(cell);
std::cout << "dimension = " << line->GetDimension() << std::endl;
std::cout << "# points = " << line->GetNumberOfPoints() << std::endl;
break;
}
case itk::CellGeometryEnum::LINE_CELL:
{
case itk::CellGeometryEnum::LINE_CELL: {
std::cout << "LineCell : " << std::endl;
auto * line = dynamic_cast<LineType *>(cell);
std::cout << "dimension = " << line->GetDimension() << std::endl;
std::cout << "# points = " << line->GetNumberOfPoints() << std::endl;
break;
}
case itk::CellGeometryEnum::TRIANGLE_CELL:
{
case itk::CellGeometryEnum::TRIANGLE_CELL: {
std::cout << "TriangleCell : " << std::endl;
auto * line = dynamic_cast<TriangleType *>(cell);
std::cout << "dimension = " << line->GetDimension() << std::endl;
std::cout << "# points = " << line->GetNumberOfPoints() << std::endl;
break;
}
default:
{
default: {
std::cout << "Cell with more than three points" << std::endl;
std::cout << "dimension = " << cell->GetDimension() << std::endl;
std::cout << "# points = " << cell->GetNumberOfPoints() << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion Examples/Filtering/DigitallyReconstructedRadiograph1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "itkRayCastInterpolateImageFunction.h"
// Software Guide : EndCodeSnippet

//#define WRITE_CUBE_IMAGE_TO_FILE
// #define WRITE_CUBE_IMAGE_TO_FILE


void
Expand Down
6 changes: 3 additions & 3 deletions Examples/Filtering/FFTDirectInverse2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
#include "itkFlipImageFilter.h"

#if !defined(ITK_USE_FFTWF)
//#error "This example only works when single precision FFTW is used
// Changing WorkPixeltype to double and changing this conditional to
// ITK_USE_FFTWD will also work.
// #error "This example only works when single precision FFTW is used
// Changing WorkPixeltype to double and changing this conditional to
// ITK_USE_FFTWD will also work.
#endif

int
Expand Down
2 changes: 1 addition & 1 deletion Examples/IO/XML/itkParticleSwarmOptimizerSAXReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ ParticleSwarmOptimizerSAXReader::ProcessBoundAttributes(
}
}
} // end if
} // end for
} // end for
}

/** Search for and return a particular attribute from the attribute list. */
Expand Down
5 changes: 3 additions & 2 deletions Modules/Bridge/NumPy/include/itkPyBuffer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ PyBuffer<TImage>::_GetArrayViewFromImage(ImageType * image)

template <class TImage>
auto
PyBuffer<TImage>::_GetImageViewFromArray(PyObject * arr, PyObject * shape, PyObject * numOfComponent)
-> const OutputImagePointer
PyBuffer<TImage>::_GetImageViewFromArray(PyObject * arr,
PyObject * shape,
PyObject * numOfComponent) -> const OutputImagePointer
{
PyObject * shapeseq = NULL;
PyObject * item = NULL;
Expand Down
30 changes: 15 additions & 15 deletions Modules/Bridge/VtkGlue/src/QuickView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ using FloatImageType = itk::Image<float, 2>;
using DoubleImageType = itk::Image<double, 2>;

template void ITKVtkGlue_EXPORT
QuickView::AddImage<CharImageType>(CharImageType * image, bool FlipVertical, std::string Description);
QuickView::AddImage<CharImageType>(CharImageType * image, bool FlipVertical, std::string Description);
template void ITKVtkGlue_EXPORT
QuickView::AddImage<UnsignedShortImageType>(UnsignedShortImageType * image, bool FlipVertical, std::string Description);
QuickView::AddImage<UnsignedShortImageType>(UnsignedShortImageType * image, bool FlipVertical, std::string Description);
template void ITKVtkGlue_EXPORT
QuickView::AddImage<ShortImageType>(ShortImageType * image, bool FlipVertical, std::string Description);
QuickView::AddImage<ShortImageType>(ShortImageType * image, bool FlipVertical, std::string Description);
template void ITKVtkGlue_EXPORT
QuickView::AddImage<UnsignedIntImageType>(UnsignedIntImageType * image, bool FlipVertical, std::string Description);
QuickView::AddImage<UnsignedIntImageType>(UnsignedIntImageType * image, bool FlipVertical, std::string Description);
template void ITKVtkGlue_EXPORT
QuickView::AddImage<IntImageType>(IntImageType * image, bool FlipVertical, std::string Description);
QuickView::AddImage<IntImageType>(IntImageType * image, bool FlipVertical, std::string Description);
template void ITKVtkGlue_EXPORT
QuickView::AddImage<UnsignedLongImageType>(UnsignedLongImageType * image, bool FlipVertical, std::string Description);
QuickView::AddImage<UnsignedLongImageType>(UnsignedLongImageType * image, bool FlipVertical, std::string Description);
template void ITKVtkGlue_EXPORT
QuickView::AddImage<LongImageType>(LongImageType * image, bool FlipVertical, std::string Description);
QuickView::AddImage<LongImageType>(LongImageType * image, bool FlipVertical, std::string Description);
template void ITKVtkGlue_EXPORT
QuickView::AddImage<FloatImageType>(FloatImageType * image, bool FlipVertical, std::string Description);
QuickView::AddImage<FloatImageType>(FloatImageType * image, bool FlipVertical, std::string Description);
template void ITKVtkGlue_EXPORT
QuickView::AddImage<DoubleImageType>(DoubleImageType * image, bool FlipVertical, std::string Description);
QuickView::AddImage<DoubleImageType>(DoubleImageType * image, bool FlipVertical, std::string Description);

template <>
void ITKVtkGlue_EXPORT
QuickView::AddImage<UnsignedCharImageType>(UnsignedCharImageType * image, bool FlipVertical, std::string Description)
QuickView::AddImage<UnsignedCharImageType>(UnsignedCharImageType * image, bool FlipVertical, std::string Description)
{
if (FlipVertical)
{
Expand All @@ -101,7 +101,7 @@ void ITKVtkGlue_EXPORT

template <typename TImage>
void ITK_TEMPLATE_EXPORT
QuickView::AddImage(TImage * image, bool FlipVertical, std::string Description)
QuickView::AddImage(TImage * image, bool FlipVertical, std::string Description)
{
using rescaleFilterType = itk::RescaleIntensityImageFilter<TImage, UnsignedCharImageType>;

Expand All @@ -116,7 +116,7 @@ void ITK_TEMPLATE_EXPORT

template <>
void ITKVtkGlue_EXPORT
QuickView::AddImage<UnsignedCharRGBImageType>(UnsignedCharRGBImageType * image,
QuickView::AddImage<UnsignedCharRGBImageType>(UnsignedCharRGBImageType * image,
bool FlipVertical,
std::string Description)
{
Expand All @@ -141,7 +141,7 @@ void ITKVtkGlue_EXPORT

template <>
void ITKVtkGlue_EXPORT
QuickView::AddRGBImage<UnsignedCharRGBImageType>(UnsignedCharRGBImageType * image,
QuickView::AddRGBImage<UnsignedCharRGBImageType>(UnsignedCharRGBImageType * image,
bool FlipVertical,
std::string Description)
{
Expand All @@ -166,7 +166,7 @@ void ITKVtkGlue_EXPORT

template <>
void ITKVtkGlue_EXPORT
QuickView::AddRGBImage<FloatRGBImageType>(FloatRGBImageType * image, bool FlipVertical, std::string Description)
QuickView::AddRGBImage<FloatRGBImageType>(FloatRGBImageType * image, bool FlipVertical, std::string Description)
{
using AdaptorType = itk::RGBToVectorImageAdaptor<FloatRGBImageType>;
AdaptorType::Pointer adaptor = AdaptorType::New();
Expand All @@ -182,7 +182,7 @@ void ITKVtkGlue_EXPORT

template <>
void ITKVtkGlue_EXPORT
QuickView::AddImage<FloatRGBImageType>(FloatRGBImageType * image, bool FlipVertical, std::string Description)
QuickView::AddImage<FloatRGBImageType>(FloatRGBImageType * image, bool FlipVertical, std::string Description)
{
using AdaptorType = itk::RGBToVectorImageAdaptor<FloatRGBImageType>;
AdaptorType::Pointer adaptor = AdaptorType::New();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ITK_TEMPLATE_EXPORT ChildTreeIterator : public TreeIteratorBase<TTreeType>
if (this != &iterator)
{
Superclass::operator=(iterator);
auto & it = static_cast<ChildTreeIterator<TTreeType> &>(iterator);
auto & it = static_cast<ChildTreeIterator<TTreeType> &>(iterator);
m_ListPosition = it.m_ListPosition;
m_ParentNode = it.m_ParentNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TreeIteratorBaseEnums
};
// Define how to print enumeration
extern ITKCOMMON_DEPRECATED_EXPORT std::ostream &
operator<<(std::ostream & out, const TreeIteratorBaseEnums::TreeIteratorBaseNode value);
operator<<(std::ostream & out, const TreeIteratorBaseEnums::TreeIteratorBaseNode value);
/** \class TreeIteratorBase
* \brief This class provides the base implementation for tree iterators.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ class TreeIteratorClone
}

/** Overload operator -> */
ObjectType * operator->() const { return m_Pointer; }
ObjectType *
operator->() const
{
return m_Pointer;
}

/** Test if the pointer has been initialized */
bool
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ operator<<(std::ostream & os, const Array<TValue> & arr)

// declaration of specialization
template <>
ITKCommon_EXPORT std::ostream & operator<<<double>(std::ostream & os, const Array<double> & arr);
ITKCommon_EXPORT std::ostream & operator<< <double>(std::ostream & os, const Array<double> & arr);
template <>
ITKCommon_EXPORT std::ostream & operator<<<float>(std::ostream & os, const Array<float> & arr);
ITKCommon_EXPORT std::ostream & operator<< <float>(std::ostream & os, const Array<float> & arr);


template <typename T>
Expand Down
6 changes: 5 additions & 1 deletion Modules/Core/Common/include/itkAutoPointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ class AutoPointer
~AutoPointer() { this->Reset(); }

/** Overload operator ->. */
ObjectType * operator->() const { return m_Pointer; }
ObjectType *
operator->() const
{
return m_Pointer;
}

/** Clear the AutoPointer. If it had a pointer the object
is deleted and the pointer is set to null. */
Expand Down
6 changes: 5 additions & 1 deletion Modules/Core/Common/include/itkBoolean.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ class Boolean
{}

/** Supports implicit conversion to `bool`. */
constexpr operator bool() const { return m_Value; }
constexpr
operator bool() const
{
return m_Value;
}

private:
bool m_Value = false;
Expand Down
22 changes: 15 additions & 7 deletions Modules/Core/Common/include/itkCellInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
// to define the Accept and GetTopologyId virtuals used
// by the MultiVisitor class
#define itkCellVisitMacro(TopologyId) \
static constexpr CellGeometryEnum GetTopologyId() { return TopologyId; } \
static constexpr CellGeometryEnum GetTopologyId() \
{ \
return TopologyId; \
} \
virtual void Accept(CellIdentifier cellid, typename CellInterface<PixelType, CellTraits>::MultiVisitor * mv) \
override \
{ \
Expand Down Expand Up @@ -381,7 +384,11 @@ class ITK_TEMPLATE_EXPORT CellInterface
* Array is ordered (xmin, xmax, ymin, ymax, ....). A pointer to the
* array is returned for convenience. This allows code like:
* "CoordRep* bounds = cell->GetBoundingBox(new CoordRep[6]);". */
CoordRepType * GetBoundingBox(CoordRepType[PointDimension * 2]) { return nullptr; }
CoordRepType *
GetBoundingBox(CoordRepType[PointDimension * 2])
{
return nullptr;
}

/** Compute the square of the diagonal length of the bounding box. */
CoordRepType
Expand All @@ -402,11 +409,12 @@ class ITK_TEMPLATE_EXPORT CellInterface
* (returned through "t" pointer).
*
* Returns whether an intersection exists. */
virtual bool IntersectBoundingBoxWithLine(CoordRepType[PointDimension * 2],
CoordRepType[PointDimension],
CoordRepType[PointDimension],
CoordRepType[PointDimension],
CoordRepType *)
virtual bool
IntersectBoundingBoxWithLine(CoordRepType[PointDimension * 2],
CoordRepType[PointDimension],
CoordRepType[PointDimension],
CoordRepType[PointDimension],
CoordRepType *)
{
return bool();
}
Expand Down
12 changes: 4 additions & 8 deletions Modules/Core/Common/include/itkColorTable.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -302,20 +302,16 @@ ColorTable<TComponent>::GetColorComponent(unsigned int c, char rgb)
{
switch (rgb)
{
case 'r':
{
case 'r': {
return m_Color[c][0];
}
case 'g':
{
case 'g': {
return m_Color[c][1];
}
case 'b':
{
case 'b': {
return m_Color[c][2];
}
default:
{
default: {
return 0;
}
}
Expand Down
7 changes: 4 additions & 3 deletions Modules/Core/Common/include/itkCompensatedSummation.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class ITK_TEMPLATE_EXPORT CompensatedSummation
GetSum() const;

/** explicit conversion */
explicit operator FloatType() const;
explicit
operator FloatType() const;

private:
AccumulateType m_Sum{};
Expand All @@ -130,9 +131,9 @@ class ITK_TEMPLATE_EXPORT CompensatedSummation
};

void ITKCommon_EXPORT
CompensatedSummationAddElement(float & compensation, float & sum, const float element);
CompensatedSummationAddElement(float & compensation, float & sum, const float element);
void ITKCommon_EXPORT
CompensatedSummationAddElement(double & compensation, double & sum, const double element);
CompensatedSummationAddElement(double & compensation, double & sum, const double element);

} // end namespace itk

Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkCompensatedSummation.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ namespace itk
{

void ITKCommon_EXPORT
CompensatedSummationAddElement(float & compensation, float & sum, const float element);
CompensatedSummationAddElement(float & compensation, float & sum, const float element);
void ITKCommon_EXPORT
CompensatedSummationAddElement(double & compensation, double & sum, const double element);
CompensatedSummationAddElement(double & compensation, double & sum, const double element);

#ifndef itkCompensatedSummation_cxx
// We try the looser pragma guards if we don't have an explicit instantiation.
Expand Down
Loading