class ClintEastwood::TheEnforcer

Lint enforcer

Public Class Methods

new(path, lint: nil, disable_reek: false, disable_rubocop: false, disable_rbp: false, disable_flog: false, disable_flay: false) click to toggle source

Initializes a new Enforce Object with the desired settings

@param path [String] The base path to lint @param lint [Array<String>] The desired subdirectories to lint (defaults to ['app', 'lib', 'config', 'spec']) @param disable_reek [Boolean] If true, this stops reek from running @param disable_rubocop [Boolean] If true, this stops rubocop from running @param disable_rbp [Boolean] If true, this stops rails best practices from running

@returns [TheEnforcer] A new enforcer object

# File lib/clint_eastwood.rb, line 22
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)
end

Public Instance Methods

enforce() click to toggle source

Runs each desired linting gem with the appropriate settings @returns [Boolean] Whether or not the linters were all successfuls

# File lib/clint_eastwood.rb, line 38
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 && flog_result && flay_result
end

Private Instance Methods

flay() click to toggle source

Run flay

# File lib/clint_eastwood.rb, line 90
def flay
  paths = @lint_paths.map { |p| File.join(@base_path, p) }.join(' ')

  system "bundle exec flay #{paths}"
end
flog() click to toggle source

Run flog

# File lib/clint_eastwood.rb, line 83
def flog
  paths = @lint_paths.map { |p| File.join(@base_path, p) }.join(' ')

  system "bundle exec flog #{paths}"
end
locate_config(filename) click to toggle source
# File lib/clint_eastwood.rb, line 50
def locate_config(filename)
  @user_config = File.join(@base_path, 'config', filename)
  @default_config = File.join(@config_path, filename)

  File.exist?(@user_config) ? @user_config : @default_config
end
rails_best_practices() click to toggle source

Run rails best practices

# File lib/clint_eastwood.rb, line 74
def rails_best_practices
  options = {}
  analyzer = RailsBestPractices::Analyzer.new(@base_path)
  analyzer.analyze
  analyzer.output
  analyzer.runner.errors.size == 0
end
reek() click to toggle source

Run reek

# File lib/clint_eastwood.rb, line 58
def reek
  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
rubocop() click to toggle source

Run rubocop

# File lib/clint_eastwood.rb, line 65
def rubocop
  @rubocop_config = locate_config('rubocop.yml')

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

  system "bundle exec rubocop --rails --config #{@rubocop_config} #{paths}"
end