This allows the define BasedOnStyle: InheritParentConfig and then clang-format looks into the parent directories for their .clang-format and takes that as a basis.
My use case is to remove the column limit for my tests.
Differential D93844
[clang-format] Add possibility to be based on parent directory HazardyKnusperkeks on Dec 27 2020, 1:38 PM. Authored by
Details This allows the define BasedOnStyle: InheritParentConfig and then clang-format looks into the parent directories for their .clang-format and takes that as a basis. My use case is to remove the column limit for my tests.
Diff Detail
Unit Tests Event TimelineComment Actions I'm a little confused why this is needed as clang-format always read up the directory tree until it see a .clang-format file, perhaps I don't quite understand the use case. Can't you just have a different .clang-format in the subdirectory? Comment Actions Yes of course I can, but I don't want to copy everything except the one thing I want to change. I have one .clang-format in my main directory and since I only want to change the column limit for my tests I want to write a .clang-format in the test directory with the content: BasedOnStyle: File ColumnLimit: 0 So when I change (or better add) a value in my main .clang-format it will also apply to my tests, without touching their file. Comment Actions It's my understanding this is akin to the InheritParentConfig option found in .clang-tidy. We have it quite lucky here at LLVM where for tests we can just use: BasedOnStyle: LLVM ColumnLimit: 0 However for other projects with their own style they could then use: # Copy the root directory clang.format config BasedOnStyle: file ColumnLimit: 0 This would also make modifying the formatting style of a project much easier as you would only need to touch the root directory .clang-format file in most cases. With this implementation I'm not too sure on the specifics though. .clang-format files are more complex to parse than .clang-tidy files so there's more edge cases to consider.
Comment Actions Exactly.
Initially I thought it shouldn't. But now I think maybe it should.
Comment Actions I like what you are suggesting, do you think BasedOnStyle: File is the best terminology as the term File is used elsewhere to mean read from the .clang_format file, how about BasedOnStyle: Inherit or why not just BasedOnStyle: InheritParentConfig to match clang-tidy?
Comment Actions
Comment Actions What I can't easily tell from the tests is if you are overriding any styles defined in the parent with a local style.
Comment Actions Yes I do, but I will try to make it clearer in the tests.
Comment Actions Okay after rechecking the code (it is a bit ago that I wrote it), what more do you need? I compare the parsed style against a base style (Google, to show that it’s not the default LLVM) modified with the values from the overwrite. Only for the last checks where I basically check the same over and over again, just trough different means I use a stored style. Comment Actions Found and fixed the case when no BasedOnStyle apart from InheritParentConfig is used.
Comment Actions As a follow up it may be wise to pass a diag handler to parseConfiguration as when we parse it a second time, we probably want to disregard any warnings (like unknown key) detected as they will have been printed on the first pass.
Comment Actions Will try to look into it.
Comment Actions Silence unused variable warnings in release and using llvm::reverse with range based for.
|
Typo: fount -> found.