<commit_before>fs = require 'fs'
path = require 'path'


# Finds all test files in the given directory.
class TestsFinder

  constructor: (@directory) ->


  # Returns the name of all files within the given directory that contain tests.
  files: ->
    files = []
    @_search_directory @directory, files
    files


  _search_directory: (dir, files) ->
    # TODO: make this return files, instead of using a param for that.
    for file in fs.readdirSync(dir)
      continue if @_is_hidden file
      filePath = path.resolve "#{dir}/#{file}"
      stat = fs.statSync filePath
      if stat.isFile()
        continue unless @_is_test_file file
        files.push filePath
      else if stat.isDirectory()
        @_search_directory filePath, files


  # Returns whether the given filesystem object is hidden.
  _is_hidden: (file) ->
    file[0] == '.'


  # Returns whether the file with the given filename contains unit tests.
  _is_test_file: (file) ->
<commit_msg>Simplify recursive file search interface<commit_after>fs = require 'fs'
path = require 'path'


# Finds all test files in the given directory.
class TestsFinder

  constructor: (@directory) ->


  # Returns the name of all files within the given directory that contain tests.
  files: ->
    @_search_directory @directory, []


  # Adds all test files in the current directory and its subdirectories
  # to the given files array.
  _search_directory: (dir, files) ->
    for file in fs.readdirSync(dir)
      continue if @_is_hidden file
      filePath = path.resolve "#{dir}/#{file}"
      stat = fs.statSync filePath
      if stat.isFile()
        continue unless @_is_test_file file
        files.push filePath
      else if stat.isDirectory()
        @_search_directory filePath, files
    files


  # Returns whether the given filesystem object is hidden.
  _is_hidden: (file) ->
    file[0] == '.'


  # Returns whether the file with the given filename contains unit tests.
  _is_test_file: (file) ->

{'fraction_non_alphanumeric': 0.08611955420466058, 'fraction_numerical': 0.0010131712259371835, 'mean_word_length': 3.006085192697769, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6779243', 'n_tokens_mistral': 581, 'n_tokens_neox': 559, 'n_words': 214}