Skip to content

Commit

Permalink
Fix column reporting in spaceAfterPropertyValue
Browse files Browse the repository at this point in the history
Closes #344
  • Loading branch information
jwilsson committed Jul 20, 2017
1 parent e254527 commit f966a12
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions lib/linters/space_after_property_value.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,33 @@ module.exports = {
message: 'Semicolon after property value should%s be preceded by %s space.',

lint: function spaceAfterPropertyValueLinter (config, node) {
const nodeEnd = node.source.end || {};
const nodeString = node.toString().trimRight();
const results = [];

switch (config.style) {
case 'no_space':
if (/.*\s$/.test(node.raws.important) || node.raws.value && /.*\s$/.test(node.raws.value.raw)) {
const position = node.positionBy({
index: nodeString.length
});

results.push({
column: node.source.start.column + node.prop.length + node.raws.between.length + node.value.length,
line: nodeEnd.line,
column: position.column,
line: position.line,
message: util.format(this.message, ' not', 'any')
});
}

break;
case 'one_space':
if (!/.*\s$/.test(node.raws.important) && !node.raws.value) {
const position = node.positionBy({
index: nodeString.length
});

results.push({
column: node.source.start.column + node.prop.length + node.raws.between.length + node.value.length,
line: nodeEnd.line,
column: position.column,
line: position.line,
message: util.format(this.message, '', 'one')
});
}
Expand Down
4 changes: 2 additions & 2 deletions test/specs/linters/space_after_property_value.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('lesshint', function () {
it('should not allow any space after "!important" when "style" is "no_space"', function () {
const source = '.foo { color: red !important ; }';
const expected = [{
column: 18,
column: 29,
line: 1,
message: 'Semicolon after property value should not be preceded by any space.'
}];
Expand Down Expand Up @@ -125,7 +125,7 @@ describe('lesshint', function () {
it('should not allow a missing space after "!important" when "style" is "one_space"', function () {
const source = '.foo { color: red !important; }';
const expected = [{
column: 18,
column: 29,
line: 1,
message: 'Semicolon after property value should be preceded by one space.'
}];
Expand Down

0 comments on commit f966a12

Please sign in to comment.