@projectwallace/css-code-coverage 0.8.2 → 0.9.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/dist/cli.js CHANGED
@@ -142,10 +142,35 @@ async function read(coverage_dir) {
142
142
  function indent(line) {
143
143
  return (line || "").replace(/^\t+/, (tabs) => " ".repeat(tabs.length * 4));
144
144
  }
145
- let line_number = (num, covered = true) => `${num.toString().padStart(5, " ")} ${covered ? "" : "━"} `;
145
+ let line_number = (num) => `${num.toString().padStart(5, " ")} │ `;
146
146
  function percentage(ratio, decimals = 2) {
147
147
  return `${(ratio * 100).toFixed(ratio === 1 ? 0 : decimals)}%`;
148
148
  }
149
+ function highlight(css, styleText$1) {
150
+ if (css.trim().startsWith("@")) {
151
+ let at_pos = css.indexOf("@");
152
+ let space_pos = css.indexOf(" ", at_pos);
153
+ let name = css.slice(0, space_pos);
154
+ let is_empty = css.endsWith("{}");
155
+ let prelude = css.slice(space_pos, is_empty ? -2 : -1);
156
+ return [
157
+ styleText$1("blueBright", name),
158
+ styleText$1("magentaBright", prelude),
159
+ is_empty ? "{}" : "{"
160
+ ].join("");
161
+ }
162
+ if (css.includes(":") && css.endsWith(";")) return [
163
+ styleText$1("cyanBright", css.slice(0, css.indexOf(":"))),
164
+ ":",
165
+ css.slice(css.indexOf(":") + 1, css.length - 1),
166
+ ";"
167
+ ].join("");
168
+ if (css.endsWith("{}")) return [styleText$1("greenBright", css.slice(0, -2)), "{}"].join("");
169
+ if (css.endsWith("}")) return css;
170
+ if (css.trim() === "") return css;
171
+ if (css.endsWith(",")) return [styleText$1("greenBright", css.slice(0, -1)), ","].join("");
172
+ return [styleText$1("greenBright", css.slice(0, -1)), "{"].join("");
173
+ }
149
174
  function print_lines({ report, context }, params, { styleText: styleText$1, print_width }) {
150
175
  let output = [];
151
176
  if (report.min_line_coverage.ok) output.push(`${styleText$1(["bold", "green"], "Success")}: total line coverage is ${percentage(report.min_line_coverage.actual)}`);
@@ -173,7 +198,7 @@ function print_lines({ report, context }, params, { styleText: styleText$1, prin
173
198
  for (let sheet of context.coverage.coverage_per_stylesheet.sort((a, b) => a.line_coverage_ratio - b.line_coverage_ratio)) if (sheet.line_coverage_ratio !== 1 && params["show-uncovered"] === "all" || min_file_line_coverage !== void 0 && min_file_line_coverage !== 0 && sheet.line_coverage_ratio < min_file_line_coverage && params["show-uncovered"] === "violations") {
174
199
  output.push();
175
200
  output.push(styleText$1("dim", "─".repeat(print_width)));
176
- output.push(sheet.url);
201
+ output.push(`File: ${sheet.url}`);
177
202
  output.push(`Coverage: ${percentage(sheet.line_coverage_ratio)}, ${sheet.covered_lines}/${sheet.total_lines} lines covered`);
178
203
  if (min_file_line_coverage && min_file_line_coverage !== 0 && sheet.line_coverage_ratio < min_file_line_coverage) {
179
204
  let lines_to_cover = min_file_line_coverage * sheet.total_lines - sheet.covered_lines;
@@ -182,10 +207,22 @@ function print_lines({ report, context }, params, { styleText: styleText$1, prin
182
207
  output.push(styleText$1("dim", "─".repeat(print_width)));
183
208
  let lines = sheet.text.split("\n");
184
209
  for (let chunk of sheet.chunks.filter((chunk$1) => !chunk$1.is_covered)) {
185
- for (let x = Math.max(chunk.start_line - NUM_LEADING_LINES, 1); x < chunk.start_line; x++) output.push([styleText$1("dim", line_number(x)), styleText$1("dim", indent(lines[x - 1]))].join(""));
186
- for (let i = chunk.start_line; i <= chunk.end_line; i++) output.push([styleText$1("red", line_number(i, false)), indent(lines[i - 1])].join(""));
187
- for (let y = chunk.end_line + 1; y < Math.min(chunk.end_line + NUM_TRAILING_LINES, lines.length); y++) output.push([styleText$1("dim", line_number(y)), styleText$1("dim", indent(lines[y - 1]))].join(""));
188
- output.push();
210
+ for (let x = Math.max(chunk.start_line - NUM_LEADING_LINES, 1); x < chunk.start_line; x++) output.push([
211
+ " ",
212
+ styleText$1("dim", line_number(x)),
213
+ styleText$1("dim", indent(lines[x - 1]))
214
+ ].join(""));
215
+ for (let i = chunk.start_line; i <= chunk.end_line; i++) output.push([
216
+ styleText$1("red", "▌"),
217
+ styleText$1("dim", line_number(i)),
218
+ highlight(indent(lines[i - 1]), styleText$1)
219
+ ].join(""));
220
+ for (let y = chunk.end_line + 1; y < Math.min(chunk.end_line + NUM_TRAILING_LINES + 1, lines.length); y++) output.push([
221
+ " ",
222
+ styleText$1("dim", line_number(y)),
223
+ styleText$1("dim", indent(lines[y - 1]))
224
+ ].join(""));
225
+ output.push("");
189
226
  }
190
227
  }
191
228
  }
@@ -218,7 +255,7 @@ function meta(data) {
218
255
  for (let key in data) console.log(` ${key}: ${data[key]}`);
219
256
  console.log(" ...");
220
257
  }
221
- function print$1({ report, context }, params) {
258
+ function print$1({ report, context }, _params) {
222
259
  let total_files = context.coverage.coverage_per_stylesheet.length;
223
260
  let total_checks = total_files + 1;
224
261
  let checks_added = 1;
package/dist/index.js CHANGED
@@ -199,7 +199,7 @@ var DOMParser = class {
199
199
  styles.push({ textContent: text });
200
200
  pos = close + 8;
201
201
  }
202
- return { querySelectorAll(selector) {
202
+ return { querySelectorAll(_selector) {
203
203
  return styles;
204
204
  } };
205
205
  }
package/package.json CHANGED
@@ -1,62 +1,63 @@
1
1
  {
2
- "name": "@projectwallace/css-code-coverage",
3
- "version": "0.8.2",
4
- "description": "Generate useful CSS Code Coverage report from browser-reported coverage",
5
- "author": "Bart Veneman <bart@projectwallace.com>",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/projectwallace/css-code-coverage.git"
9
- },
10
- "issues": "https://github.com/projectwallace/css-code-coverage/issues",
11
- "homepage": "https://github.com/projectwallace/css-code-coverage",
12
- "keywords": [
13
- "css",
14
- "code",
15
- "coverage",
16
- "testing",
17
- "used",
18
- "unused",
19
- "dead",
20
- "styles"
21
- ],
22
- "license": "EUPL-1.2",
23
- "engines": {
24
- "node": ">=20"
25
- },
26
- "type": "module",
27
- "files": [
28
- "dist"
29
- ],
30
- "bin": {
31
- "css-coverage": "dist/cli.js"
32
- },
33
- "main": "dist/index.js",
34
- "exports": {
35
- "types": "./dist/index.d.ts",
36
- "default": "./dist/index.js"
37
- },
38
- "types": "dist/index.d.ts",
39
- "scripts": {
40
- "test": "c8 --reporter=text --reporter=lcov playwright test",
41
- "build": "tsdown",
42
- "check": "tsc --noEmit",
43
- "lint": "oxlint --config .oxlintrc.json",
44
- "lint-package": "publint",
45
- "knip": "knip"
46
- },
47
- "devDependencies": {
48
- "@codecov/vite-plugin": "^1.9.1",
49
- "@playwright/test": "^1.56.0",
50
- "@types/node": "^24.9.2",
51
- "c8": "^10.1.3",
52
- "knip": "^5.66.4",
53
- "oxlint": "^1.22.0",
54
- "publint": "^0.3.14",
55
- "tsdown": "^0.15.8",
56
- "typescript": "^5.9.3"
57
- },
58
- "dependencies": {
59
- "@projectwallace/format-css": "^2.1.1",
60
- "valibot": "^1.1.0"
61
- }
2
+ "name": "@projectwallace/css-code-coverage",
3
+ "version": "0.9.0",
4
+ "description": "Generate useful CSS Code Coverage report from browser-reported coverage",
5
+ "author": "Bart Veneman <bart@projectwallace.com>",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/projectwallace/css-code-coverage.git"
9
+ },
10
+ "issues": "https://github.com/projectwallace/css-code-coverage/issues",
11
+ "homepage": "https://github.com/projectwallace/css-code-coverage",
12
+ "keywords": [
13
+ "css",
14
+ "code",
15
+ "coverage",
16
+ "testing",
17
+ "used",
18
+ "unused",
19
+ "dead",
20
+ "styles"
21
+ ],
22
+ "license": "EUPL-1.2",
23
+ "engines": {
24
+ "node": ">=20"
25
+ },
26
+ "type": "module",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "bin": {
31
+ "css-coverage": "dist/cli.js"
32
+ },
33
+ "main": "dist/index.js",
34
+ "exports": {
35
+ "types": "./dist/index.d.ts",
36
+ "default": "./dist/index.js"
37
+ },
38
+ "types": "dist/index.d.ts",
39
+ "scripts": {
40
+ "test": "c8 --reporter=text --reporter=lcov playwright test",
41
+ "build": "tsdown",
42
+ "check": "tsc --noEmit",
43
+ "lint": "oxlint --config .oxlintrc.json",
44
+ "lint-package": "publint",
45
+ "knip": "knip"
46
+ },
47
+ "devDependencies": {
48
+ "@codecov/vite-plugin": "^1.9.1",
49
+ "@playwright/test": "^1.57.0",
50
+ "@projectwallace/preset-oxlint": "^0.0.7",
51
+ "@types/node": "^25.0.3",
52
+ "c8": "^10.1.3",
53
+ "knip": "^5.82.0",
54
+ "oxlint": "^1.39.0",
55
+ "publint": "^0.3.16",
56
+ "tsdown": "^0.15.8",
57
+ "typescript": "^5.9.3"
58
+ },
59
+ "dependencies": {
60
+ "@projectwallace/format-css": "^2.2.0",
61
+ "valibot": "^1.2.0"
62
+ }
62
63
  }