Skip to content
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

lots of indent errors #7869

Open
hiroMTB opened this issue Jan 21, 2024 · 6 comments
Open

lots of indent errors #7869

hiroMTB opened this issue Jan 21, 2024 · 6 comments

Comments

@hiroMTB
Copy link
Contributor

hiroMTB commented Jan 21, 2024

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,

@artificiel
Copy link
Contributor

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.

@hiroMTB
Copy link
Contributor Author

hiroMTB commented Jan 24, 2024

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🤣

@dimitre
Copy link
Member

dimitre commented Jan 24, 2024

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

@hiroMTB
Copy link
Contributor Author

hiroMTB commented Jan 24, 2024

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

@artificiel
Copy link
Contributor

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...

@danoli3
Copy link
Member

danoli3 commented Feb 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants