Hello everyone, I am new in cppcheck
And I want to writing new rule about syntax error in "if" function
but I don't know how to notice space in cppcheck's source code.
My expected result is :
If<space>(<space>doSomeThing<space>)<space>{
<tab>doSomeThing
<tab>}
Sorry my English are not good but please help.
Thank you.
Last edit: Ngo Quang Hai Nguyen 2015-06-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It is not possible to write a Cppcheck rule that warns about spaces/tabs.
Cppcheck was not designed for stylistic checkers. Cppcheck was designed to look for bugs. Therefore, we don't care if spaces/tabs are used.
some options:
* you can try to use some other tool for spaces/tabs checks. I can't recommend any specific tool though.
* this sounds like a pattern that you can write regular expression or maybe a python/perl/etc script, that you execute separately.
* I do recommend that you try using a formatter: astyle/clang-format/etc. The formatting problems are fixed automatically then. In the Cppcheck project we use astyle and I am very happy about it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for your reply. Ngo Quang Hai Nguyen-the person who created this discussion-is my teammate. Few days ago, we have decided to contribute to cppcheck with checking naming convention.
In our point of view, after reading cppcheck-design and debug some function...
After use cppcheck to check .cpp file like:
::cpp
/ #include <iostream>
using namespace std;
int main()
{
int a = 120;
int b = a/0;
cout << b;
return 0;
}
And the result is: [/Test/main2.cpp:8]: (error) Division by zero.
We see you use token to browse all contents of files by each element as syntax-tree. We planed to write a new check class with flow:
-Get line number of element (tok) (Ex: 8 ) -> read the file from that location and take the line code as a string to check naming convention syntax
How we can get line number of tok when it matched with string what we expect?
And one more thing, we created a new class for new naming convention rules but we don't know how to call our check method to check code file as your check class. (See attach file ) .
I want to warn you before you waste your time too much. If you create this checker and it works as you want.. what do you want to do then?
I don't want that this is added in the official Cppcheck. I am very skeptic about adding checkers that warn about indentation. It could be ok if the indentation is truly misleading. But warnings about ugly code is not ok.
If you just want to compile and use this yourself, that is ok.
If you want to publish it, so those who want it can compile and use it, that is ok also.. if you want we can inform about it on the cppcheck website.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I want to check about stylistic, because I think in big source code which have a thousand line of code. If we don't follow some stylistic rule(Ex: Description of function before you declare it, some rules with space/tab for code present) etc., then it's very difficulty for other people, who want to study or maintain...that is my reason for write some checker class to check stylistic base on cppcheck.
My check class was worked by add this file to the Makefile/project like you said. I'm trying to implement my class to check "description of function before the declare of it", I think it important to help other know "What does this function do". Like your cppcheck, before the declare of function your description help me a lot when I try to study about it.
I see tok->function() return 0 if that tok is not function and return eFunction if it is function. But, in this case I just want to identified the declare of function...I want to ignore about function calling or implement...My plan is get line of token which is function declare and check the lines previous is comment (description) or not.
What should I do ?
I appreciated about your warning...My coding skill is too bad...but by the reason I give you in previous...I want to do for myself to improve my coding skill and style of code, and help other who also want to use it. I hope so....
One more thing, sorry for late to reply...because I'm still a student who started to study C++ 4 weeks ago, so I have to spend a long time to read and understand cppcheck. However, I think it's very interesting
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
One more thing, sorry for late to reply...because I'm still a student who started to study C++ 4 weeks ago, so I have to spend a long time to read and understand cppcheck. However, I think it's very interesting
Then I am impressed.. you are learning quickly!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everyone, I am new in cppcheck
And I want to writing new rule about syntax error in "if" function
but I don't know how to notice space in cppcheck's source code.
My expected result is :
If<space>(<space>doSomeThing<space>)<space>{
<tab>doSomeThing
<tab>}
Sorry my English are not good but please help.
Thank you.
Last edit: Ngo Quang Hai Nguyen 2015-06-17
It is not possible to write a Cppcheck rule that warns about spaces/tabs.
Cppcheck was not designed for stylistic checkers. Cppcheck was designed to look for bugs. Therefore, we don't care if spaces/tabs are used.
some options:
* you can try to use some other tool for spaces/tabs checks. I can't recommend any specific tool though.
* this sounds like a pattern that you can write regular expression or maybe a python/perl/etc script, that you execute separately.
* I do recommend that you try using a formatter: astyle/clang-format/etc. The formatting problems are fixed automatically then. In the Cppcheck project we use astyle and I am very happy about it.
Dear sir,
Thanks for your reply. Ngo Quang Hai Nguyen-the person who created this discussion-is my teammate. Few days ago, we have decided to contribute to cppcheck with checking naming convention.
In our point of view, after reading cppcheck-design and debug some function...
After use cppcheck to check .cpp file like:
::cpp
/ #include <iostream>
And the result is: [/Test/main2.cpp:8]: (error) Division by zero.
We see you use token to browse all contents of files by each element as syntax-tree. We planed to write a new check class with flow:
-Get line number of element (tok) (Ex: 8 ) -> read the file from that location and take the line code as a string to check naming convention syntax
How we can get line number of tok when it matched with string what we expect?
And one more thing, we created a new class for new naming convention rules but we don't know how to call our check method to check code file as your check class. (See attach file ) .
Could you give us some advises?
We looking forward to hearing from you.
Thanks you !
Last edit: Vo Quang Chanh 2015-06-19
Something like this:
Your code should work already, as far as I see. How do you compile it? Have you added this file to the Makefile/project?
I want to warn you before you waste your time too much. If you create this checker and it works as you want.. what do you want to do then?
I don't want that this is added in the official Cppcheck. I am very skeptic about adding checkers that warn about indentation. It could be ok if the indentation is truly misleading. But warnings about ugly code is not ok.
If you just want to compile and use this yourself, that is ok.
If you want to publish it, so those who want it can compile and use it, that is ok also.. if you want we can inform about it on the cppcheck website.
I want to check about stylistic, because I think in big source code which have a thousand line of code. If we don't follow some stylistic rule(Ex: Description of function before you declare it, some rules with space/tab for code present) etc., then it's very difficulty for other people, who want to study or maintain...that is my reason for write some checker class to check stylistic base on cppcheck.
My check class was worked by add this file to the Makefile/project like you said. I'm trying to implement my class to check "description of function before the declare of it", I think it important to help other know "What does this function do". Like your cppcheck, before the declare of function your description help me a lot when I try to study about it.
I see tok->function() return 0 if that tok is not function and return eFunction if it is function. But, in this case I just want to identified the declare of function...I want to ignore about function calling or implement...My plan is get line of token which is function declare and check the lines previous is comment (description) or not.
What should I do ?
I appreciated about your warning...My coding skill is too bad...but by the reason I give you in previous...I want to do for myself to improve my coding skill and style of code, and help other who also want to use it. I hope so....
One more thing, sorry for late to reply...because I'm still a student who started to study C++ 4 weeks ago, so I have to spend a long time to read and understand cppcheck. However, I think it's very interesting
I am not sure what you mean..
You are not interested in the function calls right? You just want to see where the functions are "described" and declared.
I think you should not use tok->function() then. Don't loop through tokens at all. Loop through all functions. Something like:
Some documentation for the Function class:
http://cppcheck.sourceforge.net/devinfo/doxyoutput/classFunction.html
Then I am impressed.. you are learning quickly!