Sha256: 1ec700d8453eac3239baa79eec62b697cfda8df561cb07670f987c933524c0d6

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module SCSSLint
  # Checks for spaces following the colon that separates a property's name from
  # its value.
  class Linter::SpaceAfterPropertyColon < Linter
    include LinterRegistry

    MINIMUM_SPACES_AFTER_COLON = 1

    def visit_prop(node)
      spaces = spaces_after_colon(node)

      if config['allow_extra_spaces']
        if spaces < MINIMUM_SPACES_AFTER_COLON
          add_lint node, 'Colon after property should be followed by ' <<
                         "at least #{pluralize(MINIMUM_SPACES_AFTER_COLON, 'space')} "
        end
      elsif spaces != MINIMUM_SPACES_AFTER_COLON
        add_lint node, 'Colon after property should be followed by ' <<
                       pluralize(MINIMUM_SPACES_AFTER_COLON, 'space') <<
                       " instead of #{pluralize(spaces, 'space')}"
      end
    end

  private

    def spaces_after_colon(node)
      spaces = 0
      offset = 1

      # Handle quirk where Sass parser doesn't include colon in source range
      # when property name is followed by spaces
      if character_at(node.name_source_range.end_pos, offset) == ':'
        offset += 1
      end

      while character_at(node.name_source_range.end_pos, offset) == ' '
        spaces += 1
        offset += 1
      end

      spaces
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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