@@ -78,19 +78,18 @@ def check_commas_after_args(args, arg_type)
78
78
# Sometimes the line we're looking at doesn't even contain a comma!
79
79
next unless engine . lines [ arg . line - 1 ] . include? ( ',' )
80
80
81
- offset = find_comma_offset ( arg )
81
+ comma_position = find_comma_position ( arg )
82
82
83
83
# Check for space or newline after comma (we allow arguments to be split
84
84
# up over multiple lines).
85
85
spaces = 0
86
- while ( char = character_at ( arg . source_range . end_pos , offset + 1 ) ) == ' '
86
+ while ( char = character_at ( comma_position , spaces + 1 ) ) == ' '
87
87
spaces += 1
88
- offset += 1
89
88
end
90
89
next if char == "\n " || # Ignore trailing spaces
91
90
valid_spaces_after_comma? ( spaces )
92
91
93
- add_lint arg , "Commas in #{ arg_type } should be followed by a single space"
92
+ add_lint comma_position , "Commas in #{ arg_type } should be followed by a single space"
94
93
end
95
94
end
96
95
@@ -100,20 +99,26 @@ def check_commas_after_args(args, arg_type)
100
99
# source range. Thus we need to start at the indicated range, and check
101
100
# left and right of that range, gradually moving further outward until
102
101
# we find the comma.
103
- def find_comma_offset ( arg )
102
+ def find_comma_position ( arg ) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
104
103
offset = 0
104
+ pos = arg . source_range . end_pos
105
105
106
- if character_at ( arg . source_range . end_pos , offset ) != ','
106
+ if character_at ( pos , offset ) != ','
107
107
loop do
108
108
offset += 1
109
- break if character_at ( arg . source_range . end_pos , offset ) == ','
109
+ break if ( right_char = character_at ( pos , offset ) ) == ','
110
110
offset = -offset
111
- break if character_at ( arg . source_range . end_pos , offset ) == ','
111
+ break if ( left_char = character_at ( pos , offset ) ) == ','
112
112
offset = -offset
113
+
114
+ next unless right_char . nil? && left_char . nil?
115
+ offset = 0
116
+ pos = Sass ::Source ::Position . new ( pos . line + 1 , 1 )
117
+ break if character_at ( pos , offset ) == ','
113
118
end
114
119
end
115
120
116
- offset
121
+ Sass :: Source :: Position . new ( pos . line , pos . offset + offset )
117
122
end
118
123
end
119
124
end
0 commit comments