From be2c151260678320c1133a2b57182efb18d9eb38 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 15:24:52 +0000 Subject: [PATCH] chore: update @projectwallace/css-analyzer to 10.0.0 --- package.json | 4 +- pnpm-lock.yaml | 198 ++++------------------------------------- src/complexity.ts | 44 +++++---- src/index.ts | 6 +- src/maintainability.ts | 48 +++++----- src/performance.ts | 31 ++++--- src/types.ts | 37 +++++++- 7 files changed, 121 insertions(+), 247 deletions(-) diff --git a/package.json b/package.json index 54d800e..d4ef92c 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "knip": "knip" }, "dependencies": { - "@projectwallace/css-analyzer": "^9.9.5" + "@projectwallace/css-analyzer": "^10.0.0" }, "devDependencies": { "@projectwallace/preset-oxlint": "^0.0.11", @@ -64,7 +64,7 @@ "vitest": "^5.0.5" }, "engines": { - "node": ">=16.0.0", + "node": ">=22.18", "pnpm": ">=11.16.0" }, "packageManager": "pnpm@11.16.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f98374a..4bc8297 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: '@projectwallace/css-analyzer': - specifier: ^9.9.5 - version: 9.9.5 + specifier: ^10.0.0 + version: 10.0.0 devDependencies: '@projectwallace/preset-oxlint': specifier: ^0.0.11 @@ -211,9 +211,6 @@ packages: cpu: [x64] os: [win32] - '@oxc-project/types@0.154.0': - resolution: {integrity: sha512-KYOUGQFlLWR+s4QMV2Q9ko38TZm7EdO87Qm7rvZLqk/webse/cDjtyxKhg/47l0byCbs/k46LT8qc4PKjAikzA==} - '@oxc-project/types@0.155.0': resolution: {integrity: sha512-SeE8JPwW1xs1tHeNycjUtUBdhorRa8o4jlvjwk49R7/Z291i+4DQa7JJIgOm/TaYQZx+QrPQbVJ/9c8dMIZN8Q==} @@ -564,12 +561,12 @@ packages: cpu: [x64] os: [win32] - '@projectwallace/css-analyzer@9.9.5': - resolution: {integrity: sha512-HtEWI5G/flzuoptALwvx66N4Vkq+SR2W019VI1R5RIX7MOuEOjuIIx2OKC3S9NAZAKbiopKp88ZLqy5ymmaAIg==} - engines: {node: '>=18.0.0', pnpm: '>=11.0.0'} + '@projectwallace/css-analyzer@10.0.0': + resolution: {integrity: sha512-xk/hi+dvgyC4FU1ru/jvwA00ztEJWnJwp2D3SMgeqhm7Ws2a97v3Yp4zWZqYEvNWILuDPTnCuHaQmVXpEQCd8Q==} + engines: {node: '>=22.18.0', pnpm: '>=11.0.0'} - '@projectwallace/css-parser@0.19.1': - resolution: {integrity: sha512-Qtr51nlLcfE0nfR6fBtNvzdl/P+FI8hxrkOQ5xzVyb52ewoyYkDEX3zDyGYuZh5dnIZbdO0pG0I5CMiW2Y3mjg==} + '@projectwallace/css-parser@0.20.0': + resolution: {integrity: sha512-DACi18aYryfiiEs/orFYB+1aE9uPkq8DmwwOkrKZydbwqPnP0hUl+0xESnIfbld2p2zF23ufJNfBZyV3HQD0/g==} engines: {pnpm: '>=11.0.0'} '@projectwallace/preset-oxlint@0.0.11': @@ -584,85 +581,42 @@ packages: '@quansync/fs@1.1.0': resolution: {integrity: sha512-qAPG/t3HqML1TlN7sY/pTbEjzFVAKsMjNNMGheyDosro+kT4iw2KCUoHcVdmliwWjorm4elZbgNQyU2eD97eDg==} - '@rolldown/binding-android-arm-eabi@1.2.14': - resolution: {integrity: sha512-aWR+XKH9+rW7m5fWq/5360J3mHycrx/o6xZM2DQFdJnTMdyP7/WzxPjhtLbVWdKo2y612/4U1bWqb3HQhiF7vg==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [arm] - os: [android] - '@rolldown/binding-android-arm-eabi@1.2.15': resolution: {integrity: sha512-aLcgK9gIJ3YRvrrtfSBbRa27F5WrpiTaPulnFpsHPxpUHgFlSgnU4854MHwoRGEBhfRJDWCS2WQ7lIjskE9Olw==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm] os: [android] - '@rolldown/binding-android-arm64@1.2.14': - resolution: {integrity: sha512-QiVxHofl6A8lQU7WAtOUY4QMVZXohxwz7WJJoeh8NBEUyKfIkMRKhYyq8az/1RypNiIXzNTtiS6KwHz0erxYRQ==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [arm64] - os: [android] - '@rolldown/binding-android-arm64@1.2.15': resolution: {integrity: sha512-xD7DdZCrbThKuxNg7ooQmvp07ys4J/pnSEMTG3/OdOWl6daC67m/Q4fL78sRHMxTH/N4fGUbYhcPM0MF5WFHkg==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [android] - '@rolldown/binding-darwin-arm64@1.2.14': - resolution: {integrity: sha512-lTQOzHuBIooh3jIr5XINQkjPGEuGy+Dsy0meXDr6Sjty0b99kYgGh4uBC/8mJX1T0kC8d6S0aPP1Y+bHkh6aBw==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [arm64] - os: [darwin] - '@rolldown/binding-darwin-arm64@1.2.15': resolution: {integrity: sha512-m2WuQ6r0B4OTYxyPpNLtXaMRbRDUbG8YQV2Q3KTdSSK8Th6KHCnC8jVCJt8bvYeSB5WivkkNbc85mKadaSdOxA==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [darwin] - '@rolldown/binding-darwin-x64@1.2.14': - resolution: {integrity: sha512-hyMKEGatjmBYCs/Q4sbIcL/GqpFEqsX3wc+HYVQ/85A4rxc1o7rPm4DUI4GV4k/h0ITddwFSGpqQunI14GXjTA==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [x64] - os: [darwin] - '@rolldown/binding-darwin-x64@1.2.15': resolution: {integrity: sha512-5RtnsHM36nodM9WbMy+zip0LGS/G+y5wro5RHrpOlr4ac24+1zSi9kiV2MP1myZeZ/ifEHfulQcWjnAXzc2C2A==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [x64] os: [darwin] - '@rolldown/binding-freebsd-x64@1.2.14': - resolution: {integrity: sha512-u371GbXoVXrEgP20PwzoGNOdAOqAMhzo19JzzY+V4YmmnC+DTOoqdbMu+O+54emM59Mik/UdrtWgcuEDKWRPKA==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [x64] - os: [freebsd] - '@rolldown/binding-freebsd-x64@1.2.15': resolution: {integrity: sha512-g3l09pyFqhu+135JKkbkwiKGQmwU5hUMUPJ4VdBADvuqR8d33L6H578rh8m7rtxbdp+VmX/+nzI7nvhSZlzpUQ==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [x64] os: [freebsd] - '@rolldown/binding-linux-arm-gnueabihf@1.2.14': - resolution: {integrity: sha512-BqwKsdZQf6EqVWr8fv2MrDYzAvOZ7+NYFSJESRGs87fkseEhs0TU9TXgRJTkZoRRkxTizyEg1LKUXfU3/78uqg==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [arm] - os: [linux] - '@rolldown/binding-linux-arm-gnueabihf@1.2.15': resolution: {integrity: sha512-nIe3VugI97nGQtspPxDqA4sXMUpeiocKIP/CqpY/u/vgbT+alX+cVxu1C/oVBPKg4feNTmYovE91v4DgXvXNwQ==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm] os: [linux] - '@rolldown/binding-linux-arm64-gnu@1.2.14': - resolution: {integrity: sha512-SD9kY8M009x/7s57Z1dgUVlP5+uYBgKQK0Tkr1WIWngrtUJmRCW1RJFMY7QDla2khXhmg2i5Io7MUjcmZNZ/KQ==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [arm64] - os: [linux] - libc: [glibc] - '@rolldown/binding-linux-arm64-gnu@1.2.15': resolution: {integrity: sha512-iTBjXx+B5QSvgI89lJfmqh4wTh8NabR1YZIIN3hNx4zSG0EVfVqkOvLulNpG4251pbd6/IAmZ/LefVk1Y4rPhw==} engines: {node: ^20.19.0 || >=22.12.0} @@ -670,13 +624,6 @@ packages: os: [linux] libc: [glibc] - '@rolldown/binding-linux-arm64-musl@1.2.14': - resolution: {integrity: sha512-BJ2CL19M6uuWesMgnqJzgxoI+N+eV7b0A9O9vLV42y+gitC41fNa8KElau1tHVzuLWX5GzEuxMPhAO0tQXQMkg==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [arm64] - os: [linux] - libc: [musl] - '@rolldown/binding-linux-arm64-musl@1.2.15': resolution: {integrity: sha512-uN26XOnVR7rqQupG3V9oAG2EGGatWjcJHOeDOHUFCh4TBWmP2tHTFoVN13aYbwfm0aHqJAEmcwhAu6sooIjfqQ==} engines: {node: ^20.19.0 || >=22.12.0} @@ -684,13 +631,6 @@ packages: os: [linux] libc: [musl] - '@rolldown/binding-linux-ppc64-gnu@1.2.14': - resolution: {integrity: sha512-4+Kl8daPV8NDHaD7mfCcc1pRM+Qg7ab8DyMm5FG5WoZgv4h2i3KFN1CybYBNbQqmuYm7ftJLvmMI1eHYJ22S/Q==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [ppc64] - os: [linux] - libc: [glibc] - '@rolldown/binding-linux-ppc64-gnu@1.2.15': resolution: {integrity: sha512-9nWkcdd+H+XhaA3fQIwpHnKIrfx/PQ6rO0pivr78Og07tXlUlctBBJoEYLPfhTmCR/QxEVdn6uPjHV5SymPhdw==} engines: {node: ^20.19.0 || >=22.12.0} @@ -698,13 +638,6 @@ packages: os: [linux] libc: [glibc] - '@rolldown/binding-linux-s390x-gnu@1.2.14': - resolution: {integrity: sha512-V/h8ePq1fKDrmtFMz6xcCN3DKvuvMRrwwD1q0PkBeeo4DpK64biaKvqWGVxqCeYKqeRk7gE7/iKPxLCn08O97A==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [s390x] - os: [linux] - libc: [glibc] - '@rolldown/binding-linux-s390x-gnu@1.2.15': resolution: {integrity: sha512-Ggh0ciFjLwIusLSLz7LZYEaGdxOAUJXI+Qu5JCbhPJJHEt8vP+IjRATTJheiJsdzzTYgUiHUiw3X1Ea3ZpMBdA==} engines: {node: ^20.19.0 || >=22.12.0} @@ -712,13 +645,6 @@ packages: os: [linux] libc: [glibc] - '@rolldown/binding-linux-x64-gnu@1.2.14': - resolution: {integrity: sha512-WxalXzgrLVpKC93xfpaJ3gCXUWzeCr+FRCbDVD2mUAy4L6Vo3lNVz0epUEUpxPWJkLNYUwM4OSIikv36OJ9mLg==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [x64] - os: [linux] - libc: [glibc] - '@rolldown/binding-linux-x64-gnu@1.2.15': resolution: {integrity: sha512-FHg60rS6DBePAYZ9X9F67x+JObFdmgn6tupA1C/a3B+CufFmTD4mX+e8M75tCiAO3foR/6xwVBI0KQiI7sn/rw==} engines: {node: ^20.19.0 || >=22.12.0} @@ -726,13 +652,6 @@ packages: os: [linux] libc: [glibc] - '@rolldown/binding-linux-x64-musl@1.2.14': - resolution: {integrity: sha512-3G3tnAmTpdk9jO3GQtyHXqeFD2SlecfTws/Y3M2mmj9nMBwwuLT4kur8sZKeu7ENUHSpVO3cIsm5A52LEWWwlg==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [x64] - os: [linux] - libc: [musl] - '@rolldown/binding-linux-x64-musl@1.2.15': resolution: {integrity: sha512-/cvV/7v5VGz/moiz0XKRj2dE8DzsKyhIu1KpOvJGPjRywg3yscON889UGvAe8zfiJLHup7VLjBduoGWi3HusWQ==} engines: {node: ^20.19.0 || >=22.12.0} @@ -740,36 +659,18 @@ packages: os: [linux] libc: [musl] - '@rolldown/binding-openharmony-arm64@1.2.14': - resolution: {integrity: sha512-qyr5XiNGxm2ytx17vvtcJ9nXn6v1gENETi503bJx3OGwZ1tSonj7BosxbMa/xeAfSl5iS9X6KjEWYXLu6v1L7Q==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [arm64] - os: [openharmony] - '@rolldown/binding-openharmony-arm64@1.2.15': resolution: {integrity: sha512-MyzC5Hrv/sm+Z7TSGKP/j8001RO2xQm1zOpCNVL4j0cY/VhBZviludA2YFQ7i4lH6ZAXxQm0lcMdBzM+99mE7w==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [openharmony] - '@rolldown/binding-win32-arm64-msvc@1.2.14': - resolution: {integrity: sha512-oA4o5o0S2yB199YyYXDzKUv1Z56Rc+mgOjwm7Z/vJ9Z8igiDPYvoOuDyo6g7AK/ZaF09nPhDKVnGBcYHO11GXA==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [arm64] - os: [win32] - '@rolldown/binding-win32-arm64-msvc@1.2.15': resolution: {integrity: sha512-+PgYiS+AH5omy6L45ZLxybasauJaj3M8buoT83D+nzPmCayXlxUV9hydhciCKVyIg0B/v0BtXPDE1uGqNwCPpg==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [win32] - '@rolldown/binding-win32-x64-msvc@1.2.14': - resolution: {integrity: sha512-9mE94bf2GZUaR/fUSXCMpBoWkctu421Mi0ORpm4zqfbkjKep7RxzPFa5etcGs5h+2KApoWBOA/hAJa/7saGgEQ==} - engines: {node: ^20.19.0 || >=22.12.0} - cpu: [x64] - os: [win32] - '@rolldown/binding-win32-x64-msvc@1.2.15': resolution: {integrity: sha512-HFZd2QNQYn1JbIi+Hpd7H+r/lkWxcfIu28nirZ6eCn2LafuvmExMlb/P96Sfx5tf7pPArw39IdhmCF8vmV+NhQ==} engines: {node: ^20.19.0 || >=22.12.0} @@ -1277,11 +1178,6 @@ packages: vue-tsc: optional: true - rolldown@1.2.14: - resolution: {integrity: sha512-eTBTTqMR6uHKLgcUqpJP8ntzDI6V4LYA8negAMBEI7gkgVvOdrx6VsvS2Ym+83KhOPdLCHWJu0w7UQFJZhHKNw==} - engines: {node: ^20.19.0 || >=22.12.0} - hasBin: true - rolldown@1.2.15: resolution: {integrity: sha512-6odND+fel5zVw3I4Yc2e69gvguDnX0CAAGiNDZSq4ik5WUcaLrkD2GLuog0XcODbor31hZ5ayEMgVDno+KPV5g==} engines: {node: ^20.19.0 || >=22.12.0} @@ -1484,18 +1380,22 @@ packages: yuku-ast@0.19.0: resolution: {integrity: sha512-PyCsiScaelhxBGzL8dyeJkLqvRZycoh78R31Vrt/WqYrm0hMFoKwIw/X7Dx5mBKLWAMlV9I9HEyBOHnj2gZVyw==} engines: {node: '>=14.18.0'} + deprecated: 'Yuku is now one package with one core. Use "yuku" instead: https://yuku.fyi/javascript/. Existing installs keep working but get no more fixes.' yuku-codegen@0.19.0: resolution: {integrity: sha512-uymAKHjDuaP4BEpkXC/BSLz4DUEF5oArZ5AuD3888nb2miChjWSgpPdojEJxm3pjpXkgUaCRJQyNAbnMN33wHg==} engines: {node: '>=14.18.0'} + deprecated: 'Yuku is now one package with one core. Use "yuku" instead: https://yuku.fyi/javascript/. Existing installs keep working but get no more fixes.' yuku-core@0.19.0: resolution: {integrity: sha512-kYK9e1XdfirNhkipzW0wmMcSWcVF/CWnuugodfVYRCUwvoBefweL9HzB96OiKEhsx78V5WbUxbJqlizMX869Qg==} engines: {node: '>=14.18.0'} + deprecated: 'Yuku is now one package with one core. Use "yuku" instead: https://yuku.fyi/javascript/. Existing installs keep working but get no more fixes.' yuku-parser@0.19.0: resolution: {integrity: sha512-XrBh9ZiQK5mJVRxZBAvD6LwRyAYrK3MFtH3+onyuxFL5hFD44EC3QOmIC1FjTj6H2MMwq46/NAI+NZxLZPZgxg==} engines: {node: '>=14.18.0'} + deprecated: 'Yuku is now one package with one core. Use "yuku" instead: https://yuku.fyi/javascript/. Existing installs keep working but get no more fixes.' zod@4.6.7: resolution: {integrity: sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==} @@ -1606,8 +1506,6 @@ snapshots: '@oxc-parser/binding-win32-x64-msvc@0.155.0': optional: true - '@oxc-project/types@0.154.0': {} - '@oxc-project/types@0.155.0': {} '@oxc-resolver/binding-android-arm-eabi@11.24.2': @@ -1785,11 +1683,11 @@ snapshots: '@oxlint/binding-win32-x64-msvc@1.89.0': optional: true - '@projectwallace/css-analyzer@9.9.5': + '@projectwallace/css-analyzer@10.0.0': dependencies: - '@projectwallace/css-parser': 0.19.1 + '@projectwallace/css-parser': 0.20.0 - '@projectwallace/css-parser@0.19.1': {} + '@projectwallace/css-parser@0.20.0': {} '@projectwallace/preset-oxlint@0.0.11(oxlint@1.89.0)': dependencies: @@ -1803,93 +1701,48 @@ snapshots: dependencies: quansync: 1.0.0 - '@rolldown/binding-android-arm-eabi@1.2.14': - optional: true - '@rolldown/binding-android-arm-eabi@1.2.15': optional: true - '@rolldown/binding-android-arm64@1.2.14': - optional: true - '@rolldown/binding-android-arm64@1.2.15': optional: true - '@rolldown/binding-darwin-arm64@1.2.14': - optional: true - '@rolldown/binding-darwin-arm64@1.2.15': optional: true - '@rolldown/binding-darwin-x64@1.2.14': - optional: true - '@rolldown/binding-darwin-x64@1.2.15': optional: true - '@rolldown/binding-freebsd-x64@1.2.14': - optional: true - '@rolldown/binding-freebsd-x64@1.2.15': optional: true - '@rolldown/binding-linux-arm-gnueabihf@1.2.14': - optional: true - '@rolldown/binding-linux-arm-gnueabihf@1.2.15': optional: true - '@rolldown/binding-linux-arm64-gnu@1.2.14': - optional: true - '@rolldown/binding-linux-arm64-gnu@1.2.15': optional: true - '@rolldown/binding-linux-arm64-musl@1.2.14': - optional: true - '@rolldown/binding-linux-arm64-musl@1.2.15': optional: true - '@rolldown/binding-linux-ppc64-gnu@1.2.14': - optional: true - '@rolldown/binding-linux-ppc64-gnu@1.2.15': optional: true - '@rolldown/binding-linux-s390x-gnu@1.2.14': - optional: true - '@rolldown/binding-linux-s390x-gnu@1.2.15': optional: true - '@rolldown/binding-linux-x64-gnu@1.2.14': - optional: true - '@rolldown/binding-linux-x64-gnu@1.2.15': optional: true - '@rolldown/binding-linux-x64-musl@1.2.14': - optional: true - '@rolldown/binding-linux-x64-musl@1.2.15': optional: true - '@rolldown/binding-openharmony-arm64@1.2.14': - optional: true - '@rolldown/binding-openharmony-arm64@1.2.15': optional: true - '@rolldown/binding-win32-arm64-msvc@1.2.14': - optional: true - '@rolldown/binding-win32-arm64-msvc@1.2.15': optional: true - '@rolldown/binding-win32-x64-msvc@1.2.14': - optional: true - '@rolldown/binding-win32-x64-msvc@1.2.15': optional: true @@ -2307,27 +2160,6 @@ snapshots: transitivePeerDependencies: - oxc-resolver - rolldown@1.2.14: - dependencies: - '@oxc-project/types': 0.154.0 - '@rolldown/pluginutils': 1.0.1 - optionalDependencies: - '@rolldown/binding-android-arm-eabi': 1.2.14 - '@rolldown/binding-android-arm64': 1.2.14 - '@rolldown/binding-darwin-arm64': 1.2.14 - '@rolldown/binding-darwin-x64': 1.2.14 - '@rolldown/binding-freebsd-x64': 1.2.14 - '@rolldown/binding-linux-arm-gnueabihf': 1.2.14 - '@rolldown/binding-linux-arm64-gnu': 1.2.14 - '@rolldown/binding-linux-arm64-musl': 1.2.14 - '@rolldown/binding-linux-ppc64-gnu': 1.2.14 - '@rolldown/binding-linux-s390x-gnu': 1.2.14 - '@rolldown/binding-linux-x64-gnu': 1.2.14 - '@rolldown/binding-linux-x64-musl': 1.2.14 - '@rolldown/binding-openharmony-arm64': 1.2.14 - '@rolldown/binding-win32-arm64-msvc': 1.2.14 - '@rolldown/binding-win32-x64-msvc': 1.2.14 - rolldown@1.2.15: dependencies: '@oxc-project/types': 0.155.0 @@ -2441,7 +2273,7 @@ snapshots: lightningcss: 1.33.0 picomatch: 4.0.7 postcss: 8.5.31 - rolldown: 1.2.14 + rolldown: 1.2.15 tinyglobby: 0.2.17 optionalDependencies: fsevents: 2.3.3 diff --git a/src/complexity.ts b/src/complexity.ts index e598108..b0e18f7 100644 --- a/src/complexity.ts +++ b/src/complexity.ts @@ -1,18 +1,22 @@ -import { type Specificity } from '@projectwallace/css-analyzer' -import { compareSpecificity } from '@projectwallace/css-analyzer/selectors' -import type { Analysis, Guard } from './types.js' +import { summarize_numbers } from '@projectwallace/css-analyzer' +import { summarize_specificity } from '@projectwallace/css-analyzer/collectors' +import { compare_specificity, type Specificity } from '@projectwallace/css-analyzer/selectors' +import { items, type Analysis, type Guard } from './types.js' + +const parse_specificity = (s: string) => s.split(',').map(Number) as Specificity export const guards: Guard[] = [ // Complexity per Selector should not differ too much from the most common Complexity (result: Analysis) => { - const mode = result.selectors.complexity.mode - const selectorsAboveMode = result.selectors.complexity.items.filter((c) => c > mode).length + const complexities = items(result.selectors.complexity) + const mode = summarize_numbers(result.selectors.complexity).mode + const selectorsAboveMode = complexities.filter((c) => c > mode).length const outcome = { id: 'MoreThanMostCommonSelectorComplexity', score: 0, value: result.selectors.total === 0 ? 0 : selectorsAboveMode / result.selectors.total, - actuals: result.selectors.complexity.items, + actuals: complexities, } if (selectorsAboveMode > result.selectors.total * 0.1) { @@ -25,15 +29,15 @@ export const guards: Guard[] = [ // Specificity per Selector should not differ too much from the most common Specificity (result: Analysis) => { - const mode = result.selectors.specificity.mode as Specificity - const items = result.selectors.specificity.items - const selectorsAboveMode = items.filter((c) => compareSpecificity(c, mode) > 0).length + const mode = summarize_specificity(result.specificity).mode + const all = items(result.specificity).map((s) => parse_specificity(s)) + const selectorsAboveMode = all.filter((c) => compare_specificity(c, mode) > 0).length const outcome = { id: 'MoreThanMostCommonSelectorSpecificity', score: 0, value: result.selectors.total === 0 ? 0 : selectorsAboveMode / result.selectors.total, - actuals: result.selectors.specificity.items, + actuals: all, } if (selectorsAboveMode > result.selectors.total * 0.1) { @@ -47,13 +51,13 @@ export const guards: Guard[] = [ // Maximum Selector Complexity should be low (result: Analysis) => { const MAX_SELECTOR_COMPLEXITY = 5 - const actual = result.selectors.complexity.max + const { max: actual } = summarize_numbers(result.selectors.complexity) const outcome = { id: 'MaxSelectorComplexity', score: 0, - value: result.selectors.complexity.max, - actuals: result.selectors.complexity.items, + value: actual, + actuals: items(result.selectors.complexity), } // Deduct 0.5 points per complexity over 5, up to 5 points @@ -68,13 +72,13 @@ export const guards: Guard[] = [ // Average Selector Complexity should be low (result: Analysis) => { const ALLOWED_COMPLEXITY = 2 - const actual = result.selectors.complexity.mean + const actual = summarize_numbers(result.selectors.complexity).mean const outcome = { id: 'AverageSelectorComplexity', score: 0, value: actual, - actuals: result.selectors.complexity.items, + actuals: items(result.selectors.complexity), } // Deduct 2 points per selector over 2 @@ -88,12 +92,13 @@ export const guards: Guard[] = [ (result: Analysis) => { const ALLOWED = 0.01 - const actual = result.selectors.id.ratio + const actual = + result.selectors.total === 0 ? 0 : result.selectors.ids.total / result.selectors.total const outcome = { id: 'IdSelectorRatio', score: 0, value: actual, - actuals: Object.keys(result.selectors.id.unique), + actuals: [...result.selectors.ids.unique.keys()], } if (actual > ALLOWED) { @@ -106,7 +111,10 @@ export const guards: Guard[] = [ (result: Analysis) => { const ALLOWED = 0.01 - const actual = result.declarations.importants.ratio + const actual = + result.declarations.total === 0 + ? 0 + : result.declarations.importants.total / result.declarations.total const outcome = { id: 'ImportantRatio', score: 0, diff --git a/src/index.ts b/src/index.ts index 50cd667..a81fbce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,7 @@ import { analyze } from '@projectwallace/css-analyzer' import { calculate as calculateFromAnalysis } from './core.js' +import { collectors } from './types.js' export function calculate(css: string): ReturnType { - const analysis = analyze(css) - // @ts-expect-error ReturnType resolves to the last overload (useLocations:true) - // but we call without options (useLocations:false). Guards only access common fields, so this is safe. - return calculateFromAnalysis(analysis) + return calculateFromAnalysis(analyze(css, collectors)) } diff --git a/src/maintainability.ts b/src/maintainability.ts index 2648d45..665e4f3 100644 --- a/src/maintainability.ts +++ b/src/maintainability.ts @@ -1,4 +1,5 @@ -import type { Analysis, Guard } from './types.js' +import { summarize_numbers } from '@projectwallace/css-analyzer' +import { items, type Analysis, type Guard } from './types.js' export const guards: Guard[] = [ // Source Lines of Code should be low @@ -6,12 +7,12 @@ export const guards: Guard[] = [ const outcome = { id: 'SourceLinesOfCode', score: 0, - value: result.stylesheet.sourceLinesOfCode, + value: result.stylesheet.source_lines_of_code, } - if (result.stylesheet.sourceLinesOfCode > 10000) { + if (result.stylesheet.source_lines_of_code > 10000) { // deduct 1 point per 1000 lines of code over 10,000 - const score = Math.floor((result.stylesheet.sourceLinesOfCode - 10000) / 1000) + const score = Math.floor((result.stylesheet.source_lines_of_code - 10000) / 1000) outcome.score = Math.min(15, score) } @@ -21,13 +22,13 @@ export const guards: Guard[] = [ // Average count of Selectors per RuleSet should be low (result: Analysis) => { const ALLOWED_SELECTORS_PER_RULESET = 2 - const actual = result.rules.selectors.mean + const actual = summarize_numbers(result.rules.selectors).mean const outcome = { id: 'AverageSelectorsPerRule', score: 0, value: actual, - actuals: result.rules.selectors.items, + actuals: items(result.rules.selectors), } // Deduct 5 points per selector over 2 @@ -43,18 +44,17 @@ export const guards: Guard[] = [ (result: Analysis) => { const ALLOWED_DECLARATIONS_PER_RULESET = 5 + const mean = summarize_numbers(result.rules.declarations).mean const outcome = { id: 'AverageDeclarationsPerRule', score: 0, - value: result.rules.declarations.mean, - actuals: result.rules.declarations.items, + value: mean, + actuals: items(result.rules.declarations), } // Deduct 5 points per declaration over 5 - if (result.rules.declarations.mean > ALLOWED_DECLARATIONS_PER_RULESET) { - const score = Math.floor( - (result.rules.declarations.mean - ALLOWED_DECLARATIONS_PER_RULESET) * 5, - ) + if (mean > ALLOWED_DECLARATIONS_PER_RULESET) { + const score = Math.floor((mean - ALLOWED_DECLARATIONS_PER_RULESET) * 5) outcome.score = Math.min(15, score) } @@ -64,13 +64,13 @@ export const guards: Guard[] = [ // Max number of Selectors per Rule should be low (result: Analysis) => { const MAX_SELECTORS_PER_RULESET = 10 - const max = result.rules.selectors.max + const max = summarize_numbers(result.rules.selectors).max const outcome = { id: 'MaxSelectorsPerRule', score: 0, value: max, - actuals: result.rules.selectors.items, + actuals: items(result.rules.selectors), } // Deduct 0.5 points per selectors over 10 @@ -85,13 +85,13 @@ export const guards: Guard[] = [ // Max number of Declarations per Rule should be low (result: Analysis) => { const MAX_DECLARATIONS_PER_RULESET = 10 - const max = result.rules.declarations.max || 0 + const max = summarize_numbers(result.rules.declarations).max || 0 const outcome = { id: 'MaxDeclarationsPerRule', score: 0, value: max, - actuals: result.rules.declarations.items, + actuals: items(result.rules.declarations), } // Deduct 0.5 points per declarations over 10 @@ -106,16 +106,16 @@ export const guards: Guard[] = [ // Number of Selectors per RuleSet should not differ too much from the most common amount of // Selectors per RuleSet (result: Analysis) => { - const mode = result.rules.selectors.mode - const rulesHavingMoreThanMode = result.rules.selectors.items.filter( + const mode = summarize_numbers(result.rules.selectors).mode + const rulesHavingMoreThanMode = items(result.rules.selectors).filter( (item) => item > mode, ).length const outcome = { id: 'MoreThanMostCommonSelectorsPerRule', score: 0, - value: result.rules.selectors.mode, - actuals: result.rules.selectors.items, + value: mode, + actuals: items(result.rules.selectors), } // if more than 10% of RuleSets has more Selectors than most common: @@ -132,16 +132,16 @@ export const guards: Guard[] = [ // Number of Declarations per RuleSet should not differ too much from the most common amount of // Declarations per RuleSet (result: Analysis) => { - const mode = result.rules.selectors.mode - const rulesHavingMoreThanMode = result.rules.declarations.items.filter( + const mode = summarize_numbers(result.rules.selectors).mode + const rulesHavingMoreThanMode = items(result.rules.declarations).filter( (item) => item > mode, ).length const outcome = { id: 'MoreThanMostCommonDeclarationsPerRule', score: 0, - value: result.rules.declarations.mode, - actuals: result.rules.declarations.items, + value: summarize_numbers(result.rules.declarations).mode, + actuals: items(result.rules.declarations), } // if more than 10% of RuleSets has more Declarations than most common: diff --git a/src/performance.ts b/src/performance.ts index 6bc51bb..17177d2 100644 --- a/src/performance.ts +++ b/src/performance.ts @@ -1,19 +1,22 @@ +import { summarize } from '@projectwallace/css-analyzer' import type { Analysis, Guard } from './types.js' +const uniqueness = (counts: Parameters[0]) => summarize(counts).uniqueness_ratio + export const guards: Guard[] = [ // Should not contain @import rules (result: Analysis) => ({ id: 'Imports', - score: result.atrules.import.total * 10, - value: result.atrules.import.total, - actuals: Object.keys(result.atrules.import.unique), + score: result.atrules.imports.total * 10, + value: result.atrules.imports.total, + actuals: [...result.atrules.imports.unique.keys()], }), // Should not contain empty rules (result: Analysis) => ({ id: 'EmptyRules', - score: result.rules.empty.total, - value: result.rules.empty.total, + score: result.rules.empty, + value: result.rules.empty, }), // Too many selectors appear multiple times @@ -21,11 +24,11 @@ export const guards: Guard[] = [ const outcome = { id: 'SelectorDuplications', score: 0, - value: 1 - result.selectors.uniquenessRatio, + value: 1 - uniqueness(result.selectors), } - if (result.selectors.uniquenessRatio < 0.66) { - outcome.score = Math.floor((1 - result.selectors.uniquenessRatio) * 10) + if (uniqueness(result.selectors) < 0.66) { + outcome.score = Math.floor((1 - uniqueness(result.selectors)) * 10) } return outcome @@ -36,11 +39,11 @@ export const guards: Guard[] = [ const outcome = { id: 'DeclarationDuplications', score: 0, - value: 1 - result.declarations.uniquenessRatio, + value: 1 - uniqueness(result.declarations), } - if (result.declarations.uniquenessRatio < 0.66) { - outcome.score = Math.floor((1 - result.declarations.uniquenessRatio) * 10) + if (uniqueness(result.declarations) < 0.66) { + outcome.score = Math.floor((1 - uniqueness(result.declarations)) * 10) } return outcome @@ -67,11 +70,11 @@ export const guards: Guard[] = [ // Should not contain too much embedded content // Deduct 1 point for every 250 bytes (result: Analysis) => { - const { size } = result.stylesheet.embeddedContent + const { size } = result.stylesheet.embedded return { id: 'TooMuchEmbeddedContent', - score: Math.min(20, Math.floor(size.total / 250)), - value: size.total, + score: Math.min(20, Math.floor(size / 250)), + value: size, } }, ] diff --git a/src/types.ts b/src/types.ts index 22882cb..573c5bc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,32 @@ -import type { analyze } from '@projectwallace/css-analyzer' +import { analyze, type CountResult } from '@projectwallace/css-analyzer' +import { + atrules, + declarations, + rules, + selectors, + specificity, + stylesheet, +} from '@projectwallace/css-analyzer/collectors' -export type Analysis = ReturnType +type Collectors = { + stylesheet: ReturnType + atrules: ReturnType + rules: ReturnType + selectors: ReturnType + specificity: ReturnType + declarations: ReturnType +} + +export const collectors: Collectors = { + stylesheet: stylesheet(), + atrules: atrules(), + rules: rules(), + selectors: selectors(), + specificity: specificity(), + declarations: declarations(), +} + +export type Analysis = ReturnType> export type GuardResult = { id: string @@ -10,3 +36,10 @@ export type GuardResult = { } export type Guard = (result: Analysis) => GuardResult + +/** Expand a count result into a flat list, one entry per occurrence */ +export function items(counts: CountResult): T[] { + return [...counts.unique].flatMap(([item, { count }]) => + Array.from({ length: count }, () => item), + ) +}