Class: Tmc::Commands::Lint::Linter
- Inherits:
-
Object
- Object
- Tmc::Commands::Lint::Linter
- Defined in:
- lib/tmc/commands/lint/linter.rb
Instance Method Summary collapse
- #config_file?(file) ⇒ Boolean
- #dir_contains_files?(dir, check) ⇒ Boolean
-
#initialize(dir) ⇒ Linter
constructor
A new instance of Linter.
- #lint! ⇒ Object
- #project_dir?(dir) ⇒ Boolean
- #recursive_lint(dir) ⇒ Object
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.(dir) @queue << @base_dir end |
Instance Method Details
#config_file?(file) ⇒ 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
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
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 |