-
Notifications
You must be signed in to change notification settings - Fork 10
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
Adding clang-format #37
base: master
Are you sure you want to change the base?
Conversation
Thank you very much @mredd
VS
In that case, a tool cannot possibly formatting the code properly, because clang-format cannot understand that I believe that some kinds of formatting are additional information with a semantic value the developer put in the sources just as he does with comments, it's not redundant with the code, so a tool cannot possibly calculate it by just reading the code. However your formatting file is really good, you did a good job trying to keep the formatting I'm used to. Maybe I could run clang-format once on my locale codebase and then review the differences to keep only the changes that don't break readability. |
Yeah, I get your point with the URL formatting. Clang-format requires you to make your intent explizit, otherwise it assumes you don't care about the formatting and it harmonizes it according to the project rules. This is how you tell clang-format to stay away from your linebreaks (as long as you don't violate the column limit): return Proxy::Command(
Method::post,
"/ari/channels/"+id+"/move?" + //
"app=" + app + //
( appArgs.empty() ? "" : "&appArgs=" + appArgs ), //
client
); which will be converted into this: return Proxy::Command(
Method::post,
"/ari/channels/" + id + "/move?" + //
"app=" + app + //
(appArgs.empty() ? "" : "&appArgs=" + appArgs), //
client); Noticed that And when you want it to absolutely stay away of your ASCII art, there is always I really like this because it makes it explicit where a developer cared about a specific formatting. This signals to the future reader that there is something worth paying attention to. The same works for function parameters and arguments, unless you use lambdas as direct arguments. For instance, a sloppy Proxy& Move( //
const std::string& app, //
const std::string& appArgs = {}) const //
{
OtherFunction( //
arg1, //
arg2, //
arg3); //
} gets cleaned up to Proxy& Move( //
const std::string& app, //
const std::string& appArgs = {}) const //
{
OtherFunction( //
arg1, //
arg2, //
arg3); //
} Regarding the grouping by blank lines, these get preserved by clang-format. It only harmonizes them to a single blank line where the developer put multiple in. When you really want to have a huge vertical distance, you should probably put a comment in on why the following block is special anyway. Where it messes with your blanks is around access modifier keywords (public, protected, private). But within a class/struct/function body you are free to group however you want. Check the AriModel for instance: class AriModel
{
public:
using ChannelPtr = std::shared_ptr<Channel>;
explicit AriModel(Client& c) : client(c) { Subscribe(); }
AriModel(const AriModel&) = delete;
AriModel(const AriModel&&) = delete;
AriModel& operator=(const AriModel&) = delete;
AriModel& operator=(const AriModel&&) = delete;
using ChHandler = std::function<void(ChannelPtr)>;
using ChVarSetHandler =
std::function<void(ChannelPtr, const std::string&, const std::string&)>;
using ChDtmfHandler = std::function<void(ChannelPtr, const std::string&)>;
using PlaybackHandler = std::function<void(const Playback&)>;
using StasisStartedHandler = std::function<void(ChannelPtr, bool external)>; I will provide an updated PR for you to review and decide on. |
OK @mredd , you almost convinced me :-)
|
Channel is not default-assignable because of the constant id member.
Sorry, I didn't spot that error in the Github CI. The tests are failing at all on my local machine. See #40
Do you have any specific column limit in mind? How about 120?
Where do you see a refactoring there? Can you be a bit more specific? Don't get confused by the Github diff viewer. It bails out too early and doesn't get back on track. When you ignore the whitespace changes, this is what's left: (with the old 90 columns limit) diff --git a/aricpp/basicauth.h b/aricpp/basicauth.h
index cd5f9dd..f0c8356 100644
--- a/aricpp/basicauth.h
+++ b/aricpp/basicauth.h
@@ -30,19 +30,17 @@
* DEALINGS IN THE SOFTWARE.
******************************************************************************/
-
#ifndef ARICPP_BASICAUTH_H_
#define ARICPP_BASICAUTH_H_
-#include <string>
#include <array>
+#include <string>
namespace aricpp
{
namespace
{
- static const std::string base64_chars =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
@@ -59,8 +57,10 @@ namespace
if (i == 3)
{
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
- char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
- char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
+ char_array_4[1] =
+ ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
+ char_array_4[2] =
+ ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for (auto x : char_array_4)
@@ -76,8 +76,10 @@ namespace
char_array_3[j] = '\0';
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
- char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
- char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
+ char_array_4[1] =
+ ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
+ char_array_4[2] =
+ ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for (auto j = 0; (j < i + 1); ++j)
Yeah, I saw that. I decided against it because it looks ugly when you have lots of forward declarations. With the latest change, you have it back. :-) |
This pull request adds a clang-format definition that tries to limit the amount of changes to the project. However, there are some inconsistencies in the current formatting that get reformatted by this pull request.
Feel free to pull or discard.