Skip to content

Commit

Permalink
[ci] Setup and run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
arntanguy committed Mar 20, 2024
1 parent 55c250a commit 77f00c8
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 86 deletions.
105 changes: 105 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Allman
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 0
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^(<mc_[a-z]*/)'
Priority: 1
- Regex: '^(<Tasks/)'
Priority: 2
- Regex: '^(<mc_rbdyn_urdf/)'
Priority: 3
- Regex: '^(<RBDyn/)'
Priority: 4
- Regex: '^(<SpaceVecAlg/)'
Priority: 5
- Regex: '^(<sch-core/)'
Priority: 6
- Regex: '^(<boost/)'
Priority: 7
- Regex: '^(<(nanomsg|geos|.*_msgs|ros|tf2.*)/)'
Priority: 8
- Regex: '.*'
Priority: 9
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 2
IndentWrappedFunctionNames: true
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 150
PenaltyReturnTypeOnItsOwnLine: 300
PointerAlignment: Middle
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 2
UseTab: Never
...
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repos:
- repo: meta
hooks:
- id: check-useless-excludes
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v16.0.6
hooks:
- id: clang-format
'types_or': [c++, c]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-yaml
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ find_package(mc_rtc REQUIRED)
find_description_package(nao_description)

message(STATUS "NAO_DESCRIPTION_PATH: ${NAO_DESCRIPTION_PATH}")
configure_file(include/mc_nao/config.h.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/include/mc_nao/config.h")
configure_file(include/mc_nao/config.h.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/include/mc_nao/config.h")

add_robot(nao src/nao.cpp include/mc_nao/nao.h)
target_include_directories(nao PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include")
Expand Down
63 changes: 34 additions & 29 deletions include/mc_nao/nao.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ namespace mc_robots
{
struct MC_ROBOTS_DLLAPI NAOCommonRobotModule : public mc_rbdyn::RobotModule
{
public:
public:
NAOCommonRobotModule();

protected:
void readUrdf(const std::string& robotName, const std::vector<std::string>& filteredLinks);
std::map<std::string, std::vector<double>> halfSittingPose(const rbd::MultiBody& mb) const;
std::map<std::string, std::pair<std::string, std::string>> getConvexHull(const std::map<std::string, std::pair<std::string, std::string>>& files) const;
std::map<std::string, std::pair<std::string, std::string>> stdCollisionsFiles(const rbd::MultiBody& mb) const;
const std::map<std::string, std::pair<std::string, std::string>>& convexHull() const;
const std::vector<std::map<std::string, std::vector<double>>>& bounds() const;
const std::map<std::string, std::vector<double>>& stance() const;
protected:
void readUrdf(const std::string & robotName, const std::vector<std::string> & filteredLinks);
std::map<std::string, std::vector<double>> halfSittingPose(const rbd::MultiBody & mb) const;
std::map<std::string, std::pair<std::string, std::string>> getConvexHull(
const std::map<std::string, std::pair<std::string, std::string>> & files) const;
std::map<std::string, std::pair<std::string, std::string>> stdCollisionsFiles(const rbd::MultiBody & mb) const;
const std::map<std::string, std::pair<std::string, std::string>> & convexHull() const;
const std::vector<std::map<std::string, std::vector<double>>> & bounds() const;
const std::map<std::string, std::vector<double>> & stance() const;

public:
public:
std::vector<std::string> virtualLinks;
std::vector<std::string> gripperLinks;
std::map<std::string, std::vector<double>> halfSitting;
Expand All @@ -31,39 +32,43 @@ struct MC_ROBOTS_DLLAPI NAOCommonRobotModule : public mc_rbdyn::RobotModule

struct MC_ROBOTS_DLLAPI NAONoHandRobotModule : public NAOCommonRobotModule
{
public:
public:
NAONoHandRobotModule();
};

struct MC_ROBOTS_DLLAPI NAOWithHandRobotModule : public NAOCommonRobotModule
{
public:
public:
NAOWithHandRobotModule();
};
}
} // namespace mc_robots

/*TODO Provide a different constructor to allow WithHand/NoHand instantation */
extern "C" {
ROBOT_MODULE_API void MC_RTC_ROBOT_MODULE(std::vector<std::string> & names)
{
names = {"NAO", "NAONoHand"};
}
ROBOT_MODULE_API void destroy(mc_rbdyn::RobotModule* ptr) { delete ptr; }
ROBOT_MODULE_API mc_rbdyn::RobotModule* create(const std::string& n)
extern "C"
{
ROBOT_MODULE_CHECK_VERSION("NAO")
if (n == "NAO")
ROBOT_MODULE_API void MC_RTC_ROBOT_MODULE(std::vector<std::string> & names)
{
return new mc_robots::NAOWithHandRobotModule();
names = {"NAO", "NAONoHand"};
}
else if (n == "NAONoHand")
ROBOT_MODULE_API void destroy(mc_rbdyn::RobotModule * ptr)
{
return new mc_robots::NAONoHandRobotModule();
delete ptr;
}
else
ROBOT_MODULE_API mc_rbdyn::RobotModule * create(const std::string & n)
{
mc_rtc::log::error("NAO module cannot create an object of type {}", n);
return nullptr;
ROBOT_MODULE_CHECK_VERSION("NAO")
if(n == "NAO")
{
return new mc_robots::NAOWithHandRobotModule();
}
else if(n == "NAONoHand")
{
return new mc_robots::NAONoHandRobotModule();
}
else
{
mc_rtc::log::error("NAO module cannot create an object of type {}", n);
return nullptr;
}
}
}
}
Loading

0 comments on commit 77f00c8

Please sign in to comment.