Module: Codeqa

Defined in:
lib/codeqa/utils/erb_sanitizer.rb,
lib/codeqa.rb,
lib/codeqa/runner.rb,
lib/codeqa/checker.rb,
lib/codeqa/version.rb,
lib/codeqa/sourcefile.rb,
lib/codeqa/configuration.rb,
lib/codeqa/runner_decorator.rb,
lib/codeqa/checkers/check_erb.rb,
lib/codeqa/checkers/check_pry.rb,
lib/codeqa/utils/check_errors.rb,
lib/codeqa/checkers/check_yard.rb,
lib/codeqa/checkers/check_linkto.rb,
lib/codeqa/checkers/rubocop_full.rb,
lib/codeqa/checkers/rubocop_lint.rb,
lib/codeqa/checkers/check_conflict.rb,
lib/codeqa/checkers/check_erb_html.rb,
lib/codeqa/checkers/html_validator.rb,
lib/codeqa/checkers/pattern_checker.rb,
lib/codeqa/checkers/check_rspec_focus.rb,
lib/codeqa/checkers/check_ruby_syntax.rb,
lib/codeqa/checkers/rubocop_formatter.rb,
lib/codeqa/checkers/check_strange_chars.rb,
lib/codeqa/checkers/check_utf8_encoding.rb

Overview

Defined Under Namespace

Modules: Checkers Classes: CheckErrors, Checker, Configuration, ErbSanitizer, Runner, RunnerDecorator, Sourcefile

Constant Summary collapse

CODEQA_HOME =
Pathname.new(File.join(File.dirname(__FILE__), '..')).realpath
VERSION =
'0.4.2'

Class Method Summary collapse

Class Method Details

.check(filename, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/codeqa.rb', line 32

def check(filename, options={})
  options = { :silent_success => false, :silent => false }.merge(options)
  runner = runner(filename)
  if runner.success?
    $stdout.puts(runner.display_result) unless options[:silent_success] || options[:silent]
    true
  else
    $stderr.puts runner.display_result unless options[:silent]
    false
  end
end

.configurationObject



81
82
83
# File 'lib/codeqa/configuration.rb', line 81

def configuration
  @configuration ||=  Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



85
86
87
88
# File 'lib/codeqa/configuration.rb', line 85

def configure
  yield(configuration) if block_given?
  Codeqa.register_checkers
end

.install(root = '.') ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/codeqa.rb', line 10

def install(root='.')
  require 'fileutils'
  git_root = Pathname.new "#{root}/.git"
  if File.exist?(git_root)
    pre_commit_path = git_root.join 'hooks', 'pre-commit'
    if File.exist?(pre_commit_path)
      # $stdout.puts 'moving away the old pre-commit hook -> pre-commit.bkp'
      FileUtils.mv(pre_commit_path,
                   git_root.join('hooks', 'pre-commit.bkp'),
                   :force => true)
    end
    pre_commit_template_path = Codeqa.root.join('lib', 'templates', 'pre-commit')
    # $stdout.puts 'placing new pre-commit hook'
    FileUtils.cp(pre_commit_template_path, pre_commit_path)
    FileUtils.chmod('+x', pre_commit_path)
    true
  else
    # $stderr.puts "#{root} is not in a git root"
    false
  end
end

.register_checkersObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/codeqa.rb', line 49

def register_checkers
  Codeqa::Runner.reset_checkers
  configuration.enabled_checker.each do |checker|
    begin
      checker_klass = Codeqa::Checkers.const_get(checker)
      next unless checker_klass.available?
      Codeqa::Runner.register_checker checker_klass
    rescue
      "checker <#{checker}> not known"
    end
  end
end

.rootObject



6
7
8
# File 'lib/codeqa.rb', line 6

def root
  CODEQA_HOME
end

.runner(filename) ⇒ Object



44
45
46
47
# File 'lib/codeqa.rb', line 44

def runner(filename)
  sourcefile = Codeqa::Sourcefile.new(filename)
  Codeqa::Runner.run(sourcefile)
end