Sha256: f502d24bead1db3f20e1c44e3780161dd5d69cb9c05497119cf5830e50c077a0

Contents?: true

Size: 1.56 KB

Versions: 15

Compression:

Stored size: 1.56 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].freeze

    # 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 patterns.empty?
        raise SCSSLint::Exceptions::NoFilesError,
              'No files, paths, or patterns were specified'
      end

      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.sort
    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

15 entries across 15 versions & 1 rubygems

Version Path
scss_lint-0.60.0 lib/scss_lint/file_finder.rb
scss_lint-0.59.0 lib/scss_lint/file_finder.rb
scss_lint-0.58.0 lib/scss_lint/file_finder.rb
scss_lint-0.57.1 lib/scss_lint/file_finder.rb
scss_lint-0.57.0 lib/scss_lint/file_finder.rb
scss_lint-0.56.0 lib/scss_lint/file_finder.rb
scss_lint-0.55.0 lib/scss_lint/file_finder.rb
scss_lint-0.54.0 lib/scss_lint/file_finder.rb
scss_lint-0.53.0 lib/scss_lint/file_finder.rb
scss_lint-0.52.0 lib/scss_lint/file_finder.rb
scss_lint-0.51.0 lib/scss_lint/file_finder.rb
scss_lint-0.50.3 lib/scss_lint/file_finder.rb
scss_lint-0.50.2 lib/scss_lint/file_finder.rb
scss_lint-0.50.1 lib/scss_lint/file_finder.rb
scss_lint-0.50.0 lib/scss_lint/file_finder.rb