Sha256: e69d104f0fce1be17771fa86bd24c578d60424488030c7f59f453a20465d78ba

Contents?: true

Size: 1.3 KB

Versions: 3

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

3 entries across 3 versions & 1 rubygems

Version Path
scss-lint-0.24.0 lib/scss_lint/linter/trailing_semicolon_after_property_value.rb
scss-lint-0.23.1 lib/scss_lint/linter/trailing_semicolon_after_property_value.rb
scss-lint-0.23.0 lib/scss_lint/linter/trailing_semicolon_after_property_value.rb