terryyin / lizard Goto Github PK
View Code? Open in Web Editor NEWA simple code complexity analyser without caring about the C/C++ header files or Java imports, supports most of the popular languages.
License: Other
A simple code complexity analyser without caring about the C/C++ header files or Java imports, supports most of the popular languages.
License: Other
Hfcca has already got a little user base. But the hfcca is hard to pronounce (even I don't know how to pronounce it.)
So better use a different name.
I ran lizard on various projects and got a bunch of pop from empty list errors. Here are some samples
https://www.dropbox.com/s/h43p1b4uozqly59/vgabios.c from qemu
https://www.dropbox.com/s/bpib35xzrq3hik3/arg9.C from gcc
https://www.dropbox.com/s/u5o94tbgn7do6d6/temp_arg_nontype.cpp from llvm
https://www.dropbox.com/s/k49d5ywfav58im0/johab.c from glibc
https://www.dropbox.com/s/slnz4uhxv8mul0h/common.h from tcmalloc
Traceback (most recent call last):
File "/home/cocobo/repository/lizard/lizard", line 6, in <module>
lizard_main(sys.argv)
File "/home/cocobo/repository/lizard/lizard.py", line 944, in lizard_main
printer(result, options)
File "/home/cocobo/repository/lizard/lizard.py", line 821, in print_result
code_infos, option.extensions, scheme)
File "/home/cocobo/repository/lizard/lizard.py", line 789, in print_and_save_modules
for module_info in all_modules:
File "/home/cocobo/repository/lizard/lizard.py", line 644, in __call__
filename, open(filename, 'rU').read())
File "/home/cocobo/repository/lizard/lizard.py", line 656, in analyze_source_code
for _ in tokens:
File "/home/cocobo/repository/lizard/lizard.py", line 631, in token_processor_for_function
reader.state(token)
File "/home/cocobo/repository/lizard/lizard.py", line 323, in state
self._state(token)
File "/home/cocobo/repository/lizard/lizard.py", line 457, in _state_template_in_name
if self.bracket_stack.pop() != "<":
IndexError: pop from empty list
Hi!
I stumbled upon a Python file at work for which lizard calculates a wrong CCN.
# code somewhat simplified
def method1(self):
pass
class Class1(object):
def method2(self):
if True:
pass
if True:
pass
def method1(param):
for x in (1,2):
pass
if True:
pass
if True:
pass
while True:
if True:
pass
for x in (1,2):
True
def method3(self):
if True:
for x in (1,2):
if True:
pass
else:
pass
if True:
pass
else:
pass
def method4(self):
if True:
pass
if True:
pass
if True:
if True
pass
if True:
if True:
pass
if True:
pass
else:
pass
def memoize(obj):
obj.cache = {}
Lizard tells me that method1() ranges from line 1 to line 62 and has a CCN of 20. If I remove the last two lines (memoize()), it works as expected.
Bye, Robert
Btw: lizard is a great tool and I use it every day.
When -t1
Greetings,
I tried to run hfcca.py on python2.6 and it enters an infinite loop, unfortunately i was unable to gather much info on where to start debugging.
Currently, when i try leave the process by CTRL+C, I only get ^C on the screen. Only killing python gives the prompt back.
I get no error message nor anything except the following lines:
NLOC CCN token param function@line@file
Unfortunatelly the machines where i need to run hfcca are debian 6 (python 2.6 by default) and it's out of the question install 2.7.4 on each one.
Thanks for any info
Line comment "#lizard forgives" does not work in Python
After browsing source code - looks like this was not made to work when analyzing Python code
Hi,
please check the example:
int main(){
#define C
#define D
return 0;
}
breaking the lizard. Thank you.
Lizard gets stuck on some python files. Sample
https://www.dropbox.com/s/wjl70kodhb3qtlu/cp037.py
$ ~/repository/lizard/lizard cp037.py
========================================
NLOC CCN token PARAM location
----------------------------------------
^C
Traceback (most recent call last):
File "/home/cocobo/repository/lizard/lizard", line 6, in <module>
lizard_main(sys.argv)
File "/home/cocobo/repository/lizard/lizard.py", line 944, in lizard_main
printer(result, options)
File "/home/cocobo/repository/lizard/lizard.py", line 821, in print_result
code_infos, option.extensions, scheme)
File "/home/cocobo/repository/lizard/lizard.py", line 789, in print_and_save_modules
for module_info in all_modules:
File "/home/cocobo/repository/lizard/lizard.py", line 644, in __call__
filename, open(filename, 'rU').read())
File "/home/cocobo/repository/lizard/lizard.py", line 653, in analyze_source_code
tokens = reader.generate_tokens(code)
File "/home/cocobo/repository/lizard/lizard_ext/python.py", line 23, in generate_tokens
r"|\'\'\'.*?\'\'\'" + r'|\"\"\".*?\"\"\"')
File "/home/cocobo/repository/lizard/lizard.py", line 367, in generate_tokens
return [t for t in _generate_tokens(source_code, addition)]
File "/home/cocobo/repository/lizard/lizard.py", line 352, in _generate_tokens
for token in token_pattern.findall(source_code):
KeyboardInterrupt
Parsing the Linux kernel will crash with an error like this:
Traceback (most recent call last):
File "/home/cocobo/repository/lizard/lizard", line 6, in <module>
lizard_main(sys.argv)
File "/home/cocobo/repository/lizard/lizard.py", line 923, in lizard_main
printer(result, options)
File "/home/cocobo/repository/lizard/lizard.py", line 800, in print_result
code_infos, option.extensions, scheme)
File "/home/cocobo/repository/lizard/lizard.py", line 768, in print_and_save_modules
for module_info in all_modules:
File "/home/cocobo/repository/lizard/lizard.py", line 624, in __call__
filename, open(filename, 'rU').read())
File "/home/cocobo/repository/lizard/lizard.py", line 635, in analyze_source_code
for _ in tokens:
File "/home/cocobo/repository/lizard/lizard.py", line 611, in token_processor_for_function
reader.state(token)
File "/home/cocobo/repository/lizard/lizard.py", line 323, in state
self._state(token)
File "/home/cocobo/repository/lizard/lizard.py", line 437, in _state_template_in_name
if self.bracket_stack.pop() != "<":
IndexError: pop from empty list
The problem is in the file drivers/isdn/hardware/avm/avmcard.h
Here is a small cutout
#define SEND_POLL 0x72 /*
* after load <- RECEIVE_POLL
*/
#define SEND_INIT 0x11 /*
* first message <- RECEIVE_INIT
* int32 NumApplications int32
* NumNCCIs int32 BoardNumber
*/
#define RECEIVE_POLL 0x32 /*
* <- after SEND_POLL
*/
#define RECEIVE_INIT 0x27 /*
* <- after SEND_INIT int32 length
* byte total length b1struct board
* driver revision b1struct card
* type b1struct reserved b1struct
* serial number b1struct driver
* capability b1struct d-channel
* protocol b1struct CAPI-2.0
* profile b1struct capi version
*/
#define RECEIVE_MESSAGE 0x21 /*
* <- after SEND_MESSAGE int32
* AppllID int32 Length capi-data
* ....
*/
static inline void b1_put_word(unsigned int base, unsigned int val)
{
b1_put_byte(base, val & 0xff);
b1_put_byte(base, (val >> 8) & 0xff);
b1_put_byte(base, (val >> 16) & 0xff);
b1_put_byte(base, (val >> 24) & 0xff);
}
The crash seems to be caused by those <-
in the comment sections.
Please add support to trace the current version number and exit when invoked with --version
, e.g.:
$ ./hfcca.py --version
hfcca 1.6.0
Hello,
I am using lizard as part of a larger code checking framework at work and therefore need to parse its output (great tool that works without much fiddling, by the way). In case no problems are found, a "No warning found. Excellent!" message is printed. I believe the more unix-oid way would be to print nothing and just quit quietly (that would also make parsing more straightforward). Do you think you could change this for the default settings or add a "--quiet" option or show it only for "--verbose"?
Thanks and best regards
Hi,
first of all: great tool :) I have found out that is not dealing correctly with 'ugly' ifdefs in C++.
int main(){
if(true){
return 1;
if(false){
return 0;
}
return 1;
}
Could you please look at this ?
Thanks,
Norbert
Lizard helps me write good code on a daily basis.
Had some time this weekend to write a simple tutorial / intro http://thrashing.io/tutorial/551891bccfead697722b05ad
Maybe others can find it helpful. Keep up the great work!
Lizard fails to parse a file when (a form of) the following sequence is encounterd (in regex) [a-zA-Z]<.*>>
So the following sequence is a failing sequence: a<>>
I encounterd the bug when trying to parse a java file with the following line of code:
private static final Map<String, Map<Byte, String>> VAR_NAME = ImmutableMap.<String, Map<Byte, String>> builder()
Although this is really ugly, it is valid java.
I worked around the problem by adding a space between ">>"
C++11 '{}' for uniform initialization
in constructor initialization list
seems to break some assumptions in the code
that the definition starts with the first brace.
Some files cause a maximum recursion depth exceeded error. Sample
https://www.dropbox.com/s/0pg9cwnkdoevy03/fp_and_simd.c from valgrind
Traceback (most recent call last):
File "/home/cocobo/repository/lizard/lizard", line 6, in <module>
lizard_main(sys.argv)
File "/home/cocobo/repository/lizard/lizard.py", line 944, in lizard_main
printer(result, options)
File "/home/cocobo/repository/lizard/lizard.py", line 821, in print_result
code_infos, option.extensions, scheme)
File "/home/cocobo/repository/lizard/lizard.py", line 789, in print_and_save_modules
for module_info in all_modules:
File "/home/cocobo/repository/lizard/lizard.py", line 644, in __call__
filename, open(filename, 'rU').read())
File "/home/cocobo/repository/lizard/lizard.py", line 656, in analyze_source_code
for _ in tokens:
File "/home/cocobo/repository/lizard/lizard.py", line 631, in token_processor_for_function
reader.state(token)
File "/home/cocobo/repository/lizard/lizard.py", line 323, in state
self._state(token)
File "/home/cocobo/repository/lizard/lizard.py", line 528, in _state_old_c_params
self._state(token)
File "/home/cocobo/repository/lizard/lizard.py", line 528, in _state_old_c_params
self._state(token)
...
File "/home/cocobo/repository/lizard/lizard.py", line 528, in _state_old_c_params
self._state(token)
File "/home/cocobo/repository/lizard/lizard.py", line 428, in _state_global
self.context.start_new_function(token)
File "/home/cocobo/repository/lizard/lizard.py", line 216, in start_new_function
self.current_line)
RuntimeError: maximum recursion depth exceeded
Hi,
please check the example:
class Constructor{
int m_timer;
public:
Constructor::Constructor()
:
m_timer(5)
{
int a = 0;
}
};
it doesn't work correctly even when i use -P flag.
Sorry for so strange examples :) and I think your tool is great. Such a code should be avoided.
One may want to know which function has the highest CCN score or the biggest nloc.
The third argument in the following map function repeats indefinitely (both with preprocessor set and unset (true or false)). It worrks if the third argument is removed.
r = map(analyze_source_file, files, itertools.repeat(options.use_preprocessor))
This appends None objects to the filename list and the file open function will fail.
From "map()" Python Documentation:
"If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel. If one iterable is shorter than another it is assumed to be extended with None items."
Error message:
f = open(filename)
TypeError: coercing to Unicode: need string or buffer, NoneType found
Running Ubuntu 12.04
br
Simon
I have the white list for Lizard stored in a different directory than where I run Lizard from (due to build automation).
I would like to see an option to pass a white-list to Lizard via a special command line flag.
Hi,
I am using my forked version of you repo (https://github.com/norkos/lizard.git) which is quite old one. While changing to new version I have met problem in files like:
class Timer{
Timer(int j);
Timer();
};
Timer::Timer(int j)
{
Timer::Timer()
{
for (int i = 0; i < 10; i++)
{
}
std::cout << "Branch";
}
int main(){
return 0;
}
No function is find in this file.
17 0 0.0 0 0 check.cpp
Previously I had:
10 3 32 1 Timer::Timer@[email protected]
1 1 3 0 main@[email protected]
Could you please help me ? Thank you in advance.
btw. I am aware that this code is tricky ...
They comes without ~
I am not getting the right numbers for cyclomatic_complexity for C preprocessing that is done outside of methods (i.e. it is done in the header of the file).
Is this a known issue or is there any fix for this?
Hi,
as c/c++ files we use (c|C|cpp|CPP|CC|cc|mm). Unfortunately it can happen that someone will put inline functions into headers.
Could you extend this pattern for headers file ? Complexity for function declarations already works fine.
The return type is not identified and counted. E.g.
int foo() {
}
the function will be identified as foo()
We are using lizard on objc project (thanks you for this nice tool that improve xcode using a simple script), is there any chances that brand new Swift language will be supported ?
I have no idea on how to add support for it, maybe some indication will help to support it.
Actually, it's path not filename.
You have to type the path instead of only filename.
I think the explanation in readme is too vague
Like lint tools special comments in code should be used as command for suppressing the warning.
Hi,
first of all: great tool :) I have found out that is not dealing correctly with 'ugly' ifdefs in C++.
int main(){
if(true){
return 1;
if(false){
return 0;
}
return 1;
}
Could you please look at this ?
Thanks,
Norbert
Hi
so could lizard support JS?
thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.