Skip to content

Commit

Permalink
feat: Report ranges for diagnostics (#358)
Browse files Browse the repository at this point in the history
* feat: Report ranges for diagnostics

* update snap

* update changelog

* update stylelint

* Fixes server/modules/formatter tests (#450)

Fix copied from original PR

https://github.com/stylelint/vscode-stylelint/pull/426/files#diff-f2680deb1906c0920d4e4b4f73879a32a741ed4288aabb2a218a2eef48f38211

* update snapshot

* update snapshot

* fix

* fix: test cases

---------

Co-authored-by: yosuke ota <[email protected]>
Co-authored-by: Chema Balsas <[email protected]>
  • Loading branch information
3 people authored Oct 31, 2023
1 parent 239512c commit 5ef089f
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 77 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Language server can now be restarted with the "Restart Stylelint Server" command ([#339](https://github.com/stylelint/vscode-stylelint/pull/339)).
- The warning shown for unsupported versions of Stylelint will now be shown in any workspace with a locally installed copy of Stylelint, regardless of the file type of the open file ([#340](https://github.com/stylelint/vscode-stylelint/pull/340)).
- Language server can now be disposed with `server.dispose()` and is disposed when receiving the shutdown LSP notification ([#326](https://github.com/stylelint/vscode-stylelint/pull/326)).
- Add support for range warnings ([#358](https://github.com/stylelint/vscode-stylelint/pull/358)).

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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
14 changes: 14 additions & 0 deletions test/e2e/__tests__/__snapshots__/code-actions.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ exports[`Code actions should disable rules for a specific line with a comment on
"
`;

exports[`Code actions should disable rules for a specific line with a comment on the same line 2`] = `
"#!/usr/bin/env node
/* stylelint-disable color-no-invalid-hex */
/* eslint-disable node/shebang */
'use strict';
const css = css\`
.foo {
color: #00;
}
\`;
"
`;

exports[`Code actions should disable rules for an entire file 1`] = `
"/* stylelint-disable indentation */
a {
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": "Disable for \\"indentation\\" is missing a description",
"range": Object {
"end": Object {
"character": 5,
"character": 48,
"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
Loading

0 comments on commit 5ef089f

Please sign in to comment.