-
Notifications
You must be signed in to change notification settings - Fork 460
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
Allow configuration through .clang-format files #1759
Open
EmielMatthys
wants to merge
4
commits into
diffplug:main
Choose a base branch
from
EmielMatthys:clang-format-full-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, this is all it takes for
clang
to find the.clang-format
file?The only problem is that the content of the
.clang-format
files is not being captured (ideally byFileSignature
). As currently implemented the up-to-date checking would break. What do you think aboutclangFormat().dotfile('.clang-fomat')
as an API? Is there usually only one.clang-format
file, or are there sometimes multiple?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reply.
While newer versions of clang-format allow to specify file path for the dot file, I think older versions only support
--style=file
which tells clang-format to recursively look for such a dot file in parent directories (of targeted .c/.h/... file) and uses first one it can find.I'll look into it and will try your API suggestion + FileSignature thingy 👍 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
clang
is actually searching with a recursive search, and we're specifying by pointing to a dotfile, I think that's okay. Of course there is a chance of some misconfiguration, but it's a lot better than giving the user no chance to capture the dotfile state at all.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So looking into this, I learned 2 things so far: 🤓
According to the ClangFormat docs,
--style=file
is actually the default, meaning CF will already pickup on present dotfiles in current version of PR if you do not provide a.style(...)
..style('file')
(still need to trigger it by modifying the .c file though)As of clang 14, the option also supports providing a path to a specific dot file
-style=file:<format_file_path>
That also means that for the devs who are currently using spotless without
.style
and have a.clang-format
file in the directory (or a parent directory) of the file being formatted, this PR will cause the dotfile to be picked up.Maybe that's fine but it's an impact you should be aware of.
Two remaining questions for you:
.style('file:/path/to/dotfile')
on older CF results in :stderr: Invalid value for -style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this
spotless/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java
Lines 89 to 96 in b6e30f8
FileSignature dotFile
then it will detect dotfile changes. Right now, without this PR, I believe it will not detect dotfile changes becuase it doesn't know where the files are, so it can't find them even if they are there.In terms of what to merge/implement, the most important thing is that it works for you. If you need to bump the required clang, we can bump it, and if someone needs support for older versions, they can add it.
Seems to me like a good compromise is
if (dotFile == null) { currentBehaivorBeforePR } else { clang14 format_file_path }
.