@nldd/design-system 0.27.0 → 0.27.1
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/custom-elements.json +32 -0
- package/dist/cdn/autoloader.js +141 -141
- package/dist/cdn/chunks/{accordion-item-D90CmJyl.js → accordion-item-Db9LW8AG.js} +4 -4
- package/dist/cdn/chunks/{accordion-DBM4AcGb.js → accordion-tLICRUFs.js} +4 -4
- package/dist/cdn/chunks/{activity-indicator-B6m9h0oa.js → activity-indicator-CMNIikEV.js} +5 -5
- package/dist/cdn/chunks/{admonition-B-YTkCjn.js → admonition-DEXVkTJm.js} +4 -4
- package/dist/cdn/chunks/{avatar-group-DW_xMwb_.js → avatar-group-DMU0HLBL.js} +15 -15
- package/dist/cdn/chunks/{avatar-CfBP9UZZ.js → avatar-nLrlfh4s.js} +6 -6
- package/dist/cdn/chunks/{badge-DnAuIhp1.js → badge-D1XadmOE.js} +5 -5
- package/dist/cdn/chunks/{banner-CRk2ARtC.js → banner-B4kFQlHx.js} +7 -7
- package/dist/cdn/chunks/{bar-split-view-DDgOYs7Z.js → bar-split-view-DtD4zmoP.js} +5 -5
- package/dist/cdn/chunks/{blockquote-DlfhBScg.js → blockquote-DbFjwox8.js} +3 -3
- package/dist/cdn/chunks/{box-DdU13yI4.js → box-BlwaDicI.js} +3 -3
- package/dist/cdn/chunks/{breadcrumbs-CqkR_6XN.js → breadcrumbs-DJS9-8wX.js} +5 -5
- package/dist/cdn/chunks/{button-muXGJHlo.js → button-BK8CmshL.js} +8 -8
- package/dist/cdn/chunks/{button-bar-BKkap9nk.js → button-bar-5RtXjgGl.js} +3 -3
- package/dist/cdn/chunks/{button-group-D-YTmErV.js → button-group-BYMkQNhT.js} +2 -2
- package/dist/cdn/chunks/{card-Dvqz83fC.js → card-NNl0PxBY.js} +4 -4
- package/dist/cdn/chunks/{cell-C0O8tZbX.js → cell-D2NzCBVZ.js} +6 -6
- package/dist/cdn/chunks/{checkbox-CNWROiHV.js → checkbox-CXFA_up4.js} +5 -5
- package/dist/cdn/chunks/{checkbox-field-DCYpRJfz.js → checkbox-field-sFs7GvAq.js} +7 -7
- package/dist/cdn/chunks/{checkbox-group-DxWAYp_b.js → checkbox-group-BPN4eRCX.js} +3 -3
- package/dist/cdn/chunks/{class-map-D720ceWJ.js → class-map-1XjgYGeg.js} +1 -1
- package/dist/cdn/chunks/{code-editor-DlnTXkHx.js → code-editor-KZEaMAN7.js} +5 -5
- package/dist/cdn/chunks/{code-viewer-DyJzo36-.js → code-viewer-CJwpLKb1.js} +7 -7
- package/dist/cdn/chunks/{codemirror-input-DPSOMYZ4.js → codemirror-input-CYBNNf0-.js} +5 -5
- package/dist/cdn/chunks/{collection-i7H8zkQ8.js → collection-BdUB8qeL.js} +8 -8
- package/dist/cdn/chunks/{combo-box-CpNl_us0.js → combo-box-DxWW-zeE.js} +9 -9
- package/dist/cdn/chunks/{container-YWW7mHNa.js → container-Dhf1Ahi8.js} +2 -2
- package/dist/cdn/chunks/{custom-element-D8yf5dqU.js → custom-element-DtLjpays.js} +1 -1
- package/dist/cdn/chunks/{date-field-DzhUp4Rk.js → date-field-D83r9gjY.js} +12 -12
- package/dist/cdn/chunks/{date-picker-CGvsvK3g.js → date-picker-D8qv2iuG.js} +10 -10
- package/dist/cdn/chunks/{decorate-1aEyfetK.js → decorate-BhnGmemK.js} +1 -1
- package/dist/cdn/chunks/{described-by-mixin-DffYoaxu.js → described-by-mixin-Jh_PTTde.js} +2 -2
- package/dist/cdn/chunks/{description-cell-DEw6xc2o.js → description-cell-nQKMluy8.js} +6 -6
- package/dist/cdn/chunks/{dev-checks-CTopJcdE.js → dev-checks-Bet7bhMS.js} +87 -49
- package/dist/cdn/chunks/{directive-helpers-BQml5ahH.js → directive-helpers-dLE2M1R1.js} +1 -1
- package/dist/cdn/chunks/{dist-DAf6EMuK.js → dist-BTuJ-NyU.js} +2 -2
- package/dist/cdn/chunks/{dist-B5t9fS8q.js → dist-BbwC3zHR.js} +2 -2
- package/dist/cdn/chunks/{dist-BYbLHkMP.js → dist-BpqJqkl_.js} +1 -1
- package/dist/cdn/chunks/{dist-D59Ae7dj.js → dist-C9xmfEc_.js} +1 -1
- package/dist/cdn/chunks/{dist-CIX4JLW1.js → dist-CYKK2xXE.js} +3 -3
- package/dist/cdn/chunks/{dist-DevfJ4Mu.js → dist-Cdmhq-4P.js} +2 -2
- package/dist/cdn/chunks/{dist-BKnqQxdv.js → dist-DJSiRJRL.js} +1 -1
- package/dist/cdn/chunks/{dist-C8ZY_QIK.js → dist-DwevYbXo.js} +1 -1
- package/dist/cdn/chunks/{dist-B87Ag4L-.js → dist-Dzlvec4O.js} +1 -1
- package/dist/cdn/chunks/{dist-qHSPGfTO.js → dist-EP5KATv0.js} +1 -1
- package/dist/cdn/chunks/{dist-Cr8NctvS.js → dist-u6MS5-M8.js} +3 -3
- package/dist/cdn/chunks/{divider-44rkHLYj.js → divider-DjT76fuO.js} +2 -2
- package/dist/cdn/chunks/{document-tab-bar-CcSKzhEy.js → document-tab-bar-CO2M1bFc.js} +9 -9
- package/dist/cdn/chunks/{dropdown-CJPjI-p1.js → dropdown-CdQ1beF2.js} +5 -5
- package/dist/cdn/chunks/{file-field-B4HQKpkI.js → file-field-D0UlnM9R.js} +13 -13
- package/dist/cdn/chunks/{form-obggZEpt.js → form-BV9wifov.js} +1 -1
- package/dist/cdn/chunks/{form-actions-HaBfh6vm.js → form-actions-DDeF8urg.js} +2 -2
- package/dist/cdn/chunks/{form-associated-mixin-BByNH679.js → form-associated-mixin-Cm1N24gR.js} +2 -2
- package/dist/cdn/chunks/{form-field-CwYXsuvv.js → form-field-IeKadcwe.js} +5 -5
- package/dist/cdn/chunks/{form-section-B2UZx_-z.js → form-section-C350G5wg.js} +1 -1
- package/dist/cdn/chunks/{full-bleed-section-BSnWghWY.js → full-bleed-section-CR3zsX7K.js} +3 -3
- package/dist/cdn/chunks/{hero-CzbuEAUM.js → hero-Ch5el5J5.js} +4 -4
- package/dist/cdn/chunks/{icon-CkCT7sPE.js → icon-Dj98ov4G.js} +2 -2
- package/dist/cdn/chunks/{icon-button-BBGwCfYp.js → icon-button-HKoCqWG3.js} +9 -9
- package/dist/cdn/chunks/{icon-cell-DcHnXV-8.js → icon-cell-C1I-oIWn.js} +5 -5
- package/dist/cdn/chunks/{identity-C0fujsxK.js → identity-DNkEDJ8m.js} +6 -6
- package/dist/cdn/chunks/{if-defined-CL4nn-Q-.js → if-defined-CZ1Fmb74.js} +1 -1
- package/dist/cdn/chunks/{image-BgtqLXfM.js → image-KXTd-hL-.js} +8 -8
- package/dist/cdn/chunks/{inline-dialog-BYRIWhkm.js → inline-dialog-BTI0xmIT.js} +6 -6
- package/dist/cdn/chunks/{just-in-time-education-DwH3ubhZ.js → just-in-time-education-BtjbYffu.js} +5 -5
- package/dist/cdn/chunks/{kanban-BIZUoBj-.js → kanban-DNXtL34O.js} +5 -5
- package/dist/cdn/chunks/{kanban-column-CtjCIgaR.js → kanban-column-D0ujQ2_W.js} +4 -4
- package/dist/cdn/chunks/{keyboard-shortcut-BHylGMNu.js → keyboard-shortcut-BikzmCBH.js} +3 -3
- package/dist/cdn/chunks/{languages-DghCYmiz.js → languages-CPd7_I8H.js} +12 -12
- package/dist/cdn/chunks/{link-S53veJpD.js → link-DqMeRYFm.js} +6 -6
- package/dist/cdn/chunks/{link-group-B2_vdANe.js → link-group-BKn4MHA-.js} +2 -2
- package/dist/cdn/chunks/{list-C8hY4uGW.js → list-C8Dnks-q.js} +8 -8
- package/dist/cdn/chunks/{list-item-CK1Rli4F.js → list-item-CSP1a_cN.js} +5 -5
- package/dist/cdn/chunks/{list-item-segment-KyrcOFDA.js → list-item-segment-BvFqXXnA.js} +3 -3
- package/dist/cdn/chunks/{menu-m67vk1Z4.js → menu-LZ0DmVCe.js} +13 -13
- package/dist/cdn/chunks/{menu-bar-item-DKW198ZW.js → menu-bar-item-DENdrp0m.js} +6 -6
- package/dist/cdn/chunks/{menu-bar-BRoqy5zp.js → menu-bar-rsGd3kKq.js} +6 -6
- package/dist/cdn/chunks/{menu-divider-DDPBPK-o.js → menu-divider-BptK2nug.js} +3 -3
- package/dist/cdn/chunks/{menu-group-uZXsE-uu.js → menu-group-0B34NyN5.js} +4 -4
- package/dist/cdn/chunks/{menu-item-BOvb4QLd.js → menu-item-55vjckz2.js} +4 -4
- package/dist/cdn/chunks/{menu.template-v6VnRUNJ.js → menu.template-B_HMnBsa.js} +5 -5
- package/dist/cdn/chunks/{modal-dialog-BNq0r-1L.js → modal-dialog-DQY_0Qlk.js} +4 -4
- package/dist/cdn/chunks/{multi-line-text-field-Bfq47I3P.js → multi-line-text-field-DB4Vflno.js} +6 -6
- package/dist/cdn/chunks/{navigation-split-view-BiPoxCLL.js → navigation-split-view-Dbhrxni9.js} +4 -4
- package/dist/cdn/chunks/{notification-DjZXBv4J.js → notification-dtrMLORo.js} +6 -6
- package/dist/cdn/chunks/{number-field-tqoQLrgZ.js → number-field-Ctxk40as.js} +8 -8
- package/dist/cdn/chunks/{one-half-one-half-section-CyIm21PD.js → one-half-one-half-section-Bx6KLSY5.js} +3 -3
- package/dist/cdn/chunks/{one-third-two-thirds-section-CpnK0vzB.js → one-third-two-thirds-section-Bql0Xrsc.js} +3 -3
- package/dist/cdn/chunks/{one-time-code-field-6sMEfzoY.js → one-time-code-field-B-y5gRLi.js} +7 -7
- package/dist/cdn/chunks/{overflow-menu-IfYEX8tm.js → overflow-menu-Cs1VLcX7.js} +1 -1
- package/dist/cdn/chunks/{page-w4XAfBWD.js → page-Bdkit86l.js} +6 -6
- package/dist/cdn/chunks/{page-footer-ET6j1N2Z.js → page-footer-D68JiIFE.js} +4 -4
- package/dist/cdn/chunks/{page-section-mixin-D9JL2q9A.js → page-section-mixin-Bmlpcmrw.js} +3 -3
- package/dist/cdn/chunks/{pagination-D7QFUu8x.js → pagination-BH6UQbby.js} +6 -6
- package/dist/cdn/chunks/{password-field-Ck5wx6pg.js → password-field-Dz0znv2L.js} +8 -8
- package/dist/cdn/chunks/{popover-DOmi5m85.js → popover-C6j3sO70.js} +5 -5
- package/dist/cdn/chunks/{progress-bar-BDNcB06i.js → progress-bar-BA_5dDXK.js} +7 -7
- package/dist/cdn/chunks/{progress-circle-BAMztpb3.js → progress-circle-DsCyTyw-.js} +7 -7
- package/dist/cdn/chunks/{radio-button-field-BbPk0nM_.js → radio-button-field-JsQalrMs.js} +6 -6
- package/dist/cdn/chunks/{radio-button-group-lxzwku00.js → radio-button-group-Bqn43LYh.js} +3 -3
- package/dist/cdn/chunks/{radio-button-DAps6n0Q.js → radio-button-pcE5Vo5k.js} +4 -4
- package/dist/cdn/chunks/{render-marked-ClMFyNu0.js → render-marked-DAVGoeYa.js} +1 -1
- package/dist/cdn/chunks/{reorder-handle-cell-Cap2u2zx.js → reorder-handle-cell-r4OuA45S.js} +4 -4
- package/dist/cdn/chunks/{reorder-handle-mixin-CnRKPVqU.js → reorder-handle-mixin-Co5E_Y7l.js} +2 -2
- package/dist/cdn/chunks/{repeat-CIyCvHHQ.js → repeat-DoLR8W_a.js} +2 -2
- package/dist/cdn/chunks/{rich-text-CblFmHY-.js → rich-text-CEmzxZRC.js} +3 -3
- package/dist/cdn/chunks/{row-header-mixin-C8z9StDU.js → row-header-mixin-BCYXiXva.js} +2 -2
- package/dist/cdn/chunks/{scroll-fade-C_L9CJrR.js → scroll-fade-OSFrYTum.js} +2 -2
- package/dist/cdn/chunks/{search-field-JeUPcBjZ.js → search-field-CT483s7J.js} +10 -10
- package/dist/cdn/chunks/{segmented-control-DtycvVyp.js → segmented-control-5zMasjz7.js} +7 -7
- package/dist/cdn/chunks/{shadow-resets-DgR56wQK.js → shadow-resets-DR73IFIL.js} +2 -2
- package/dist/cdn/chunks/{sheet-XtRs26hN.js → sheet-CDXX61d_.js} +3 -3
- package/dist/cdn/chunks/{shell-CCaEEGna.js → shell-C4vAeA49.js} +3 -3
- package/dist/cdn/chunks/{side-by-side-split-view-mhXD4Lde.js → side-by-side-split-view-D9_u1TIS.js} +4 -4
- package/dist/cdn/chunks/{sidebar-section-Cwd4LSE6.js → sidebar-section-vWX-ymIa.js} +7 -7
- package/dist/cdn/chunks/{simple-section-BuiaCGks.js → simple-section-CEw2oC7K.js} +3 -3
- package/dist/cdn/chunks/{skip-link-nTlmioFt.js → skip-link-DcOGlfM9.js} +4 -4
- package/dist/cdn/chunks/{slider-C0rNQEIY.js → slider-B108QDlz.js} +9 -9
- package/dist/cdn/chunks/{spacer-CeSO9CP1.js → spacer-CpfTNtbZ.js} +2 -2
- package/dist/cdn/chunks/{spacer-cell-NhlxEdhA.js → spacer-cell-DBm7_AUi.js} +4 -4
- package/dist/cdn/chunks/{split-button-BR-ccA6_.js → split-button-DxgDxdan.js} +7 -7
- package/dist/cdn/chunks/{split-view-divider-HcIV0yli.js → split-view-divider-6_RDvANN.js} +2 -2
- package/dist/cdn/chunks/{split-view-pane-BgFUL3BV.js → split-view-pane-9tEGLRZC.js} +3 -3
- package/dist/cdn/chunks/{stacked-split-view-j77p3uE2.js → stacked-split-view-CRMEMwtv.js} +4 -4
- package/dist/cdn/chunks/{static-html-CGoLwgpW.js → static-html-CmXnRyP6.js} +1 -1
- package/dist/cdn/chunks/{status-bar-ByJ21hV2.js → status-bar-Blk_iYSD.js} +4 -4
- package/dist/cdn/chunks/{step-bar-CRxF0S42.js → step-bar-DM4a_0PG.js} +5 -5
- package/dist/cdn/chunks/{step-cell-C-gOxNA6.js → step-cell-CUs8AKJq.js} +5 -5
- package/dist/cdn/chunks/{stepper-Dmljb7Qc.js → stepper-JwxPNJRc.js} +7 -7
- package/dist/cdn/chunks/{style-map-CK811FGv.js → style-map-DUDIMhuW.js} +1 -1
- package/dist/cdn/chunks/{swatch-picker-DtAgTXLo.js → swatch-picker-BXs7Ob4o.js} +6 -6
- package/dist/cdn/chunks/{switch-Bqion92b.js → switch-CWKoOyz7.js} +5 -5
- package/dist/cdn/chunks/{switch-field-CWobTcEn.js → switch-field-BgX9mNOA.js} +6 -6
- package/dist/cdn/chunks/{tab-bar-DPtRjP8Z.js → tab-bar-BNaJSB38.js} +8 -8
- package/dist/cdn/chunks/{table-C4CFiDgr.js → table-dgJdHR92.js} +5 -5
- package/dist/cdn/chunks/{tag-Bo23A60g.js → tag-DHHf_gxq.js} +4 -4
- package/dist/cdn/chunks/{term-DPMEWR-t.js → term-DNLqQErM.js} +12 -12
- package/dist/cdn/chunks/{text-CuiMvMZQ.js → text-CK1-qJ6d.js} +3 -3
- package/dist/cdn/chunks/{text-cell-E3yc99xw.js → text-cell-CrKBqL5A.js} +8 -8
- package/dist/cdn/chunks/{text-editor-BVmHiq_b.js → text-editor-B0A2vNpD.js} +10 -10
- package/dist/cdn/chunks/{text-field-DOv1aI_F.js → text-field-CqYxSiKy.js} +6 -6
- package/dist/cdn/chunks/{time-field-BhlLk6tt.js → time-field-DHm6KQsG.js} +14 -14
- package/dist/cdn/chunks/{time-picker-A4-HeVas.js → time-picker-C_BE5oNq.js} +5 -5
- package/dist/cdn/chunks/{title-EMt-SYKV.js → title-BpREzeX9.js} +4 -4
- package/dist/cdn/chunks/{title-cell--EE-L_8a.js → title-cell-C4ZL3mJo.js} +8 -8
- package/dist/cdn/chunks/{toggle-button-BLwpxmQs.js → toggle-button-COQdr-hZ.js} +8 -8
- package/dist/cdn/chunks/{toggle-button-group-scdxolJt.js → toggle-button-group-D4vTcGce.js} +2 -2
- package/dist/cdn/chunks/{token-DVgXuCRO.js → token-1DfHVSVj.js} +5 -5
- package/dist/cdn/chunks/{token-field-CICQXLlO.js → token-field-s_mCjtcZ.js} +11 -11
- package/dist/cdn/chunks/{toolbar-Des2gaH2.js → toolbar-Bz_8d1v-.js} +8 -8
- package/dist/cdn/chunks/{toolbar-item-CkwQ2UyY.js → toolbar-item-B-EDYaPf.js} +3 -3
- package/dist/cdn/chunks/{toolbar-title-PoOf794l.js → toolbar-title-Cl8VPHYK.js} +4 -4
- package/dist/cdn/chunks/{toolbar.styles-DzreUGTp.js → toolbar.styles-BiT7JPsr.js} +3 -3
- package/dist/cdn/chunks/{tooltip-CMCT2iiD.js → tooltip-DhPeqDvL.js} +4 -4
- package/dist/cdn/chunks/{top-navigation-bar-BfMGgTIy.js → top-navigation-bar-CHWqoNms.js} +17 -17
- package/dist/cdn/chunks/{top-title-bar-CvvldlNt.js → top-title-bar-DUp0bSIU.js} +6 -6
- package/dist/cdn/chunks/{translations-C5JpcNNC.js → translations-C6WKR-hE.js} +1 -1
- package/dist/cdn/chunks/{two-thirds-one-third-section-BTkeIiHm.js → two-thirds-one-third-section-CftZqodu.js} +3 -3
- package/dist/cdn/chunks/{validation-list-BasB3ZaT.js → validation-list-BdTSfsD6.js} +3 -3
- package/dist/cdn/chunks/{visibility-mixin-BxhcJG-x.js → visibility-mixin-DL737l0g.js} +2 -2
- package/dist/cdn/chunks/{visually-hidden-ByHY8pKl.js → visually-hidden-DvU3wAD4.js} +2 -2
- package/dist/cdn/chunks/{window-B5blEfMR.js → window-7XYqha2V.js} +4 -4
- package/dist/cdn/chunks/{with-translations-QDhHJYMT.js → with-translations-nT8q6ELU.js} +3 -3
- package/dist/components/content/image/image.d.ts +1 -4
- package/dist/components/content/image/image.d.ts.map +1 -1
- package/dist/components/content/image/image.js +1 -4
- package/dist/components/content/image/image.js.map +1 -1
- package/dist/components/content/tooltip/tooltip.d.ts +1 -4
- package/dist/components/content/tooltip/tooltip.d.ts.map +1 -1
- package/dist/components/content/tooltip/tooltip.js +1 -4
- package/dist/components/content/tooltip/tooltip.js.map +1 -1
- package/dist/components/layout/page/page.d.ts +4 -0
- package/dist/components/layout/page/page.d.ts.map +1 -1
- package/dist/components/layout/page/page.js +4 -0
- package/dist/components/layout/page/page.js.map +1 -1
- package/dist/components/layout/page/page.styles.js +2 -2
- package/dist/components/layout/shell/shell.d.ts +2 -0
- package/dist/components/layout/shell/shell.d.ts.map +1 -1
- package/dist/components/layout/shell/shell.js +2 -0
- package/dist/components/layout/shell/shell.js.map +1 -1
- package/dist/nldd.min.js +2 -2
- package/dist/utilities/dev-checks.d.ts +6 -0
- package/dist/utilities/dev-checks.d.ts.map +1 -1
- package/dist/utilities/dev-checks.js +42 -16
- package/dist/utilities/dev-checks.js.map +1 -1
- package/dist/utilities/dev-rules.generated.d.ts.map +1 -1
- package/dist/utilities/dev-rules.generated.js +27 -2
- package/dist/utilities/dev-rules.generated.js.map +1 -1
- package/lint/css.js +58 -26
- package/lint/data.generated.json +1 -1
- package/lint/engine.js +29 -12
- package/lint/fix.js +103 -12
- package/lint/format.js +4 -3
- package/lint/frontends.js +153 -35
- package/lint/linter.js +174 -25
- package/lint/main.js +7 -2
- package/lint/project.js +50 -12
- package/lint/rule-compiler.js +20 -11
- package/lint/rule-data.js +8 -0
- package/lint/rule.schema.json +2 -1
- package/lint/session.js +42 -18
- package/lint/tree.js +5 -2
- package/package.json +1 -1
package/lint/linter.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { existsSync, readFileSync } from 'node:fs';
|
|
7
7
|
import { dirname, extname, join } from 'node:path';
|
|
8
|
-
import {
|
|
8
|
+
import { declarationsIn, designSystemTester, enclosingBlock, TOKEN_PREFIX, tokenReferencesIn, withoutComments } from './css.js';
|
|
9
9
|
import { createEngine } from './engine.js';
|
|
10
10
|
import { canFix, stuckTags } from './fix.js';
|
|
11
11
|
import { applyWrappers, parseSource, parseStylesheet, readerOf } from './frontends.js';
|
|
@@ -58,7 +58,19 @@ function fromAncestors(node, tags, anyDescendantAttrs) {
|
|
|
58
58
|
return attrs;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
/** Per tag and attribute, the rules in `api` about a name that is gone: `nldd-text-editor` → `appearance` → its two rules. */
|
|
62
|
+
function removedAttributeRules(rules) {
|
|
63
|
+
const by = {};
|
|
64
|
+
for (const rule of rules) {
|
|
65
|
+
if (rule.group !== 'api' || !rule.removed) continue;
|
|
66
|
+
for (const [tag] of rule.context.matchAll(/\bnldd-[\w-]+/g)) {
|
|
67
|
+
for (const name of rule.removed) ((by[tag] ??= {})[name] ??= new Set()).add(rule.id);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return by;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function checkAttributes(node, { tags, icons, anyChildAttrs, anyDescendantAttrs, globalAttrs, isPlainHtml, removedBy = {} }, report) {
|
|
62
74
|
if (node.templated) return;
|
|
63
75
|
const contract = tags[node.name];
|
|
64
76
|
// A parent in another file may be the one reading it, so any child attribute goes.
|
|
@@ -93,7 +105,12 @@ function checkAttributes(node, { tags, icons, anyChildAttrs, anyDescendantAttrs,
|
|
|
93
105
|
// `[show]` next to `appSheetSync` may be an input of that directive, or a typo.
|
|
94
106
|
const maybeInput = isPlainHtml && value === BOUND && hasAppDirective(node);
|
|
95
107
|
if (maybeInput) report('unknown-attribute', `${node.name} has no attribute \`${name}\`. That is fine if a directive on this element takes it.`, name, 'hint');
|
|
96
|
-
else
|
|
108
|
+
else {
|
|
109
|
+
// A bound value of a name that is gone: the rules about its values say what took its place.
|
|
110
|
+
const gone = [...(removedBy[node.name]?.[name] ?? [])];
|
|
111
|
+
const see = gone.length > 0 ? ` It was removed: see ${gone.map((id) => `\`nldd explain ${id}\``).join(' and ')}.` : '';
|
|
112
|
+
report('unknown-attribute', `${node.name} has no attribute \`${name}\`.${see}`, name);
|
|
113
|
+
}
|
|
97
114
|
}
|
|
98
115
|
}
|
|
99
116
|
}
|
|
@@ -195,13 +212,56 @@ function createPositions(source) {
|
|
|
195
212
|
/** Files where `//` is no comment: in markup it starts a url, and a built page is one line. */
|
|
196
213
|
const MARKUP_FILE = /\.(html?|j2|jinja2?|tmpl|gohtml|vue|astro|md)$/;
|
|
197
214
|
|
|
215
|
+
const STYLESHEET_FILE = /\.(css|scss|sass|less|styl|pcss)$/;
|
|
216
|
+
|
|
217
|
+
/** Inside markup, `//` is a comment again in the script of a component and in Sass, Less and Stylus. */
|
|
218
|
+
const LINE_COMMENT_STYLE = /\blang\s*=\s*["']?(scss|sass|less|stylus)\b/i;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* The source with its comments blanked, region by region, and where its stylesheets are:
|
|
222
|
+
* a whole stylesheet file, or each `<style>` in markup.
|
|
223
|
+
* @returns {{ plain: string, sheets: [number, number][] }}
|
|
224
|
+
*/
|
|
225
|
+
function codeRegions(source, filename) {
|
|
226
|
+
if (STYLESHEET_FILE.test(filename)) return { plain: withoutComments(source), sheets: [[0, source.length]] };
|
|
227
|
+
if (!MARKUP_FILE.test(filename)) return { plain: withoutComments(source), sheets: [] };
|
|
228
|
+
const markup = withoutComments(source, false);
|
|
229
|
+
const component = /\.(vue|astro)$/.test(filename);
|
|
230
|
+
const sheets = [];
|
|
231
|
+
const parts = [];
|
|
232
|
+
let at = 0;
|
|
233
|
+
const region = (start, end, lineComments) => {
|
|
234
|
+
parts.push(markup.slice(at, start), withoutComments(source.slice(start, end), lineComments, true));
|
|
235
|
+
at = end;
|
|
236
|
+
};
|
|
237
|
+
const frontmatter = /\.astro$/.test(filename) && /^---\r?\n[\s\S]*?\n---/.exec(source);
|
|
238
|
+
if (frontmatter) region(4, frontmatter[0].length - 3, true);
|
|
239
|
+
for (const match of source.matchAll(/<(script|style)\b([^>]*)>([\s\S]*?)<\/\1\s*>/gi)) {
|
|
240
|
+
// A tag inside an HTML comment is blanked in the markup.
|
|
241
|
+
if (match.index < at || markup[match.index] !== '<') continue;
|
|
242
|
+
const start = match.index + match[1].length + match[2].length + 2;
|
|
243
|
+
const end = start + match[3].length;
|
|
244
|
+
if (match[1].toLowerCase() === 'style') {
|
|
245
|
+
sheets.push([start, end]);
|
|
246
|
+
region(start, end, LINE_COMMENT_STYLE.test(match[2]));
|
|
247
|
+
} else if (component) region(start, end, true);
|
|
248
|
+
}
|
|
249
|
+
parts.push(markup.slice(at));
|
|
250
|
+
return { plain: parts.join(''), sheets };
|
|
251
|
+
}
|
|
252
|
+
|
|
198
253
|
/**
|
|
199
254
|
* A stylesheet a page links to, on disk next to it: relative to the page, or from the
|
|
200
255
|
* root of the site for a path that starts with a slash, as in a built site.
|
|
201
256
|
*/
|
|
202
257
|
function linkedFile(href, filename) {
|
|
203
258
|
if (typeof href !== 'string' || !href || /^([a-z]+:|\/\/)/i.test(href)) return undefined;
|
|
204
|
-
|
|
259
|
+
let path;
|
|
260
|
+
try {
|
|
261
|
+
path = decodeURI(href.replace(/[?#].*$/, ''));
|
|
262
|
+
} catch {
|
|
263
|
+
return undefined;
|
|
264
|
+
}
|
|
205
265
|
if (extname(path) !== '.css') return undefined;
|
|
206
266
|
if (!path.startsWith('/')) {
|
|
207
267
|
const file = join(dirname(filename), path);
|
|
@@ -226,11 +286,15 @@ export function createLinter(data = loadData(), { wrappers = {}, severities: con
|
|
|
226
286
|
globalAttrs: Object.assign({}, ...Object.values(data.tags).map((tag) => tag.globalAttrs ?? {})),
|
|
227
287
|
translations: data.translations ?? {},
|
|
228
288
|
removedKeys: data.removedKeys ?? {},
|
|
289
|
+
removedBy: removedAttributeRules(data.rules),
|
|
229
290
|
};
|
|
230
|
-
const engine = createEngine({ classes: data.classes, tags: data.tags, designSystemCss: data.designSystemCss });
|
|
231
|
-
const isDesignSystemBlock = (css) => isDesignSystemCss(css, data.designSystemCss ?? {});
|
|
232
291
|
const tokens = new Set([...(data.tokens ?? []), ...projectTokens]);
|
|
292
|
+
const tokenList = [...tokens];
|
|
233
293
|
const removedTokens = data.removedTokens ?? {};
|
|
294
|
+
const internalContext = new Set(data.internalContext ?? []);
|
|
295
|
+
const isDesignSystemBlock = designSystemTester(data.designSystemCss ?? {}, (name) => tokens.has(name) || internalContext.has(name));
|
|
296
|
+
const engine = createEngine({ classes: data.classes, tags: data.tags, designSystemCss: data.designSystemCss, isDesignSystemCss: isDesignSystemBlock });
|
|
297
|
+
const internalMessage = (name, verb) => `\`${name}\` is wiring between design system components, so ${verb} it is not supported.`;
|
|
234
298
|
// Longest first, so --_button-group-gap belongs to button-group and not to button.
|
|
235
299
|
const components = Object.keys(data.tags)
|
|
236
300
|
.filter((tag) => tag.startsWith('nldd-'))
|
|
@@ -271,45 +335,110 @@ export function createLinter(data = loadData(), { wrappers = {}, severities: con
|
|
|
271
335
|
return (offset) => ranges.some(([start, end]) => offset >= start && offset < end);
|
|
272
336
|
}
|
|
273
337
|
|
|
338
|
+
/**
|
|
339
|
+
* What a name that stops short can be: the tokens that are this name with one more
|
|
340
|
+
* word, such as the line height a font token ends in, or the one token that starts with it.
|
|
341
|
+
*/
|
|
342
|
+
function longerNames(name) {
|
|
343
|
+
const longer = tokenList.filter((token) => token.startsWith(`${name}-`) && !token.slice(name.length + 1).includes('-'));
|
|
344
|
+
// `--primitives-font-family-mono` for `-monospace`: one token starts with what was written.
|
|
345
|
+
// Not after a number: `--primitives-area-16` is no short `--primitives-area-160`.
|
|
346
|
+
const starting = /\d$/.test(name) ? [] : tokenList.filter((token) => token.startsWith(name));
|
|
347
|
+
if (longer.length < 2 && starting.length === 1) return ` The closest is \`${starting[0]}\`.`;
|
|
348
|
+
if (longer.length < 2 || longer.length > 6) return '';
|
|
349
|
+
return ` The tokens with this name end in ${longer.map((token) => `\`${token.slice(name.length)}\``).join(', ').replace(/, ([^,]*)$/, ' or $1')}.`;
|
|
350
|
+
}
|
|
351
|
+
|
|
274
352
|
const LINK_CONTEXT = ['--context-link-color', '--context-link-is-hovered-color', '--context-link-is-active-color'];
|
|
275
353
|
|
|
354
|
+
const removedEvents = data.removedEvents ?? {};
|
|
355
|
+
const eventPatterns = (() => {
|
|
356
|
+
const names = Object.keys(removedEvents).sort((a, b) => b.length - a.length).map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
357
|
+
if (names.length === 0) return [];
|
|
358
|
+
const name = `(${names.join('|')})`;
|
|
359
|
+
return [
|
|
360
|
+
// addEventListener('tabchange').
|
|
361
|
+
{ pattern: new RegExp(`\\b(?:add|remove)EventListener\\(\\s*(['"\`])${name}\\1`, 'dg'), fixable: true },
|
|
362
|
+
// An emitter's on('tabchange'), once(…) or off(…): the same name may belong to another library, so no fix.
|
|
363
|
+
{ pattern: new RegExp(`(?<![\\w$])(?:on|once|off)\\(\\s*(['"\`])${name}\\1`, 'dg'), fixable: false },
|
|
364
|
+
// @tabchange and v-on: in Vue, Lit and Alpine, hx-on in htmx.
|
|
365
|
+
{ pattern: new RegExp(`(?<![\\w-])(?:@|v-on:|x-on:|(?:data-)?hx-on(?::|::|-|--))${name}(?![\\w-])`, 'dg'), fixable: true },
|
|
366
|
+
// (tabchange)="…" in Angular: an attribute with a quoted value, so `(tabchange) => …` in a script is not one.
|
|
367
|
+
{ pattern: new RegExp(`(?<=\\s)\\(${name}\\)\\s*=\\s*['"]`, 'dg'), fixable: true },
|
|
368
|
+
];
|
|
369
|
+
})();
|
|
370
|
+
|
|
371
|
+
/** A listener on the name of an event a component no longer fires: it is never called, and nothing says so. */
|
|
372
|
+
function eventFindings(source, filename) {
|
|
373
|
+
if (eventPatterns.length === 0) return [];
|
|
374
|
+
const { plain } = codeRegions(source, filename);
|
|
375
|
+
const findings = [];
|
|
376
|
+
for (const { pattern, fixable } of eventPatterns) {
|
|
377
|
+
for (const match of plain.matchAll(pattern)) {
|
|
378
|
+
const group = match.length - 1;
|
|
379
|
+
const name = match[group];
|
|
380
|
+
const [offset, endOffset] = match.indices[group];
|
|
381
|
+
const { last, use } = removedEvents[name];
|
|
382
|
+
const message = use
|
|
383
|
+
? `\`${name}\` was renamed to \`${use}\` after ${last}, so a listener on the old name is never called.`
|
|
384
|
+
: `\`${name}\` is no longer fired after ${last}, so this listener is never called.`;
|
|
385
|
+
findings.push({ rule: 'event-renamed', severity: BUILT_IN_RULES['event-renamed'].severity, message, tag: name, offset, endOffset, ...(use && fixable ? { fix: { event: use } } : {}) });
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return findings;
|
|
389
|
+
}
|
|
390
|
+
|
|
276
391
|
/**
|
|
277
392
|
* The design system's tokens the app names, and the internal variables of a component it
|
|
278
393
|
* sets. Read from the text, so a stylesheet, a style attribute and a style object
|
|
279
394
|
* in a script all count. A token the file or the project declares itself is its own.
|
|
280
395
|
*/
|
|
281
396
|
function cssFindings(source, filename, roots) {
|
|
282
|
-
const
|
|
397
|
+
const { plain, sheets } = codeRegions(source, filename);
|
|
283
398
|
const inDesignSystemCss = designSystemRanges(roots);
|
|
284
|
-
const
|
|
399
|
+
const allDeclared = declarationsIn(plain);
|
|
400
|
+
const declared = allDeclared.filter((each) => !inDesignSystemCss(each.offset));
|
|
285
401
|
const ownTokens = new Set(declared.map(({ name }) => name).filter((name) => TOKEN_PREFIX.test(name)));
|
|
286
402
|
const findings = [];
|
|
287
|
-
const report = (rule, message, { name, offset }) =>
|
|
288
|
-
findings.push({ rule, severity: BUILT_IN_RULES[rule].severity, message, tag: name, offset, endOffset: offset + name.length });
|
|
289
|
-
for (const reference of
|
|
290
|
-
const { name, offset } = reference;
|
|
403
|
+
const report = (rule, message, { name, offset }, fix) =>
|
|
404
|
+
findings.push({ rule, severity: BUILT_IN_RULES[rule].severity, message, tag: name, offset, endOffset: offset + name.length, fix });
|
|
405
|
+
for (const reference of tokenReferencesIn(plain)) {
|
|
406
|
+
const { name, offset, fallback } = reference;
|
|
291
407
|
if (tokens.has(name) || ownTokens.has(name) || inDesignSystemCss(offset)) continue;
|
|
408
|
+
if (internalContext.has(name)) {
|
|
409
|
+
report('internal-context-no-use', internalMessage(name, 'reading'), reference);
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
292
412
|
const removed = removedTokens[name];
|
|
293
|
-
|
|
413
|
+
// A successor that left in a later release is no advice, and no fix.
|
|
414
|
+
const use = removed?.use && tokens.has(removed.use) ? removed.use : undefined;
|
|
415
|
+
// With a fallback the page shows that now, so the new name would change what it looks like.
|
|
416
|
+
const shown = use && fallback ? ' The fallback shows until you do, so `--fix` leaves this one.' : '';
|
|
417
|
+
const instead = use ? ` Use \`${use}\`.${shown}` : longerNames(name);
|
|
294
418
|
const message = removed
|
|
295
419
|
? `\`${name}\` was removed after ${removed.last}.${instead}`
|
|
296
|
-
: `There is no token \`${name}\` in this version
|
|
297
|
-
report('token-not-found', message, reference);
|
|
420
|
+
: `There is no token \`${name}\` in this version.${instead}`;
|
|
421
|
+
report('token-not-found', message, reference, use && !fallback ? { token: use } : undefined);
|
|
298
422
|
}
|
|
299
423
|
for (const declaration of declared) {
|
|
424
|
+
if (internalContext.has(declaration.name)) report('internal-context-no-use', internalMessage(declaration.name, 'setting'), declaration);
|
|
300
425
|
if (!declaration.name.startsWith('--_')) continue;
|
|
301
426
|
const component = components.find((name) => declaration.name.startsWith(`--_${name}-`));
|
|
302
427
|
if (!component) continue;
|
|
303
428
|
report('local-variable-no-override', `\`${declaration.name}\` is internal to nldd-${component}, so setting it is not supported.`, declaration);
|
|
304
429
|
}
|
|
305
|
-
const plain = withoutComments(source, lineComments);
|
|
306
430
|
const linkBlocks = new Set();
|
|
307
|
-
|
|
431
|
+
// Also in a block that looks like the design system's: it sets all three, so `:root { --context-link-color: red }` is the app's.
|
|
432
|
+
for (const declaration of allDeclared) {
|
|
308
433
|
if (!LINK_CONTEXT.includes(declaration.name)) continue;
|
|
309
|
-
const {
|
|
434
|
+
const { offset, name } = declaration;
|
|
435
|
+
const sheet = sheets.find(([from, to]) => offset >= from && offset < to);
|
|
436
|
+
const quotedKey = /["'`]/.test(plain[offset - 1] ?? '') && /["'`]/.test(plain[offset + name.length] ?? '');
|
|
437
|
+
const scope = sheet ? { quotes: false, strings: true, from: sheet[0], to: sheet[1] } : quotedKey ? { quotes: false } : {};
|
|
438
|
+
const { start, end } = enclosingBlock(plain, offset, scope);
|
|
310
439
|
if (linkBlocks.has(start)) continue;
|
|
311
440
|
linkBlocks.add(start);
|
|
312
|
-
const set = new Set(
|
|
441
|
+
const set = new Set(allDeclared.filter(({ offset }) => offset >= start && offset < end).map(({ name }) => name));
|
|
313
442
|
const missing = LINK_CONTEXT.filter((name) => !set.has(name));
|
|
314
443
|
if (missing.length === 0) continue;
|
|
315
444
|
report('link-context-needs-states', `Set ${missing.map((name) => `\`${name}\``).join(' and ')} here too, or a link on this surface turns back to the default color.`, declaration);
|
|
@@ -355,6 +484,10 @@ export function createLinter(data = loadData(), { wrappers = {}, severities: con
|
|
|
355
484
|
const testsRemovedValue = (rule) =>
|
|
356
485
|
rule.removed?.some((name) => new RegExp(`\\[${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*[~|^$*]?=`).test(rule.context));
|
|
357
486
|
|
|
487
|
+
/** The attributes whose value, as written here, a rule in `api` names: that value is what the rule is about. */
|
|
488
|
+
const goneValues = (rule, node) =>
|
|
489
|
+
rule.group === 'api' ? [...node.attrs].filter(([name, value]) => typeof value === 'string' && rule.context.includes(`[${name}="${value}"]`)).map(([name]) => name) : [];
|
|
490
|
+
|
|
358
491
|
function lintRoots(roots, isPlainHtml) {
|
|
359
492
|
const findings = [];
|
|
360
493
|
const counts = { failed: 0, passed: 0, cantTell: 0 };
|
|
@@ -363,15 +496,15 @@ export function createLinter(data = loadData(), { wrappers = {}, severities: con
|
|
|
363
496
|
for (const rule of rules) {
|
|
364
497
|
for (const { node, outcome } of engine.evaluate(rule, root)) {
|
|
365
498
|
counts[outcome]++;
|
|
366
|
-
// A name that is gone is wrong whatever the binding holds.
|
|
367
|
-
const namesRemoved = rule.removed?.some((name) => node.attrs.get(name) === BOUND);
|
|
499
|
+
// A name that is gone is wrong whatever the binding holds, but not for a rule about one of its values.
|
|
500
|
+
const namesRemoved = !testsRemovedValue(rule) && rule.removed?.some((name) => node.attrs.get(name) === BOUND);
|
|
368
501
|
if (outcome !== 'failed' && !(outcome === 'cantTell' && namesRemoved)) continue;
|
|
369
502
|
findings.push({
|
|
370
503
|
rule: rule.id,
|
|
371
504
|
severity: rule.severity,
|
|
372
505
|
message: rule.message,
|
|
373
506
|
node,
|
|
374
|
-
covers: [...(rule.removed ?? []), ...Object.keys(rule.fix?.value ?? {})],
|
|
507
|
+
covers: [...(rule.removed ?? []), ...Object.keys(rule.fix?.value ?? {}), ...goneValues(rule, node)],
|
|
375
508
|
fix: isOurs(node, rule, isPlainHtml) && !(outcome === 'cantTell' && testsRemovedValue(rule)) ? rule.fix : undefined,
|
|
376
509
|
});
|
|
377
510
|
}
|
|
@@ -381,7 +514,8 @@ export function createLinter(data = loadData(), { wrappers = {}, severities: con
|
|
|
381
514
|
}
|
|
382
515
|
|
|
383
516
|
/** @returns {Promise<{ findings: object[], counts: object }>} */
|
|
384
|
-
async function lintSource(source, filename) {
|
|
517
|
+
async function lintSource(source, filename, { only } = {}) {
|
|
518
|
+
if (only === 'events') return lintEvents(source, filename);
|
|
385
519
|
const parsed = applyWrappers(await parseSource(source, filename), wrappers);
|
|
386
520
|
const isPlainHtml = /\.(html?|j2|jinja2?|tmpl|gohtml)$/.test(filename);
|
|
387
521
|
const roots = readPropertyNames(parsed, data.tags, isPlainHtml);
|
|
@@ -397,6 +531,7 @@ export function createLinter(data = loadData(), { wrappers = {}, severities: con
|
|
|
397
531
|
line,
|
|
398
532
|
column: 1,
|
|
399
533
|
});
|
|
534
|
+
const jsx = /\.[jt]sx$/.test(filename) || Boolean(parsed.jsx);
|
|
400
535
|
const all = findings
|
|
401
536
|
.map(({ node, severity, covers, attribute, ...finding }) => ({
|
|
402
537
|
...finding,
|
|
@@ -406,14 +541,15 @@ export function createLinter(data = loadData(), { wrappers = {}, severities: con
|
|
|
406
541
|
endOffset: node.endOffset,
|
|
407
542
|
mention: node.mention,
|
|
408
543
|
startTag: node.startTag,
|
|
544
|
+
jsx,
|
|
409
545
|
...position(node.offset),
|
|
410
546
|
}))
|
|
411
547
|
.concat(
|
|
412
|
-
[...cssFindings(source, filename, roots), ...unreadMarkup(source, filename, parsed)]
|
|
548
|
+
[...cssFindings(source, filename, roots), ...eventFindings(source, filename), ...unreadMarkup(source, filename, parsed)]
|
|
413
549
|
.filter(({ rule }) => ranInSource(rule))
|
|
414
550
|
.map((finding) => ({ ...finding, ...position(finding.offset) })),
|
|
415
551
|
);
|
|
416
|
-
const stuck = stuckTags(source, all,
|
|
552
|
+
const stuck = stuckTags(source, all, jsx);
|
|
417
553
|
for (const finding of all) {
|
|
418
554
|
if (finding.fix && (!canFix(source, finding) || (finding.fix.tag && stuck.has(finding.tag)))) finding.fix = undefined;
|
|
419
555
|
}
|
|
@@ -439,6 +575,19 @@ export function createLinter(data = loadData(), { wrappers = {}, severities: con
|
|
|
439
575
|
return { findings: located, counts };
|
|
440
576
|
}
|
|
441
577
|
|
|
578
|
+
/** A script the scan reads only for the events it listens to, such as a `.ts` file. */
|
|
579
|
+
function lintEvents(source, filename) {
|
|
580
|
+
const { suppressed } = readSuppressions(source, canonical);
|
|
581
|
+
const position = createPositions(source);
|
|
582
|
+
const findings = eventFindings(source, filename)
|
|
583
|
+
.map((finding) => ({ ...finding, ...position(finding.offset) }))
|
|
584
|
+
.filter((finding) => !suppressed.get(finding.line)?.has(finding.rule))
|
|
585
|
+
.map((finding) => ({ ...finding, severity: severities[finding.rule] ?? finding.severity }))
|
|
586
|
+
.filter((finding) => finding.severity !== 'off');
|
|
587
|
+
for (const finding of findings) if (finding.fix && !canFix(source, finding)) finding.fix = undefined;
|
|
588
|
+
return { findings, counts: {} };
|
|
589
|
+
}
|
|
590
|
+
|
|
442
591
|
/** Evaluates one rule on a snippet, for the examples of that rule. */
|
|
443
592
|
async function outcomesOf(rule, snippet) {
|
|
444
593
|
const isDocument = snippet.startsWith('<html');
|
package/lint/main.js
CHANGED
|
@@ -6,7 +6,7 @@ import { parseArgs } from 'node:util';
|
|
|
6
6
|
import { formatGithub, formatJson, formatStatistics, formatText } from './format.js';
|
|
7
7
|
import { BUILT_IN_RULES, createCanonical, loadData, GROUPS, OPT_IN_GROUPS, resolveSeverities } from './rule-data.js';
|
|
8
8
|
import { rulesAboutTag } from './rule-index.js';
|
|
9
|
-
import { applyBaseline, looseInBaseline, tightenBaseline, readBaseline, readConfig, writeBaseline } from './project.js';
|
|
9
|
+
import { applyBaseline, looseInBaseline, tightenBaseline, readBaseline, readConfig, relativePath, writeBaseline } from './project.js';
|
|
10
10
|
import { knownKeys, lintProject } from './session.js';
|
|
11
11
|
|
|
12
12
|
const USAGE = `Usage:
|
|
@@ -124,10 +124,15 @@ async function runLint(data, paths, options) {
|
|
|
124
124
|
severities,
|
|
125
125
|
input: options.stdin ? { filename: options.filename ?? 'stdin.html', source: readFileSync(0, 'utf8') } : undefined,
|
|
126
126
|
fix: options.fix,
|
|
127
|
-
keep: (filename) => inBaseline.has(
|
|
127
|
+
keep: (filename) => inBaseline.has(relativePath(root, filename)),
|
|
128
128
|
});
|
|
129
129
|
const { results } = session;
|
|
130
130
|
for (const filename of session.notUtf8) console.error(`Skipped ${relative(root, filename)}: it is not UTF-8.`);
|
|
131
|
+
for (const { entry, file } of session.partialExcludes) {
|
|
132
|
+
console.error(`"exclude" entry "${entry}" no longer leaves out ${file}: an entry is a whole file or directory name now.`);
|
|
133
|
+
}
|
|
134
|
+
for (const filename of session.symlinks) console.error(`Skipped ${relative(root, filename)}: it is a symbolic link.`);
|
|
135
|
+
for (const filename of session.unstable) console.error(`Stopped fixing ${relative(root, filename)}: fixes kept changing it. Run --fix again, or look at the findings.`);
|
|
131
136
|
if (options.fix) console.error(`Fixed ${session.fixed} in ${session.fixedFiles} of ${session.files} files.`);
|
|
132
137
|
if (session.references) {
|
|
133
138
|
const { references } = session;
|
package/lint/project.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { execFileSync } from 'node:child_process';
|
|
4
4
|
import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs';
|
|
5
|
-
import { extname, join, relative, resolve } from 'node:path';
|
|
5
|
+
import { extname, join, relative, resolve, sep } from 'node:path';
|
|
6
6
|
import { declarations, TOKEN_PREFIX } from './css.js';
|
|
7
7
|
|
|
8
8
|
export const IGNORED_DIRECTORIES = new Set(['node_modules', 'dist', 'build', 'coverage', '.git', '.next', '.nuxt']);
|
|
@@ -19,6 +19,9 @@ export const UNREAD_EXTENSIONS = ['.svelte', '.php', '.twig', '.erb', '.ejs', '.
|
|
|
19
19
|
/** An app's own stylesheets: read for the tokens they name, and in full when the group pure is on. */
|
|
20
20
|
export const STYLESHEET_EXTENSIONS = ['.css', '.scss', '.sass', '.less'];
|
|
21
21
|
|
|
22
|
+
/** Scripts a scan reads only for the events they listen to: a listener on a renamed event fails silently. */
|
|
23
|
+
export const SCRIPT_EXTENSIONS = ['.ts', '.mts', '.mjs', '.cjs'];
|
|
24
|
+
|
|
22
25
|
/** Where a tag name stands outside markup: a renamed tag reads these, also a `.js` the linter reads as markup. */
|
|
23
26
|
export const REFERENCE_EXTENSIONS = ['.js', '.mjs', '.cjs', '.ts', '.css', '.scss', '.less'];
|
|
24
27
|
|
|
@@ -51,11 +54,20 @@ function trackedFiles(root, extensions) {
|
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
|
|
57
|
+
/** A path from the root with `/`, as in the config, the baseline and CI annotations, on every platform. */
|
|
58
|
+
export const relativePath = (root, file) => relative(root, file).split(sep).join('/');
|
|
59
|
+
|
|
60
|
+
const normalizeEntry = (entry) => entry.replace(/\\/g, '/').replace(/^\.\//, '').replace(/\/+$/, '');
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* An entry is a file or directory name, or a path of them, anywhere in the path: `legacy`
|
|
64
|
+
* and `src/legacy/` exclude `src/legacy/a.html`, and neither excludes `src/legacy-new.html`.
|
|
65
|
+
*/
|
|
54
66
|
function matchesExclude(path, patterns) {
|
|
55
|
-
return patterns.some((
|
|
67
|
+
return patterns.map(normalizeEntry).some((entry) => entry !== '' && `/${path}/`.includes(`/${entry}/`));
|
|
56
68
|
}
|
|
57
69
|
|
|
58
|
-
|
|
70
|
+
function listFiles(paths, root, extensions) {
|
|
59
71
|
const files =
|
|
60
72
|
paths.length === 0
|
|
61
73
|
? (trackedFiles(root, extensions) ?? walkDirectory(root, [], extensions))
|
|
@@ -64,7 +76,24 @@ export function findFiles(paths, root, exclude = [], extensions = DEFAULT_EXTENS
|
|
|
64
76
|
if (!existsSync(full)) throw new Error(`No such file or directory: ${path}`);
|
|
65
77
|
return statSync(full).isDirectory() ? walkDirectory(full, [], extensions) : [full];
|
|
66
78
|
});
|
|
67
|
-
return [...new Set(files)].filter((file) => existsSync(file)
|
|
79
|
+
return [...new Set(files)].filter((file) => existsSync(file));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function findFiles(paths, root, exclude = [], extensions = DEFAULT_EXTENSIONS) {
|
|
83
|
+
return listFiles(paths, root, extensions).filter((file) => !matchesExclude(relativePath(root, file), exclude));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Entries that leave out nothing, while up to 0.27 they matched part of a name in one of
|
|
88
|
+
* these files: `gen` left out `generated/a.html`. Each with the first such file.
|
|
89
|
+
*/
|
|
90
|
+
export function partialExcludes(paths, root, exclude = [], extensions = DEFAULT_EXTENSIONS) {
|
|
91
|
+
const files = listFiles(paths, root, extensions).map((file) => relativePath(root, file));
|
|
92
|
+
return exclude.flatMap((entry) => {
|
|
93
|
+
if (normalizeEntry(entry) === '' || files.some((file) => matchesExclude(file, [entry]))) return [];
|
|
94
|
+
const file = files.find((one) => one.includes(normalizeEntry(entry)));
|
|
95
|
+
return file ? [{ entry, file }] : [];
|
|
96
|
+
});
|
|
68
97
|
}
|
|
69
98
|
|
|
70
99
|
/** The average line length above which a script counts as minified. */
|
|
@@ -85,8 +114,9 @@ const namesTokens = (source) => /var\(\s*--(primitives|semantics|components|cont
|
|
|
85
114
|
* and the variables it sets, and only then. `keep` says a file has to be read
|
|
86
115
|
* anyway, as one the baseline names.
|
|
87
116
|
*/
|
|
88
|
-
export function isRelevant({ filename, source }, { wrappers, keep = () => false } = {}) {
|
|
117
|
+
export function isRelevant({ filename, source }, { wrappers, keep = () => false, events } = {}) {
|
|
89
118
|
if (keep(filename)) return true;
|
|
119
|
+
if (events?.test(source)) return true;
|
|
90
120
|
if (isStylesheet(filename)) return namesTokens(source);
|
|
91
121
|
return /nldd-|Nldd/.test(source) || namesTokens(source) || Boolean(wrappers);
|
|
92
122
|
}
|
|
@@ -114,7 +144,9 @@ export function readConfig(root, knownRules) {
|
|
|
114
144
|
if (config.wrappers !== undefined && (!isMap(config.wrappers) || !Object.values(config.wrappers).every((tag) => typeof tag === 'string'))) {
|
|
115
145
|
throw new Error(`${CONFIG_FILE}: "wrappers" maps a component to a tag name.`);
|
|
116
146
|
}
|
|
117
|
-
if (config.exclude !== undefined && !Array.isArray(config.exclude)
|
|
147
|
+
if (config.exclude !== undefined && (!Array.isArray(config.exclude) || !config.exclude.every((entry) => typeof entry === 'string'))) {
|
|
148
|
+
throw new Error(`${CONFIG_FILE}: "exclude" takes a list of paths.`);
|
|
149
|
+
}
|
|
118
150
|
for (const [rule, level] of Object.entries(config.rules ?? {})) {
|
|
119
151
|
if (!knownRules.has(rule)) throw new Error(`${CONFIG_FILE}: unknown rule "${rule}".`);
|
|
120
152
|
if (!['off', 'hint', 'warn', 'error'].includes(level)) {
|
|
@@ -144,10 +176,16 @@ function mergeRenamed(entries, canonical) {
|
|
|
144
176
|
export function readBaseline(root, canonical = (id) => id) {
|
|
145
177
|
const path = join(root, BASELINE_FILE);
|
|
146
178
|
if (!existsSync(path)) return {};
|
|
147
|
-
|
|
179
|
+
let baseline;
|
|
180
|
+
try {
|
|
181
|
+
baseline = JSON.parse(readFileSync(path, 'utf8'));
|
|
182
|
+
} catch (error) {
|
|
183
|
+
throw new Error(`${BASELINE_FILE}: ${error.message}`);
|
|
184
|
+
}
|
|
185
|
+
// A baseline written on Windows by an older version has backslashes in its keys.
|
|
148
186
|
return Object.fromEntries(
|
|
149
187
|
Object.entries(baseline).map(([file, entries]) => [
|
|
150
|
-
file,
|
|
188
|
+
file.replace(/\\/g, '/'),
|
|
151
189
|
mergeRenamed(entries, canonical),
|
|
152
190
|
]),
|
|
153
191
|
);
|
|
@@ -156,7 +194,7 @@ export function readBaseline(root, canonical = (id) => id) {
|
|
|
156
194
|
const baselineKey = ({ rule, tag }) => `${rule}|${tag}`;
|
|
157
195
|
|
|
158
196
|
export function applyBaseline(filename, findings, baseline, root) {
|
|
159
|
-
const accepted = { ...baseline[
|
|
197
|
+
const accepted = { ...baseline[relativePath(root, filename)] };
|
|
160
198
|
return findings.filter((finding) => {
|
|
161
199
|
const key = baselineKey(finding);
|
|
162
200
|
// A hint is never in a baseline, so it must not use up a warning of the same rule.
|
|
@@ -179,7 +217,7 @@ export function looseInBaseline(results, baseline, root, ran) {
|
|
|
179
217
|
let loose = 0;
|
|
180
218
|
for (const { filename, findings } of results) {
|
|
181
219
|
const found = countFindings(findings);
|
|
182
|
-
for (const [entry, count] of Object.entries(baseline[
|
|
220
|
+
for (const [entry, count] of Object.entries(baseline[relativePath(root, filename)] ?? {})) {
|
|
183
221
|
if (ran(entry.split('|')[0])) loose += Math.max(0, count - (found[entry] ?? 0));
|
|
184
222
|
}
|
|
185
223
|
}
|
|
@@ -193,7 +231,7 @@ export function looseInBaseline(results, baseline, root, ran) {
|
|
|
193
231
|
export function tightenBaseline(results, root, canonical, ran) {
|
|
194
232
|
if (!existsSync(join(root, BASELINE_FILE))) return undefined;
|
|
195
233
|
const baseline = readBaseline(root, canonical);
|
|
196
|
-
const read = new Map(results.map(({ filename, findings }) => [
|
|
234
|
+
const read = new Map(results.map(({ filename, findings }) => [relativePath(root, filename), countFindings(findings)]));
|
|
197
235
|
// Only the rules that ran can be compared; what the others accepted moves along as it is.
|
|
198
236
|
const ranOnly = (entries) => Object.fromEntries(Object.entries(entries).filter(([entry]) => ran(entry.split('|')[0])));
|
|
199
237
|
const sameCounts = (a, b) => {
|
|
@@ -234,7 +272,7 @@ export function tightenBaseline(results, root, canonical, ran) {
|
|
|
234
272
|
export function writeBaseline(results, root, canonical, ran = () => true) {
|
|
235
273
|
const baseline = readBaseline(root, canonical);
|
|
236
274
|
for (const { filename, findings } of results) {
|
|
237
|
-
const key =
|
|
275
|
+
const key = relativePath(root, filename);
|
|
238
276
|
const kept = Object.entries(baseline[key] ?? {}).filter(([entry]) => !ran(entry.split('|')[0]));
|
|
239
277
|
delete baseline[key];
|
|
240
278
|
if (kept.length === 0 && findings.every(({ severity }) => severity === 'hint')) continue;
|
package/lint/rule-compiler.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
import { parse, stringify } from 'css-what';
|
|
15
15
|
import { OPT_IN_GROUPS } from './rule-data.js';
|
|
16
|
-
import {
|
|
16
|
+
import { designSystemTester } from './css.js';
|
|
17
17
|
import { BOUND } from './tree.js';
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -25,9 +25,13 @@ const CLASS_EXCEPTIONS = {
|
|
|
25
25
|
'form-input': { input: { attribute: 'type', value: 'hidden' } },
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
/** In W- a bound or spread value may be the excepted one; in W+ (`favorable`) it may be any other. */
|
|
29
|
+
function excepted(className, node, favorable = true) {
|
|
29
30
|
const exception = CLASS_EXCEPTIONS[className]?.[node.name];
|
|
30
|
-
|
|
31
|
+
if (!exception) return false;
|
|
32
|
+
const value = node.attrs.get(exception.attribute);
|
|
33
|
+
if (!favorable && (value === BOUND || (node.spread && value === undefined))) return true;
|
|
34
|
+
return value === exception.value;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
/** Pseudo-classes of CSS itself, which mean the same everywhere. */
|
|
@@ -96,7 +100,7 @@ function acceptedCheck(tags, allowUnknown) {
|
|
|
96
100
|
if (seen.has(parent)) return false;
|
|
97
101
|
const next = new Set(seen).add(parent);
|
|
98
102
|
// Accepted in any of the places the file uses it is enough.
|
|
99
|
-
return parent.placements.some((place) => accepted(node, place.parent, chain, next));
|
|
103
|
+
return parent.placements.some((place) => accepted(node, place.parent, [...chain], next));
|
|
100
104
|
}
|
|
101
105
|
if (parent.opaque) return allowUnknown;
|
|
102
106
|
if (!parent.name.startsWith('nldd-')) {
|
|
@@ -179,25 +183,27 @@ const VOCABULARY = {
|
|
|
179
183
|
},
|
|
180
184
|
// CSS the design system ships: a block it recognizes, or a stylesheet with nothing else in it.
|
|
181
185
|
'design-system': {
|
|
182
|
-
source: ({
|
|
186
|
+
source: ({ isDesignSystemCss }) => (node) => node.designSystem ?? (node.css !== undefined && isDesignSystemCss(node.css)),
|
|
183
187
|
optIn: true,
|
|
184
188
|
},
|
|
185
189
|
};
|
|
186
190
|
|
|
187
191
|
/** The name a pseudo-class goes by in W+, or the name itself when unknown changes nothing. */
|
|
188
192
|
export function favorableName(name) {
|
|
189
|
-
return VOCABULARY[name]?.favorable ? `may-be-${name}` : name;
|
|
193
|
+
return VOCABULARY[name]?.favorable || CLASS_EXCEPTIONS[name] ? `may-be-${name}` : name;
|
|
190
194
|
}
|
|
191
195
|
|
|
192
196
|
/** What each pseudo-class means in source, for css-select. */
|
|
193
|
-
export function sourcePseudos({ classes = {}, tags = {}, designSystemCss = {} } = {}) {
|
|
197
|
+
export function sourcePseudos({ classes = {}, tags = {}, designSystemCss = {}, isDesignSystemCss = designSystemTester(designSystemCss) } = {}) {
|
|
194
198
|
const shared = Object.fromEntries(
|
|
195
|
-
Object.entries(classes).
|
|
199
|
+
Object.entries(classes).flatMap(([name, members]) => {
|
|
196
200
|
const set = new Set(members);
|
|
197
|
-
|
|
201
|
+
const strict = [name, (node) => set.has(node.name) && !excepted(name, node, false)];
|
|
202
|
+
return CLASS_EXCEPTIONS[name] ? [strict, [favorableName(name), (node) => set.has(node.name) && !excepted(name, node)]] : [strict];
|
|
198
203
|
}),
|
|
199
204
|
);
|
|
200
|
-
const
|
|
205
|
+
const isInput = classes['form-input'] ? shared[favorableName('form-input')] : () => false;
|
|
206
|
+
const context = { tags, isDesignSystemCss, isInput };
|
|
201
207
|
const own = Object.entries(VOCABULARY).flatMap(([name, entry]) => [
|
|
202
208
|
[name, entry.source(context)],
|
|
203
209
|
...(entry.favorable ? [[favorableName(name), entry.favorable(context)]] : []),
|
|
@@ -259,6 +265,8 @@ export function forBrowser(selector, classes = {}) {
|
|
|
259
265
|
return stringify(compileList(parse(selector), classes, selector));
|
|
260
266
|
}
|
|
261
267
|
|
|
268
|
+
const LOGICAL_PSEUDOS = new Set(['is', 'where', 'matches', 'not']);
|
|
269
|
+
|
|
262
270
|
const toProperty = (name) => name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
263
271
|
|
|
264
272
|
/**
|
|
@@ -271,7 +279,8 @@ export function assertProperties(assert) {
|
|
|
271
279
|
const visit = (tokens, negated) => {
|
|
272
280
|
for (const token of tokens) {
|
|
273
281
|
if (token.type === 'attribute' && token.action === 'exists' && !negated) names.push(toProperty(token.name));
|
|
274
|
-
|
|
282
|
+
// `:has([x])` asks about a descendant, so a property on this element does not answer it.
|
|
283
|
+
if (token.type === 'pseudo' && Array.isArray(token.data) && LOGICAL_PSEUDOS.has(token.name)) {
|
|
275
284
|
for (const inner of token.data) visit(inner, token.name === 'not' ? !negated : negated);
|
|
276
285
|
}
|
|
277
286
|
}
|
package/lint/rule-data.js
CHANGED
|
@@ -81,6 +81,10 @@ export const BUILT_IN_RULES = {
|
|
|
81
81
|
severity: 'warn',
|
|
82
82
|
description: 'The design system has no token with this name, so the declaration that uses it does nothing.',
|
|
83
83
|
},
|
|
84
|
+
'event-renamed': {
|
|
85
|
+
severity: 'warn',
|
|
86
|
+
description: 'The component no longer fires an event with this name, so a listener on it is never called.',
|
|
87
|
+
},
|
|
84
88
|
'translation-key-not-found': {
|
|
85
89
|
severity: 'warn',
|
|
86
90
|
description: 'The element has no translation key with this name, so the text stays Dutch.',
|
|
@@ -89,6 +93,10 @@ export const BUILT_IN_RULES = {
|
|
|
89
93
|
severity: 'warn',
|
|
90
94
|
description: 'A `--_` variable belongs to the inside of one component and can change in any release. Use the component\'s attributes, or open an issue for what is missing.',
|
|
91
95
|
},
|
|
96
|
+
'internal-context-no-use': {
|
|
97
|
+
severity: 'warn',
|
|
98
|
+
description: 'This `--context-` variable is wiring between components and can change in any release. Use the component\'s attributes, or open an issue for what is missing.',
|
|
99
|
+
},
|
|
92
100
|
'link-context-needs-states': {
|
|
93
101
|
severity: 'warn',
|
|
94
102
|
description: 'A surface that gives links a color sets all three link colors, or a link on it turns back to the default blue on hover or press.',
|
package/lint/rule.schema.json
CHANGED
|
@@ -20,10 +20,11 @@
|
|
|
20
20
|
"description": "What `--fix` changes. Only what keeps the meaning, for every value; anything else stays a finding.",
|
|
21
21
|
"properties": {
|
|
22
22
|
"rename": { "type": "object", "additionalProperties": { "type": "string" }, "description": "Attributes in `removed` that got another name, old to new." },
|
|
23
|
-
"value": { "type": "object", "additionalProperties": { "type": "object", "additionalProperties": { "type": "string" } }, "description": "Per attribute, values that got another name, old to new. Only a value written out in the markup." },
|
|
23
|
+
"value": { "type": "object", "additionalProperties": { "type": "object", "additionalProperties": { "type": "string" } }, "description": "Per attribute, values that got another name, old to new. Only a value written out in the markup, in quotes or as a literal in the braces of JSX." },
|
|
24
24
|
"remove": { "type": "array", "items": { "type": "string" }, "description": "Attributes in `removed` that do nothing any more." },
|
|
25
25
|
"flag": { "type": "object", "additionalProperties": { "type": "string" }, "description": "Attributes in `removed` whose value became a boolean attribute, old to new. The context names the value; only a value written out in the markup." },
|
|
26
26
|
"tag": { "type": "string", "description": "The new tag of a component in `removed` that got another name." },
|
|
27
|
+
"translation": { "type": "object", "additionalProperties": { "type": "string" }, "description": "Attributes in `removed` whose text became a translation key, attribute to key. The text goes in `translations`; only a value written out in the markup." },
|
|
27
28
|
"wrap": { "type": "string", "description": "The element that the text of an element goes in, with any inline elements. Only content written out in the markup, with inline elements only." }
|
|
28
29
|
}
|
|
29
30
|
},
|