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

Source code formatting: Should we run a make style operation on all the CPP/H files? #106

Open
maxieds opened this issue Jun 1, 2022 · 0 comments

Comments

@maxieds
Copy link
Contributor

maxieds commented Jun 1, 2022

This topic drives me crazy every time I come back to this code! From platform to platform, terminal variant to terminal variant, and then even editor changes like vim on Linux back to MacVim on MacOS, the indentation in the source files ALWAYS gets mucked up. Case in point (from this file I just looked at to fix #105):

void DiagramWindow::drawWidgets(cairo_t *crDraw = NULL) {
    
    if(exportButton) { 
         exportButton->redraw();
    }
    if(m_cbShowTicks) { 
     m_cbShowTicks->redraw();
    }
    if(m_cbDrawBases) { 
     m_cbDrawBases->redraw();
    }
    if(baseColorPaletteImgBtn) {
     baseColorPaletteImgBtn->redraw();
    }
    if(baseColorPaletteChangeBtn) {
     baseColorPaletteChangeBtn->redraw();
    }
    for(int m = 0; m < 3; m++) {
        if(m_menus[m] != NULL && !m_menus[m]->active()) {
        m_menus[m]->redraw();
    }
    }
    if(crDraw != NULL) {
     cairo_save(crDraw);
     CairoColor_t::FromFLColorType(GUI_WINDOW_BGCOLOR).ApplyRGBAColor(crDraw);
     cairo_rectangle(crDraw, 0, 0, w(), h());
     cairo_fill(crDraw);
     cairo_restore(crDraw);
    }
/* ... REMAINDER OMITTED ... */

An option I am taking from the Chameleon Mini firmware is to create a make style target in our Makefile that makes all of this (and other configurable nit picky coding style habits) easy to update:

style:
        ## : Make sure astyle is installed
        @which astyle >/dev/null || ( echo "Please install 'astyle' package first" ; exit 1 )
        ## : Remove spaces & tabs at EOL, add LF at EOF if needed on *.c, *.h, Makefile
        find . \( -name "*.[ch]" -or -name "Makefile" \)                      \
            -exec perl -pi -e 's/[ \t]+$$//' {} \;                            \
            -exec sh -c "tail -c1 {} | xxd -p | tail -1 | grep -q -v 0a$$" \; \
            -exec sh -c "echo >> {}" \;
        ## : Apply astyle on *.c, *.h
        find . -name "*.[ch]" -exec astyle --formatted --mode=c --suffix=none \
            --indent=spaces=4 --indent-switches                               \
            --keep-one-line-blocks --max-instatement-indent=60                \
            --style=google --pad-oper --unpad-paren --pad-header              \
            --align-pointer=name {} \;

My only reservation is that the resulting commit post-style formatting operation will be large and involve most of the source files. Of course, this is reasonable because we are pushing the lines over by spaces everywhere. I thought I would get input before doing this:
@ceheitsch Can you please weight in on the decision?

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

1 participant