Skip to content

Commit

Permalink
Add offset as column in SpaceAfterComma linter message
Browse files Browse the repository at this point in the history
  • Loading branch information
ivantsepp authored and sds committed Aug 18, 2016
1 parent 21d2444 commit a229ca1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/scss_lint/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def name

# Helper for creating lint from a parse tree node
#
# @param node_or_line_or_location [Sass::Script::Tree::Node, Fixnum, SCSSLint::Location]
# @param node_or_line_or_location [Sass::Script::Tree::Node, Fixnum,
# SCSSLint::Location, Sass::Source::Position]
# @param message [String]
def add_lint(node_or_line_or_location, message)
@lints << Lint.new(self,
Expand Down Expand Up @@ -165,6 +166,8 @@ def visit_comment(_node)
def extract_location(node_or_line_or_location)
if node_or_line_or_location.is_a?(Location)
node_or_line_or_location
elsif node_or_line_or_location.is_a?(Sass::Source::Position)
Location.new(node_or_line_or_location.line, node_or_line_or_location.offset)
elsif node_or_line_or_location.respond_to?(:source_range) &&
node_or_line_or_location.source_range
location_from_range(node_or_line_or_location.source_range)
Expand Down
3 changes: 2 additions & 1 deletion lib/scss_lint/linter/space_after_comma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def check_commas_after_args(args, arg_type)
next if char == "\n" || # Ignore trailing spaces
valid_spaces_after_comma?(spaces)

add_lint comma_position, "Commas in #{arg_type} should be followed by a single space"
style_message = config['style'].tr('_', ' ')
add_lint comma_position, "Commas in #{arg_type} should be followed by #{style_message}"
end
end

Expand Down
49 changes: 49 additions & 0 deletions spec/scss_lint/linter/space_after_comma_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,30 @@

it { should report_lint line: 4 }
end

context 'column number' do
let(:scss) { <<-SCSS }
p {
property: $a,$b;
}
SCSS

it 'is the correct column' do
subject.lints.first.location.column.should == 15
end
end

context 'linter message' do
let(:scss) { <<-SCSS }
p {
property: $a,$b;
}
SCSS

it 'specifies the style' do
subject.lints.first.description.should == 'Commas in lists should be followed by one space'
end
end
end

context 'when more than one space is preferred' do
Expand Down Expand Up @@ -745,6 +769,19 @@
it { should_not report_lint }
end
end

context 'linter message' do
let(:scss) { <<-SCSS }
p {
property: $a,$b;
}
SCSS

it 'specifies the style' do
subject.lints.first.description.should ==
'Commas in lists should be followed by at least one space'
end
end
end

context 'when no space is preferred' do
Expand Down Expand Up @@ -1078,5 +1115,17 @@
it { should_not report_lint }
end
end

context 'linter message' do
let(:scss) { <<-SCSS }
p {
property: $a, $b;
}
SCSS

it 'specifies the style' do
subject.lints.first.description.should == 'Commas in lists should be followed by no space'
end
end
end
end

0 comments on commit a229ca1

Please sign in to comment.