Sha256: 10f89f18484bf3eefc9de608bf17f0cc2c406a11c840dd75d5cff069fde9822c

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

module SCSSLint
  module Utils
    # Given a selector array which is a list of strings with Sass::Script::Nodes
    # interspersed within them, return an array of strings representing those
    # selectors with the Sass::Script::Nodes removed (i.e., ignoring
    # interpolation). For example:
    #
    # .selector-one, .selector-#{$var}-two
    #
    # becomes:
    #
    # .selector-one, .selector--two
    #
    # This is useful for lints that wish to ignore interpolation, since
    # interpolation can't be resolved at this step.
    def extract_string_selectors(selector_array)
      selector_array.reject { |item| item.is_a? Sass::Script::Node }.
                     join.
                     split
    end

    # Given a selector array, returns whether it contains any placeholder
    # selectors with invalid names.
    def selector_has_bad_placeholder?(selector_array)
      extract_string_selectors(selector_array).any? do |selector_str|
        selector_str =~ /%\w*#{INVALID_NAME_CHARS}/
      end
    end

    def node_has_bad_name?(node)
      node.name =~ /#{INVALID_NAME_CHARS}/
    end

  private

    INVALID_NAME_CHARS = '[_A-Z]'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scss-lint-0.9.0 lib/scss_lint/utils.rb