Skip to content

Commit 44fc8eb

Browse files
committed
update AGLint to v4.0.0-alpha.7 and use type guards for fix commands
- Update AGLint dependency from v4.0.0-alpha.6 to v4.0.0-alpha.7 - Update minimum supported AGLint version to v4.0.0-alpha.7 - Remove LinterSuggestion type import - Use AGLint's built-in type guards (isLinterFixCommand, isLinterSuggestions) instead of type assertions - Refactor code action handling to validate fix and suggestion types before processing
1 parent 89fbcfa commit 44fc8eb

4 files changed

Lines changed: 42 additions & 38 deletions

File tree

pnpm-lock.yaml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ packages:
44
- test/static/aglint
55

66
catalog:
7-
'@adguard/aglint': ^4.0.0-alpha.6
7+
'@adguard/aglint': ^4.0.0-alpha.7

server/src/server.ts

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import type {
1818
LinterPositionRange,
1919
LinterResult,
2020
LinterRunOptions,
21-
LinterSuggestion,
2221
} from '@adguard/aglint/linter';
2322
import { CommentMarker, type ConfigCommentRule, ConfigCommentRuleParser } from '@adguard/agtree';
2423
import debounce from 'debounce';
@@ -538,34 +537,10 @@ connection.onCodeAction((params) => {
538537

539538
if (diagnostic.data?.fix) {
540539
// eslint-disable-next-line prefer-destructuring
541-
const fix = diagnostic.data.fix as LinterFixCommand;
542-
const actionFix = CodeAction.create(`Fix AGLint rule '${code}'`, CodeActionKind.QuickFix);
540+
const fix = diagnostic.data.fix;
543541

544-
actionFix.edit = {
545-
documentChanges: [
546-
TextDocumentEdit.create(
547-
{ uri: textDocument.uri, version: textDocument.version },
548-
[
549-
convertAglintFixToVsCodeCodeEdit(
550-
textDocument,
551-
fix,
552-
),
553-
],
554-
),
555-
],
556-
};
557-
actions.push(actionFix);
558-
}
559-
560-
if (diagnostic.data?.suggestions) {
561-
// eslint-disable-next-line prefer-destructuring
562-
const suggestions: LinterSuggestion[] = diagnostic.data.suggestions;
563-
564-
for (const suggestion of suggestions) {
565-
const actionFix = CodeAction.create(
566-
`Apply suggestion '${suggestion.message}' from AGLint rule '${code}'`,
567-
CodeActionKind.QuickFix,
568-
);
542+
if (aglint?.linter.isLinterFixCommand(fix)) {
543+
const actionFix = CodeAction.create(`Fix AGLint rule '${code}'`, CodeActionKind.QuickFix);
569544

570545
actionFix.edit = {
571546
documentChanges: [
@@ -574,7 +549,7 @@ connection.onCodeAction((params) => {
574549
[
575550
convertAglintFixToVsCodeCodeEdit(
576551
textDocument,
577-
suggestion.fix as LinterFixCommand,
552+
fix,
578553
),
579554
],
580555
),
@@ -584,6 +559,35 @@ connection.onCodeAction((params) => {
584559
}
585560
}
586561

562+
if (diagnostic.data?.suggestions) {
563+
// eslint-disable-next-line prefer-destructuring
564+
const suggestions = diagnostic.data.suggestions;
565+
566+
if (aglint?.linter.isLinterSuggestions(suggestions)) {
567+
for (const suggestion of suggestions) {
568+
const actionFix = CodeAction.create(
569+
`Apply suggestion '${suggestion.message}' from AGLint rule '${code}'`,
570+
CodeActionKind.QuickFix,
571+
);
572+
573+
actionFix.edit = {
574+
documentChanges: [
575+
TextDocumentEdit.create(
576+
{ uri: textDocument.uri, version: textDocument.version },
577+
[
578+
convertAglintFixToVsCodeCodeEdit(
579+
textDocument,
580+
suggestion.fix,
581+
),
582+
],
583+
),
584+
],
585+
};
586+
actions.push(actionFix);
587+
}
588+
}
589+
}
590+
587591
// If we are here, it means that we have a linter rule name,
588592
// so we need to suggest disabling this rule for the line
589593
const action = CodeAction.create(`Disable AGLint rule '${code}' for this line`, CodeActionKind.QuickFix);

server/src/utils/aglint-loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class LoadedAglint {
119119
* Minimum version of the external AGLint module that is supported by the VSCode extension.
120120
* If the version is lower than this, the extension cannot use the external AGLint module.
121121
*/
122-
const MIN_AGLINT_VERSION = '4.0.0-alpha.4';
122+
const MIN_AGLINT_VERSION = '4.0.0-alpha.7';
123123

124124
/**
125125
* Load the installed AGLint module.

0 commit comments

Comments
 (0)