Sha256: 11b582558229d6a992f9f33e9a5e88d6f6ac9a881f508360f06ccabdb0182738

Contents?: true

Size: 1.52 KB

Versions: 6

Compression:

Stored size: 1.52 KB

Contents

require 'find'

module SCSSLint
  # Finds all SCSS files that should be linted given a set of paths, globs, and
  # configuration.
  class FileFinder
    # List of extensions of files to include when only a directory is specified
    # as a path.
    VALID_EXTENSIONS = %w[.css .scss]

    # Create a {FileFinder}.
    #
    # @param config [SCSSLint::Config]
    def initialize(config)
      @config = config
    end

    # Find all files that match given the specified options.
    #
    # @param patterns [Array<String>] a list of file paths and glob patterns
    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

      matched_files.reject { |file| @config.excluded_file?(file) }
    end

  private

    # @param list [Array]
    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

    # @param file [String]
    # @return [true,false]
    def scssish_file?(file)
      return false unless FileTest.file?(file)

      VALID_EXTENSIONS.include?(File.extname(file))
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
scss_lint-0.43.2 lib/scss_lint/file_finder.rb
scss_lint-0.43.1 lib/scss_lint/file_finder.rb
scss_lint-0.43.0 lib/scss_lint/file_finder.rb
scss_lint-0.42.2 lib/scss_lint/file_finder.rb
scss_lint-0.42.1 lib/scss_lint/file_finder.rb
scss_lint-0.42.0 lib/scss_lint/file_finder.rb