Class: Chutney::ChutneyLint

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/chutney.rb

Overview

gherkin linter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*files) ⇒ ChutneyLint

Returns a new instance of ChutneyLint.



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/chutney.rb', line 65

def initialize(*files)
  @files = files
  @results = Hash.new { |h, k| h[k] = [] }
  i18n_paths = Dir[File.expand_path(File.join(__dir__, 'config/locales')) + '/*.yml']

  i18n_paths.each do |path|
    next if I18n.load_path.include?(path)

    I18n.load_path << path
    I18n.backend.reload!
  end
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



61
62
63
# File 'lib/chutney.rb', line 61

def files
  @files
end

#resultsObject (readonly)

Returns the value of attribute results.



61
62
63
# File 'lib/chutney.rb', line 61

def results
  @results
end

#verboseObject

Returns the value of attribute verbose.



60
61
62
# File 'lib/chutney.rb', line 60

def verbose
  @verbose
end

Instance Method Details

#analyseObject Also known as: analyze



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/chutney.rb', line 91

def analyse
  if configuration.respond_to?(:using_user_configuration?) &&
     !configuration.quiet? &&
     !configuration.using_user_configuration?
    warn('Chutney: no local configuration found, using gem defaults. Run `chutney -l` to list enabled ' \
         'enabled linters, `chutney --init` to install a local configuration file or `chutney --quiet` ' \
         'to disable this message.')
  end

  files.each do |f|
    lint(f)
  end
  @results
end

#configurationObject



78
79
80
81
82
83
84
85
# File 'lib/chutney.rb', line 78

def configuration
  unless @config
    default_file = [File.expand_path('..', __dir__), '**/config', 'chutney_defaults.yml']
    config_file = Dir.glob(File.join(default_file)).first.freeze
    @config = Configuration.new(config_file)
  end
  @config
end

#configuration=(config) ⇒ Object



87
88
89
# File 'lib/chutney.rb', line 87

def configuration=(config)
  @config = config
end

#lintersObject



109
110
111
# File 'lib/chutney.rb', line 109

def linters
  @linters ||= Linter.descendants.filter { |l| configuration.dig(l.linter_name, 'Enabled') }
end

#linters=(*linters) ⇒ Object



113
114
115
# File 'lib/chutney.rb', line 113

def linters=(*linters)
  @linters = linters
end