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

Try-blocks counts every line #21

Closed
AndersSteenNilsen opened this issue May 19, 2022 · 1 comment
Closed

Try-blocks counts every line #21

AndersSteenNilsen opened this issue May 19, 2022 · 1 comment

Comments

@AndersSteenNilsen
Copy link

From https://www.sonarsource.com/docs/CognitiveComplexity.pdf: instance, in the following example, there is no nesting increment for the method itself or for the try because neither structure results in either a structural or a hybrid increment:

also:

However, the if, for, while, and catch structures are all subject to both structural and
nesting increments.

In [1]: get_code_snippet_compexity('''
    ...: def my_method():
    ...:   try:
    ...:     print('hello')
    ...:     print('hello')
    ...:   except Exception as e:    # +1 nesting = 0
    ...:       return 0
    ...:         ''')
Out[1]: 2

In [2]: get_code_snippet_compexity('''
    ...: def my_method():
    ...:   try:
    ...:     print('hello')
    ...:     print('hello')
    ...:     print('hello')
    ...:   except Exception as e:    # +1 nesting = 0
    ...:       return 0
    ...:         ''')
Out[2]: 3

All these should be 1...?

@AndersSteenNilsen
Copy link
Author

OOoops, deplicate of #20

@AndersSteenNilsen AndersSteenNilsen closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant