Skip to content

Commit

Permalink
Modified to properly run reek and added flog and flay
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Beattie committed Aug 8, 2016
1 parent d3f506d commit aa58a75
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 18 deletions.
18 changes: 16 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
PATH
remote: .
specs:
clint_eastwood (0.0.5)
clint_eastwood (0.0.6)
flay (~> 2.8.0)
flog (~> 4.4.0)
rails_best_practices (~> 1.17.0)
reek (~> 4.2.3)
rubocop (~> 0.42.0)
Expand Down Expand Up @@ -31,12 +33,22 @@ GEM
thread_safe (~> 0.3, >= 0.3.1)
equalizer (0.0.11)
erubis (2.7.0)
flay (2.8.0)
erubis (~> 2.7.0)
path_expander (~> 1.0)
ruby_parser (~> 3.0)
sexp_processor (~> 4.0)
flog (4.4.0)
path_expander (~> 1.0)
ruby_parser (~> 3.1, > 3.1.0)
sexp_processor (~> 4.4)
i18n (0.7.0)
ice_nine (0.11.2)
json (2.0.2)
json (1.8.3)
minitest (5.9.0)
parser (2.3.1.2)
ast (~> 2.2)
path_expander (1.0.0)
powerpack (0.1.1)
rails_best_practices (1.17.0)
activesupport
Expand All @@ -60,6 +72,8 @@ GEM
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
ruby_parser (3.8.2)
sexp_processor (~> 4.1)
sexp_processor (4.7.0)
thor (0.19.1)
thread_safe (0.3.5)
Expand Down
2 changes: 2 additions & 0 deletions clint_eastwood.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Gem::Specification.new do |spec|
spec.add_dependency 'rubocop', '~> 0.42.0'
spec.add_dependency 'thor', '~> 0.19.1'
spec.add_dependency 'rails_best_practices', '~> 1.17.0'
spec.add_dependency 'flog', '~> 4.4.0'
spec.add_dependency 'flay', '~> 2.8.0'

spec.executables = ['clint']
end
File renamed without changes.
38 changes: 24 additions & 14 deletions lib/clint_eastwood.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'clint_eastwood/version'
require 'reek'
require 'rails_best_practices'
require_relative 'better_rails_best_practices.rb'

Expand All @@ -18,13 +19,15 @@ class TheEnforcer
# @param disable_rbp [Boolean] If true, this stops rails best practices from running
#
# @returns [TheEnforcer] A new enforcer object
def initialize(path, lint: nil, disable_reek: false, disable_rubocop: false, disable_rbp: false)
def initialize(path, lint: nil, disable_reek: false, disable_rubocop: false, disable_rbp: false, disable_flog: false, disable_flay: false)
gem_path = File.expand_path(File.dirname(__FILE__))
@config_path = File.join(gem_path, '../config')

@disable_rubocop = disable_rubocop
@disable_reek = disable_reek
@disable_rbp = disable_rbp
@disable_flog = disable_flog
@disable_flay = disable_flay

@base_path = path
@lint_paths = lint || %w(app lib config spec)
Expand All @@ -36,8 +39,10 @@ def enforce
reek_result = @disable_reek || reek
rubocop_result = @disable_rubocop || rubocop
rbp_result = @disable_rbp || rails_best_practices
flog_result = @disable_flog || flog
flay_result = @disable_flay || flay

reek_result && rubocop_result && rbp_result
reek_result && rubocop_result && rbp_result && flog_result && flay_result
end

private
Expand All @@ -51,18 +56,9 @@ def locate_config(filename)

# Run reek
def reek
@reek_config = locate_config('reek.yml')

reek_command = []

@lint_paths.each do |path|
reek_command << File.join(@base_path, path)
end

reek_command.concat ['--config', "#{@reek_config}"]

# Reek returns the number of errors, so make sure it's zero
Reek::CLI::Application.new(reek_command).execute == 0
paths = @lint_paths.map { |p| File.join(@base_path, p) }.join(' ')
configuration = locate_config('reek_config.reek')
system "bundle exec reek --config #{configuration} #{paths}"
end

# Run rubocop
Expand All @@ -82,5 +78,19 @@ def rails_best_practices
analyzer.output
analyzer.runner.errors.size == 0
end

# Run flog
def flog
paths = @lint_paths.map { |p| File.join(@base_path, p) }.join(' ')

system "bundle exec flog #{paths}"
end

# Run flay
def flay
paths = @lint_paths.map { |p| File.join(@base_path, p) }.join(' ')

system "bundle exec flay #{paths}"
end
end
end
8 changes: 7 additions & 1 deletion lib/clint_eastwood/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class CLI < Thor
option 'disable-rbp', type: :boolean
option 'disable-rubocop', type: :boolean
option 'disable-reek', type: :boolean
option 'disable-flog', type: :boolean
option 'disable-flay', type: :boolean
option 'warn', type: :boolean

default_task :lint
Expand Down Expand Up @@ -42,13 +44,17 @@ def load_and_configure
disable_rbp = options['disable-rbp'] || false
disable_rubocop = options['disable-rubocop'] || false
disable_reek = options['disable-reek'] || false
disable_flog = options['disable-flog'] || false
disable_flay = options['disable-flay'] || false

ClintEastwood::TheEnforcer.new(
path,
lint: options[:lint],
disable_rbp: disable_rbp,
disable_rubocop: disable_rubocop,
disable_reek: disable_reek
disable_reek: disable_reek,
disable_flog: disable_flog,
disable_flay: disable_flay
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/clint_eastwood/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Clint Eastwood
module ClintEastwood
VERSION = '0.0.6'
VERSION = '0.0.7'
end

0 comments on commit aa58a75

Please sign in to comment.