From 1a305347487bbeb3c45ef94a9dbd78e3bd687a26 Mon Sep 17 00:00:00 2001 From: Tony Ross Date: Fri, 22 Feb 2019 11:38:06 -0600 Subject: [PATCH] Fix: Off-by-one error with hint-css-prefix-order 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. --- packages/hint-css-prefix-order/src/hint.ts | 11 ++++- packages/hint-css-prefix-order/tests/tests.ts | 40 +++++++++---------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/packages/hint-css-prefix-order/src/hint.ts b/packages/hint-css-prefix-order/src/hint.ts index 39cb1150d0e..c4008c16fd3 100644 --- a/packages/hint-css-prefix-order/src/hint.ts +++ b/packages/hint-css-prefix-order/src/hint.ts @@ -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 }; diff --git a/packages/hint-css-prefix-order/tests/tests.ts b/packages/hint-css-prefix-order/tests/tests.ts index aa945c92d95..9f80876746a 100644 --- a/packages/hint-css-prefix-order/tests/tests.ts +++ b/packages/hint-css-prefix-order/tests/tests.ts @@ -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') @@ -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') @@ -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 } } ], @@ -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 } } ], @@ -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') @@ -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') @@ -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') @@ -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')