[cfe-dev] how clang-tidy finds clang-format file

Adam Cieszkiel via cfe-dev cfe-dev at lists.llvm.org
Fri Jul 21 04:33:24 PDT 2017


Hello,

Thank you for the response.

I tried 'run-clang-tidy.py' and it started to work but I had to add one
additional line to the script: 'invocation.append('-style=file')' so it
takes .clang-format from the current directory otherwise it used some
default formatting:

 84 def apply_fixes(args, tmpdir):
 85   """Calls clang-apply-fixes on a given directory. Deletes the dir when
done."""
 86   invocation = [args.clang_apply_replacements_binary]
 87   if args.format:
 88     invocation.append('-format')
* 89     invocation.append('-style=file')*
 90   invocation.append(tmpdir)
 91   subprocess.call(invocation)
 92   shutil.rmtree(tmpdir)

Thanks for that.

Still...
I do not know why it does not work just without using
'clang-apply-replacements'
as an intermediate step and it does not apply .clang-format.

Can it be a bug in the version 4.0?
Do you have any other ideas how I could get it working? Or someone who
could help?

I will try maybe to build it from source on a different platform.
In the last resort I will have to take a look at the source code and check.

Thank you in advance.

Best regards,
Adam.

On Fri, Jul 21, 2017 at 1:28 AM, Piotr Padlewski <piotr.padlewski at gmail.com>
wrote:

> This probably not gonna solve the issue, but have you tried
> run-clang-tidy.py? (extra/clang-tidy/tools/run-clang-tidy.py). It export
> the fixes and applies them automatically, and runs on multiple threads.
>
> Piotr
>
> 2017-07-20 14:47 GMT-07:00 Adam Cieszkiel <acieszkiel at gmail.com>:
>
>> Hello,
>>
>> Thank you for the answer.
>>
>> It was my first guess and I was surprised that it did not work.
>>
>> I have to use '-export-fixes=' so it works. Then the fixes are written
>> into json file and 'clang-apply-replacements -format -style=file' does the
>> job.
>> But it does want to work without this exporting.
>>
>> In version 5.0 I just use option '-format-style=file' and it uses
>> .clang-format file in the closest parent directory as described in the
>> documentation:
>> https://clang.llvm.org/extra/clang-tidy/index.html
>>
>> But in version 4.0 there is only option "-style" which seems to not offer
>> such option and does not work with .clang-format from the folder I run
>> clang-tidy.
>>
>> -style=<string>              -                                 Fallback style for reformatting after inserting fixes                                 if there is no clang-format config file found.
>>
>>
>> I am not sure why it it like that.
>>
>> Best regards,
>> Adam.
>>
>>
>>
>>
>> On Thu, Jul 20, 2017 at 11:18 PM, Piotr Padlewski <
>> piotr.padlewski at gmail.com> wrote:
>>
>>> Hi Adam,
>>> it should look for ".clang-format" from the place where you run
>>> clang-tidy. I hope it helps.
>>>
>>> Piotr
>>>
>>> 2017-07-20 13:25 GMT-07:00 Adam Cieszkiel via cfe-dev <
>>> cfe-dev at lists.llvm.org>:
>>>
>>>> Hello,
>>>>
>>>> I have a question:
>>>> Do you know maybe how to make clang-tidy in version 4.0 use formatting
>>>> style for fixes (-fix) from .clang-format file?
>>>>
>>>> I tried in many different ways but I failed.
>>>>
>>>> Documentation mentions 'clang-format config file to be found' but
>>>> anywhere I put it, it is still not used by clang-tidy also if I put in in
>>>> location pointed by '-p' option.
>>>>
>>>> http://releases.llvm.org/4.0.0/tools/clang/tools/extra/docs/
>>>> clang-tidy/index.html
>>>>
>>>> -style=<string>              -                                 Fallback style for reformatting after inserting fixes                                 if there is no clang-format config file found.
>>>>
>>>> I have no idea where I should put .clang-format file so it could be
>>>> used by clang-tidy for applying clang-tidy fixes.
>>>>
>>>> Thank you in advance.
>>>>
>>>> _______________________________________________
>>>> cfe-dev mailing list
>>>> cfe-dev at lists.llvm.org
>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170721/49cd1128/attachment.html>


More information about the cfe-dev mailing list