class StartMatchEmpty

Warns when a PatternRange has a start_pattern that matches the empty string

Public Class Methods

display_options(indent, options) click to toggle source

Displays the state of the options

@return (see GrammarPlugin.display_options)

# File lib/textmate_grammar/linters/start_match_empty.rb, line 44
def self.display_options(indent, options)
    ",\n#{indent}zeroLengthStart?: #{options[:zeroLengthStart?]}"
end
options() click to toggle source

Contributes the option :zeroLengthStart?

:zeroLengthStart? disables this linter

@return (see GrammarPlugin.options)

# File lib/textmate_grammar/linters/start_match_empty.rb, line 35
def self.options
    [:zeroLengthStart?]
end

Public Instance Methods

pre_lint(pattern, options) click to toggle source

(see GrammarLinter#pre_lint)

# File lib/textmate_grammar/linters/start_match_empty.rb, line 12
def pre_lint(pattern, options)
    return true unless pattern.is_a? PatternRange

    regexp = with_no_warnings do
        Regexp.new(pattern.start_pattern.evaluate.gsub("\\G", '\uFFFF'))
    end
    if "" =~ regexp and !options[:zeroLengthStart?]
        puts "Warning: #{pattern.start_pattern.evaluate}"
        puts "matches the zero length string (\"\").\n\n"
        puts "This means that the patternRange always matches"
        puts "You can disable this warning by setting :zeroLengthStart? to true."
        puts "The pattern is:\n#{pattern}"
    end
    true # return true for warnings
end