From a3e9699eb9ec4c83471e49c68d1a2eb09e2bff60 Mon Sep 17 00:00:00 2001 From: whaffman Date: Tue, 30 Sep 2025 11:17:43 +0200 Subject: [PATCH] feat: reorder include statements to ensure corresponding headers are placed first --- format.sh | 7 +++---- webserv/client/Client.cpp | 1 + webserv/config/AConfig.cpp | 1 + webserv/config/ConfigManager.cpp | 1 + webserv/config/GlobalConfig.cpp | 1 + webserv/config/LocationConfig.cpp | 3 ++- webserv/config/ServerConfig.cpp | 3 ++- webserv/config/directive/ADirective.cpp | 1 + webserv/config/directive/BoolDirective.cpp | 3 ++- webserv/config/directive/DirectiveFactory.cpp | 3 ++- webserv/config/directive/IntDirective.cpp | 3 ++- webserv/config/directive/IntStringDirective.cpp | 3 ++- webserv/config/directive/SizeDirective.cpp | 3 ++- webserv/config/directive/StringDirective.cpp | 3 ++- webserv/config/directive/VectorDirective.cpp | 3 ++- webserv/http/HttpHeaders.cpp | 3 ++- webserv/http/HttpRequest.cpp | 3 ++- webserv/log/FileChannel.cpp | 1 + webserv/log/Log.cpp | 3 ++- webserv/log/StdoutChannel.cpp | 3 ++- webserv/server/Server.cpp | 3 ++- webserv/socket/Socket.cpp | 3 ++- 22 files changed, 39 insertions(+), 19 deletions(-) diff --git a/format.sh b/format.sh index 0230092..ac4c33e 100755 --- a/format.sh +++ b/format.sh @@ -3,9 +3,8 @@ ./check_iwyu.sh ./fix_iwyu_auto.sh -# Reorder includes to put corresponding header first -./reorder_includes.sh - find webserv -name "*.hpp" -o -name "*.cpp" | xargs sed -i -E 's/#include "(.*)"/#include <\1>/g' find webserv -name "*.cpp" -o -name "*.hpp" | xargs clang-format -i -find webserv -name "*.hpp" -exec sh -c 'if ! grep -q "#pragma once" "$1"; then echo "Missing #pragma once in $1"; fi' _ {} \; \ No newline at end of file +find webserv -name "*.hpp" -exec sh -c 'if ! grep -q "#pragma once" "$1"; then echo "Missing #pragma once in $1"; fi' _ {} \; +# Reorder includes to put corresponding header first +./reorder_includes.sh \ No newline at end of file diff --git a/webserv/client/Client.cpp b/webserv/client/Client.cpp index dd30556..5539f46 100644 --- a/webserv/client/Client.cpp +++ b/webserv/client/Client.cpp @@ -1,4 +1,5 @@ #include + #include // for ConfigManager #include // for ServerConfig #include // for ErrorHandler diff --git a/webserv/config/AConfig.cpp b/webserv/config/AConfig.cpp index eccde86..5ec043e 100644 --- a/webserv/config/AConfig.cpp +++ b/webserv/config/AConfig.cpp @@ -1,4 +1,5 @@ #include // for AConfig + #include // for ADirective #include // for DirectiveFactory #include // for trim diff --git a/webserv/config/ConfigManager.cpp b/webserv/config/ConfigManager.cpp index 01ff916..69762cc 100644 --- a/webserv/config/ConfigManager.cpp +++ b/webserv/config/ConfigManager.cpp @@ -1,4 +1,5 @@ #include + #include // for GlobalConfig #include // for removeComments #include // for Log diff --git a/webserv/config/GlobalConfig.cpp b/webserv/config/GlobalConfig.cpp index 660d9e4..ec1a0bc 100644 --- a/webserv/config/GlobalConfig.cpp +++ b/webserv/config/GlobalConfig.cpp @@ -1,4 +1,5 @@ #include + #include // for findCorrespondingClosingBrace #include // for Log diff --git a/webserv/config/LocationConfig.cpp b/webserv/config/LocationConfig.cpp index 6f8658e..7bbbea9 100644 --- a/webserv/config/LocationConfig.cpp +++ b/webserv/config/LocationConfig.cpp @@ -1,5 +1,6 @@ -#include // for AConfig #include + +#include // for AConfig #include // for Log, LOCATION LocationConfig::LocationConfig(const std::string &block, const AConfig *parent) : AConfig(parent) diff --git a/webserv/config/ServerConfig.cpp b/webserv/config/ServerConfig.cpp index f30bfad..f33bfb6 100644 --- a/webserv/config/ServerConfig.cpp +++ b/webserv/config/ServerConfig.cpp @@ -1,6 +1,7 @@ +#include + #include // for AConfig #include // for LocationConfig -#include #include // for findCorrespondingClosingBrace, trim #include // for Log, LOCATION diff --git a/webserv/config/directive/ADirective.cpp b/webserv/config/directive/ADirective.cpp index 28f45aa..5c39545 100644 --- a/webserv/config/directive/ADirective.cpp +++ b/webserv/config/directive/ADirective.cpp @@ -1,4 +1,5 @@ #include + #include // for DirectiveValue, operator<< DirectiveValue ADirective::getValue() const diff --git a/webserv/config/directive/BoolDirective.cpp b/webserv/config/directive/BoolDirective.cpp index 4f06914..d8d675a 100644 --- a/webserv/config/directive/BoolDirective.cpp +++ b/webserv/config/directive/BoolDirective.cpp @@ -1,5 +1,6 @@ -#include // for ADirective #include // for IntDirective + +#include // for ADirective #include // for DirectiveValueType #include // for trim diff --git a/webserv/config/directive/DirectiveFactory.cpp b/webserv/config/directive/DirectiveFactory.cpp index 49263db..d92a84c 100644 --- a/webserv/config/directive/DirectiveFactory.cpp +++ b/webserv/config/directive/DirectiveFactory.cpp @@ -1,5 +1,6 @@ -#include // for BoolDirective #include // for DirectiveFactory + +#include // for BoolDirective #include // for IntDirective #include // for IntStringDirective #include // for SizeDirective diff --git a/webserv/config/directive/IntDirective.cpp b/webserv/config/directive/IntDirective.cpp index 5067dc9..1dcee92 100644 --- a/webserv/config/directive/IntDirective.cpp +++ b/webserv/config/directive/IntDirective.cpp @@ -1,6 +1,7 @@ +#include // for IntDirective + #include // for ADirective #include // for DirectiveValueType -#include // for IntDirective IntDirective::IntDirective(const std::string &name, const std::string &value) : ADirective(name) // NOLINT(bugprone-easily-swappable-parameters) diff --git a/webserv/config/directive/IntStringDirective.cpp b/webserv/config/directive/IntStringDirective.cpp index 25bc6bd..41c9dbc 100644 --- a/webserv/config/directive/IntStringDirective.cpp +++ b/webserv/config/directive/IntStringDirective.cpp @@ -1,6 +1,7 @@ +#include // for IntDirective + #include // for ADirective #include // for DirectiveValueType -#include // for IntDirective #include // for trim #include // for basic_istringstream, basic_istream::operator>>, istringstream diff --git a/webserv/config/directive/SizeDirective.cpp b/webserv/config/directive/SizeDirective.cpp index 1ba8264..3c7cefe 100644 --- a/webserv/config/directive/SizeDirective.cpp +++ b/webserv/config/directive/SizeDirective.cpp @@ -1,6 +1,7 @@ +#include // for SizeDirective + #include // for ADirective #include // for DirectiveValueType -#include // for SizeDirective #include // for trim #include // for __transform_fn, transform diff --git a/webserv/config/directive/StringDirective.cpp b/webserv/config/directive/StringDirective.cpp index 0b7be9b..f25e519 100644 --- a/webserv/config/directive/StringDirective.cpp +++ b/webserv/config/directive/StringDirective.cpp @@ -1,6 +1,7 @@ +#include // for IntDirective + #include // for ADirective #include // for DirectiveValueType -#include // for IntDirective StringDirective::StringDirective(const std::string &name, const std::string &value) : ADirective(name) // NOLINT(bugprone-easily-swappable-parameters) diff --git a/webserv/config/directive/VectorDirective.cpp b/webserv/config/directive/VectorDirective.cpp index e26de0f..086d410 100644 --- a/webserv/config/directive/VectorDirective.cpp +++ b/webserv/config/directive/VectorDirective.cpp @@ -1,6 +1,7 @@ +#include // for IntDirective + #include // for ADirective #include // for DirectiveValueType -#include // for IntDirective #include // for basic_stringstream, stringstream diff --git a/webserv/http/HttpHeaders.cpp b/webserv/http/HttpHeaders.cpp index 6a75d38..02cdfbb 100644 --- a/webserv/http/HttpHeaders.cpp +++ b/webserv/http/HttpHeaders.cpp @@ -1,6 +1,7 @@ +#include // for HttpHeaders + #include // for trim #include // for CRLF -#include // for HttpHeaders #include #include // for __transform_fn, transform diff --git a/webserv/http/HttpRequest.cpp b/webserv/http/HttpRequest.cpp index 75bf86b..b801f01 100644 --- a/webserv/http/HttpRequest.cpp +++ b/webserv/http/HttpRequest.cpp @@ -1,7 +1,8 @@ +#include + #include // for Client #include // for stoul #include // for CRLF, DOUBLE_CRLF, BAD_REQUEST -#include #include // for Log, LOCATION #include // for map diff --git a/webserv/log/FileChannel.cpp b/webserv/log/FileChannel.cpp index 40b85b9..e5435b3 100644 --- a/webserv/log/FileChannel.cpp +++ b/webserv/log/FileChannel.cpp @@ -1,4 +1,5 @@ #include + #include // for Log #include // for system_clock diff --git a/webserv/log/Log.cpp b/webserv/log/Log.cpp index 8a66ef3..5b5fdbf 100644 --- a/webserv/log/Log.cpp +++ b/webserv/log/Log.cpp @@ -1,6 +1,7 @@ +#include + #include // for Channel #include // for FileChannel -#include #include // for StdoutChannel #include // for duration_cast, operator-, steady_clock, duration, seconds diff --git a/webserv/log/StdoutChannel.cpp b/webserv/log/StdoutChannel.cpp index a2cad0b..5fdd5ec 100644 --- a/webserv/log/StdoutChannel.cpp +++ b/webserv/log/StdoutChannel.cpp @@ -1,6 +1,7 @@ -#include // for Log #include +#include // for Log + #include // for operator<<, setfill, setw #include // for basic_ostream, operator<<, basic_ostream::operator<<, cerr, cout, flush, ostream diff --git a/webserv/server/Server.cpp b/webserv/server/Server.cpp index ce4fe0c..83d0eec 100644 --- a/webserv/server/Server.cpp +++ b/webserv/server/Server.cpp @@ -1,8 +1,9 @@ +#include + #include // for Client #include // for ConfigManager #include // for ServerConfig #include // for Log -#include #include // for Socket #include // for errno diff --git a/webserv/socket/Socket.cpp b/webserv/socket/Socket.cpp index 60a584a..633f8ff 100644 --- a/webserv/socket/Socket.cpp +++ b/webserv/socket/Socket.cpp @@ -1,6 +1,7 @@ -#include #include +#include + #include #include