GNUWeeb / GNUWeebBot

High-performance bot Telegram, running on Linux environment, written in C.
GNU General Public License v2.0
13 stars 8 forks source link

[CI] Any Linter or Indent checker? #30

Closed nrudesu closed 3 years ago

nrudesu commented 3 years ago

One of contributor often forget about indentations rule.

So, I think we need CI for this project, but new problem occur. We need pick linter software is suitable and set it to our configuration or just make own indent checker

TODO :

ammarfaizi2 commented 3 years ago

I think we can write something up. It shouldn't be too hard for indentation checking.

Static analyzer with simple PHP or Python or Perl script can do this.

ammarfaizi2 commented 3 years ago

Just for fun, I did something really quick in awk:

{ state = 1 }
/^\x20+/ { state = 0 }
{ if (state == 0) print "Wrong indentation character"; }

Which is incomprehensible line noise. Also it doesn't show the line number where the thing goes wrong.

That thing is excessively stupid, in other words, but hey, it's good to see "ok, what does that tell us". We have wrong indentation character.

nrudesu commented 3 years ago

@Im-Fernanda confirm to me want to write it

nrudesu commented 3 years ago

So @Im-Fernanda, give us some detail about this. Do you need another repository, or this repository is enough for you?

ghost commented 3 years ago

I will tell you the details later when this actually works because I'm not completely sure if it can be used normally.

nrudesu commented 3 years ago

Okay fine, we will wait about this

ammarfaizi2 commented 3 years ago

@nrudesu

Do you need another repository, or this repository is enough for you?

Create another branch on this repository is okay? I can start to initialize and wire this part up if you want to.

siarie commented 3 years ago

Ok, so the most problem is about indentation? Have you ever heard about editorconfig. It's not a linter anyway.

The website says:

EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs.

I use it a lot and it's enough to solve the problem (especially for indentation).

Having a linter will make it much better. But if you want a quick solution, maybe editorconfig can be consideration.

ammarfaizi2 commented 3 years ago

@siarie how would you integrate editorconfig with CI (GitHub Workflow)?

ammarfaizi2 commented 3 years ago

I took a look at this https://github.com/editorconfig/editorconfig.github.com/pull/48 It seems to be GitHub web editor rather than static analysis in CI which will yield a failure message when wrong indentation is found.

siarie commented 3 years ago

how would you integrate editorconfig with CI (GitHub Workflow)?

I don't know about CI stuff. I just use editorconfig on my editor/IDE.

If you looking for static analysis check this out.

Another reference:

nrudesu commented 3 years ago

@Im-Fernanda confirm to me want to write it

@Im-Fernanda changes the mind, he want to use existing lint program, so I edited the issue descriptions and @Im-Fernanda please tell us about ur idea

Create another branch on this repository is okay? I can start to initialize and wire this part up if you want to.

Okay

cpplint?

hmmm, thinking...

ammarfaizi2 commented 3 years ago

@siarie looks good to me. I am playing around with cpplint right now.

ammarfaizi2@integral:~/project/now/GNUWeebBot$ for i in $(find src/gwbot -name '*.c'); do python3 ~/project/now/cpplint/cpplint.py  --filter=-whitespace/tab,-whitespace/braces,+whitespace/indent,+whitespace/line_length $i; done;
Click me!
ammarfaizi2@integral:~/project/now/GNUWeebBot$ for i in $(find src/gwbot -name '*.c'); do python3 ~/project/now/cpplint/cpplint.py  --filter=-whitespace/tab,-whitespace/braces,+whitespace/indent,+whitespace/line_length $i; done;
src/gwbot/db.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
Done processing src/gwbot/db.c
Total errors found: 1
src/gwbot/argv.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
Done processing src/gwbot/argv.c
Total errors found: 1
src/gwbot/print.c:77:  Consider using localtime_r(...) instead of localtime(...) for improved thread safety.  [runtime/threadsafe_fn] [2]
src/gwbot/print.c:78:  Consider using asctime_r(...) instead of asctime(...) for improved thread safety.  [runtime/threadsafe_fn] [2]
Done processing src/gwbot/print.c
Total errors found: 2
src/gwbot/gwbot.c:255:  Line ends in whitespace.  Consider deleting these extra spaces.  [whitespace/end_of_line] [4]
src/gwbot/gwbot.c:730:  Lines should be <= 80 characters long  [whitespace/line_length] [2]
src/gwbot/gwbot.c:733:  Redundant blank line at the start of a code block should be deleted.  [whitespace/blank_line] [2]
src/gwbot/gwbot.c:1084:  Redundant blank line at the start of a code block should be deleted.  [whitespace/blank_line] [2]
src/gwbot/gwbot.c:1231:  Redundant blank line at the end of a code block should be deleted.  [whitespace/blank_line] [3]
Done processing src/gwbot/gwbot.c
Total errors found: 5
Done processing src/gwbot/lib/shell.c
src/gwbot/lib/tg_event.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
src/gwbot/lib/tg_event.c:23:  Using C-style cast.  Use static_cast(...) instead  [readability/casting] [4]
src/gwbot/lib/tg_event.c:108:  Line ends in whitespace.  Consider deleting these extra spaces.  [whitespace/end_of_line] [4]
src/gwbot/lib/tg_event.c:112:  Line ends in whitespace.  Consider deleting these extra spaces.  [whitespace/end_of_line] [4]
src/gwbot/lib/tg_event.c:175:  Line ends in whitespace.  Consider deleting these extra spaces.  [whitespace/end_of_line] [4]
Done processing src/gwbot/lib/tg_event.c
Total errors found: 5
src/gwbot/lib/tg_api/pin_chat_message.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
Done processing src/gwbot/lib/tg_api/pin_chat_message.c
Total errors found: 1
src/gwbot/lib/tg_api/kick_chat_member.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
Done processing src/gwbot/lib/tg_api/kick_chat_member.c
Total errors found: 1
src/gwbot/lib/tg_api/get_chat_administrators.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
Done processing src/gwbot/lib/tg_api/get_chat_administrators.c
Total errors found: 1
src/gwbot/lib/tg_api/unpin_chat_message.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
Done processing src/gwbot/lib/tg_api/unpin_chat_message.c
Total errors found: 1
src/gwbot/lib/tg_api/unban_chat_member.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
Done processing src/gwbot/lib/tg_api/unban_chat_member.c
Total errors found: 1
src/gwbot/lib/tg_api/send_message.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
src/gwbot/lib/tg_api/send_message.c:42:  Almost always, snprintf is better than strcpy  [runtime/printf] [4]
Done processing src/gwbot/lib/tg_api/send_message.c
Total errors found: 2
src/gwbot/lib/tg_api/restrict_chat_member.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
Done processing src/gwbot/lib/tg_api/restrict_chat_member.c
Total errors found: 1
src/gwbot/lib/tg_api.old.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
Done processing src/gwbot/lib/tg_api.old.c
Total errors found: 1
src/gwbot/lib/tg_api.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
src/gwbot/lib/tg_api.c:143:  Line ends in whitespace.  Consider deleting these extra spaces.  [whitespace/end_of_line] [4]
src/gwbot/lib/tg_api.c:186:  Lines should be <= 80 characters long  [whitespace/line_length] [2]
Done processing src/gwbot/lib/tg_api.c
Total errors found: 3
src/gwbot/lib/arena.c:42:  Using C-style cast.  Use reinterpret_cast(...) instead  [readability/casting] [4]
Done processing src/gwbot/lib/arena.c
Total errors found: 1
src/gwbot/lib/string.c:34:  Using C-style cast.  Use reinterpret_cast(...) instead  [readability/casting] [4]
src/gwbot/lib/string.c:68:  Empty loop bodies should use {} or continue  [whitespace/empty_loop_body] [5]
Done processing src/gwbot/lib/string.c
Total errors found: 2
Done processing src/gwbot/event_logger.c
src/gwbot/main.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
Done processing src/gwbot/main.c
Total errors found: 1
src/gwbot/help.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
Done processing src/gwbot/help.c
Total errors found: 1
src/gwbot/modules/003_admin/admin.c:17:  Include the directory when naming .h files  [build/include_subdir] [4]
src/gwbot/modules/003_admin/admin.c:108:  Weird number of spaces at line-start.  Are you using a 2-space indent?  [whitespace/indent] [3]
src/gwbot/modules/003_admin/admin.c:117:  Line ends in whitespace.  Consider deleting these extra spaces.  [whitespace/end_of_line] [4]
src/gwbot/modules/003_admin/admin.c:177:  If you can, use sizeof(reply_text) instead of 128 as the 2nd arg to snprintf.  [runtime/printf] [3]
src/gwbot/modules/003_admin/admin.c:186:  If you can, use sizeof(reply_text) instead of 128 as the 2nd arg to snprintf.  [runtime/printf] [3]
src/gwbot/modules/003_admin/admin.c:195:  If you can, use sizeof(reply_text) instead of 128 as the 2nd arg to snprintf.  [runtime/printf] [3]
src/gwbot/modules/003_admin/admin.c:203:  If you can, use sizeof(reply_text) instead of 128 as the 2nd arg to snprintf.  [runtime/printf] [3]
src/gwbot/modules/003_admin/admin.c:548:  Line ends in whitespace.  Consider deleting these extra spaces.  [whitespace/end_of_line] [4]
src/gwbot/modules/003_admin/admin.c:621:  Lines should be <= 80 characters long  [whitespace/line_length] [2]
src/gwbot/modules/003_admin/admin.c:668:  Lines should be <= 80 characters long  [whitespace/line_length] [2]
src/gwbot/modules/003_admin/admin.c:703:  Redundant blank line at the start of a code block should be deleted.  [whitespace/blank_line] [2]
src/gwbot/modules/003_admin/admin.c:871:  Redundant blank line at the start of a code block should be deleted.  [whitespace/blank_line] [2]
src/gwbot/modules/003_admin/admin.c:909:  Redundant blank line at the start of a code block should be deleted.  [whitespace/blank_line] [2]
src/gwbot/modules/003_admin/admin.c:931:  Redundant blank line at the start of a code block should be deleted.  [whitespace/blank_line] [2]
src/gwbot/modules/003_admin/admin.c:933:  Redundant blank line at the start of a code block should be deleted.  [whitespace/blank_line] [2]
Done processing src/gwbot/modules/003_admin/admin.c
Total errors found: 15
src/gwbot/modules/000_debug/debug.c:19:  Include the directory when naming .h files  [build/include_subdir] [4]
src/gwbot/modules/000_debug/debug.c:47:  Line ends in whitespace.  Consider deleting these extra spaces.  [whitespace/end_of_line] [4]
src/gwbot/modules/000_debug/debug.c:95:  Using C-style cast.  Use reinterpret_cast(...) instead  [readability/casting] [4]
Done processing src/gwbot/modules/000_debug/debug.c
Total errors found: 3
src/gwbot/modules/002_translate/translate.c:18:  Include the directory when naming .h files  [build/include_subdir] [4]
src/gwbot/modules/002_translate/translate.c:318:  Lines should be <= 80 characters long  [whitespace/line_length] [2]
src/gwbot/modules/002_translate/translate.c:397:  If an else has a brace on one side, it should have it on both  [readability/braces] [5]
Done processing src/gwbot/modules/002_translate/translate.c
Total errors found: 3
src/gwbot/modules/001_standard/standard.c:18:  Include the directory when naming .h files  [build/include_subdir] [4]
Done processing src/gwbot/modules/001_standard/standard.c
Total errors found: 1
src/gwbot/routes.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
Done processing src/gwbot/routes.c
Total errors found: 1
src/gwbot/event_handler.c:0:  No copyright message found.  You should have a line: "Copyright [year] "  [legal/copyright] [5]
src/gwbot/event_handler.c:7:  Include the directory when naming .h files  [build/include_subdir] [4]
Done processing src/gwbot/event_handler.c
Total errors found: 2
src/gwbot/config.c:44:  If an else has a brace on one side, it should have it on both  [readability/braces] [5]
src/gwbot/config.c:47:  If an else has a brace on one side, it should have it on both  [readability/braces] [5]
src/gwbot/config.c:51:  If an else has a brace on one side, it should have it on both  [readability/braces] [5]
src/gwbot/config.c:54:  If an else has a brace on one side, it should have it on both  [readability/braces] [5]
src/gwbot/config.c:57:  If an else has a brace on one side, it should have it on both  [readability/braces] [5]
src/gwbot/config.c:60:  If an else has a brace on one side, it should have it on both  [readability/braces] [5]
src/gwbot/config.c:63:  If an else has a brace on one side, it should have it on both  [readability/braces] [5]
src/gwbot/config.c:66:  If an else has a brace on one side, it should have it on both  [readability/braces] [5]
src/gwbot/config.c:72:  If an else has a brace on one side, it should have it on both  [readability/braces] [5]
src/gwbot/config.c:76:  If an else has a brace on one side, it should have it on both  [readability/braces] [5]
src/gwbot/config.c:79:  If an else has a brace on one side, it should have it on both  [readability/braces] [5]
src/gwbot/config.c:85:  If an else has a brace on one side, it should have it on both  [readability/braces] [5]
Done processing src/gwbot/config.c
Total errors found: 12
ammarfaizi2@integral:~/project/now/GNUWeebBot$ 
ghost commented 3 years ago

Previously i had an idea how to use flake8 but i thought it was too bloat because he needs a lot of pre requisites dependencies, but I think it is easier to integrate with CI.

reference https://flake8.pycqa.org/en/latest/

ammarfaizi2 commented 3 years ago

@Im-Fernanda can you try flake8 to examine current codebase and send me the output? Would like to see how is the output compared to the cpplint.

siarie commented 3 years ago

@Im-Fernanda isn't flake8 for python?

@ammarfaizi2 check editorconfig-checker for Continuous Integration.

ghost commented 3 years ago

@Im-Fernanda isn't flake8 for python?

linter for all languages not python only

nrudesu commented 3 years ago

@Im-Fernanda changes the mind, he want to use existing lint program, so I edited the issue descriptions and @Im-Fernanda please tell us about ur idea

seriously, @Im-Fernanda makes me confuse, lmao. but finally he write his own linter. I already fork it.

https://github.com/GNUWeeb/linter-C