<commit_before>require 'forwardable'

module Overcommit::Hook
  # Functionality common to all hooks.
  class Base
    extend Forwardable

    def_delegators :@context, :modified_files

    def initialize(config, context)
      @config = config.for_hook(self)
      @context = context
    end

    # Runs the hook.
    def run
      raise NotImplementedError, 'Hook must define `run`'
    end

    def name
      self.class.name.split('::').last
    end

    def description
      @config['description'] || "Running #{name}"
    end

    def required?
      @config['required']
    end

    def quiet?
      @config['quiet']
    end

    def enabled?
      @config['enabled'] != false
    end

    def skip?
      @config['skip']
    end

    def run?
      enabled? &&
        (!skip? || required?) &&
        !(requires_modified_files? && applicable_files.empty?)
    end

    def in_path?(cmd)
      Overcommit::Utils.in_path?(cmd)
    end

    def execute(cmd)
      Overcommit::Utils.execute(cmd)
    end

    # Gets a list of staged files that apply to this hook based on its
    # configured `include` and `exclude` lists.
    def applicable_files
      @applicable_files ||= modified_files.select { |file| applicable_file?(file) }
    end

  private

    def requires_modified_files?
      @config['requires_files']
    end

    def applicable_file?(file)
      includes = Array(@config['include']).map { |glob| convert_glob_to_absolute(glob) }
      included = includes.empty? ||
                 includes.any? { |glob| matches_path?(glob, file) }

      excludes = Array(@config['exclude']).map { |glob| convert_glob_to_absolute(glob) }
      excluded = excludes.any? { |glob| matches_path?(glob, file) }

      included && !excluded
    end

    def convert_glob_to_absolute(glob)
      repo_root = Overcommit::Utils.repo_root
      File.join(repo_root, glob)
    end

    # Return whether a pattern matches the given path.
    #
    # @param pattern [String]
    # @param path [String]
    def matches_path?(pattern, path)
      File.fnmatch?(pattern, path,
                    File::FNM_PATHNAME | # Wildcard doesn't match separator
                    File::FNM_DOTMATCH | # Wildcards match dotfiles
                    File::FNM_EXTGLOB    # Support {,} globbing
      )
    end
  end
end<commit_msg>Remove reference to FNM_EXTGLOB<commit_after>require 'forwardable'

module Overcommit::Hook
  # Functionality common to all hooks.
  class Base
    extend Forwardable

    def_delegators :@context, :modified_files

    def initialize(config, context)
      @config = config.for_hook(self)
      @context = context
    end

    # Runs the hook.
    def run
      raise NotImplementedError, 'Hook must define `run`'
    end

    def name
      self.class.name.split('::').last
    end

    def description
      @config['description'] || "Running #{name}"
    end

    def required?
      @config['required']
    end

    def quiet?
      @config['quiet']
    end

    def enabled?
      @config['enabled'] != false
    end

    def skip?
      @config['skip']
    end

    def run?
      enabled? &&
        (!skip? || required?) &&
        !(requires_modified_files? && applicable_files.empty?)
    end

    def in_path?(cmd)
      Overcommit::Utils.in_path?(cmd)
    end

    def execute(cmd)
      Overcommit::Utils.execute(cmd)
    end

    # Gets a list of staged files that apply to this hook based on its
    # configured `include` and `exclude` lists.
    def applicable_files
      @applicable_files ||= modified_files.select { |file| applicable_file?(file) }
    end

  private

    def requires_modified_files?
      @config['requires_files']
    end

    def applicable_file?(file)
      includes = Array(@config['include']).map { |glob| convert_glob_to_absolute(glob) }
      included = includes.empty? ||
                 includes.any? { |glob| matches_path?(glob, file) }

      excludes = Array(@config['exclude']).map { |glob| convert_glob_to_absolute(glob) }
      excluded = excludes.any? { |glob| matches_path?(glob, file) }

      included && !excluded
    end

    def convert_glob_to_absolute(glob)
      repo_root = Overcommit::Utils.repo_root
      File.join(repo_root, glob)
    end

    # Return whether a pattern matches the given path.
    #
    # @param pattern [String]
    # @param path [String]
    def matches_path?(pattern, path)
      File.fnmatch?(pattern, path,
                    File::FNM_PATHNAME | # Wildcard doesn't match separator
                    File::FNM_DOTMATCH   # Wildcards match dotfiles
      )
    end
  end
end
{'fraction_non_alphanumeric': 0.10672195547795722, 'fraction_numerical': 0.0, 'mean_word_length': 2.5172678434382196, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '895673', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1349, 'n_words': 349}