Module: LintTrappings::FileFinder

Defined in:
lib/lint_trappings/file_finder.rb

Overview

Finds files that should be linted.

Class Method Summary collapse

Class Method Details

.find(options) ⇒ Array<String>

Return list of lintable files given the specified set of paths and glob pattern search criteria.

The distinction between paths and globs is so files with a ‘*` in their name can still be matched if necessary without treating them as a glob pattern.

Parameters:

  • options (Hash)

Options Hash (options):

  • :included_paths (Array<String>)

    files/directories to include

  • :excluded_paths (Array<String>)

    files/directories to exclude

  • :included_patterns (Array<String>)

    glob patterns to include

  • :excluded_patterns (Array<String>)

    glob patterns to exclude

  • :file_extensions (Array<String>)

    extensions of files to include when searching directories specified by included_paths

Returns:

  • (Array<String>)

    list of matching files in lexicographic order

Raises:



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lint_trappings/file_finder.rb', line 26

def find(options)
  included_paths = options.fetch(:included_paths, []).map { |p| normalize_path(p) }
  excluded_paths = options.fetch(:excluded_paths, []).map { |p| normalize_path(p) }
  included_patterns = options.fetch(:included_patterns, []).map { |p| normalize_path(p) }
  excluded_patterns = options.fetch(:excluded_patterns, []).map { |p| normalize_path(p) }
  allowed_extensions = options.fetch(:allowed_extensions)

  included_files = expand_paths(included_paths, included_patterns, allowed_extensions)
  matching_files = filter_files(included_files, excluded_paths, excluded_patterns)

  matching_files.uniq.sort
end