Sha256: 750c3ccbe7023758fe3fc907129e0c55dfcaa96966257b204eec93630606f8cc

Contents?: true

Size: 1017 Bytes

Versions: 9

Compression:

Stored size: 1017 Bytes

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']]
      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

9 entries across 9 versions & 1 rubygems

Version Path
scss_lint-0.50.2 lib/scss_lint/linter/border_zero.rb
scss_lint-0.50.1 lib/scss_lint/linter/border_zero.rb
scss_lint-0.50.0 lib/scss_lint/linter/border_zero.rb
scss_lint-0.49.0 lib/scss_lint/linter/border_zero.rb
scss_lint-0.48.0 lib/scss_lint/linter/border_zero.rb
scss_lint-0.47.1 lib/scss_lint/linter/border_zero.rb
scss_lint-0.47.0 lib/scss_lint/linter/border_zero.rb
scss_lint-0.46.0 lib/scss_lint/linter/border_zero.rb
scss_lint-0.45.0 lib/scss_lint/linter/border_zero.rb