terryyin / lizard

A simple code complexity analyser without caring about the C/C++ header files or Java imports, supports most of the popular languages.
Other
1.85k stars 250 forks source link

Exclude code in C/C++ 'assert' from CCN #79

Closed rakhimov closed 8 years ago

rakhimov commented 8 years ago

Consider a simple use case:


assert((conditional_expression) && "More description...");

This line adds 1 + CCN(conditional_expression) if the assertion is counted as a part of a function.

Since assertions are mostly used to check (pre, post)-conditions, to explicitly state assumptions, and to catch programmer errors, they are not expected to be a part of the flow of a function. Moreover, assertions with side-effects is a very bad idea. The function should stay the same if all the assertions are removed (in release mode, for example).

Review on Reviewable

rakhimov commented 8 years ago

The implementation currently breaks the decorator based _state_imp function design. @terryyin , any hints how to integrate this PR gracefully?

terryyin commented 8 years ago

@rakhimov thanks for the pull request. I get your idea:-)

Yeah, I've been refactoring the state-machine to make it more modularised. The new design isn't quite completed yet.

I'm thinking to implement it with an "extension" first for now...

Any way. Let me merge and then show you my idea.

terryyin commented 8 years ago

I created a new extension (lizard_ext/lizardignoreassert.py), which can be used with:

lizard -EIgnoreAssert

https://github.com/terryyin/lizard/commit/5d23f3e08470d76703fe846357566971c357bdd0

rakhimov commented 8 years ago

I like this approach. Thanks for putting extra work to make this PR fit.