Sha256: d459fc3b127e6b5a8f1ac31dfe94b90bea9dc2a8c6ef969600f3682994d01fcd

Contents?: true

Size: 855 Bytes

Versions: 7

Compression:

Stored size: 855 Bytes

Contents

module SCSSLint
  # Reports the use of literals for properties where variables are prefered.
  class Linter::VariableForProperty < Linter
    include LinterRegistry

    IGNORED_VALUES = %w[currentColor inherit transparent]

    def visit_root(_node)
      @properties = Set.new(config['properties'])
      yield if @properties.any?
    end

    def visit_prop(node)
      property_name = node.name.join
      return unless @properties.include?(property_name)
      return if ignored_value?(node.value)
      return if node.children.first.is_a?(Sass::Script::Tree::Variable)

      add_lint(node, "Property #{property_name} should use " \
                     'a variable rather than a literal value')
    end

  private

    def ignored_value?(value)
      value.respond_to?(:value) &&
        IGNORED_VALUES.include?(value.value.to_s)
    end
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
scss_lint-0.41.0 lib/scss_lint/linter/variable_for_property.rb
scss_lint-0.40.1 lib/scss_lint/linter/variable_for_property.rb
scss_lint-0.40.0 lib/scss_lint/linter/variable_for_property.rb
scss_lint-0.39.0 lib/scss_lint/linter/variable_for_property.rb
scss_lint-0.38.0 lib/scss_lint/linter/variable_for_property.rb
scss-lint-0.38.0 lib/scss_lint/linter/variable_for_property.rb
scss-lint-bliss-1.0.0 lib/scss_lint/linter/variable_for_property.rb