Sha256: b1500884de7f460df528c696efac929a34050b59a47fee88110ab2a83b1c3427

Contents?: true

Size: 1 KB

Versions: 18

Compression:

Stored size: 1 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

    EXPECTED_SPACES_AFTER_COLON = 1

    def visit_prop(node)
      spaces = spaces_after_colon(node)

      if spaces != EXPECTED_SPACES_AFTER_COLON
        add_lint node, 'Colon after property should be followed by ' <<
                       "#{pluralize(EXPECTED_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

18 entries across 18 versions & 1 rubygems

Version Path
scss-lint-0.21.0 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.20.3 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.20.2 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.20.1 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.20.0 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.19.0 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.18.0 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.17.3 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.17.2 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.17.1 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.17.0 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.16.1 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.16.0 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.15.0 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.14.0 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.13.0 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.12.1 lib/scss_lint/linter/space_after_property_colon.rb
scss-lint-0.12.0 lib/scss_lint/linter/space_after_property_colon.rb