Sha256: f2c9144056f2a08411c44b008f745a3a686dc0457e32fab779c6657585c28e6e

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

module SCSSLint
  # Enforce a particular value for empty borders.
  class Linter::BorderZero < Linter
    include LinterRegistry

    CONVENTION_TO_PREFERENCE = {
      'zero' => %w[0 none],
      'none' => %w[none 0],
    }.freeze

    BORDER_PROPERTIES = %w[
      border
      border-top
      border-right
      border-bottom
      border-left
    ].freeze

    def visit_root(_node)
      @preference = CONVENTION_TO_PREFERENCE[config['convention'].to_s]
      unless @preference
        raise "Invalid `convention` specified: #{config['convention']}." \
              "Must be one of [#{CONVENTION_TO_PREFERENCE.keys.join(', ')}]"
      end
      yield # Continue linting children
    end

    def visit_prop(node)
      return unless BORDER_PROPERTIES.include?(node.name.first.to_s)
      check_border(node, node.name.first.to_s, node.value.to_sass.strip)
    end

  private

    def check_border(node, border_property, border_value)
      return unless %w[0 none].include?(border_value)
      return if @preference[0] == border_value

      add_lint(node, "`#{border_property}: #{@preference[0]}` is preferred over " \
                     "`#{border_property}: #{@preference[1]}`")
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
scss_lint-0.55.0 lib/scss_lint/linter/border_zero.rb
scss_lint-0.54.0 lib/scss_lint/linter/border_zero.rb
scss_lint-0.53.0 lib/scss_lint/linter/border_zero.rb
scss_lint-0.52.0 lib/scss_lint/linter/border_zero.rb
scss_lint-0.51.0 lib/scss_lint/linter/border_zero.rb
scss_lint-0.50.3 lib/scss_lint/linter/border_zero.rb