Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Report ranges for diagnostics #358

Merged
merged 11 commits into from
Oct 31, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Object {
"message": "Unexpected empty block (block-no-empty)",
"range": Object {
"end": Object {
"character": 3,
"character": 4,
"line": 0,
},
"start": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Object {
"message": "Expected \\"#bbbbbb\\" to be \\"#bbb\\" (color-hex-length)",
"range": Object {
"end": Object {
"character": 19,
"character": 25,
"line": 2,
},
"start": Object {
Expand Down
5 changes: 4 additions & 1 deletion src/utils/stylelint/warning-to-diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export function warningToDiagnostic(
ruleMetadata?: stylelint.LinterResult['ruleMetadata'],
): Diagnostic {
const start = Position.create(warning.line - 1, warning.column - 1);
const end = Position.create(warning.line - 1, warning.column);
const end =
typeof warning.endLine === 'number' && typeof warning.endColumn === 'number'
? Position.create(warning.endLine - 1, warning.endColumn - 1)
: Position.create(warning.line - 1, warning.column);

const ruleDocUrl = ruleMetadata?.[warning.rule]?.url;

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/__tests__/__snapshots__/config-basedir.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Array [
"message": "Expected indentation of 8 spaces (indentation)",
"range": Object {
"end": Object {
"character": 3,
"character": 14,
"line": 1,
},
"start": Object {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/__tests__/__snapshots__/config-file.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Array [
"message": "Unexpected empty block (block-no-empty)",
"range": Object {
"end": Object {
"character": 3,
"character": 4,
"line": 0,
},
"start": Object {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/__tests__/__snapshots__/ignore-disables.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Array [
"message": "Expected indentation of 4 spaces (indentation)",
"range": Object {
"end": Object {
"character": 3,
"character": 14,
"line": 3,
},
"start": Object {
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/__tests__/__snapshots__/lint.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Array [
"message": "Unexpected invalid hex color \\"#y3\\" (color-no-invalid-hex)",
"range": Object {
"end": Object {
"character": 12,
"character": 14,
"line": 6,
},
"start": Object {
Expand All @@ -45,7 +45,7 @@ Array [
"message": "Expected indentation of 4 spaces (indentation)",
"range": Object {
"end": Object {
"character": 3,
"character": 13,
"line": 2,
},
"start": Object {
Expand All @@ -69,7 +69,7 @@ Array [
"message": "Expected indentation of 4 spaces (indentation)",
"range": Object {
"end": Object {
"character": 3,
"character": 13,
"line": 2,
},
"start": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Array [
"message": "Rule \\"foo\\" isn't enabled",
"range": Object {
"end": Object {
"character": 1,
"character": 36,
"line": 0,
},
"start": Object {
Expand All @@ -23,7 +23,7 @@ Array [
"message": "Rule \\"foo\\" isn't enabled",
"range": Object {
"end": Object {
"character": 1,
"character": 31,
"line": 2,
},
"start": Object {
Expand All @@ -39,7 +39,7 @@ Array [
"message": "Rule \\"foo\\" isn't enabled",
"range": Object {
"end": Object {
"character": 1,
"character": 26,
"line": 4,
},
"start": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Array [
"message": "Needless disable for \\"indentation\\"",
"range": Object {
"end": Object {
"character": 3,
"character": 55,
"line": 2,
},
"start": Object {
Expand All @@ -23,7 +23,7 @@ Array [
"message": "Needless disable for \\"indentation\\"",
"range": Object {
"end": Object {
"character": 1,
"character": 34,
"line": 6,
},
"start": Object {
Expand All @@ -39,7 +39,7 @@ Array [
"message": "Needless disable for \\"indentation\\"",
"range": Object {
"end": Object {
"character": 17,
"character": 55,
"line": 14,
},
"start": Object {
Expand All @@ -55,7 +55,7 @@ Array [
"message": "Needless disable for \\"indentation\\"",
"range": Object {
"end": Object {
"character": 1,
"character": 34,
"line": 17,
},
"start": Object {
Expand All @@ -71,7 +71,7 @@ Array [
"message": "Needless disable for \\"unknown\\"",
"range": Object {
"end": Object {
"character": 3,
"character": 55,
"line": 2,
},
"start": Object {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/__tests__/__snapshots__/validate.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Array [
"message": "Expected indentation of 4 spaces (indentation)",
"range": Object {
"end": Object {
"character": 3,
"character": 13,
"line": 2,
},
"start": Object {
Expand Down
34 changes: 17 additions & 17 deletions test/integration/stylelint-vscode/__snapshots__/test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Array [
"message": "Unexpected unknown at-rule \\"@unknown\\" (scss/at-rule-no-unknown)",
"range": Object {
"end": Object {
"character": 1,
"character": 30,
ota-meshi marked this conversation as resolved.
Show resolved Hide resolved
"line": 0,
},
"start": Object {
Expand Down Expand Up @@ -53,7 +53,7 @@ Array [
"message": "Expected indentation of 0 tabs (indentation)",
"range": Object {
"end": Object {
"character": 3,
"character": 14,
"line": 0,
},
"start": Object {
Expand Down Expand Up @@ -203,7 +203,7 @@ Array [
"message": "Expected numeric font-weight notation (font-weight-notation)",
"range": Object {
"end": Object {
"character": 30,
"character": 33,
"line": 2,
},
"start": Object {
Expand All @@ -222,7 +222,7 @@ Array [
"message": "Expected numeric font-weight notation (font-weight-notation)",
"range": Object {
"end": Object {
"character": 7,
"character": 12,
"line": 4,
},
"start": Object {
Expand All @@ -246,8 +246,8 @@ Array [
"message": "Unexpected unit (length-zero-no-unit)",
"range": Object {
"end": Object {
"character": 11,
"line": 3,
"character": 10,
"line": 1,
},
"start": Object {
"character": 10,
Expand All @@ -271,7 +271,7 @@ Object {
"message": "Unexpected unknown type selector \\"unknown\\" (selector-type-no-unknown)",
"range": Object {
"end": Object {
"character": 1,
"character": 7,
"line": 1,
},
"start": Object {
Expand Down Expand Up @@ -327,7 +327,7 @@ Object {
"message": "Expected indentation of 2 spaces (indentation)",
"range": Object {
"end": Object {
"character": 4,
"character": 12,
"line": 1,
},
"start": Object {
Expand All @@ -350,7 +350,7 @@ Object {
"message": "Rule \\"foo\\" isn't enabled",
"range": Object {
"end": Object {
"character": 1,
"character": 36,
"line": 1,
},
"start": Object {
Expand All @@ -366,7 +366,7 @@ Object {
"message": "Rule \\"foo\\" isn't enabled",
"range": Object {
"end": Object {
"character": 1,
"character": 31,
"line": 3,
},
"start": Object {
Expand All @@ -382,7 +382,7 @@ Object {
"message": "Rule \\"foo\\" isn't enabled",
"range": Object {
"end": Object {
"character": 1,
"character": 26,
"line": 5,
},
"start": Object {
Expand All @@ -408,7 +408,7 @@ Object {
"message": "Expected indentation of 4 spaces (indentation)",
"range": Object {
"end": Object {
"character": 3,
"character": 47,
"line": 2,
},
"start": Object {
Expand All @@ -424,7 +424,7 @@ Object {
"message": "Needless disable for \\"indentation\\"",
"range": Object {
"end": Object {
"character": 3,
"character": 46,
"line": 2,
},
"start": Object {
Expand All @@ -440,7 +440,7 @@ Object {
"message": "Needless disable for \\"indentation\\"",
"range": Object {
"end": Object {
"character": 1,
"character": 34,
"line": 6,
},
"start": Object {
Expand All @@ -456,7 +456,7 @@ Object {
"message": "Needless disable for \\"indentation\\"",
"range": Object {
"end": Object {
"character": 17,
"character": 55,
"line": 13,
},
"start": Object {
Expand All @@ -472,7 +472,7 @@ Object {
"message": "Needless disable for \\"indentation\\"",
"range": Object {
"end": Object {
"character": 1,
"character": 34,
"line": 16,
},
"start": Object {
Expand Down Expand Up @@ -521,7 +521,7 @@ Object {
"message": "Expected indentation of 2 spaces (indentation)",
"range": Object {
"end": Object {
"character": 4,
"character": 12,
"line": 1,
},
"start": Object {
Expand Down