rintenki 0.1.0 → 0.2.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.
package/bin/rintenki.js CHANGED
@@ -5,6 +5,13 @@ const { resolve, relative } = require("path");
5
5
  const { glob } = require("tinyglobby");
6
6
  const { lint, fix } = require("../index");
7
7
 
8
+ let loadParser;
9
+ try {
10
+ loadParser = require("@rintenki/parser-utils").loadParser;
11
+ } catch {
12
+ loadParser = () => undefined;
13
+ }
14
+
8
15
  const COLORS = {
9
16
  red: "\x1b[31m",
10
17
  yellow: "\x1b[33m",
@@ -144,7 +151,19 @@ Examples:
144
151
  let totalFixed = 0;
145
152
 
146
153
  for (const file of files) {
147
- let html = readFileSync(file, "utf-8");
154
+ let source = readFileSync(file, "utf-8");
155
+ let lineOffset = 0;
156
+
157
+ // Preprocess non-HTML files (Vue, ERB, etc.)
158
+ const parser = loadParser(file, config?.parser);
159
+ if (parser) {
160
+ const preprocessed = parser.preprocess(source);
161
+ source = preprocessed.html;
162
+ lineOffset = preprocessed.lineOffset;
163
+ if (!source) continue;
164
+ }
165
+
166
+ let html = source;
148
167
 
149
168
  if (args.fix) {
150
169
  const fixResult = fix(html, config);
@@ -158,6 +177,13 @@ Examples:
158
177
  const result = lint(html, config);
159
178
  const rel = relative(process.cwd(), file);
160
179
 
180
+ // Remap line numbers to original file positions
181
+ if (lineOffset > 0) {
182
+ for (const d of result.diagnostics) {
183
+ if (d.line != null) d.line += lineOffset;
184
+ }
185
+ }
186
+
161
187
  for (const d of result.diagnostics) {
162
188
  if (d.severity === "error") totalErrors++;
163
189
  else totalWarnings++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rintenki",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "A fast HTML linter powered by html5ever + napi-rs",
5
5
  "author": "Kazuhiro Kobayashi <https://github.com/kzhrk>",
6
6
  "license": "MIT",
Binary file
Binary file