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.



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

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.



74
75
76
# File 'lib/scss_lint/linter/space_around_operator.rb', line 74

def operator_source
  @operator_source
end

Instance Method Details

#adjust_for_interpolationObject



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

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



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

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



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

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

#space_msg(operator) ⇒ Object



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

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