Class: GherkinLint::GherkinLint
- Inherits:
-
Object
- Object
- GherkinLint::GherkinLint
- Defined in:
- lib/gherkin_lint.rb
Overview
gherkin linter
Constant Summary collapse
- DEFAULT_CONFIG =
Dir.glob(File.join(default_file)).first.freeze
- LINTER =
Linter.descendants
Instance Attribute Summary collapse
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #analyze(file) ⇒ Object
- #disable(disabled_linters) ⇒ Object
-
#disable_all ⇒ Object
Testing feature.
- #disable_tags ⇒ Object
- #enable(enabled_linters) ⇒ Object
- #enabled(linter_name, value) ⇒ Object
- #evaluate_members(linter) ⇒ Object
-
#initialize(path = nil) ⇒ GherkinLint
constructor
A new instance of GherkinLint.
- #parse(file) ⇒ Object
- #print(issues) ⇒ Object
- #report ⇒ Object
- #set_linter ⇒ Object
- #to_json(input) ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ GherkinLint
Returns a new instance of GherkinLint.
45 46 47 48 49 50 |
# File 'lib/gherkin_lint.rb', line 45 def initialize(path = nil) @files = {} @linter = [] @config = Configuration.new path || DEFAULT_CONFIG @verbose = false end |
Instance Attribute Details
#verbose ⇒ Object
Returns the value of attribute verbose.
40 41 42 |
# File 'lib/gherkin_lint.rb', line 40 def verbose @verbose end |
Instance Method Details
#analyze(file) ⇒ Object
94 95 96 |
# File 'lib/gherkin_lint.rb', line 94 def analyze(file) @files[file] = parse file end |
#disable(disabled_linters) ⇒ Object
62 63 64 65 66 |
# File 'lib/gherkin_lint.rb', line 62 def disable(disabled_linters) disabled_linters.each do |linter| enabled linter, false end end |
#disable_all ⇒ Object
Testing feature
69 70 71 72 73 |
# File 'lib/gherkin_lint.rb', line 69 def disable_all @config.config.each do |member| @config.config[member[0]]['Enabled'] = false end end |
#disable_tags ⇒ Object
113 114 115 |
# File 'lib/gherkin_lint.rb', line 113 def LINTER.map { |lint| "disable#{lint.new.class.name.split('::').last}" } end |
#enable(enabled_linters) ⇒ Object
56 57 58 59 60 |
# File 'lib/gherkin_lint.rb', line 56 def enable(enabled_linters) enabled_linters.each do |linter| enabled linter, true end end |
#enabled(linter_name, value) ⇒ Object
52 53 54 |
# File 'lib/gherkin_lint.rb', line 52 def enabled(linter_name, value) @config.config[linter_name]['Enabled'] = value if @config.config.key? linter_name end |
#evaluate_members(linter) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/gherkin_lint.rb', line 85 def evaluate_members(linter) @config.config[linter.class.name.split('::').last].each do |member, value| next if member.downcase.casecmp('enabled').zero? member = member.downcase.to_sym raise 'Member not found! Check the YAML' unless linter.respond_to? member linter.public_send(member, value) end end |
#parse(file) ⇒ Object
98 99 100 |
# File 'lib/gherkin_lint.rb', line 98 def parse(file) to_json File.read(file) end |
#print(issues) ⇒ Object
124 125 126 127 |
# File 'lib/gherkin_lint.rb', line 124 def print(issues) puts 'There are no issues' if issues.empty? && @verbose issues.each { |issue| puts issue.render } end |
#report ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/gherkin_lint.rb', line 102 def report issues = @linter.map do |linter| linter.lint_files(@files, ) linter.issues end.flatten print issues return 0 if issues.select { |issue| issue.class == Error }.empty? -1 end |
#set_linter ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/gherkin_lint.rb', line 75 def set_linter @linter = [] LINTER.each do |linter| new_linter = linter.new linter_enabled = @config.config[new_linter.class.name.split('::').last]['Enabled'] evaluate_members(new_linter) if linter_enabled @linter.push new_linter if linter_enabled end end |
#to_json(input) ⇒ Object
117 118 119 120 121 122 |
# File 'lib/gherkin_lint.rb', line 117 def to_json(input) parser = Gherkin::Parser.new scanner = Gherkin::TokenScanner.new input parser.parse(scanner) end |