I’d like to programmatically report on the complexity (probably cyclomatic complexity would be the correct measure here) of our Erlang code. When I search the web for information, I get links to papers, but no actual tooling.
I know that elvis has a warning about the complexity of functions. Has anyone extracted this code, so it can be used to generate a report?
You might try Next generation code analysis | CodeScene.
Which supports Erlang out of the box and is free for open source projects (assuming you are willing to give it enough privileges on github).
The actual expert on that part of the code (i.e., the developer that did all the research and actually wrote the code for the rule) is Juan, but I don’t think he has a user on this forum.
Nevertheless, @rlipscombe … That part of elvis_core is not the simplest one to extract. IIRC, it depends quite heavily on elvis_code module, and the dependencies katana-code and zipper. I believe that it might be easier to just copy/re-implement the logic with fewer dependencies somewhere else. In fact, if you’re interested in creating a repository just for that… I would be super-happy to help.
So, I see a few choices for you to achieve your goal:
Use the same dependencies and copy the logic from elvis_style.
Rewrite that logic using fewer dependencies (e.g. working directly with erl_syntax instead of using elvis_code and friends).
Rewrite that logic using more modern and versatile AST tools, like the ones @robertoaloi and his friends use on WhatsApp’s erlfmt, elp, etc…
Find Juan on slack, github, etc… and ask him
If you need to analyze code that’s already compiled (i.e., with no macros)… #2 is by far the best option.
If you need to analyze source code… then any of the others might work.
PS: Now I have 2 ideas for Spawnfest projects… and 0 Spawnfests this year.