Help discover a good refactoring candidates using cyclomatic complexity and frequency of editing files
churn
is a package that helps you identify .ex
files in your project that could be good candidates for refactoring. It examines each Elixir file in the path it is provided and:
- Checks how many commits it has.
- Calculates the cyclomatic complexity.
- Creates a score based on these two values.
The results are displayed in a table:
You can use some of existing flags to precise Churn results
--min-score-to-show (-s shortcut)
Example:
-s 2
--commit-since (-t shortcut)
Example:
-t "2 months ago"
--directories-to-scan (-d shortcut)
Example:
-d lib,test
--file-extensions [-e shortcut]
Example
-e "ex,exs"
--files-to-ignore [-i shortcut]
Example
-i "lib/churn/hello_world.ex"
--config [-c shortcut]
Example
-C foo/bar.exs
The package can be installed by adding churn
to your list of dependencies in mix.exs
and then you need to copy .churn.exs
file into your project.
Update your mix.exs
:
def deps do
[
{:churn, "~> 0.1", only: :dev}
]
end
Copy and configure the .churn.exs
file:
%{
#
# Minimum score to show in a table.
#
min_score_to_show: 0,
#
# Provide a human readable time to use git-log history for churn.
#
commit_since: "1 year ago",
#
# Describes output type for the Churn results
#
output_type: :console,
#
# Where to find a files to analyse and seeking for refactoring candidates.
#
directories_to_scan: ["lib"],
#
# Which extensions should be used for seeking project files.
#
file_extensions: ["ex", "exs"],
#
# Determines files should we ignore and protect from analysis.
#
files_to_ignore: []
}
Docs: https://hexdocs.pm/churn.