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

Run various linters on pull requests #53

Merged
merged 7 commits into from
Oct 22, 2021
Merged

Conversation

dbarbier
Copy link
Contributor

@dbarbier dbarbier commented Sep 2, 2021

This PR is quite self-explanatory, it adds a new "Code style" check at the bottom of this page in the checks tab.

Mark this PR as a draft for now, we have to discuss which linters do we want to apply and on which files, eg. do we want to reformat documentation and notebooks too? Also this PR should be applied only when there is no conflict with other PRs.

Checks will be performed on PRs created after this PR is merged, and if some check fails, author will have to fix source files.

@dbarbier
Copy link
Contributor Author

dbarbier commented Sep 2, 2021

It is fairly easy to reformat C++ source files as well with clang-format, but we need to decide on some coding style guidelines. A comparison between most used guidelines can be found at https://github.com/motine/cppstylelineup, please tell which one yu want.

@galleon
Copy link
Contributor

galleon commented Sep 3, 2021

@fteicht or @jeromerobert can you comment and contribute on which c++ style to apply on C++ files

@fteicht
Copy link
Collaborator

fteicht commented Sep 3, 2021

Thanks @dbarbier for digging int the topic. Personally I am used to the LLVM style that I like a lot. The Google style is fine to me too. What do you think @jeromerobert ?

@jeromerobert
Copy link
Contributor

LLVM is also my prefered one. I used Webkit for a while but 2 spaces indentation is definitely better. Google is good except when it create one line if statments. Chromium is also good but has a bit too many (IMHO useless) line breaks.

@dbarbier
Copy link
Contributor Author

dbarbier commented Sep 3, 2021

Okay I just added some commits to call clang-format with LLVM style on all C++ files in cpp/src directory. As mentioned in 545c3c7 I had to disable sort of includes, otherwise there are build failures.

If linters report errors, sources have to be modified
before being merged.  Since builds take time on runners,
abort early to not waste CPU cycles.

Add .clang-format configuration file generated by

  clang-format-9 --dump-config --style=LLVM > .clang-format
  clang-format-9 --dump-config --style='{SortIncludes: false}' > new-clang-format && mv new-clang-format .clang-format

Github's ubuntu-latest runners have clang-format versions
between 6 and 10, but there is no clang-format 10 on Debian,
and thus use version 9.

We have to set SortIncludes to false, otherwise there are build
failures because files in /impl/ subdirectories may be #include'd
too early.  This problem should be fixed, but for now do not sort
includes.
@dbarbier
Copy link
Contributor Author

dbarbier commented Sep 6, 2021

Force-pushed to fix conflicts

@dbarbier dbarbier marked this pull request as ready for review September 22, 2021 11:38
@dbarbier
Copy link
Contributor Author

Black is now run on docs and examples too, and data files are no more processed. This PR is no more a draft and can be reviewed.

Copy link
Collaborator

@neo-alex neo-alex left a comment

Choose a reason for hiding this comment

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

OK for me on Python side (incl. doc generation). Might still need review from Florent to check C++ side.

@dbarbier
Copy link
Contributor Author

Since there are many open pull requests, I dropped commits which were applying linters in order to avoid conflicts.

@fteicht
Copy link
Collaborator

fteicht commented Oct 19, 2021

Since there are many open pull requests, I dropped commits which were applying linters in order to avoid conflicts.

Ok but how can I review it, then? Which script do I need to run on my side?

@dbarbier
Copy link
Contributor Author

Ok but how can I review it, then? Which script do I need to run on my side?

git checkout db/black
pre-commit run -a

This can be reactivated when all files are fixed.  At the moment,
files are not modified to avoid conflicts with other PRs.
@galleon
Copy link
Contributor

galleon commented Oct 21, 2021

Since there are many open pull requests, I dropped commits which were applying linters in order to avoid conflicts.

Ok but how can I review it, then? Which script do I need to run on my side?

@dbarbier @fteicht seems to need support on how to test this PR on his machine I guess.

@galleon
Copy link
Contributor

galleon commented Oct 21, 2021

Might also be interesting to have a pre-commit hook for json as you suggested in #72. I would suggest to have 4 spaces indentation (default in VSCode).

@dbarbier
Copy link
Contributor Author

It is IMO more important to have this PR merged and source files modified without messing with other PRs.

@fteicht
Copy link
Collaborator

fteicht commented Oct 21, 2021

The C++ linter does not seem to cut long lines. Is there a way to configure it so it can cut the lines appropriately like black does on Python files?

1 similar comment
@fteicht
Copy link
Collaborator

fteicht commented Oct 21, 2021

The C++ linter does not seem to cut long lines. Is there a way to configure it so it can cut the lines appropriately like black does on Python files?

Brew does not provide clang-format v9, so MacOS users may not be able
to easily run pre-commit locally.  We may try with v8, but since it is
unclear whether we really need a versioned dependency on clang-format,
let us try with an unversioned one for now, and we will get back to a
versioned dependency if discrepancies are found.
@dbarbier
Copy link
Contributor Author

Okay the problem was that clang-format-9 was not found on Mac. Brew does not provide this version, so I removed the versioned dependency. Output is the same as before, hopefully we do not need to pin a specific version.

@fteicht
Copy link
Collaborator

fteicht commented Oct 22, 2021

The issue was that clang-format version was hard set to a version that I don't have installed on my computer. The last commit corrects this, and now I can indeed see the effects of running the linter on the C++ code. The PR is fine with me, then. Thanks!

@fteicht fteicht self-requested a review October 22, 2021 07:22
@fteicht fteicht merged commit 287b632 into airbus:master Oct 22, 2021
@dbarbier dbarbier deleted the db/black branch October 25, 2021 08:16
@dbarbier dbarbier restored the db/black branch October 25, 2021 08:19
@dbarbier dbarbier deleted the db/black branch October 25, 2021 08:22
@dbarbier dbarbier mentioned this pull request Oct 25, 2021
10 tasks
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.

5 participants