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

Extension "Count Nested Control Structures" -ENS fails on most Rust code #341

Open
snowpoke opened this issue Jan 25, 2022 · 0 comments
Open

Comments

@snowpoke
Copy link

The extension fails often enough that the program won't finish in most larger crates.

How to reproduce

git clone https://github.com/rust-lang/cargo
cd cargo
git checkout tags/0.59.0
lizard -ENS

will cause the following output:

Error: Fail to parse file './src/cargo/core/source/source_id.rs'
======================================================
  NLOC    CCN   token  PARAM  length   NS   location  
------------------------------------------------------
       4      1     24      1       6     0 source_id@15-20@./src/cargo/core/source/mod.rs
       9      2    132      1      20     0 supports_checksums@24-43@./src/cargo/core/source/mod.rs
      12      4    121      1      15     0 update@47-61@./src/cargo/core/source/mod.rs
       5      1     64      3      23     0 finish_download@63-85@./src/cargo/core/source/mod.rs
       4      1     20      1       6     0 describe@89-94@./src/cargo/core/source/mod.rs
       7      1     54      2      11     0 add_to_yanked_whitelist@99-109@./src/cargo/core/source/mod.rs
       3      1     18      1       3     0 source_id@113-115@./src/cargo/core/source/mod.rs
       3      1     18      1       3     0 replaced_source_id@118-120@./src/cargo/core/source/mod.rs
       3      1     18      1       3     0 supports_checksums@123-125@./src/cargo/core/source/mod.rs
       3      1     18      1       3     0 requires_precise@128-130@./src/cargo/core/source/mod.rs
       3      1     41      3       3     0 query@133-135@./src/cargo/core/source/mod.rs
       3      1     41      3       3     0 fuzzy_query@138-140@./src/cargo/core/source/mod.rs
       3      1     23      1       3     0 update@143-145@./src/cargo/core/source/mod.rs
       3      1     27      2       3     0 download@148-150@./src/cargo/core/source/mod.rs
       3      1     36      3       3     0 finish_download@152-154@./src/cargo/core/source/mod.rs
       3      1     27      2       3     0 fingerprint@157-159@./src/cargo/core/source/mod.rs
       3      1     27      2       3     0 verify@162-164@./src/cargo/core/source/mod.rs
       3      1     18      1       3     0 describe@166-168@./src/cargo/core/source/mod.rs
       3      1     18      1       3     0 is_replaced@170-172@./src/cargo/core/source/mod.rs
       3      1     26      2       3     0 add_to_yanked_whitelist@174-176@./src/cargo/core/source/mod.rs
       3      1     27      2       3     0 is_yanked@178-180@./src/cargo/core/source/mod.rs
      15      1     34      0      15     0 new@261-275@./src/cargo/core/source/mod.rs
       8      1     36      2       8     0 get_mut@278-285@./src/cargo/core/source/mod.rs
Traceback (most recent call last):
  File "/home/snowpoke/.local/bin/lizard", line 8, in <module>
    sys.exit(main())
  File "/home/snowpoke/.local/lib/python3.9/site-packages/lizard.py", line 1043, in main
    warning_count = printer(result, options, schema, AllResult)
  File "/home/snowpoke/.local/lib/python3.9/site-packages/lizard.py", line 830, in print_result
    result = print_and_save_modules(result, scheme)
  File "/home/snowpoke/.local/lib/python3.9/site-packages/lizard.py", line 797, in print_and_save_modules
    for module_info in all_fileinfos:
  File "/home/snowpoke/.local/lib/python3.9/site-packages/lizard.py", line 545, in __call__
    return self.analyze_source_code(
  File "/home/snowpoke/.local/lib/python3.9/site-packages/lizard.py", line 565, in analyze_source_code
    for _ in reader(tokens, reader):
  File "/home/snowpoke/.local/lib/python3.9/site-packages/lizard_languages/code_reader.py", line 160, in __call__
    for token in tokens:
  File "/home/snowpoke/.local/lib/python3.9/site-packages/lizard_ext/extension_base.py", line 11, in __call__
    self._state(token)
  File "/home/snowpoke/.local/lib/python3.9/site-packages/lizard_ext/lizardns.py", line 104, in _block_ending
    self.structure_piles[-1] = 0
IndexError: list assignment index out of range

When lizard fails on Rust code, it always fails with the same error message as above.

If you need an example of a crate where lizard does not fail, there is https://github.com/ssokolow/rust-cli-boilerplate, where it computes NS values above 0 on most files and does not crash.

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