Module: Syntaxer

Defined in:
lib/syntaxer/reader.rb,
lib/syntaxer.rb,
lib/syntaxer/writer.rb,
lib/syntaxer/runner.rb,
lib/syntaxer/wizzard.rb,
lib/syntaxer/checker.rb,
lib/syntaxer/printer.rb,
lib/syntaxer/railtie.rb,
lib/syntaxer/repository.rb,
lib/syntaxer/file_status.rb,
lib/syntaxer/progress_bar.rb,
lib/syntaxer/language_definition.rb

Overview

Author:

Defined Under Namespace

Modules: Reader, Runners Classes: Checker, FileStatus, Git, GitRepositoryError, LanguageDefinition, LanguageDefinitionException, LanguageRules, PlainChecker, Printer, ProgressBar, Railtie, RepoChecker, Repository, RepositoryError, Runner, Svn, SvnRepositoryError, Wizzard, Writer

Constant Summary

DEFAULT_FILES_MASK =
"**/*"
SYNTAXER_RULES_FILE =
File.join(File.dirname(__FILE__), "..", "syntaxer_rules.dist.rb")
SYNTAXER_CONFIG_FILE_NAME =
"syntaxer.rb"

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Class Attribute Details

+ (Object) hook (readonly)

Returns the value of attribute hook



29
30
31
# File 'lib/syntaxer.rb', line 29

def hook
  @hook
end

+ (Object) jslint (readonly)

Returns the value of attribute jslint



29
30
31
# File 'lib/syntaxer.rb', line 29

def jslint
  @jslint
end

+ (Object) reader (readonly)

Returns the value of attribute reader



29
30
31
# File 'lib/syntaxer.rb', line 29

def reader
  @reader
end

+ (Object) repository (readonly)

Returns the value of attribute repository



29
30
31
# File 'lib/syntaxer.rb', line 29

def repository
  @repository
end

+ (Object) results (readonly)

Returns the value of attribute results



29
30
31
# File 'lib/syntaxer.rb', line 29

def results
  @results
end

+ (Object) root_path (readonly)

Returns the value of attribute root_path



29
30
31
# File 'lib/syntaxer.rb', line 29

def root_path
  @root_path
end

+ (Object) warnings (readonly)

Returns the value of attribute warnings



29
30
31
# File 'lib/syntaxer.rb', line 29

def warnings
  @warnings
end

Class Method Details

+ (Boolean) check_syntax(options = {})

Main method to be used for syntax checking.

Parameters:

  • options (Hash) (defaults to: {})

    the options to perform syntax checking

Options Hash (options):

  • :root_path (String) — default: Dir.getwd

    The starting point, which will be used for all relative path's

  • :languages (String) — default: :all

    Type of languages to be used in checking

  • :repository (String) — default: git|svn

    Type of repository

  • :config_file(SYNTAXER_RULES_FILE) (String)

    File with syntax rules and language definitions

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/syntaxer.rb', line 45

def check_syntax(options = {})
  @root_path = options[:root_path]
  @warnings = options[:warnings]
  @hook = options[:hook]
  @jslint = options[:jslint]
  Printer.quite = options[:quite] || false
  Printer.loud = options[:loud] || false
  
  @reader = Reader::DSLReader.load(options[:config_file])

  if @jslint # if jslint option passed set from command line we have to add new rule with indicated dir
    rule = LanguageDefinition.new(:javascript, %w{js}, nil, [@jslint+"*", @jslint+"**/*"], nil, nil, nil, true, true)
    rule.exec_rule = Runner.javascript.call
    @reader.add_rule rule
  end

  @repository = Repository.factory(@root_path, options[:repository]) if options[:repository]

  $stdmyout = StringIO.new
  checker = Checker.process(self)
  Printer.print_result checker

  exit(1) unless checker.error_files.empty? && $stdmyout.string.empty?
end

+ (Object) configure {|_self| ... }

Yields:

  • (_self)

Yield Parameters:

  • _self (Syntaxer)

    the object that the method was called on



31
32
33
# File 'lib/syntaxer.rb', line 31

def configure
  yield(self) if block_given?
end

+ (Nil) make_hook(options)

This method generate and put hook to .git/hooks

Returns:

  • (Nil)

Raises:

  • ArgumentError if no repository indicated

  • ArgumentError if SVN is indicated. SVN is not supported yet.

See Also:

  • #check_syntax


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/syntaxer.rb', line 78

def make_hook(options)
  @root_path = options[:root_path]
  raise ArgumentError, 'Indicate repository type' unless options.include?(:repository)
  raise ArgumentError, "SVN is temporarily not supported" if options[:repository].to_sym == :svn
  
  repo = Repository.factory(@root_path, options[:repository])
  hook_file = "#{@root_path}/.git/hooks/pre-commit"
  hook_string = "syntaxer -r git --hook"
  hook_string += " -c config/syntaxer.rb" if options[:rails]
  hook_string += " -c #{options[:config_file]}" unless options[:config_file].nil?
  
  File.open(hook_file, 'w') do |f|
    f.puts hook_string
  end
  File.chmod(0755, hook_file)
rescue Exception => e
  puts e.message.color(:red)
  raise e
end

+ (Object) wizzard(options)



98
99
100
# File 'lib/syntaxer.rb', line 98

def wizzard(options)
  Wizzard.start
end