Skip to content

Format with clang-format 10 #3385

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

Closed
wants to merge 9 commits into from
Closed

Conversation

pfultz2
Copy link
Contributor

@pfultz2 pfultz2 commented Aug 5, 2021

No description provided.

@pfultz2
Copy link
Contributor Author

pfultz2 commented Aug 5, 2021

There is a runformat script to format all files using clang-format 10. However, developers can use git clang-format to only format their changes.

Copy link
Owner

@danmar danmar left a comment

Choose a reason for hiding this comment

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

looks good to me. just wonder if it's possible to fix the indentation for private/protected/public.

const std::map<std::string, std::size_t> &mFiles;
Settings &mSettings;
ErrorLogger &mErrorLogger;
private:
Copy link
Owner

Choose a reason for hiding this comment

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

I would prefer no indentation for private/protected/public

@danmar
Copy link
Owner

danmar commented Aug 5, 2021

astyle is a small simple tool. imho it is simple to compile it myself on linux/windows.

do you know how people will be able to install clang format version 10 on windows/linux? I would prefer to not install the whole llvm/clang/etc stuff but I guess they just bundle everything together..

@pfultz2
Copy link
Contributor Author

pfultz2 commented Aug 5, 2021

astyle is a small simple tool. imho it is simple to compile it myself on linux/windows.

Well version 3.1 is easier to build and install. We could try a newer version, but astyle has had no updates for 2 years whereas clang-format is being actively developed. So it seems like we might need to move to clang-format in the future anyways.

do you know how people will be able to install clang format version 10 on windows/linux?

For ubuntu you can install it with apt install clang-format-10. Most linux distros have some version of clang-format. Even if the version doesn't match the same, developers can still format the code with git clang-format so it wont affect code they are not changing.

For windows, you can download the binaries here.

@pfultz2
Copy link
Contributor Author

pfultz2 commented Aug 5, 2021

looks good to me. just wonder if it's possible to fix the indentation for private/protected/public

I updated it to outdent the labels.

@danmar
Copy link
Owner

danmar commented Aug 6, 2021

Even if the version doesn't match the same

my recent debian distro only has clang-format-7 :-(

I think a docker image with clang-format would be relatively ok for me but it's a quite complex dependency.

I think it's important that I can reformat all code.

occasional contributors can use git clang-format.

@danmar
Copy link
Owner

danmar commented Aug 6, 2021

Well version 3.1 is easier to build and install. We could try a newer version, but astyle has had no updates for 2 years whereas clang-format is being actively developed. So it seems like we might need to move to clang-format in the future anyways.

I would not say we need to abandon it as long as we have no obvious problems. You have had problems to compile astyle right? I don't really understand what the problem is for you.

@danmar
Copy link
Owner

danmar commented Aug 6, 2021

For windows, you can download the binaries here.

It's not very good. That installation binary is 160MB .. and if all that is needed is clang-format this will not be appreciated.

I am not strongly against clang-format but we need to consider that it can't be built easily and the installation is either missing or massive on many platforms.

@pfultz2
Copy link
Contributor Author

pfultz2 commented Aug 6, 2021

my recent debian distro only has clang-format-7

I could switch it to use clang-format-7, instead. I picked clang-format-10 since it was the latest version available on ubuntu 18.04 LTS.

I would not say we need to abandon it as long as we have no obvious problems.

Well its broken. I just checked with 3.1(the latest version), and it still breaks with compile errors(perhaps moving the comment around might fix it). Also, it makes a lot of code unreadable(like here), and we can workaround it with using INDENT-OFF but that just kind of defeats the purpose of having an automatic formatting tool. There also doesn't seem to be further development to fix those issues in astyle.

You have had problems to compile astyle right?

I had issues with older versions of astyle. Astyle 3.0 or later seems to work fine(I didnt realized you switched to a newer version).

@pfultz2
Copy link
Contributor Author

pfultz2 commented Aug 6, 2021

I am not strongly against clang-format but we need to consider that it can't be built easily and the installation is either missing or massive on many platforms.

There is uncrustify which is more actively develop(and developed on github so it would be easier to add bug fixes), but I dont have any experience on how well it works. It doesn't use dijkstra's algorithm to find the best code format, so it might still format code in unreadable manner.

The only other alternative that is still lightweight would be to consider building a our own formatter on top of simplecpp using dijkstra's algorithm to find the best code format. Clang format doesn't use clang's parser only its lexer. So we could use simplecpp to do the lexing and then apply a similar approach as what is done in clang-format.

@pfultz2
Copy link
Contributor Author

pfultz2 commented Aug 7, 2021

So uncrustify looks like it does a better job than astyle. I opened #3388 to format with uncrustify. There are a lot of settings so you can tweak it further if you would like to use that instead of clang-format. It can be easily built with cget install uncrustify@uncrustify-0.72.0 or using cmake ..;make install

@danmar
Copy link
Owner

danmar commented Aug 7, 2021

Thanks! I feel that uncrustify is a much better alternative than clang-format. I close this PR.

@danmar danmar closed this Aug 7, 2021
@pfultz2 pfultz2 deleted the clang-format branch August 7, 2021 15:38
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.

2 participants