Class: Tmc::Commands::Lint::Linter

Inherits:
Object
  • Object
show all
Defined in:
lib/tmc/commands/lint/linter.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Linter

Returns a new instance of Linter.



7
8
9
10
11
12
13
# File 'lib/tmc/commands/lint/linter.rb', line 7

def initialize(dir)
  @queue = Array.new
  @project_dir = Array.new
  @config_files = Array.new
  @base_dir = File.expand_path(dir)
  @queue << @base_dir
end

Instance Method Details

#config_file?(file) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/tmc/commands/lint/linter.rb', line 33

def config_file?(file)
  config_file_name = file.split("/")[-1]
  %w(metadata.yml course_options.yml).include? config_file_name
end

#dir_contains_files?(dir, check) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# File 'lib/tmc/commands/lint/linter.rb', line 42

def dir_contains_files?(dir, check)
  dirs = Dir.glob(File.join(dir, '*'))
  dirs.each do |d|
    check.delete d.gsub(dir + "/","")
  end
  check.empty?
end

#lint!Object



29
30
31
# File 'lib/tmc/commands/lint/linter.rb', line 29

def lint!
  recursive_lint(@base_dir)
end

#project_dir?(dir) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/tmc/commands/lint/linter.rb', line 38

def project_dir?(dir)
  dir_contains_files?(dir, %w(src test))
end

#recursive_lint(dir) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tmc/commands/lint/linter.rb', line 15

def recursive_lint(dir)
  puts "Checking #{dir} recursively"
  if project_dir?(dir)
    @project_dir << dir
  end
  Dir.glob(File.join(dir, '*')).each do |d|
    if File.directory? d
      recursive_lint(d)
    elsif config_file?(d)
      @config_files << d
    end
  end
end