<commit_before>require 'roxml'
module CukeSniffer
  class StepDefinition < RulesEvaluator
    include CukeSniffer::Constants
    include CukeSniffer::RuleConfig

    xml_accessor :start_line
    xml_accessor :regex
    xml_accessor :parameters, :as => [], :in => "parameters"
    xml_accessor :nested_steps, :as => {:key => 'location', :value => 'call'}, :in => "nested_steps"
    xml_accessor :calls, :as => {:key => 'location', :value => 'call'}, :in => "calls"
    xml_accessor :code, :as => [], :in => "code"

    SIMPLE_NESTED_STEP_REGEX = /steps(\s|\()"#{STEP_STYLES}(?<step_string>.*)"\)?$/
    SAME_LINE_COMPLEX_STEP_REGEX = /^steps(\s|\()%(q|Q)?{#{STEP_STYLES}(?<step_string>.*)}\)?$/
    START_COMPLEX_STEP_REGEX = /^steps(\s|\()%(q|Q)?\{\s*/
    END_COMPLEX_STEP_REGEX = /}/
    START_COMPLEX_WITH_STEP_REGEX = /steps(\s|\()%(q|Q)?\{#{STEP_STYLES}(?<step_string>.*)$/
    END_COMPLEX_WITH_STEP_REGEX = /#{STEP_STYLES}(?<step_string>.*)}/

    def initialize(location, raw_code)
      super(location)

      @parameters = []
      @calls = {}
      @nested_steps = {}
      @start_line = location.match(/:(?<line>\d*)$/)[:line].to_i

      end_match_index = (raw_code.size - 1) - raw_code.reverse.index("end")
      @code = raw_code[1...end_match_index]

      raw_code.each do |line|
        if line =~ STEP_DEFINITION_REGEX
          matches = STEP_DEFINITION_REGEX.match(line)
          @regex = Regexp.new(matches[:step])
          @parameters = matches[:parameters].split(",") unless matches[:parameters].nil?<commit_msg>adjusted the step definition regex's again after seeing them work in the wild. The specs still passed but it had more problems in a live project so reverting a little bit for now.<commit_after>require 'roxml'
module CukeSniffer
  class StepDefinition < RulesEvaluator
    include CukeSniffer::Constants
    include CukeSniffer::RuleConfig

    xml_accessor :start_line
    xml_accessor :regex
    xml_accessor :parameters, :as => [], :in => "parameters"
    xml_accessor :nested_steps, :as => {:key => 'location', :value => 'call'}, :in => "nested_steps"
    xml_accessor :calls, :as => {:key => 'location', :value => 'call'}, :in => "calls"
    xml_accessor :code, :as => [], :in => "code"

    SIMPLE_NESTED_STEP_REGEX = /steps\s"#{STEP_STYLES}(?<step_string>.*)"$/
    SAME_LINE_COMPLEX_STEP_REGEX = /^steps\s%(q|Q)?{#{STEP_STYLES}(?<step_string>.*)}$/
    START_COMPLEX_STEP_REGEX = /^steps\s%(q|Q)?\{\s*/
    END_COMPLEX_STEP_REGEX = /}$/
    START_COMPLEX_WITH_STEP_REGEX = /steps\s%(q|Q)?\{#{STEP_STYLES}(?<step_string>.*)$/
    END_COMPLEX_WITH_STEP_REGEX = /#{STEP_STYLES}(?<step_string>.*)}$/
    def initialize(location, raw_code)
      super(location)

      @parameters = []
      @calls = {}
      @nested_steps = {}
      @start_line = location.match(/:(?<line>\d*)$/)[:line].to_i

      end_match_index = (raw_code.size - 1) - raw_code.reverse.index("end")
      @code = raw_code[1...end_match_index]

      raw_code.each do |line|
        if line =~ STEP_DEFINITION_REGEX
          matches = STEP_DEFINITION_REGEX.match(line)
          @regex = Regexp.new(matches[:step])
          @parameters = matches[:parameters].split(",") unless matches[:parameters].nil?
{'fraction_non_alphanumeric': 0.17709305944600062, 'fraction_numerical': 0.0012449424214130097, 'mean_word_length': 3.811377245508982, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2473540', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1171, 'n_words': 197}