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

[CI] Any Linter or Indent checker? #30

Closed
4 tasks done
nrudesu opened this issue May 9, 2021 · 18 comments · Fixed by #31 or #32
Closed
4 tasks done

[CI] Any Linter or Indent checker? #30

nrudesu opened this issue May 9, 2021 · 18 comments · Fixed by #31 or #32
Assignees

Comments

@nrudesu
Copy link
Contributor

nrudesu commented May 9, 2021

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 :

  • Research about linter software
  • Make linter software + add some option alternative
  • Waiting for review or pick external lint software
  • Then add it to CI
@ammarfaizi2
Copy link
Contributor

ammarfaizi2 commented May 9, 2021

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
Copy link
Contributor

ammarfaizi2 commented May 9, 2021

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
Copy link
Contributor Author

nrudesu commented May 9, 2021

@im-fernanda confirm to me want to write it

@nrudesu nrudesu assigned nrudesu and ghost May 9, 2021
@nrudesu
Copy link
Contributor Author

nrudesu commented May 9, 2021

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

@ghost
Copy link

ghost commented May 9, 2021

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

@nrudesu
Copy link
Contributor Author

nrudesu commented May 9, 2021

Okay fine, we will wait about this

@ammarfaizi2
Copy link
Contributor

ammarfaizi2 commented May 9, 2021

@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
Copy link
Member

siarie commented May 9, 2021

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
Copy link
Contributor

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

@ammarfaizi2
Copy link
Contributor

I took a look at this editorconfig/editorconfig.github.com#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
Copy link
Member

siarie commented May 9, 2021

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
Copy link
Contributor Author

nrudesu commented May 9, 2021

@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
Copy link
Contributor

ammarfaizi2 commented May 9, 2021

@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
Copy link

ghost commented May 9, 2021

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
Copy link
Contributor

@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
Copy link
Member

siarie commented May 9, 2021

@im-fernanda isn't flake8 for python?

@ammarfaizi2 check editorconfig-checker for Continuous Integration.

@ghost
Copy link

ghost commented May 9, 2021

@im-fernanda isn't flake8 for python?

linter for all languages not python only

@nrudesu
Copy link
Contributor Author

nrudesu commented May 9, 2021

@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

ammarfaizi2 added a commit that referenced this issue May 9, 2021
This implementation can detect bad trailing whitespace and missing LF
at the EOF. But some tabs indentation checker is still a bit conflict
with Linux kernel coding style when it lines up multiple arguments that
are broken down into multiple lines.

We plan to fix the conflict in the near future, but it is not an urgent
issue at the moment.

Fixes: #30

Suggested-by: Sri Aspari <sriaspari@gmail.com>
Signed-off-by: Ammar Faizi <ammarfaizi2@gmail.com>
irvanmalik48 added a commit that referenced this issue May 9, 2021
(1) Add B_NATIVE build

`B_NATIVE` is a variable for Makefile, if it is set to 1 then the 
compiler will optimize the code with `-mtune=native` and `-march=native`


(2) Implement editorconfig checker workflow

This implementation can detect bad trailing whitespace and missing LF
at the EOF. But some tabs indentation checker is still a bit conflict
with Linux kernel coding style when it lines up multiple arguments that
are broken down into multiple lines.

We plan to fix the conflict in the near future, but it is not an urgent
issue at the moment.

Fixes: #30


Suggested-by: Sri Aspari <sriaspari@gmail.com>
Co-authored-by: Ammar Faizi <ammarfaizi2@gmail.com>
Signed-off-by: Ammar Faizi <ammarfaizi2@gmail.com>
Signed-off-by: Irvan Malik <irvanmalik48@gmail.com>
komori-k added a commit that referenced this issue May 10, 2021
Improve static analysis

  - Make editorconfig-checker checks header files as well (not only C).
  - Implement better indentation checker tool.
  - Clean up missed code styles reported by these shiny tools.

Fixes: #30
Signed-off-by: Ammar Faizi <ammarfaizi2@gmail.com>
Co-authored-by: Ammar Faizi <ammarfaizi2@gmail.com>
Reviewed-by: Komori Kuzuyu <komori.kzy@gmail.com>
Signed-off-by: Komori Kuzuyu <komori.kzy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants