Hacker News new | past | comments | ask | show | jobs | submit login
Credo: Static code analysis for Elixir with a focus on consistency and teaching (github.com/rrrene)
137 points by rrrene on Aug 24, 2016 | hide | past | favorite | 8 comments



Heard a talk about this at the last Elixir meetup in Cologne, looks pretty amazing – especially because of the focus on great explanations.

(Should copy more lints from https://github.com/Manishearth/rust-clippy though! ;))


I just ran this on some old code and it told me a function was too complex (it is!) and could use refactoring, that's some smart linting :-)


The implementation is actually quite simple. It checks that the function length is more than 4 lines of code AND that you are not Robert Martin. If that's the case, it prints "Your function is too complex".


It determines this by computing the cyclomatic complexity of the function. You can think of the cyclomatic complexity as being the number of distinct paths through a function.

The rich support for quoting / unquoting code in Elixir makes it possible to easily compute metrics like this. The implementation in Credo essentially walks through the code, keeping track of how many "branch" operations are encountered.

https://github.com/rrrene/credo/blob/master/lib/credo/check/...


I don't know if it's coincidence, but over in https://www.reddit.com/r/elixir/ today, someone happened to post

"Automated Elixir code review with Github, Credo and Travis CI" https://medium.com/@fazibear/automated-elixir-code-review-wi...


I first happened upon Credo while building a console-based version of 2048 (this was the early stages of learning Elixir). Running Credo on my code for the first time was a delight. It made me instantly wish for similar tools for our non-Elixir code bases at work.

For those venturing into Elixir, Credo is especially useful. While I'm experienced in functional programming, Credo was a great way to learn more idiomatic usage of Elixir.

While Haskell has the fantastic ghc-mod for guided refactoring, Go has gofmt, and Ruby has rubocop among others, I find Credo to be a nice blend of the best features of all these tools. I also appreciate the UI, which groups feedback into 3 visually-distinct categories: Code Readability, Refactoring Opportunities, and Warnings [1]. This makes it makes it easy to prioritize your changes.

If you'd like more background on Credo, The Elixir Fountain [2] recently hosted a nice podcast with the creator of Credo, René Föhring [3].

[1] http://credo-ci.org/ [2] http://elixirfountain.com/ [3] https://soundcloud.com/elixirfountain/elixir-fountain-rene-f...


We have been using this as a build step for our services, it's possible to configure what exactly it will fail you on. Has been very helpful and not only helped us ensure good code, but taught us some good Elixir conventions as well!


This looks great. I've been using dogma and haven't found an inline function disable like this appears to have with @lint. I'll give it a try soon.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: