how clang-tidy finds clang-format file

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how clang-tidy finds clang-format file

Sumner, Brian via cfe-dev
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.

-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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how clang-tidy finds clang-format file

Sumner, Brian via cfe-dev
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 <[hidden email]>:
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.

-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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how clang-tidy finds clang-format file

Sumner, Brian via cfe-dev
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:

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 <[hidden email]> 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 <[hidden email]>:
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.

-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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how clang-tidy finds clang-format file

Sumner, Brian via cfe-dev
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 <[hidden email]>:
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:

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 <[hidden email]> 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 <[hidden email]>:
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.

-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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev





_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how clang-tidy finds clang-format file

Sumner, Brian via cfe-dev
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 <[hidden email]> 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 <[hidden email]>:
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:

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 <[hidden email]> 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 <[hidden email]>:
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.

-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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev






_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how clang-tidy finds clang-format file

Sumner, Brian via cfe-dev
Hello again,

I took a look at the code and based on my research in version 4.0 there is no code to apply formatting for fixes.
It was added in the following commit: 
[clang-tidy] Format code around applied fixes
Summary:
Add -format option (disabled by default for now) to trigger formatting
of replacements.


In this commit: [clang-tidy] Make format style customizable:

There was added documentation which was misleading because format could not be applied - it was only found but not used:

+    -style=<string>              -
+                                   Fallback style for reformatting after inserting fixes
+                                   if there is no clang-format config file found.

When I added the fragment of the missing code in version 4.0 and recompiled from source it started to work as expected.

This was the missing part in 'clang-tidy/ClangTidy.cpp in finish method of the ErrorReporter class':

+        if (llvm::Expected<tooling::Replacements> FormattedReplacements =
+                format::formatReplacements(Code, *Replacements, *Style)) {
+          Replacements = std::move(FormattedReplacements);
+          if (!Replacements)
+            llvm_unreachable("!Replacements");
+        } else {
+          llvm::errs() << llvm::toString(FormattedReplacements.takeError())
+                       << ". Skipping formatting.\n";
+        }

Please confirm my findings if you would be that kind.

Thank you in advance.

Best regards,
Adam.


On Fri, Jul 21, 2017 at 1:33 PM, Adam Cieszkiel <[hidden email]> wrote:
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 <[hidden email]> 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 <[hidden email]>:
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:

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 <[hidden email]> 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 <[hidden email]>:
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.

-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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev







_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...