This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Add option to specify explicit config file
Needs ReviewPublic

Authored by gigadude on May 25 2017, 12:18 PM.

Details

Summary

This diff extends the -style=file option to allow a config file to be specified explicitly. This is useful (for instance) when adding IDE commands to reformat code to a personal style.

Usage:

clang-format -style=file:<configfilepath> ...

Diff Detail

Event Timeline

gigadude created this revision.May 25 2017, 12:18 PM
djasper added inline comments.May 26 2017, 5:00 AM
lib/Format/Format.cpp
2017

I think not finding the config file should be an error.

gigadude updated this revision to Diff 100929.May 31 2017, 3:33 PM

Return a "Config file <name> not found" error if the file: style's file isn't found.

alexfh edited edge metadata.Jun 1 2017, 3:25 AM

Please add a test for the new -style syntax.

@alexfh do you mean to the clang-format-test.el file (which I don't know how to run) or to the FormatTests? If the latter would the right place be TEST(FormatStyle, GetStyleOfFile)?

gigadude updated this revision to Diff 101276.Jun 2 2017, 2:12 PM

Add FormatTest for style=file:<path>

ioeric edited edge metadata.

The patch has "Context not available" issue (i.e. I couldn't expand to see code around the changes). Could you re-upload the diff?

lib/Format/Format.cpp
1966

Could you also update the comment in include/clang/Format/Format.h?

2027

I think the logic of parsing config files should be similar in the "--style=file" case. Could you pull it into a function to avoid duplication?

alexfh added a comment.Jul 4 2017, 7:02 AM

Please re-upload the patch with the full context (see http://llvm.org/docs/Phabricator.html).

alexfh requested changes to this revision.Jul 4 2017, 7:02 AM
This revision now requires changes to proceed.Jul 4 2017, 7:02 AM
alexfh edited reviewers, added: krasimir; removed: alexfh.Mar 14 2018, 7:47 AM
krasimir added inline comments.Mar 14 2018, 9:29 AM
unittests/Format/FormatTest.cpp
10429 ↗(On Diff #101276)

Please also add tests for what's the expected behavior with relative paths.

This revision now requires review to proceed.Nov 24 2021, 3:30 AM