rintenki-lsp-server 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/server.js +53 -20
  2. package/package.json +2 -2
package/dist/server.js CHANGED
@@ -68,11 +68,20 @@ function toLspDiagnostic(d) {
68
68
  severity: toDiagnosticSeverity(d.severity),
69
69
  source: "rintenki",
70
70
  code: d.rule,
71
- message: d.message,
71
+ message: d.hint ? `${d.message}\nhint: ${d.hint}` : d.message,
72
72
  data: { fixable: d.fixable },
73
73
  };
74
74
  }
75
75
  const SUPPORTED_LANGUAGES = ["html", "vue", "erb", "javascriptreact", "typescriptreact"];
76
+ const FIXABLE_RULES = [
77
+ "case-sensitive-tag-name",
78
+ "case-sensitive-attr-name",
79
+ "attr-value-quotes",
80
+ "no-boolean-attr-value",
81
+ "no-default-value",
82
+ "character-reference",
83
+ "doctype",
84
+ ];
76
85
  function validateDocument(document) {
77
86
  if (!SUPPORTED_LANGUAGES.includes(document.languageId)) {
78
87
  return;
@@ -113,27 +122,51 @@ connection.onCodeAction((params) => {
113
122
  if (fixableDiagnostics.length === 0)
114
123
  return [];
115
124
  const text = document.getText();
116
- const fixResult = (0, rintenki_1.fix)(text, config);
117
- if (fixResult.fixedCount === 0)
118
- return [];
119
125
  const lastLine = Math.max(document.lineCount - 1, 0);
120
- return [
121
- {
122
- title: "Fix all auto-fixable rintenki issues",
123
- kind: node_js_1.CodeActionKind.QuickFix,
124
- diagnostics: fixableDiagnostics,
125
- edit: {
126
- changes: {
127
- [params.textDocument.uri]: [
128
- node_js_1.TextEdit.replace({
129
- start: { line: 0, character: 0 },
130
- end: { line: lastLine, character: Number.MAX_SAFE_INTEGER },
131
- }, fixResult.output),
132
- ],
126
+ const fullRange = {
127
+ start: { line: 0, character: 0 },
128
+ end: { line: lastLine, character: Number.MAX_SAFE_INTEGER },
129
+ };
130
+ const actions = [];
131
+ // Per-rule Quick Fix actions
132
+ const ruleNames = [...new Set(fixableDiagnostics.map((d) => d.code))];
133
+ for (const rule of ruleNames) {
134
+ const ruleDiagnostics = fixableDiagnostics.filter((d) => d.code === rule);
135
+ // Create a config that only enables this specific rule for fixing
136
+ const ruleOnlyConfig = {
137
+ rules: Object.fromEntries(FIXABLE_RULES.map((r) => [r, r === rule ? (config?.rules?.[r] ?? true) : "off"])),
138
+ };
139
+ const fixResult = (0, rintenki_1.fix)(text, ruleOnlyConfig);
140
+ if (fixResult.fixedCount > 0) {
141
+ actions.push({
142
+ title: `Fix: ${rule}`,
143
+ kind: node_js_1.CodeActionKind.QuickFix,
144
+ diagnostics: ruleDiagnostics,
145
+ edit: {
146
+ changes: {
147
+ [params.textDocument.uri]: [node_js_1.TextEdit.replace(fullRange, fixResult.output)],
148
+ },
133
149
  },
134
- },
135
- },
136
- ];
150
+ });
151
+ }
152
+ }
153
+ // Fix all action
154
+ if (ruleNames.length > 1) {
155
+ const fixResult = (0, rintenki_1.fix)(text, config);
156
+ if (fixResult.fixedCount > 0) {
157
+ actions.push({
158
+ title: "Fix all auto-fixable rintenki issues",
159
+ kind: node_js_1.CodeActionKind.QuickFix,
160
+ diagnostics: fixableDiagnostics,
161
+ edit: {
162
+ changes: {
163
+ [params.textDocument.uri]: [node_js_1.TextEdit.replace(fullRange, fixResult.output)],
164
+ },
165
+ },
166
+ });
167
+ }
168
+ }
169
+ return actions;
137
170
  });
138
171
  documents.listen(connection);
139
172
  connection.listen();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rintenki-lsp-server",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "LSP server for rintenki HTML linter",
5
5
  "author": "Kazuhiro Kobayashi <https://github.com/kzhrk>",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "dependencies": {
27
27
  "vscode-languageserver": "9.0.1",
28
28
  "vscode-languageserver-textdocument": "1.0.12",
29
- "rintenki": "0.3.0"
29
+ "rintenki": "0.4.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "typescript": "6.0.2"