Class: FlatIncludes

Inherits:
GrammarLinter show all
Defined in:
lib/ruby_grammar_builder/linters/flat_includes.rb

Overview

Internal check, ensures that :includes is nil or a flat array

Instance Method Summary collapse

Methods inherited from GrammarLinter

#post_lint

Methods inherited from GrammarPlugin

display_options, options

Instance Method Details

#pre_lint(pattern, options) ⇒ Boolean

Runs the linter on each pattern

Parameters:

  • pattern (PatternBase, Symbol, Hash)

    the pattern to lint

  • options (Hash)

    hash of any of the option keys provided by self.options. options will only be populated when pattern is a PatternBase

Returns:

  • (Boolean)

    the result of the lint



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby_grammar_builder/linters/flat_includes.rb', line 12

def pre_lint(pattern, options)
    return true unless pattern.is_a? PatternBase
    return true if pattern.arguments[:includes].nil?

    if pattern.arguments[:includes].is_a?(Array) &&
       pattern.arguments[:includes].none? { |v| v.is_a? Array }
        flat = true
        pattern.arguments[:includes].map do |s|
            flat = false unless pre_lint(s, options)
        end
        return flat
    end

    puts "The pattern `#{pattern.name}' does not have a flat includes array."
    puts "This is an internal error"

    false
end