Class: JsonLint::Linter

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonlint/linter.rb

Defined Under Namespace

Classes: KeyOverlapDetector

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLinter

Returns a new instance of Linter.



10
11
12
# File 'lib/jsonlint/linter.rb', line 10

def initialize
  @errors = Hash.new {|h,k| h[k] = [] }
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/jsonlint/linter.rb', line 8

def errors
  @errors
end

Instance Method Details

#check(path) ⇒ Object

Raises:



18
19
20
21
22
# File 'lib/jsonlint/linter.rb', line 18

def check(path)
  raise FileNotFoundError, "#{path} does not exist" unless File.exist?(path)

  check_syntax_valid(path) && check_overlapping_keys(path)
end

#check_all(*files_to_check) ⇒ Object



14
15
16
# File 'lib/jsonlint/linter.rb', line 14

def check_all(*files_to_check)
  files_to_check.flatten.each {|f| check(f) }
end

#display_errorsObject



28
29
30
31
32
33
34
35
# File 'lib/jsonlint/linter.rb', line 28

def display_errors
  errors.each do |path, errors|
    puts path
    errors.each do |err|
      puts "  #{err}"
    end
  end
end

#has_errors?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/jsonlint/linter.rb', line 24

def has_errors?
  ! errors.empty?
end