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

Add clang format to clean up code #39

Merged
merged 10 commits into from
Apr 14, 2020

Conversation

ElectricRCAircraftGuy
Copy link
Collaborator

@ElectricRCAircraftGuy ElectricRCAircraftGuy commented Apr 14, 2020

Added clang-format to auto-format the code, and ran it on the main Arduino .ino file.

To run the formatter, simply do this from the command line (see main README for both
Windows and Linux installation instructions):

./run_clang-format.sh 

This should be done before all PRs are merged forever and onward into the future, as a standard practice by the person making the PR before we will merge the PR.

Fixes #21

…ude`s to top of .ino file

...and alphabetize them
I set every single setting, meticulously going through this
documentation online to do so:
https://clang.llvm.org/docs/ClangFormatStyleOptions.html
…on 11 of clang-format but I only have version 6

Version 6 Style Options documentation is here:
https://releases.llvm.org/6.0.1/tools/clang/docs/ClangFormatStyleOptions.html

I had to comment out or modify every line that was giving a clang-format
error when running clang-format. These lines I commented out or changed
are apparently only for version 11, but I have version 6.
1. AlwaysBreakAfterReturnType - change from "All" to "None", as All was
an accident and makes functions look like this:

    void
    main()
    {
    }

instead of this:

    void main()
    {
    }

None is really what I want for sure.

2. IndentPPDirectives - change from "BeforeHash" to "AfterHash", as
"BeforeHash" isn't  supported on clang-format v6 (only on later
versions), and "AfterHash" is good enough.
…out getting a good editor

I explained how to set tab size in Arduino IDE from 2 to 4, but also
recommended just getting a good editor, and setting the IDE to "Use
external editor", so you just build with it, but no longer edit with it.

Good editor examples & descriptions
(I added detailed descriptions for these editors):
  1. Eclipse
  2. Sublime Text 3
@ElectricRCAircraftGuy
Copy link
Collaborator Author

ElectricRCAircraftGuy commented Apr 14, 2020

After merging this PR, I could use some help from you getting clang-format running on your Windows machine so you can document the process in the main readme. I've written it up already but am not on a Windows machine to test, so I did some guessing and online searching a bit.

By the way, using github to review code can be challenging. I highly recommend using meld instead as a git difftool to view changes from one branch to another. It's an incredible file comparison tool for Windows or Linux. See how to set it up here: https://stackoverflow.com/questions/14821358/git-mergetool-with-meld-on-windows/48979939#48979939 @giorakor @nimrod46

@nimrod46
Copy link
Member

Yep windows version works with that installation instruction, you can update the readme, I approved the PR

Now that @nimrod46 has tested the instructions and says they work, I can
remove the part saying the instructions were untested and I needed help
to test them.
@ElectricRCAircraftGuy ElectricRCAircraftGuy merged commit b64f3db into master Apr 14, 2020
@ElectricRCAircraftGuy ElectricRCAircraftGuy deleted the add_clang_format_to_clean_up_code branch April 14, 2020 16:52
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

Successfully merging this pull request may close these issues.

Code Formatting: Add linter to auto-format; consider using clang-format tool for this purpose
3 participants