Skip to content
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

Clang-formatter results in different formatting? #596

Closed
chrishkchris opened this issue Feb 10, 2020 · 17 comments
Closed

Clang-formatter results in different formatting? #596

chrishkchris opened this issue Feb 10, 2020 · 17 comments

Comments

@chrishkchris
Copy link
Contributor

chrishkchris commented Feb 10, 2020

I used the clang-formatter with VS-code after I alter the tensor.h file, it results in different format with the dev branch.

format
fromat2

The tensor.cc should have re-formatted before in PR #581. So, did I use incorrect setting in clang-formatter?

@dcslin
Copy link
Member

dcslin commented Feb 11, 2020

Hi @chrishkchris , I have tested on windows at my side. Could you please check again your configuration? I hope this guide could help: https://github.com/apache/singa-doc/blob/0efbdbee811901fbcd7ce1f2d057669cb246e4c9/docs-site/docs/contribute-code.md

You might need to install LLVM in windows, and add below lines to VS Code configuration:

"[cpp]": {
    "editor.defaultFormatter": "xaver.clang-format"
},
"cpplint.cpplintPath": "path/to/cpplint",

"editor.formatOnSave": true,
"python.formatting.provider": "yapf",
"python.linting.enabled": true,
"python.linting.lintOnSave": true,

@chrishkchris
Copy link
Contributor Author

I have installed LLVM, and the following VS code configuration:

{
"git.ignoreMissingGitWarning": true,
"python.pythonPath": "C:\ProgramData\Anaconda3",

"[cpp]": {
"editor.defaultFormatter": "xaver.clang-format"
},
"cpplint.cpplintPath": "c:\ProgramData\Anaconda3\Scripts\cpplint.exe",

"editor.formatOnSave": true,
"python.formatting.provider": "yapf",
"python.linting.enabled": true,
"python.linting.lintOnSave": true,
"python.linting.pylintEnabled": true,
"python.linting.pylamaEnabled": false,
"C_Cpp.dimInactiveRegions": false
}

Seems to be strange. I think my setting corresponding to clang-formatter is the same as you?

@chrishkchris
Copy link
Contributor Author

is it due to the different of cpplint we uses?
I was using pip install cpplint

@dcslin
Copy link
Member

dcslin commented Feb 11, 2020

@dcslin
Copy link
Member

dcslin commented Feb 11, 2020

is it due to the different of cpplint we uses?
I was using pip install cpplint

clang-format is independent from cpplint

@chrishkchris
Copy link
Contributor Author

yes, I am using
env

@chrishkchris
Copy link
Contributor Author

version is the same?

@dcslin
Copy link
Member

dcslin commented Feb 11, 2020

version is the same?

extension is auto updated i think

@dcslin
Copy link
Member

dcslin commented Feb 11, 2020

may be for workaround could you try to set 'clang-format.language.cpp.style' this option to google.

@chrishkchris
Copy link
Contributor Author

may be for workaround could you try to set 'clang-format.language.cpp.style' this option to google.

ok, I will try this one

@chrishkchris
Copy link
Contributor Author

may be for workaround could you try to set 'clang-format.language.cpp.style' this option to google.

ok, I will try this one

Yes, this is the solution
need to add in the json
"clang-format.language.cpp.style": "google"

Could you update this to the instruction so everyone can use the same? thanks a lot

@chrishkchris
Copy link
Contributor Author

@shicong I will submit a PR in singa-doc to make this clear in the introduction

@chrishkchris
Copy link
Contributor Author

@shicong I have updated the instruction in apache/singa-doc#4. I will close this issue when everything is okay. Thanks a lot for your advice!

@chrishkchris
Copy link
Contributor Author

In apache/singa-doc#4, I also added also the google style for python yapf :
"python.formatting.yapfArgs" : ["--style" , "{based_on_style: google}" ]
This will be good if VSCode cannot catch the .style.yapf and .clang-format in the project root directory, where I encountered this problem in the remote edit environment (WinSCP)

@dcslin
Copy link
Member

dcslin commented Feb 19, 2020

Hi @chrishkchris FYI
#603

@nudles
Copy link
Member

nudles commented Mar 8, 2020

@chrishkchris is this issue fixed?

@chrishkchris
Copy link
Contributor Author

@nudles I think to solve is to use the same version of formatters as well as the same config for all the contributors, where I addressed in the new doc repo for the instruction of how to do the formatting apache/singa-doc#4
Although my method may not resolve 100% of the problem (some people may use not exactly the same version, e.g. LVMM 9.0 vs 10.0), but should resolve most of the problem.

@XJDKC I remembered that Rulin has even proposed a better method than me (the same docker container with the formatter pre-installed, with the same git hooks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants