Skip to content

Code formatting#1191

Merged
TheZ3ro merged 5 commits intokeepassxreboot:developfrom
louib:code_formatting
Apr 2, 2018
Merged

Code formatting#1191
TheZ3ro merged 5 commits intokeepassxreboot:developfrom
louib:code_formatting

Conversation

@louib
Copy link
Copy Markdown
Member

@louib louib commented Nov 17, 2017

Fixes #1168

@droidmonkey @adolfogc @TheZ3ro what would you think about this?

How has this been tested?

cd build
make format

@TheZ3ro
Copy link
Copy Markdown
Contributor

TheZ3ro commented Nov 17, 2017

This will need all the code correctly formatted before merging

Anyway seems nice to me!

@louib
Copy link
Copy Markdown
Member Author

louib commented Nov 17, 2017

@TheZ3ro we could do the formatting of all the code just before the next major, to avoid conflicts when backporting / upporting changes.

.travis.yml Outdated

script:
- cmake -DCMAKE_BUILD_TYPE=${CONFIG} -DWITH_GUI_TESTS=ON -DWITH_ASAN=ON -DWITH_XC_HTTP=ON -DWITH_XC_AUTOTYPE=ON -DWITH_XC_YUBIKEY=ON $CMAKE_ARGS ..
- make format; git diff --exit-code
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@adolfogc
Copy link
Copy Markdown
Contributor

@louib Nice work!

@adolfogc
Copy link
Copy Markdown
Contributor

we could do the formatting of all the code just before the next major, to avoid conflicts when backporting / upporting changes.

I would like to propose the use of clang-tidy when making this one-time refactoring, as it could help fix some cases of missing readability braces around statements. Other checks could also be used, like the modernize-* ones.


This project follows the [Qt Coding Style](https://wiki.qt.io/Qt_Coding_Style). All submissions are expected to follow this style.
The coding style of the project is enforced using llvm's `clang-format` formatting tool. A thorough description
of the coding style can be found in the `.clang-format` file, but the main conventions are presented here.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be useful to mention here the use of //clang-format off and //clang-format on for having ClangFormat ignore certain sections of the code? To illustrate the possible use-cases, an example could also be provided. I'm thinking on something like:

When deemed necessary, you can use //clang-format off and //clang-format on to have ClangFormat ignore certain parts of the code. For instance, from project's code-base:

// clang-format off
int binary =
    ((hmac[offset] & 0x7f) << 24)
    | ((hmac[offset + 1] & 0xff) << 16)
    | ((hmac[offset + 2] & 0xff) << 8)
    | (hmac[offset + 3] & 0xff);
// clang-format on

In the example above, the manual formatting resulted in more readable code than the ClangFormat changes, hence the need for using the special comment lines.

@adolfogc
Copy link
Copy Markdown
Contributor

@louib After trying this branch, I have another observation:

The steps I followed:

git clone https://github.com/louib/keepassxc.git
cd keepassxc
git checkout code_formatting
mkdir build && cd build
cmake ..
make format

The error I got:

Configuration file(s) do(es) not support Objective-C: /Users/adolfogc/Downloads/keepassxc/.clang-format
make[3]: *** [CMakeFiles/format] Error 1
make[2]: *** [CMakeFiles/format.dir/all] Error 2
make[1]: *** [CMakeFiles/format.dir/rule] Error 2
make: *** [format] Error 2

❗️ Please note ClangFormat did affect the project files as expected.

Possible solution:

See my other comments in the code.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

set(THIRD_PARTY_DIRS
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include autotype/mac here.

streams/QtIOCompressor
)

set(THIRD_PARTY_FILES
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include core/ScreenLockListenerMac.h and core/ScreenLockListenerMac.cpp here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have all the third party files centralised in one directory...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure those two are third party code, they need to be excluded because they contain Objective-C code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not third-party.

Maybe we can exclude them in another group? 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just renamed the lists so that we can exclude both third-party and obj-c files.

@TheZ3ro
Copy link
Copy Markdown
Contributor

TheZ3ro commented Nov 19, 2017

I like this solution @louib

@louib
Copy link
Copy Markdown
Member Author

louib commented Nov 19, 2017

@adolfogc I tried setting up clang-tidy but wasn't able to come up with a complete solution with the limited amount of time I had. Help would be appreciated, but it could be in a different PR I guess.

Can you try again make format on Mac, I added the obj-c files to the excluded directories.


Formatting can be performed automatically by calling `make format` from the `build/` directory.

Note that [formatting can be disabled on a piece of code](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#disabling-formatting-on-a-piece-of-code) if manual formatting is deemed more readable.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@adolfogc
Copy link
Copy Markdown
Contributor

@louib I tested again using macOS, I can confirm the issue is now fixed.

@adolfogc
Copy link
Copy Markdown
Contributor

@louib

I tried setting up clang-tidy but wasn't able to come up with a complete solution with the limited amount of time I had. Help would be appreciated, but it could be in a different PR I guess.

Sure, we can work on it in a next PR.

@louib
Copy link
Copy Markdown
Member Author

louib commented Nov 19, 2017

@adolfogc cool, thanks!

If you guys are good with the solution we can keep this PR open until before the next major release and then format the codebase and merge.

I'd still like to have @droidmonkey 's approval since he wasn't convinced by the brute-force approach of enforcing formatting. My rationale for using git diff is that contributors can actually see in travis which sections of the code are not formatted properly and thus know that it's a formatting problem.

Copy link
Copy Markdown
Contributor

@TheZ3ro TheZ3ro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it's an approval. Leaving the PR open until all the code is formatted before 2.3.0

@phoerious
Copy link
Copy Markdown
Member

phoerious commented Nov 21, 2017

I give my approval under the condition that we have a rough look through the code in advance and identify sections that need // clang-format off and submit them as addendum to this PR.

@droidmonkey
Copy link
Copy Markdown
Member

I'm good with this approach as long as we make a massive reformat (that doesn't impact functionality) right before we complete 2.3.0

@louib louib added this to the v2.3.0 milestone Dec 3, 2017
@louib louib removed the discussion label Jan 13, 2018
@phoerious
Copy link
Copy Markdown
Member

After #1305 and #1327 are merged, we could do the reformatting. But this PR needs to be adjusted for TeamCity.

@louib louib force-pushed the code_formatting branch 2 times, most recently from 2b3d14f to d494741 Compare January 14, 2018 15:17
@louib
Copy link
Copy Markdown
Member Author

louib commented Jan 14, 2018

@phoerious ping me when both PRs are merged, I'll do the formatting. Not sure how to do the TeamCity adjustment though.

@phoerious phoerious changed the base branch from develop to release/2.3.0 February 1, 2018 20:42
@phoerious phoerious modified the milestones: v2.3.1, v2.3.2 Mar 6, 2018
@louib
Copy link
Copy Markdown
Member Author

louib commented Mar 8, 2018

@phoerious I'll let you take care of this one.

@louib louib force-pushed the code_formatting branch 2 times, most recently from d8fea07 to a24d127 Compare March 18, 2018 15:23
@louib louib changed the base branch from develop to release/2.3.2 March 18, 2018 15:23
@louib
Copy link
Copy Markdown
Member Author

louib commented Mar 18, 2018

@phoerious rebased, changed base branch and reformatted the code.

@droidmonkey
Copy link
Copy Markdown
Member

Do we still want to do this for 2.3.2 or 2.4 (ie develop)

@TheZ3ro
Copy link
Copy Markdown
Contributor

TheZ3ro commented Mar 19, 2018

Sincerely, I think 2.4 it's better

@louib louib modified the milestones: v2.3.2, v2.4.0 Mar 24, 2018
@louib louib changed the base branch from release/2.3.2 to develop March 31, 2018 16:22
@louib louib force-pushed the code_formatting branch from a24d127 to 9897b09 Compare March 31, 2018 16:22
@louib
Copy link
Copy Markdown
Member Author

louib commented Mar 31, 2018

@keepassxreboot/core-developers rebased to develop and removed exclusion of http/ directory.

@TheZ3ro
Copy link
Copy Markdown
Contributor

TheZ3ro commented Mar 31, 2018

I think we can merge this, everybody agrees?

@droidmonkey
Copy link
Copy Markdown
Member

droidmonkey commented Mar 31, 2018

Lets bite the bullet and do it before we get too far down the road

@TheZ3ro
Copy link
Copy Markdown
Contributor

TheZ3ro commented Mar 31, 2018

Seems that new code was added with #1702, we need to re-update this PR now

@louib louib force-pushed the code_formatting branch from 9897b09 to 74efc57 Compare March 31, 2018 19:57
@louib
Copy link
Copy Markdown
Member Author

louib commented Mar 31, 2018

@TheZ3ro should be good now.

@TheZ3ro TheZ3ro merged commit dd246f1 into keepassxreboot:develop Apr 2, 2018
@weslly weslly mentioned this pull request Apr 5, 2018
@louib louib deleted the code_formatting branch June 14, 2018 21:42
@c4rlo c4rlo mentioned this pull request Jan 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants