Skip to content

Commit

Permalink
Fix: Off-by-one error with hint-css-prefix-order
Browse files Browse the repository at this point in the history
Locations reported by `postcss` are one-based wheraes those used within
`webhint` are zero-based. The hint-compat-api already accounted for
this discrepency and now hint-css-prefix-order does as well.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Close #1955
  • Loading branch information
antross authored and molant committed Feb 22, 2019
1 parent 173e35b commit 091a3b1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
11 changes: 10 additions & 1 deletion packages/hint-css-prefix-order/src/hint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ type DeclarationPair = {

/** Convert `NodeSource` details to a `ProblemLocation`. */
const getLocation = (decl: Declaration): ProblemLocation => {
return decl.source && decl.source.start || {
const start = decl.source && decl.source.start;

if (start) {
return {
column: start.column - 1,
line: start.line - 1
};
}

return {
column: 0,
line: 0
};
Expand Down
40 changes: 20 additions & 20 deletions packages/hint-css-prefix-order/tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const tests: HintTest[] = [
reports: [{
message: `'appearance' should be listed after '-webkit-appearance'.`,
position: {
column: 5,
line: 3
column: 4,
line: 2
}
}],
serverConfig: generateConfig('interleaved-prefixes')
Expand All @@ -43,8 +43,8 @@ const tests: HintTest[] = [
reports: [{
message: `'appearance' should be listed after '-webkit-appearance'.`,
position: {
column: 5,
line: 2
column: 4,
line: 1
}
}],
serverConfig: generateConfig('mixed-with-prefixes-last')
Expand All @@ -55,15 +55,15 @@ const tests: HintTest[] = [
{
message: `'appearance' should be listed after '-webkit-appearance'.`,
position: {
column: 5,
line: 2
column: 4,
line: 1
}
},
{
message: `'appearance' should be listed after '-webkit-appearance'.`,
position: {
column: 5,
line: 8
column: 4,
line: 7
}
}
],
Expand All @@ -75,15 +75,15 @@ const tests: HintTest[] = [
{
message: `'appearance' should be listed after '-webkit-appearance'.`,
position: {
column: 5,
line: 2
column: 4,
line: 1
}
},
{
message: `'background-size' should be listed after '-moz-background-size'.`,
position: {
column: 5,
line: 5
column: 4,
line: 4
}
}
],
Expand All @@ -102,8 +102,8 @@ const tests: HintTest[] = [
reports: [{
message: `'display: grid' should be listed after 'display: -ms-grid'.`,
position: {
column: 5,
line: 2
column: 4,
line: 1
}
}],
serverConfig: generateConfig('prefixed-values-last')
Expand All @@ -121,8 +121,8 @@ const tests: HintTest[] = [
reports: [{
message: `'appearance' should be listed after '-moz-appearance'.`,
position: {
column: 5,
line: 2
column: 4,
line: 1
}
}],
serverConfig: generateConfig('prefixes-last-moz')
Expand All @@ -132,8 +132,8 @@ const tests: HintTest[] = [
reports: [{
message: `'appearance' should be listed after '-webkit-appearance'.`,
position: {
column: 12,
line: 1
column: 11,
line: 0
}
}],
serverConfig: generateConfig('prefixes-last-same-line')
Expand All @@ -143,8 +143,8 @@ const tests: HintTest[] = [
reports: [{
message: `'appearance' should be listed after '-webkit-appearance'.`,
position: {
column: 5,
line: 2
column: 4,
line: 1
}
}],
serverConfig: generateConfig('prefixes-last-webkit')
Expand Down

0 comments on commit 091a3b1

Please sign in to comment.