Class: GherkinLint::GherkinLint
- Inherits:
-
Object
- Object
- GherkinLint::GherkinLint
- Defined in:
- lib/gherkin_lint.rb
Overview
gherkin linter
Constant Summary collapse
- LINTER =
[ AvoidOutlineForSingleExample, AvoidPeriod, AvoidScripting, BackgroundDoesMoreThanSetup, BackgroundRequiresMultipleScenarios, BadScenarioName, BeDeclarative, FileNameDiffersFeatureName, MissingExampleName, MissingFeatureDescription, MissingFeatureName, MissingScenarioName, MissingTestAction, MissingVerification, InvalidFileName, InvalidStepFlow, SameTagForAllScenarios, TooClumsy, TooManyDifferentTags, TooManySteps, TooManyTags, TooLongStep, UniqueScenarioNames, UnknownVariable, UnusedVariable, UseBackground, UseOutline ].freeze
Instance Method Summary collapse
- #analyze(file) ⇒ Object
- #disable(disabled_linter) ⇒ Object
- #disable_tags ⇒ Object
- #enable(enabled_linter) ⇒ Object
- #enable_all ⇒ Object
-
#initialize ⇒ GherkinLint
constructor
A new instance of GherkinLint.
- #parse(file) ⇒ Object
- #print(issues) ⇒ Object
- #report ⇒ Object
- #set_linter(enabled_linter, disabled_linter = []) ⇒ Object
- #to_json(input, file = 'generated.feature') ⇒ Object
Constructor Details
#initialize ⇒ GherkinLint
Returns a new instance of GherkinLint.
69 70 71 72 73 |
# File 'lib/gherkin_lint.rb', line 69 def initialize @files = {} @linter = [] enable_all end |
Instance Method Details
#analyze(file) ⇒ Object
100 101 102 |
# File 'lib/gherkin_lint.rb', line 100 def analyze(file) @files[file] = parse file end |
#disable(disabled_linter) ⇒ Object
83 84 85 |
# File 'lib/gherkin_lint.rb', line 83 def disable(disabled_linter) set_linter(LINTER.map { |linter| linter.new.name.split('::').last }, disabled_linter) end |
#disable_tags ⇒ Object
121 122 123 |
# File 'lib/gherkin_lint.rb', line 121 def LINTER.map { |lint| "disable#{lint.new.class.name.split('::').last}" } end |
#enable(enabled_linter) ⇒ Object
79 80 81 |
# File 'lib/gherkin_lint.rb', line 79 def enable(enabled_linter) set_linter(enabled_linter) end |
#enable_all ⇒ Object
75 76 77 |
# File 'lib/gherkin_lint.rb', line 75 def enable_all disable [] end |
#parse(file) ⇒ Object
104 105 106 107 |
# File 'lib/gherkin_lint.rb', line 104 def parse(file) content = File.read file to_json(content, file) end |
#print(issues) ⇒ Object
134 135 136 137 |
# File 'lib/gherkin_lint.rb', line 134 def print(issues) puts "There are #{issues.length} Issues" unless issues.empty? issues.each { |issue| puts issue } end |
#report ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/gherkin_lint.rb', line 109 def report issues = @linter.map do |linter| linter.lint_files(@files, ) linter.issues end.flatten issues.each { |issue| puts issue.render } return 0 if issues.select { |issue| issue.class == Error }.empty? -1 end |
#set_linter(enabled_linter, disabled_linter = []) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/gherkin_lint.rb', line 87 def set_linter(enabled_linter, disabled_linter = []) @linter = [] enabled_linter = Set.new enabled_linter disabled_linter = Set.new disabled_linter LINTER.each do |linter| new_linter = linter.new name = new_linter.class.name.split('::').last next unless enabled_linter.include? name next if disabled_linter.include? name @linter.push new_linter end end |
#to_json(input, file = 'generated.feature') ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/gherkin_lint.rb', line 125 def to_json(input, file = 'generated.feature') io = StringIO.new formatter = Gherkin::Formatter::JSONFormatter.new(io) parser = Gherkin::Parser::Parser.new(formatter, true) parser.parse(input, file, 0) formatter.done MultiJson.load io.string end |