This is an archive of the discontinued LLVM Phabricator instance.

add option -fallback-style=fail (fail if -style=file falls back)
AcceptedPublic

Authored by pseyfert on Mar 8 2017, 8:59 AM.

Details

Reviewers
klimek
djasper
Summary

I want to provide information to the clang-format user if the style
is/can be used, or if clang-format sees itself forced to fall back to
the fallback-style. I.e. in contrast to doing nothing, as with
-fallback-style=none, I want clang-format to fail. Kind of as a reminder
to the user "hey, maybe you forgot to add your .clang-format file to
your project".

I was thinking about doing this through an option
-fallback-style=fail. Do you think that is the right approach?

If yes, I gave it a try and wrote the attached one-off patch, which adds
the option -fallback-style=fail.

I *briefly* tested it on my system by building make clang-format[1] and
tried what happens when no .clang-format file exists and I run
clang-format -style=file -fallback-style=fail main.cc on a minimal
hello world c++ file.

NB: the patch does contain an update of the unit test, but I did not
manage to run it (problems with the system I was running on …).

Thanks in advance for feedback,

Paul

For reference:
This addresses what I asked on Stackoverflow
http://stackoverflow.com/questions/41758865/determine-if-clang-format-finds-clang-format-file-in-a-shell-or-cmake-script

and is a duplication of my pull request on github
https://github.com/llvm-mirror/clang/pull/21

[1]: when following steps 1-3 from
https://clang.llvm.org/get_started.html and then running `make
clang-format` in step 7 instead of make.

Diff Detail

Repository
rL LLVM

Event Timeline

pseyfert created this revision.Mar 8 2017, 8:59 AM

Can you make a full-context diff please?

pseyfert updated this revision to Diff 96889.Apr 27 2017, 3:28 AM
djasper added inline comments.Apr 27 2017, 4:27 AM
lib/Format/Format.cpp
1984

Invert the order here (remove the "!"), so that the error case becomes and early exist.

1986

No "else" after "return" (http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return).

Also, we generally don't use braces around single-statement ifs.

pseyfert updated this revision to Diff 96906.Apr 27 2017, 6:10 AM

Implementing comments by @djasper

djasper accepted this revision.Apr 27 2017, 6:15 AM

Looks good.

This revision is now accepted and ready to land.Apr 27 2017, 6:15 AM