class StandardNaming

Checks for names to match expected naming format see www.sublimetext.com/docs/3/scope_naming.html

Constants

EXPECTED_NAMES

@return [Hash] a summarization of expected names

Public Instance Methods

check_tag(tag) click to toggle source

Checks a tag for standard naming scheme

@param [String] tag the tag to check

@return [void] nothing

# File lib/ruby_grammar_builder/linters/standard_naming.rb, line 191
def check_tag(tag)
    result, pos, root = recursive_check_tag(tag)
    return if result

    valid_prefix = (pos > 0) ? tag[0..(pos-1)].join(".") + "." : ""

    puts "The prefix `#{tag[0..pos].join('.')}' does not follow the standard format"
    puts "The expected prefixes at this level are:"
    root.keys.each do |key|
        if root[:key] == false
            puts "- #{valid_prefix}#{key}"
        else
            puts "  #{valid_prefix}#{key}"
        end
    end
end
pre_lint(pattern, _options) click to toggle source

Checks for names to match expected naming format

@return [True] warnings to not return false

# File lib/ruby_grammar_builder/linters/standard_naming.rb, line 213
def pre_lint(pattern, _options)
    return true unless pattern.is_a? PatternBase

    pattern.each(true) do |pat|
        next unless pat.arguments[:tag_as]

        pat.arguments[:tag_as].split(" ").each { |tag| check_tag(tag.split(".")) }
    end

    true
end
recursive_check_tag(tag, index = 0, root = EXPECTED_NAMES) click to toggle source

Checks the tag keys at this level

@param [Array<string>] tag an array of tag components @param [Numeric] index The index into tag to check @param [Hash] root the hash to check against

@return [Boolean] If this is a valid tag

# File lib/ruby_grammar_builder/linters/standard_naming.rb, line 171
def recursive_check_tag(tag, index = 0, root = EXPECTED_NAMES)
    if root.has_key?(tag[index])
        next_part = root[tag[index]]
        return recursive_check_tag(tag, index+1, next_part) if next_part.is_a? Hash

        return [next_part, index, root]
    elsif root.has_key? "*"
        return [root["*"], index, root]
    end

    [false, index, root]
end