Sha256: 60517be3cc508275db123895dd9cf45f5944f81473df35fb0fdc010c35697363

Contents?: true

Size: 1.37 KB

Versions: 6

Compression:

Stored size: 1.37 KB

Contents

module SCSSLint
  class Linter::UsageName < Linter
    include LinterRegistry

    def visit_extend(node)
      if selector_has_bad_placeholder?(node.selector)
        add_name_lint(node, node.selector.join, 'placeholder')
      end
    end

    def visit_mixin(node)
      check(node, 'mixin')
      yield # Continue into content block of this mixin's block
    end

    def visit_script_funcall(node)
      check(node, 'function') unless FUNCTION_WHITELIST.include?(node.name)
    end

    def visit_script_variable(node)
      check(node, 'variable')
    end

  private

    FUNCTION_WHITELIST = %w[
      rotateX rotateY rotateZ
      scaleX scaleY scaleZ
      skewX skewY
      translateX translateY translateZ
    ].to_set

    def check(node, node_type)
      add_name_lint(node, node.name, node_type) if node_has_bad_name?(node)
    end

    def add_name_lint(node, name, node_type)
      fixed_name = name.downcase.gsub(/_/, '-')

      add_lint(node, "All uses of #{node_type} `#{name}` should be written " <<
                     "in lowercase as `#{fixed_name}`")
    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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
scss-lint-0.13.0 lib/scss_lint/linter/usage_name.rb
scss-lint-0.12.1 lib/scss_lint/linter/usage_name.rb
scss-lint-0.12.0 lib/scss_lint/linter/usage_name.rb
scss-lint-0.11.1 lib/scss_lint/linter/usage_name.rb
scss-lint-0.10.1 lib/scss_lint/linter/usage_name.rb
scss-lint-0.10.0 lib/scss_lint/linter/usage_name.rb