Skip to content

Commit

Permalink
ci: End of file checker (#2435)
Browse files Browse the repository at this point in the history
This PR contains an automated checker for C++ line endings and applied fixes for the current state of the code base.

Since this pops up from time to time during review and is sometimes randomly changed in unrelated PRs (especially by myself) I would like to add an automated check for "correct" line endings. Sadly I didn't find a clang format flag for that.
  • Loading branch information
andiwand authored Sep 11, 2023
1 parent b10f804 commit 8f07d6c
Show file tree
Hide file tree
Showing 84 changed files with 173 additions and 82 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ jobs:
- name: Check
run: >
CI/check_pragma_once.sh
end_of_line:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- name: Check
run: >
CI/check_end_of_file.py . --exclude "thirdparty/*" --reject-multiple-newlines --github
boost_test_macro:
runs-on: ubuntu-latest
steps:
Expand Down
83 changes: 83 additions & 0 deletions CI/check_end_of_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env python3

import os
import sys
import argparse
from subprocess import check_output


def main():
p = argparse.ArgumentParser()
p.add_argument("input")
p.add_argument("--exclude", nargs="+")
p.add_argument("--fix", action="store_true")
p.add_argument("--reject-multiple-newlines", action="store_true")
p.add_argument("--github", action="store_true")
args = p.parse_args()

files = (
str(
check_output(
[
"find",
args.input,
"-iname",
"*.cpp",
"-or",
"-iname",
"*.hpp",
"-or",
"-iname",
"*.ipp",
]
+ sum((["-not", "-path", exclude] for exclude in args.exclude), [])
),
"utf-8",
)
.strip()
.split("\n")
)

failed = []

for file in files:
file = os.path.normpath(file)

with open(file) as f:
lines = f.readlines()

if not lines[-1].endswith("\n"):
print(f"Missing newline at end of file: {file}")
if args.fix:
with open(file, "a") as f:
f.write("\n")
else:
failed.append(file)
if args.github:
print(
f"::error file={file},line={len(lines)},title=End of file check::missing newline"
)
elif args.reject_multiple_newlines and lines[-1] == "\n":
print(f"Multiple newlines at end of file: {file}")
if args.fix:
while lines[-1] == "\n":
lines.pop(-1)
with open(file, "w") as f:
f.write("".join(lines))
else:
failed.append(file)
if args.github:
print(
f"::error file={{{file}}},line={{{len(lines)}}},title=End of file check::multiple newlines"
)

if failed:
print(f"failed for files: {' '.join(failed)}")
return 1

print("success")
return 0


if "__main__" == __name__:
sys.exit(main())
2 changes: 1 addition & 1 deletion Core/include/Acts/Digitization/CartesianSegmentation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,4 @@ inline std::pair<double, double> CartesianSegmentation::pitch() const {
return std::pair<double, double>(pitchX, pitchY);
}

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Geometry/AbstractVolume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ class AbstractVolume : public Volume {
std::vector<BoundarySurfacePtr> m_boundarySurfaces;
};

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Geometry/ConeLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ class ConeLayer : virtual public ConeSurface, public Layer {
ConeLayer(const ConeLayer& cla, const Transform3& shift);
};

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Geometry/CuboidVolumeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,4 @@ stream_t& CuboidVolumeBounds::dumpT(stream_t& dt) const {
<< get(eHalfLengthZ) << ")";
return dt;
}
} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Geometry/CylinderLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ class CylinderLayer : public CylinderSurface, public Layer {
CylinderLayer(const CylinderLayer& cla, const Transform3& shift);
};

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Geometry/GenericApproachDescriptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ class GenericApproachDescriptor : public ApproachDescriptor {
std::vector<const Surface*> m_surfaceCache;
};

} // namespace Acts
} // namespace Acts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ class IConfinedTrackingVolumeBuilder {
virtual const std::string& identification() const = 0;
};

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Geometry/ILayerArrayCreator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ class ILayerArrayCreator {
double max, BinningType btype = arbitrary,
BinningValue bvalue = binX) const = 0;
};
} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Geometry/ITrackingGeometryBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ class ITrackingGeometryBuilder {
virtual std::unique_ptr<const TrackingGeometry> trackingGeometry(
const GeometryContext& gctx) const = 0;
};
} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Geometry/ITrackingVolumeArrayCreator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ class ITrackingVolumeArrayCreator {
const GeometryContext& gctx, const TrackingVolumeVector& vols,
BinningValue bVal) const = 0;
};
} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Geometry/LayerArrayCreator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ class LayerArrayCreator : public ILayerArrayCreator {
double offset) const;
};

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Geometry/PlaneLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ class PlaneLayer : virtual public PlaneSurface, public Layer {
PlaneLayer(const PlaneLayer& pla, const Transform3& shift);
};

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Geometry/TrackingVolumeArrayCreator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ class TrackingVolumeArrayCreator : public ITrackingVolumeArrayCreator {
/// logging instance
std::unique_ptr<const Logger> m_logger;
};
} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Geometry/TrapezoidVolumeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@ inline void TrapezoidVolumeBounds::checkConsistency() noexcept(false) {
}
}

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Surfaces/DiamondBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ inline void DiamondBounds::checkConsistency() noexcept(false) {
}
}

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Surfaces/DiscBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ class DiscBounds : public SurfaceBounds {
virtual bool insideRadialBounds(double R, double tolerance = 0.) const = 0;
};

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Surfaces/DiscTrapezoidBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,4 @@ inline void DiscTrapezoidBounds::checkConsistency() noexcept(false) {
}
}

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Surfaces/EllipseBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ inline void EllipseBounds::checkConsistency() noexcept(false) {
}
}

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Surfaces/LineBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ inline void LineBounds::checkConsistency() noexcept(false) {
}
}

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Surfaces/PlanarBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ class PlanarBounds : public SurfaceBounds {
virtual const RectangleBounds& boundingBox() const = 0;
};

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Surfaces/SurfaceError.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ namespace std {
// register with STL
template <>
struct is_error_code_enum<Acts::SurfaceError> : std::true_type {};
} // namespace std
} // namespace std
2 changes: 1 addition & 1 deletion Core/include/Acts/Utilities/detail/ContextType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ class ContextType {
std::any m_data;
};

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Utilities/detail/MPL/all_of.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ template <bool... values>
constexpr bool all_of_v = all_of<values...>::value;
} // namespace detail

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Utilities/detail/MPL/any_of.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ template <bool... values>
constexpr bool any_of_v = any_of<values...>::value;
} // namespace detail

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Utilities/detail/MPL/are_sorted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ struct are_sorted<false, false, T, a, b, N...> {
/// @endcond
} // namespace detail
/// @endcond
} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Utilities/detail/MPL/are_within.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ struct are_within<T, MIN, MAX, a, others...> {
/// @endcond
} // namespace detail
/// @endcond
} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Utilities/detail/MPL/at_index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ struct at_index<T, 0, next, others...> {
/// @endcond
} // namespace detail
/// @endcond
} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Utilities/detail/MPL/get_position.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ struct get_position<T, target, next, others...> {
/// @endcond
} // namespace detail
/// @endcond
} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Utilities/detail/MPL/has_duplicates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ template <typename... Args>
constexpr bool has_duplicates_v = has_duplicates<Args...>::value;
} // namespace detail

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Utilities/detail/MPL/is_contained.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ struct is_contained<T, target, next> {
/// @endcond
} // namespace detail
/// @endcond
} // namespace Acts
} // namespace Acts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ struct RealQuadraticEquation {
};

} // namespace detail
} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Vertexing/AMVFInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ struct VertexInfo {
std::map<const input_track_t*, const BoundTrackParameters> ip3dParams;
};

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Vertexing/KalmanVertexUpdater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ void update(Vertex<input_track_t>& vtx, TrackAtVertex<input_track_t>& trk,
} // Namespace KalmanVertexUpdater
} // Namespace Acts

#include "KalmanVertexUpdater.ipp"
#include "KalmanVertexUpdater.ipp"
2 changes: 1 addition & 1 deletion Core/include/Acts/Vertexing/VertexFinderConcept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ template <typename finder>
constexpr bool VertexFinderConcept =
Acts::Concepts ::VertexFinder::VertexFinderConcept<finder>::value;

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/include/Acts/Vertexing/VertexFitterConcept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ template <typename fitter>
constexpr bool VertexFitterConcept =
Acts::Concepts ::VertexFitter::VertexFitterConcept<fitter>::value;

} // namespace Acts
} // namespace Acts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ void PlyVisualization3D<T>::clear() {
m_vertices.clear();
m_faces.clear();
m_edges.clear();
}
}
2 changes: 1 addition & 1 deletion Core/src/Geometry/PlaneLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ void Acts::PlaneLayer::buildApproachDescriptor() {
// @todo check if we can provide the layer at surface creation
m_approachDescriptor =
std::make_unique<const GenericApproachDescriptor>(std::move(aSurfaces));
}
}
2 changes: 1 addition & 1 deletion Core/src/Geometry/ProtoLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ void ProtoLayer::add(const GeometryContext& gctx, const Surface& surface) {
measure(gctx, m_surfaces);
}

} // namespace Acts
} // namespace Acts
2 changes: 1 addition & 1 deletion Core/src/Geometry/ProtoLayerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ std::vector<Acts::ProtoLayer> Acts::ProtoLayerHelper::protoLayers(
}

return finalProtoLayers;
}
}
2 changes: 1 addition & 1 deletion Core/src/Surfaces/ConvexPolygonBounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ Acts::ConvexPolygonBounds<Acts::PolygonDynamic>::boundingBox() const {
void Acts::ConvexPolygonBounds<Acts::PolygonDynamic>::checkConsistency() const
noexcept(false) {
convex_impl(m_vertices);
}
}
2 changes: 1 addition & 1 deletion Core/src/Vertexing/FsmwMode1dFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ Acts::Result<double> Acts::FsmwMode1dFinder::getMode(

return (begin->first * begin->second + end->first * end->second) /
(begin->second + end->second);
}
}
2 changes: 1 addition & 1 deletion Core/src/Visualization/IVisualization3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ void Acts::IVisualization3D::replaceExtension(std::string& path,
} else {
path += suffix;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) {
m_particleGun->GeneratePrimaryVertex(anEvent);
}

} // namespace ActsExamples::Geant4::HepMC3
} // namespace ActsExamples::Geant4::HepMC3
Loading

0 comments on commit 8f07d6c

Please sign in to comment.