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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading