casbin / casbin-cpp

An authorization library that supports access control models like ACL, RBAC, ABAC in C/C++
https://casbin.org
Apache License 2.0
222 stars 61 forks source link

Setup a code style linter #49

Closed hsluoyz closed 4 years ago

hsluoyz commented 4 years ago

I can usually find a lot of code style issues in our code like this PR: https://github.com/casbin/casbin-cpp/pull/48. I don't want to review and fix them one by one. We need a systematic and automatic way to solve it.

How does C/C++ solve the code linting issue? I want a solution better working for multiple OSes, multiple IDEs. I only know something like EditorConfig: https://editorconfig.org/

What tool does C/C++ project often use for code linter?

hsluoyz commented 4 years ago

Any suggestions? @xcaptain @nodece @GopherJ @divy9881 @zipochan

xcaptain commented 4 years ago

I think clang-format is good, maybe we can give it a try

hsluoyz commented 4 years ago

@xcaptain not bad!

divy9881 commented 4 years ago

https://github.com/marketplace/actions/ros-style-guide-c-format Its a github-action for automatic C++ code-formatter according to clang format

divy9881 commented 4 years ago

some other github-actions: https://github.com/marketplace/actions/c-code-linter-clang-tidy-and-cppcheck https://github.com/marketplace/actions/c-c-code-linter-clang-tidy-clang-format-and-cppcheck

Let me know, which one, I will set it up.

hsluoyz commented 4 years ago

@xcaptain @divy9881

I have several criteria:

  1. Works for all OSes: Windows, Linux, (better have macOS)
  2. Works for IDEs: Jetbrains CLion, Visual Studio, (better have VSCode)

Which ones fulfill these?

divy9881 commented 4 years ago

I have several criteria:

Works for all OSes: Windows, Linux, (better have macOS) Works for IDEs: Jetbrains CLion, Visual Studio, (better have VSCode) Which ones fulfill these?

Sorry, I didn't understand your question, the above links are the links to the github-actions, it gets triggered after all other build-tasks are successful and after may be merging.

hsluoyz commented 4 years ago

The linter I mean here is that when I type in code, the IDE will auto format my code. Usually IDE has its built-in linter or kind of similar things. But I want a standardized tool to work for all IDEs.

Your server-side linter hooks are also useful. We can have both. I don't give up client-side IDE linter because I still want to see how my code is formatted in my eyes. I don't want to give the control to the machine.

divy9881 commented 4 years ago

Then, I think we can set-up just git-hook for code linting using npm and clang-format as node-package, like node-casbin.

hsluoyz commented 4 years ago

Will npm package work for CLion?

divy9881 commented 4 years ago

Will npm package work for CLion?

To setup a git-hook a contributor will have to install the npm packages from command line tool and after he adds the changed files to the staging area through git add the code formatting triggers automatically.

hsluoyz commented 4 years ago

Then I think maybe a tool like https://editorconfig.org/ is better. It's just a config file inside the repo (like Travis CI config). And the IDE can automatically recognize it and apply the code format checking.

GopherJ commented 4 years ago

IDE is not related to this repo I believe,developers need to use their own tool.

But it's true that we need some lint actions to?validate PR code style,is there already an action for clang-format? in vim I use clang,clang-format

code can be formstted onced saved

This repo can also have custom style lint config but it's normally not necessary

ZipoChan commented 4 years ago

Add the clangformat for Visual Studio.

ZipoChan commented 4 years ago

@hsluoyz Have added clang-format,which can be used in visual studio.

hsluoyz commented 4 years ago

Fixed in: https://github.com/casbin/casbin-cpp/issues/49