Fix #690: Apply clang-format consistently with CI (#691)

* Fix #690: Apply clang-format consistently with CI

Applied clang-format-19 to all source files to enforce consistent
formatting according to the existing .clang-format configuration.
Added auto-clang-format GitHub Actions workflow (from
cpp-best-practices/cmake_template) that runs on pull requests to
automatically format and commit any style violations going forward.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
leftibot 2026-04-17 18:45:41 -06:00 committed by GitHub
parent 1cbbba38f9
commit 9680c93bd1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 167 additions and 121 deletions

View File

@ -1,10 +1,14 @@
# clang-format: 11 # clang-format: 19
AccessModifierOffset: -2 AccessModifierOffset: -2
AlignAfterOpenBracket: Align AlignAfterOpenBracket: Align
AlignConsecutiveBitFields: false AlignConsecutiveBitFields: false
AllowShortBlocksOnASingleLine: false AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLambdasOnASingleLine: All AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakTemplateDeclarations: true AlwaysBreakTemplateDeclarations: true
BasedOnStyle: WebKit BasedOnStyle: WebKit
BinPackArguments: true BinPackArguments: true
@ -13,12 +17,14 @@ BreakBeforeBraces: Attach
ColumnLimit: 0 ColumnLimit: 0
Cpp11BracedListStyle: true Cpp11BracedListStyle: true
FixNamespaceComments: true FixNamespaceComments: true
IfMacros: ['SECTION']
IncludeBlocks: Preserve IncludeBlocks: Preserve
IndentCaseLabels: true IndentCaseLabels: true
IndentPPDirectives: None IndentPPDirectives: None
IndentWidth: 2 IndentWidth: 2
KeepEmptyLinesAtTheStartOfBlocks: false KeepEmptyLinesAtTheStartOfBlocks: false
NamespaceIndentation: All NamespaceIndentation: All
PackConstructorInitializers: CurrentLine
PenaltyBreakBeforeFirstCallParameter: 200 PenaltyBreakBeforeFirstCallParameter: 200
PenaltyBreakComment: 5 PenaltyBreakComment: 5
PenaltyBreakFirstLessLess: 50 PenaltyBreakFirstLessLess: 50
@ -27,6 +33,10 @@ PointerAlignment: Right
SortIncludes: true SortIncludes: true
SpaceAfterTemplateKeyword: false SpaceAfterTemplateKeyword: false
SpaceBeforeCpp11BracedList: false SpaceBeforeCpp11BracedList: false
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterIfMacros: false
SpaceInEmptyBlock: false SpaceInEmptyBlock: false
Standard: Latest Standard: Latest
TabWidth: 2 TabWidth: 2

27
.github/workflows/auto-clang-format.yml vendored Normal file
View File

@ -0,0 +1,27 @@
name: auto-clang-format
on:
push:
branches:
- develop
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: DoozyX/clang-format-lint-action@v0.20
with:
source: '.'
exclude: './third_party ./external ./unittests/catch.hpp'
extensions: 'h,cpp,hpp'
clangFormatVersion: 19
inplace: True
- uses: EndBug/add-and-commit@v9
with:
author_name: Clang Robot
author_email: robot@example.com
message: ':art: Committing clang-format changes'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -11,8 +11,8 @@
#ifndef CHAISCRIPT_EMSCRIPTEN_EVAL_HPP_ #ifndef CHAISCRIPT_EMSCRIPTEN_EVAL_HPP_
#define CHAISCRIPT_EMSCRIPTEN_EVAL_HPP_ #define CHAISCRIPT_EMSCRIPTEN_EVAL_HPP_
#include <string>
#include <chaiscript/chaiscript.hpp> #include <chaiscript/chaiscript.hpp>
#include <string>
namespace detail { namespace detail {
inline chaiscript::ChaiScript &get_chai_instance() { inline chaiscript::ChaiScript &get_chai_instance() {

View File

@ -65,7 +65,6 @@ namespace chaiscript {
return false; return false;
} }
bool is_explicit() const noexcept { return m_option_explicit; } bool is_explicit() const noexcept { return m_option_explicit; }
void set_explicit(const bool t_explicit) noexcept { m_option_explicit = t_explicit; } void set_explicit(const bool t_explicit) noexcept { m_option_explicit = t_explicit; }

View File

@ -543,8 +543,7 @@ namespace chaiscript {
auto pair = std::make_pair( auto pair = std::make_pair(
detail::Cast_Helper<Left>::cast(from_pair.first, nullptr), detail::Cast_Helper<Left>::cast(from_pair.first, nullptr),
detail::Cast_Helper<Right>::cast(from_pair.second, nullptr) detail::Cast_Helper<Right>::cast(from_pair.second, nullptr));
);
return Boxed_Value(std::move(pair)); return Boxed_Value(std::move(pair));
}; };

View File

@ -138,7 +138,8 @@ namespace chaiscript {
m_engine.add(fun([this](const std::function<void(const std::string &)> &t_handler) { m_engine.add(fun([this](const std::function<void(const std::string &)> &t_handler) {
m_print_handler = t_handler; m_print_handler = t_handler;
}), "set_print_handler"); }),
"set_print_handler");
m_engine.add(fun([this](const std::function<std::string(const std::string &)> &t_reader) { m_engine.add(fun([this](const std::function<std::string(const std::string &)> &t_reader) {
m_file_reader = t_reader; m_file_reader = t_reader;
@ -291,7 +292,6 @@ namespace chaiscript {
} }
public: public:
/// \brief Set a custom handler for print output, used by both print_string and println_string /// \brief Set a custom handler for print output, used by both print_string and println_string
/// \param[in] t_handler Function to call with the string to print /// \param[in] t_handler Function to call with the string to print
void set_print_handler(std::function<void(const std::string &)> t_handler) { void set_print_handler(std::function<void(const std::string &)> t_handler) {

View File

@ -10,13 +10,13 @@
#ifndef CHAISCRIPT_EVAL_HPP_ #ifndef CHAISCRIPT_EVAL_HPP_
#define CHAISCRIPT_EVAL_HPP_ #define CHAISCRIPT_EVAL_HPP_
#include <algorithm>
#include <exception> #include <exception>
#include <functional> #include <functional>
#include <limits> #include <limits>
#include <map> #include <map>
#include <memory> #include <memory>
#include <ostream> #include <ostream>
#include <algorithm>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <vector> #include <vector>
@ -1271,8 +1271,7 @@ namespace chaiscript {
const auto process_statement = [&](const AST_Node_Impl<T> &stmt) { const auto process_statement = [&](const AST_Node_Impl<T> &stmt) {
if (stmt.identifier == AST_Node_Type::Def) { if (stmt.identifier == AST_Node_Type::Def) {
const auto &def_node = static_cast<const Def_AST_Node<T> &>(stmt); const auto &def_node = static_cast<const Def_AST_Node<T> &>(stmt);
target_ns[def_node.children[0]->text] = target_ns[def_node.children[0]->text] = Boxed_Value(Def_AST_Node<T>::make_proxy_function(def_node, t_ss));
Boxed_Value(Def_AST_Node<T>::make_proxy_function(def_node, t_ss));
} else if (stmt.identifier == AST_Node_Type::Assign_Decl } else if (stmt.identifier == AST_Node_Type::Assign_Decl
|| stmt.identifier == AST_Node_Type::Const_Assign_Decl) { || stmt.identifier == AST_Node_Type::Const_Assign_Decl) {
const auto &var_name = stmt.children[0]->text; const auto &var_name = stmt.children[0]->text;

View File

@ -1,8 +1,8 @@
#ifndef CHAISCRIPT_SIMPLEJSON_WRAP_HPP #ifndef CHAISCRIPT_SIMPLEJSON_WRAP_HPP
#define CHAISCRIPT_SIMPLEJSON_WRAP_HPP #define CHAISCRIPT_SIMPLEJSON_WRAP_HPP
#include "json.hpp"
#include "../dispatchkit/dynamic_object.hpp" #include "../dispatchkit/dynamic_object.hpp"
#include "json.hpp"
namespace chaiscript { namespace chaiscript {
class json_wrap { class json_wrap {

View File

@ -605,7 +605,9 @@ TEST_CASE("Utility_Test utility class wrapper for enum") {
} }
// Issue #601: add_class for enums should work directly with ChaiScript reference // Issue #601: add_class for enums should work directly with ChaiScript reference
enum class Issue601_EnumClass { Apple, Banana, Pear }; enum class Issue601_EnumClass { Apple,
Banana,
Pear };
TEST_CASE("Issue 601: add_class enum with ChaiScript reference directly") { TEST_CASE("Issue 601: add_class enum with ChaiScript reference directly") {
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser()); chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
@ -626,7 +628,9 @@ TEST_CASE("Issue 601: add_class enum with ChaiScript reference directly") {
} }
// Also test non-scoped enum directly with ChaiScript reference // Also test non-scoped enum directly with ChaiScript reference
enum Issue601_PlainEnum { Issue601_Red = 0, Issue601_Green = 1, Issue601_Blue = 2 }; enum Issue601_PlainEnum { Issue601_Red = 0,
Issue601_Green = 1,
Issue601_Blue = 2 };
TEST_CASE("Issue 601: add_class plain enum with ChaiScript reference directly") { TEST_CASE("Issue 601: add_class plain enum with ChaiScript reference directly") {
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser()); chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
@ -1532,7 +1536,8 @@ TEST_CASE("ChaiScript default has all functions") {
TEST_CASE("Issue #421 - Switch with type_conversion does not compare destroyed objects") { TEST_CASE("Issue #421 - Switch with type_conversion does not compare destroyed objects") {
struct MyType { struct MyType {
int value; int value;
explicit MyType(int v) : value(v) {} explicit MyType(int v)
: value(v) {}
}; };
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser()); chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
@ -1761,45 +1766,44 @@ TEST_CASE("push_back on script vector with vector_conversion") {
result += s; result += s;
} }
return result; return result;
}), "join_strings"); }),
"join_strings");
// push_back on an empty script-created vector must be visible // push_back on an empty script-created vector must be visible
CHECK(chai.eval<bool>( CHECK(chai.eval<bool>(
"auto x = [];" "auto x = [];"
"x.push_back(\"Hello\");" "x.push_back(\"Hello\");"
"x.size() == 1" "x.size() == 1"));
));
// push_back on a vector with initial elements must grow correctly // push_back on a vector with initial elements must grow correctly
CHECK(chai.eval<bool>( CHECK(chai.eval<bool>(
"auto y = [\"a\", \"b\"];" "auto y = [\"a\", \"b\"];"
"y.push_back(\"c\");" "y.push_back(\"c\");"
"y.push_back(\"d\");" "y.push_back(\"d\");"
"y.size() == 4" "y.size() == 4"));
));
// Verify the actual content is preserved after push_back // Verify the actual content is preserved after push_back
CHECK(chai.eval<std::string>( CHECK(chai.eval<std::string>(
"auto z = [];" "auto z = [];"
"z.push_back(\"World\");" "z.push_back(\"World\");"
"z[0]" "z[0]")
) == "World"); == "World");
// Round-trip: build a vector in script, push_back elements, then pass it // Round-trip: build a vector in script, push_back elements, then pass it
// to a C++ function via vector_conversion and verify the contents // to a C++ function via vector_conversion and verify the contents
CHECK(chai.eval<std::string>( CHECK(chai.eval<std::string>(
"auto v = [\"one\", \"two\"];" "auto v = [\"one\", \"two\"];"
"v.push_back(\"three\");" "v.push_back(\"three\");"
"join_strings(v)" "join_strings(v)")
) == "one,two,three"); == "one,two,three");
// Verify conversion works on a freshly created vector too // Verify conversion works on a freshly created vector too
CHECK(chai.eval<std::string>( CHECK(chai.eval<std::string>(
"auto w = [];" "auto w = [];"
"w.push_back(\"hello\");" "w.push_back(\"hello\");"
"w.push_back(\"world\");" "w.push_back(\"world\");"
"join_strings(w)" "join_strings(w)")
) == "hello,world"); == "hello,world");
} }
// Regression test for issue #607: AST_Node_Trace must be a complete type // Regression test for issue #607: AST_Node_Trace must be a complete type
@ -1962,20 +1966,23 @@ TEST_CASE("Namespace block rejects non-declaration statements") {
namespace bad { namespace bad {
1 + 2 1 + 2
} }
)"), chaiscript::exception::eval_error); )"),
chaiscript::exception::eval_error);
CHECK_THROWS_AS(chai.eval(R"( CHECK_THROWS_AS(chai.eval(R"(
namespace bad { namespace bad {
print("hello") print("hello")
} }
)"), chaiscript::exception::eval_error); )"),
chaiscript::exception::eval_error);
CHECK_THROWS_AS(chai.eval(R"( CHECK_THROWS_AS(chai.eval(R"(
var x = 5 var x = 5
namespace bad { namespace bad {
x = 10 x = 10
} }
)"), chaiscript::exception::eval_error); )"),
chaiscript::exception::eval_error);
} }
TEST_CASE("C++ runtime_error thrown from registered function is catchable in ChaiScript") { TEST_CASE("C++ runtime_error thrown from registered function is catchable in ChaiScript") {
@ -2061,7 +2068,8 @@ TEST_CASE("Typed catch with no match propagates exception") {
catch(string e) { catch(string e) {
// wrong type, should not match // wrong type, should not match
} }
)"), chaiscript::Boxed_Value); )"),
chaiscript::Boxed_Value);
} }
TEST_CASE("Typed catch with no match still runs finally block") { TEST_CASE("Typed catch with no match still runs finally block") {
@ -2078,7 +2086,8 @@ TEST_CASE("Typed catch with no match still runs finally block") {
finally { finally {
finally_ran = true finally_ran = true
} }
)"), chaiscript::Boxed_Value); )"),
chaiscript::Boxed_Value);
CHECK(chai.eval<bool>("finally_ran") == true); CHECK(chai.eval<bool>("finally_ran") == true);
} }
@ -2093,7 +2102,8 @@ TEST_CASE("Multiple C++ exception types from registered functions") {
case 2: throw std::logic_error("logic"); case 2: throw std::logic_error("logic");
default: return which; default: return which;
} }
}), "cpp_multi_throw"); }),
"cpp_multi_throw");
CHECK(chai.eval<int>(R"( CHECK(chai.eval<int>(R"(
var catch_count = 0 var catch_count = 0
@ -2122,7 +2132,8 @@ TEST_CASE("Exception from C++ binary operator is catchable in ChaiScript") {
chai.add(chaiscript::constructor<ThrowingType(int)>(), "ThrowingType"); chai.add(chaiscript::constructor<ThrowingType(int)>(), "ThrowingType");
chai.add(chaiscript::fun([](const ThrowingType &, const ThrowingType &) -> ThrowingType { chai.add(chaiscript::fun([](const ThrowingType &, const ThrowingType &) -> ThrowingType {
throw std::runtime_error("cpp operator+ threw"); throw std::runtime_error("cpp operator+ threw");
}), "+"); }),
"+");
CHECK(chai.eval<bool>(R"( CHECK(chai.eval<bool>(R"(
var caught = false var caught = false
@ -2150,7 +2161,8 @@ TEST_CASE("Exception from C++ [] operator is catchable in ChaiScript") {
chai.add(chaiscript::fun([](const IndexableType &, int idx) -> int { chai.add(chaiscript::fun([](const IndexableType &, int idx) -> int {
if (idx < 0) { throw std::out_of_range("negative index"); } if (idx < 0) { throw std::out_of_range("negative index"); }
return idx; return idx;
}), "[]"); }),
"[]");
CHECK(chai.eval<int>("var obj = IndexableType(0); obj[5]") == 5); CHECK(chai.eval<int>("var obj = IndexableType(0); obj[5]") == 5);

View File

@ -9,9 +9,9 @@
#define CHAISCRIPT_NO_DYNLOAD #define CHAISCRIPT_NO_DYNLOAD
#endif #endif
#include <chaiscript/chaiscript.hpp>
#include "../emscripten/chaiscript_eval.hpp" #include "../emscripten/chaiscript_eval.hpp"
#include <cassert> #include <cassert>
#include <chaiscript/chaiscript.hpp>
#include <cmath> #include <cmath>
#include <string> #include <string>

View File

@ -10,9 +10,9 @@
#define CHAISCRIPT_NO_DYNLOAD #define CHAISCRIPT_NO_DYNLOAD
#endif #endif
#include <chaiscript/chaiscript.hpp>
#include "../emscripten/chaiscript_eval.hpp" #include "../emscripten/chaiscript_eval.hpp"
#include <cassert> #include <cassert>
#include <chaiscript/chaiscript.hpp>
#include <iostream> #include <iostream>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>