class SCSSLint::FileFinder
Finds all SCSS files that should be linted given a set of paths, globs, and configuration.
Constants
- VALID_EXTENSIONS
List of extensions of files to include when only a directory is specified as a path.
Public Class Methods
new(config)
click to toggle source
Create a {FileFinder}.
@param config [SCSSLint::Config]
# File lib/scss_lint/file_finder.rb, line 14 def initialize(config) @config = config end
Public Instance Methods
find(patterns)
click to toggle source
Find all files that match given the specified options.
@param patterns [Array<String>] a list of file paths and glob patterns
# File lib/scss_lint/file_finder.rb, line 21 def find(patterns) # If no explicit patterns given, use patterns listed in config patterns = @config.scss_files if patterns.empty? matched_files = extract_files_from(patterns) if matched_files.empty? raise SCSSLint::Exceptions::NoFilesError, "No SCSS files matched by the patterns: #{patterns.join(' ')}" end filtered_files = matched_files.reject { |file| @config.excluded_file?(file) } if filtered_files.empty? raise SCSSLint::Exceptions::AllFilesFilteredError, "All files matched by the patterns [#{patterns.join(', ')}] " \ "were excluded by the patterns: [#{@config.exclude_patterns.join(', ')}]" end filtered_files end
Private Instance Methods
extract_files_from(list)
click to toggle source
@param list [Array]
# File lib/scss_lint/file_finder.rb, line 44 def extract_files_from(list) files = [] list.each do |file| if File.directory?(file) Find.find(file) do |f| files << f if scssish_file?(f) end else files << file # Otherwise include file as-is end end files.uniq end
scssish_file?(file)
click to toggle source
@param file [String] @return [true,false]
# File lib/scss_lint/file_finder.rb, line 62 def scssish_file?(file) return false unless FileTest.file?(file) VALID_EXTENSIONS.include?(File.extname(file)) end