Sha256: 2ee311bab758833593a33fd507cca8d5d4f508ea0d522001289c2b43da850bdb

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

module SCSSLint
  # Checks for uses of properties where a Compass mixin would be preferred.
  class Linter::Compass::PropertyWithMixin < Linter::Compass
    include LinterRegistry

    def visit_prop(node)
      check_for_properties_with_mixins(node)
      check_for_inline_block(node)
    end

  private

    # Set of properties where the Compass mixin version is preferred
    PROPERTIES_WITH_MIXINS = %w[
      background-clip
      background-origin
      border-radius
      box-shadow
      box-sizing
      opacity
      text-shadow
      transform
    ].to_set

    def check_for_properties_with_mixins(node)
      prop_name = node.name.join
      return unless PROPERTIES_WITH_MIXINS.include?(prop_name) &&
                    !ignore_compass_mixin?(prop_name)

      add_lint node, "Use the Compass `#{prop_name}` mixin instead of the property"
    end

    def check_for_inline_block(node)
      prop_name = node.name.join
      return unless prop_name == 'display' &&
                    node.value.first.to_sass == 'inline-block' &&
                    !ignore_compass_mixin?('inline-block')

      add_lint node,
               'Use the Compass `inline-block` mixin instead of `display: inline-block`'
    end

    def ignore_compass_mixin?(prop_name)
      config.fetch('ignore', []).include?(prop_name)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
scss_lint-0.60.0 lib/scss_lint/linter/compass/property_with_mixin.rb
scss_lint-0.59.0 lib/scss_lint/linter/compass/property_with_mixin.rb
scss_lint-0.58.0 lib/scss_lint/linter/compass/property_with_mixin.rb
scss_lint-0.57.1 lib/scss_lint/linter/compass/property_with_mixin.rb
scss_lint-0.57.0 lib/scss_lint/linter/compass/property_with_mixin.rb
scss_lint-0.56.0 lib/scss_lint/linter/compass/property_with_mixin.rb