lib/scss_lint/linter/border_zero.rb in scss-lint-0.33.0 vs lib/scss_lint/linter/border_zero.rb in scss-lint-0.34.0

- old
+ new

@@ -1,23 +1,39 @@ module SCSSLint - # Reports when `border: 0` can be used instead of `border: none`. + # Enforce a particular value for empty borders. class Linter::BorderZero < Linter include LinterRegistry - def visit_prop(node) - return unless BORDER_PROPERTIES.include?(node.name.first.to_s) - return unless node.value.to_sass.strip == 'none' + CONVENTION_TO_PREFERENCE = { + 'zero' => %w[0 none], + 'none' => %w[none 0], + } - add_lint(node, '`border: 0;` is preferred over `border: none;`') - end - - private - BORDER_PROPERTIES = %w[ border border-top border-right border-bottom border-left ] + + 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.value.to_sass.strip) + end + + private + + def check_border(node, border) + return unless %w[0 none].include?(border) + return if @preference[0] == border + + add_lint(node, "`border: #{@preference[0]} is preferred over " \ + "`border: #{@preference[1]}`") + end end end