Class: SCSSLint::Linter::SpaceAroundOperator::OperationSources

Inherits:
Object
  • Object
show all
Defined in:
lib/scss_lint/linter/space_around_operator.rb

Overview

A helper class for storing and adjusting the sources of the different components of an Operation node.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, linter) ⇒ OperationSources

Returns a new instance of OperationSources.



78
79
80
81
82
83
84
# File 'lib/scss_lint/linter/space_around_operator.rb', line 78

def initialize(node, linter)
  @node = node
  @linter = linter
  @source = normalize_source(@linter.source_fm_range(@node.source_range))
  @left_range = @node.operand1.source_range
  @right_range = @node.operand2.source_range
end

Instance Attribute Details

#operator_sourceObject (readonly)

Returns the value of attribute operator_source.



76
77
78
# File 'lib/scss_lint/linter/space_around_operator.rb', line 76

def operator_source
  @operator_source
end

Instance Method Details

#adjust_for_interpolationObject



96
97
98
99
100
# File 'lib/scss_lint/linter/space_around_operator.rb', line 96

def adjust_for_interpolation
  @source = normalize_source(@linter.source_fm_range(slide_to_the_left(@node.source_range)))
  @left_range = slide_to_the_left(@node.operand1.source_range)
  @right_range = slide_to_the_left(@node.operand2.source_range)
end

#adjust_sourcesObject



86
87
88
89
90
91
92
93
94
# File 'lib/scss_lint/linter/space_around_operator.rb', line 86

def adjust_sources
  # We need to #chop at the end because an operation's operand1 _always_
  # includes one character past the actual operand (which is either a
  # whitespace character, or the first character of the operation).
  @left_source = normalize_source(@linter.source_fm_range(@left_range))
  @right_source = normalize_source(@linter.source_fm_range(@right_range))
  @operator_source = calculate_operator_source
  adjust_left_boundary
end

#no_space_msg(operator) ⇒ Object



106
107
108
# File 'lib/scss_lint/linter/space_around_operator.rb', line 106

def no_space_msg(operator)
  NO_SPACE_MSG % [@source, @left_source, operator, @right_source]
end

#space_msg(operator) ⇒ Object



102
103
104
# File 'lib/scss_lint/linter/space_around_operator.rb', line 102

def space_msg(operator)
  SPACE_MSG % [@source, @left_source, operator, @right_source]
end