openframeworks/openFrameworks

lots of indent errors

hiroMTB opened this issue · 6 comments

I found quite lots of indent errors like below. Those are only part of it.
Is there a way to auto-formating code before PR or each commit?

bool of3dPrimitive::hasScaling() const{
glm::vec3 scale = getScale();
return (scale.x != 1.f || scale.y != 1.f || scale.z != 1.f);

const ofTextureData& tdata = inTexture.getTextureData();
if(bNormalized){
mapTexCoords( 0, 0, tdata.tex_t, tdata.tex_u );
}else{
mapTexCoords(0, 0, inTexture.getWidth(), inTexture.getHeight());
}
auto tcoords = getTexCoords();
mapTexCoords(tcoords.x, tcoords.y, tcoords.z, tcoords.w);
}

// glut works with static callbacks UGH, so we need static variables here:
static ofWindowMode windowMode;
static bool bNewScreenMode;
static int buttonInUse;
static bool bEnableSetupScreen;
static bool bDoubleBuffered;
static int requestedWidth;
static int requestedHeight;
static int nonFullScreenX;
static int nonFullScreenY;
static int windowW;
static int windowH;
static int nFramesSinceWindowResized;
static ofOrientation orientation;
static ofAppGlutWindow * instance;

glfwSetWindowPosCallback(windowP, nullptr);
glfwSetFramebufferSizeCallback( windowP, nullptr);
glfwSetWindowCloseCallback( windowP, nullptr );
glfwSetScrollCallback( windowP, nullptr );
glfwSetDropCallback( windowP, nullptr );
glfwSetWindowRefreshCallback(windowP, nullptr);

glfwSetKeyCallback(windowP, keyboard_cb);
glfwSetCharCallback(windowP, char_cb);
glfwSetWindowSizeCallback(windowP, resize_cb);
glfwSetWindowPosCallback(windowP,position_cb);
glfwSetFramebufferSizeCallback(windowP, framebuffer_size_cb);
glfwSetWindowCloseCallback(windowP, exit_cb);
glfwSetScrollCallback(windowP, scroll_cb);

/* register cleanup handler, and set the new terminal mode */
atexit(reset_terminal_mode);
// setup new_termios for raw keyboard input
cfmakeraw(&new_termios);
// handle "\n" properly
new_termios.c_oflag |= OPOST;
//new_termios.c_oflag |= ONLCR;
// set the new_termios
tcsetattr(0, TCSANOW, &new_termios);
}

private:
int width, height;
ofBaseApp * ofAppPtr;
std::unique_ptr<ofCoreEvents> coreEvents;
std::shared_ptr<ofBaseRenderer> currentRenderer;
};

OF_3D_PRIMITIVE_PLANE,
OF_3D_PRIMITIVE_SPHERE,
OF_3D_PRIMITIVE_ICO_SPHERE,
OF_3D_PRIMITIVE_BOX,
OF_3D_PRIMITIVE_CONE,
OF_3D_PRIMITIVE_CYLINDER,

hello @hiroMTB!

since last year there is a .clang-format file in the repository. it follows pretty well the previous formatting, with a little bit more spaces around some markers.

about auto-formatting, there was sort of a "soft decision" made not to blanket the git history with a "clang-format" white-space commits, but to reformat when a file needs a change (the commits being squashed, it can be performed as a separate commit in for the PR review, but it will no show up in the final history/blame (and the whitespace exclusion in git works relatively well to not register as "changes")).

also sometimes macros and "nicely indented data tables" are better to exclude from clang-format, which means a manual review is always preferable after a reformat.

there are different ways to apply the formatting; the git clang-format is one, and I use this automator approach on Xcode.

Wow! Thank you for your detailed explanation. I will try clang-format and automator.

if we rely on manual review, probably we will keep seeing indent errors for future. But I can understand your point too.
Maybe we can arrange "format party" every month🤣

it would be great to format the entire core in one PR, but this has the potential to break a lot of PRs.
I think it is ok if it is right before the next release

oh! I see, good point!
Btw, how do the other big C++ projects manage this issue? Maintainers do it manually?

well when I looked last year nothing clear was found, and I subscribed here NVIDIA/stdexec#905 thinking that when @ericniebler figures it out we can evaluate their choices...

clang-format is definitely the way.

However it does not explicitly support A Style.
We can override this by adding a .clang-format file in root directory with some custom settings to make it more A Style:

---
Language:        Cpp
# Based on Google style as a starting point
BasedOnStyle:  Google

# Indentation width
IndentWidth:     4

# Use spaces instead of tabs for indentation
UseTab:          Never

# Brace wrapping
BraceWrapping:
  AfterClass:      true
  AfterControlStatement: true
  AfterEnum:       true
  AfterFunction:   true
  AfterNamespace:  true
  AfterStruct:     true
  AfterUnion:      true
  BeforeCatch:     true
  BeforeElse:      true
  IndentBraces:    false

# Column limit
ColumnLimit:     80

# Pointer and reference alignment
PointerAlignment: Left

# Includes sorting
IncludeCategories:
  - Regex:           '^<ext/.*\.h>'
    Priority:        2
  - Regex:           '^<.*\.h>'
    Priority:        1
  - Regex:           '^".*'
    Priority:        0
IncludeBlocks:   Regroup

# Control the alignment of assignments
AlignConsecutiveAssignments: true

# Control the alignment of declarations
AlignConsecutiveDeclarations: true