Ruby Code Duplication Detection with Flay

Flay is terribly useful, but has terribly usability …

If the repo was not such a mess I’d make PRs to fix it, but tests are not even runnable and PRs to make the Readme readabe got rejected … so I’m not going to bother … a small excerpt from Samson
More config options can be found on it’s homepage
Just wanted to share this useful rake task which found a bunch of duplication and already prevented me from adding new duplication twice 🙂

desc "Analyze for code duplication (large, identical syntax trees) with fuzzy matching."
task :flay do
  require 'flay' # do not require in production
  files = Dir["{config,lib,app/**/*.{rb,erb}"]
  files -= [
    # Things you want to ignore
  ]
  flay = Flay.run([*files, '--mass', '25']) # mass threshold is shown mass / occurrences
  abort "Code duplication found" if flay.report.any?
end
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s