Sha256: 32e566ec09e41f8a57495301f6bebb8ae338841a03f1209a65ffecdc3c15019a

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module SCSSLint
  # Checks properties for a trailing semicolon (unless that property is a
  # namespace which has nested properties).
  class Linter::TrailingSemicolonAfterPropertyValue < Linter
    include LinterRegistry

    def visit_prop(node)
      has_nested_props = has_nested_properties?(node)

      unless has_nested_props
        if has_space_before_semicolon?(node)
          line = node.source_range.end_pos
          add_lint line, 'Property declaration should be terminated by a semicolon'
        elsif !ends_with_semicolon?(node)
          # Adjust line since lack of semicolon results in end of source range
          # being on the next line
          line = node.source_range.end_pos.line - 1
          add_lint line,
                   'Property declaration should not have a space before ' <<
                   'the terminating semicolon'
        end
      end

      yield if has_nested_props
    end

  private

    def has_nested_properties?(node)
      node.children.any? { |n| n.is_a?(Sass::Tree::PropNode) }
    end

    # Checks that the property is ended by a semicolon (with no whitespace)
    def ends_with_semicolon?(node)
      source_from_range(node.source_range) =~ /;$/
    end

    def has_space_before_semicolon?(node)
      source_from_range(node.source_range) =~ /\s;$/
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scss-lint-0.22.0 lib/scss_lint/linter/trailing_semicolon_after_property_value.rb