@nldd/design-system 0.13.2 → 0.14.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/README.md +4 -2
- package/custom-elements.json +1425 -136
- package/dist/components/actions/button/button.d.ts +0 -2
- package/dist/components/actions/button/button.d.ts.map +1 -1
- package/dist/components/actions/button/button.js +17 -33
- package/dist/components/actions/button/button.js.map +1 -1
- package/dist/components/actions/button/button.template.js +2 -2
- package/dist/components/actions/button-bar/button-bar.d.ts +0 -2
- package/dist/components/actions/button-bar/button-bar.d.ts.map +1 -1
- package/dist/components/actions/button-bar/button-bar.js +2 -12
- package/dist/components/actions/button-bar/button-bar.js.map +1 -1
- package/dist/components/actions/button-group/button-group.d.ts.map +1 -1
- package/dist/components/actions/button-group/button-group.js +9 -10
- package/dist/components/actions/button-group/button-group.js.map +1 -1
- package/dist/components/actions/icon-button/icon-button.d.ts +0 -1
- package/dist/components/actions/icon-button/icon-button.d.ts.map +1 -1
- package/dist/components/actions/icon-button/icon-button.js +4 -11
- package/dist/components/actions/icon-button/icon-button.js.map +1 -1
- package/dist/components/actions/icon-button/icon-button.template.js +2 -2
- package/dist/components/actions/menu/menu-divider.d.ts +1 -0
- package/dist/components/actions/menu/menu-divider.d.ts.map +1 -1
- package/dist/components/actions/menu/menu-divider.js +1 -0
- package/dist/components/actions/menu/menu-divider.js.map +1 -1
- package/dist/components/actions/menu/menu-group.d.ts +1 -0
- package/dist/components/actions/menu/menu-group.d.ts.map +1 -1
- package/dist/components/actions/menu/menu-group.js +1 -0
- package/dist/components/actions/menu/menu-group.js.map +1 -1
- package/dist/components/actions/menu/menu-item.d.ts +1 -0
- package/dist/components/actions/menu/menu-item.d.ts.map +1 -1
- package/dist/components/actions/menu/menu-item.js +4 -7
- package/dist/components/actions/menu/menu-item.js.map +1 -1
- package/dist/components/actions/menu/menu.d.ts +1 -4
- package/dist/components/actions/menu/menu.d.ts.map +1 -1
- package/dist/components/actions/menu/menu.js +3 -17
- package/dist/components/actions/menu/menu.js.map +1 -1
- package/dist/components/actions/split-button/split-button.d.ts.map +1 -1
- package/dist/components/actions/split-button/split-button.js +2 -1
- package/dist/components/actions/split-button/split-button.js.map +1 -1
- package/dist/components/actions/toolbar/toolbar-item.d.ts +0 -2
- package/dist/components/actions/toolbar/toolbar-item.d.ts.map +1 -1
- package/dist/components/actions/toolbar/toolbar-item.js +2 -20
- package/dist/components/actions/toolbar/toolbar-item.js.map +1 -1
- package/dist/components/actions/toolbar/toolbar-title.d.ts.map +1 -1
- package/dist/components/actions/toolbar/toolbar-title.js +2 -1
- package/dist/components/actions/toolbar/toolbar-title.js.map +1 -1
- package/dist/components/actions/toolbar/toolbar.d.ts.map +1 -1
- package/dist/components/actions/toolbar/toolbar.js +2 -1
- package/dist/components/actions/toolbar/toolbar.js.map +1 -1
- package/dist/components/button.i18n-DiDGynnq.js +8 -0
- package/dist/components/components.js +352 -706
- package/dist/components/content/avatar/avatar.d.ts +0 -2
- package/dist/components/content/avatar/avatar.d.ts.map +1 -1
- package/dist/components/content/avatar/avatar.js +2 -27
- package/dist/components/content/avatar/avatar.js.map +1 -1
- package/dist/components/content/avatar-group/avatar-group.d.ts +0 -1
- package/dist/components/content/avatar-group/avatar-group.d.ts.map +1 -1
- package/dist/components/content/avatar-group/avatar-group.js +2 -24
- package/dist/components/content/avatar-group/avatar-group.js.map +1 -1
- package/dist/components/content/blockquote/blockquote.d.ts.map +1 -1
- package/dist/components/content/blockquote/blockquote.js +2 -1
- package/dist/components/content/blockquote/blockquote.js.map +1 -1
- package/dist/components/content/code-viewer/code-viewer.d.ts +1 -0
- package/dist/components/content/code-viewer/code-viewer.d.ts.map +1 -1
- package/dist/components/content/code-viewer/code-viewer.diff.d.ts +2 -0
- package/dist/components/content/code-viewer/code-viewer.diff.d.ts.map +1 -1
- package/dist/components/content/code-viewer/code-viewer.diff.js +1 -4
- package/dist/components/content/code-viewer/code-viewer.diff.js.map +1 -1
- package/dist/components/content/code-viewer/code-viewer.js +13 -11
- package/dist/components/content/code-viewer/code-viewer.js.map +1 -1
- package/dist/components/content/icon/icon.d.ts +3 -0
- package/dist/components/content/icon/icon.d.ts.map +1 -1
- package/dist/components/content/icon/icon.js +19 -15
- package/dist/components/content/icon/icon.js.map +1 -1
- package/dist/components/content/identity/identity.d.ts.map +1 -1
- package/dist/components/content/identity/identity.js +2 -1
- package/dist/components/content/identity/identity.js.map +1 -1
- package/dist/components/content/image/image.d.ts +5 -11
- package/dist/components/content/image/image.d.ts.map +1 -1
- package/dist/components/content/image/image.js +14 -31
- package/dist/components/content/image/image.js.map +1 -1
- package/dist/components/content/image/lqip-encoder-element.d.ts.map +1 -1
- package/dist/components/content/image/lqip-encoder-element.js +2 -1
- package/dist/components/content/image/lqip-encoder-element.js.map +1 -1
- package/dist/components/content/keyboard-shortcut/keyboard-shortcut.d.ts.map +1 -1
- package/dist/components/content/keyboard-shortcut/keyboard-shortcut.js +2 -1
- package/dist/components/content/keyboard-shortcut/keyboard-shortcut.js.map +1 -1
- package/dist/components/content/rich-text/rich-text.d.ts.map +1 -1
- package/dist/components/content/rich-text/rich-text.js +2 -1
- package/dist/components/content/rich-text/rich-text.js.map +1 -1
- package/dist/components/content/tag/tag.d.ts.map +1 -1
- package/dist/components/content/tag/tag.js +5 -5
- package/dist/components/content/tag/tag.js.map +1 -1
- package/dist/components/content/text/text.d.ts.map +1 -1
- package/dist/components/content/text/text.js +2 -1
- package/dist/components/content/text/text.js.map +1 -1
- package/dist/components/content/title/title.d.ts +1 -5
- package/dist/components/content/title/title.d.ts.map +1 -1
- package/dist/components/content/title/title.js +15 -27
- package/dist/components/content/title/title.js.map +1 -1
- package/dist/components/content/token/token.d.ts.map +1 -1
- package/dist/components/content/token/token.js +2 -1
- package/dist/components/content/token/token.js.map +1 -1
- package/dist/components/content/tooltip/tooltip.d.ts.map +1 -1
- package/dist/components/content/tooltip/tooltip.js +2 -1
- package/dist/components/content/tooltip/tooltip.js.map +1 -1
- package/dist/components/content/visually-hidden/visually-hidden.js +1 -1
- package/dist/components/content/visually-hidden/visually-hidden.js.map +1 -1
- package/dist/components/{decorate-Cz9-peTN.js → decorate-x12uDAK4.js} +9 -1
- package/dist/components/dev-checks-BgrW077W.js +2503 -0
- package/dist/components/element-state-BnarBv0M.js +42 -0
- package/dist/components/forms/form/form.d.ts +1 -96
- package/dist/components/forms/form/form.d.ts.map +1 -1
- package/dist/components/forms/form/form.js +1 -0
- package/dist/components/forms/form/form.js.map +1 -1
- package/dist/components/forms/form-actions/form-actions.d.ts.map +1 -1
- package/dist/components/forms/form-actions/form-actions.js +2 -1
- package/dist/components/forms/form-actions/form-actions.js.map +1 -1
- package/dist/components/forms/form-field/form-field.d.ts +1 -2
- package/dist/components/forms/form-field/form-field.d.ts.map +1 -1
- package/dist/components/forms/form-field/form-field.js +10 -26
- package/dist/components/forms/form-field/form-field.js.map +1 -1
- package/dist/components/forms/form-section/form-section.d.ts +1 -67
- package/dist/components/forms/form-section/form-section.d.ts.map +1 -1
- package/dist/components/forms/form-section/form-section.js +2 -16
- package/dist/components/forms/form-section/form-section.js.map +1 -1
- package/dist/components/forms/validation-list/validation-list.d.ts.map +1 -1
- package/dist/components/forms/validation-list/validation-list.js +7 -6
- package/dist/components/forms/validation-list/validation-list.js.map +1 -1
- package/dist/components/{icon-DRpTWSIg.js → icon-IgCyk9ui.js} +17 -4
- package/dist/components/{icon-button-DUEmWlBD.js → icon-button-B5tH4b3c.js} +8 -17
- package/dist/components/icon-button.i18n-1_N-wN6x.js +10 -0
- package/dist/components/inputs/checkbox/checkbox.d.ts.map +1 -1
- package/dist/components/inputs/checkbox/checkbox.js +2 -1
- package/dist/components/inputs/checkbox/checkbox.js.map +1 -1
- package/dist/components/inputs/checkbox-field/checkbox-field.d.ts.map +1 -1
- package/dist/components/inputs/checkbox-field/checkbox-field.js +2 -1
- package/dist/components/inputs/checkbox-field/checkbox-field.js.map +1 -1
- package/dist/components/inputs/code-editor/code-editor.d.ts.map +1 -1
- package/dist/components/inputs/code-editor/code-editor.js +2 -1
- package/dist/components/inputs/code-editor/code-editor.js.map +1 -1
- package/dist/components/inputs/combo-box/combo-box.d.ts.map +1 -1
- package/dist/components/inputs/combo-box/combo-box.js +4 -5
- package/dist/components/inputs/combo-box/combo-box.js.map +1 -1
- package/dist/components/inputs/date-field/date-field.d.ts.map +1 -1
- package/dist/components/inputs/date-field/date-field.js +2 -1
- package/dist/components/inputs/date-field/date-field.js.map +1 -1
- package/dist/components/inputs/date-picker/date-picker.d.ts.map +1 -1
- package/dist/components/inputs/date-picker/date-picker.js +2 -1
- package/dist/components/inputs/date-picker/date-picker.js.map +1 -1
- package/dist/components/inputs/dropdown/dropdown.d.ts.map +1 -1
- package/dist/components/inputs/dropdown/dropdown.js +5 -4
- package/dist/components/inputs/dropdown/dropdown.js.map +1 -1
- package/dist/components/inputs/file-field/file-field.d.ts.map +1 -1
- package/dist/components/inputs/file-field/file-field.js +2 -1
- package/dist/components/inputs/file-field/file-field.js.map +1 -1
- package/dist/components/inputs/multi-line-text-field/multi-line-text-field.d.ts.map +1 -1
- package/dist/components/inputs/multi-line-text-field/multi-line-text-field.js +2 -4
- package/dist/components/inputs/multi-line-text-field/multi-line-text-field.js.map +1 -1
- package/dist/components/inputs/number-field/number-field.d.ts.map +1 -1
- package/dist/components/inputs/number-field/number-field.js +2 -4
- package/dist/components/inputs/number-field/number-field.js.map +1 -1
- package/dist/components/inputs/password-field/password-field.d.ts.map +1 -1
- package/dist/components/inputs/password-field/password-field.js +2 -1
- package/dist/components/inputs/password-field/password-field.js.map +1 -1
- package/dist/components/inputs/radio-button/radio-button.d.ts.map +1 -1
- package/dist/components/inputs/radio-button/radio-button.js +2 -1
- package/dist/components/inputs/radio-button/radio-button.js.map +1 -1
- package/dist/components/inputs/radio-button-field/radio-button-field.d.ts.map +1 -1
- package/dist/components/inputs/radio-button-field/radio-button-field.js +2 -1
- package/dist/components/inputs/radio-button-field/radio-button-field.js.map +1 -1
- package/dist/components/inputs/radio-button-group/radio-button-group.d.ts +0 -1
- package/dist/components/inputs/radio-button-group/radio-button-group.d.ts.map +1 -1
- package/dist/components/inputs/radio-button-group/radio-button-group.js +2 -6
- package/dist/components/inputs/radio-button-group/radio-button-group.js.map +1 -1
- package/dist/components/inputs/search-field/search-field.d.ts.map +1 -1
- package/dist/components/inputs/search-field/search-field.js +2 -1
- package/dist/components/inputs/search-field/search-field.js.map +1 -1
- package/dist/components/inputs/segmented-control/segmented-control.d.ts +0 -1
- package/dist/components/inputs/segmented-control/segmented-control.d.ts.map +1 -1
- package/dist/components/inputs/segmented-control/segmented-control.js +2 -11
- package/dist/components/inputs/segmented-control/segmented-control.js.map +1 -1
- package/dist/components/inputs/slider/slider.d.ts.map +1 -1
- package/dist/components/inputs/slider/slider.js +2 -1
- package/dist/components/inputs/slider/slider.js.map +1 -1
- package/dist/components/inputs/stepper/stepper.d.ts.map +1 -1
- package/dist/components/inputs/stepper/stepper.js +2 -1
- package/dist/components/inputs/stepper/stepper.js.map +1 -1
- package/dist/components/inputs/switch/switch.d.ts.map +1 -1
- package/dist/components/inputs/switch/switch.js +2 -4
- package/dist/components/inputs/switch/switch.js.map +1 -1
- package/dist/components/inputs/switch-field/switch-field.d.ts.map +1 -1
- package/dist/components/inputs/switch-field/switch-field.js +2 -1
- package/dist/components/inputs/switch-field/switch-field.js.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.d.ts.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.js +7 -3
- package/dist/components/inputs/text-editor/text-editor.js.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.mentions.d.ts +2 -0
- package/dist/components/inputs/text-editor/text-editor.mentions.d.ts.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.mentions.js +14 -2
- package/dist/components/inputs/text-editor/text-editor.mentions.js.map +1 -1
- package/dist/components/inputs/text-field/text-field.d.ts +1 -5
- package/dist/components/inputs/text-field/text-field.d.ts.map +1 -1
- package/dist/components/inputs/text-field/text-field.js +6 -23
- package/dist/components/inputs/text-field/text-field.js.map +1 -1
- package/dist/components/inputs/time-field/time-field.d.ts.map +1 -1
- package/dist/components/inputs/time-field/time-field.js +2 -1
- package/dist/components/inputs/time-field/time-field.js.map +1 -1
- package/dist/components/inputs/time-picker/time-picker.d.ts.map +1 -1
- package/dist/components/inputs/time-picker/time-picker.js +2 -1
- package/dist/components/inputs/time-picker/time-picker.js.map +1 -1
- package/dist/components/inputs/toggle-button/toggle-button.d.ts +0 -2
- package/dist/components/inputs/toggle-button/toggle-button.d.ts.map +1 -1
- package/dist/components/inputs/toggle-button/toggle-button.js +2 -23
- package/dist/components/inputs/toggle-button/toggle-button.js.map +1 -1
- package/dist/components/inputs/toggle-button-group/toggle-button-group.d.ts +0 -2
- package/dist/components/inputs/toggle-button-group/toggle-button-group.d.ts.map +1 -1
- package/dist/components/inputs/toggle-button-group/toggle-button-group.js +2 -12
- package/dist/components/inputs/toggle-button-group/toggle-button-group.js.map +1 -1
- package/dist/components/inputs/token-field/token-field.d.ts.map +1 -1
- package/dist/components/inputs/token-field/token-field.js +2 -1
- package/dist/components/inputs/token-field/token-field.js.map +1 -1
- package/dist/components/just-in-time-education.i18n-BJ5ovWVB.js +370 -0
- package/dist/components/layout/box/box.d.ts.map +1 -1
- package/dist/components/layout/box/box.js +2 -1
- package/dist/components/layout/box/box.js.map +1 -1
- package/dist/components/layout/card/card.d.ts +0 -1
- package/dist/components/layout/card/card.d.ts.map +1 -1
- package/dist/components/layout/card/card.js +2 -15
- package/dist/components/layout/card/card.js.map +1 -1
- package/dist/components/layout/card/card.template.js +2 -2
- package/dist/components/layout/collection/collection.d.ts +0 -2
- package/dist/components/layout/collection/collection.d.ts.map +1 -1
- package/dist/components/layout/collection/collection.js +8 -24
- package/dist/components/layout/collection/collection.js.map +1 -1
- package/dist/components/layout/container/container.d.ts +6 -3
- package/dist/components/layout/container/container.d.ts.map +1 -1
- package/dist/components/layout/container/container.js +17 -23
- package/dist/components/layout/container/container.js.map +1 -1
- package/dist/components/layout/divider/divider.js +1 -1
- package/dist/components/layout/divider/divider.js.map +1 -1
- package/dist/components/layout/page/page.d.ts +2 -3
- package/dist/components/layout/page/page.d.ts.map +1 -1
- package/dist/components/layout/page/page.js +9 -12
- package/dist/components/layout/page/page.js.map +1 -1
- package/dist/components/layout/page-footer/page-footer.d.ts.map +1 -1
- package/dist/components/layout/page-footer/page-footer.js +6 -7
- package/dist/components/layout/page-footer/page-footer.js.map +1 -1
- package/dist/components/layout/page-sections/full-bleed-section/full-bleed-section.d.ts.map +1 -1
- package/dist/components/layout/page-sections/full-bleed-section/full-bleed-section.js +2 -1
- package/dist/components/layout/page-sections/full-bleed-section/full-bleed-section.js.map +1 -1
- package/dist/components/layout/page-sections/hero/hero-corner.d.ts +0 -1
- package/dist/components/layout/page-sections/hero/hero-corner.d.ts.map +1 -1
- package/dist/components/layout/page-sections/hero/hero-corner.js +9 -28
- package/dist/components/layout/page-sections/hero/hero-corner.js.map +1 -1
- package/dist/components/layout/page-sections/hero/hero.d.ts +1 -4
- package/dist/components/layout/page-sections/hero/hero.d.ts.map +1 -1
- package/dist/components/layout/page-sections/hero/hero.js +7 -29
- package/dist/components/layout/page-sections/hero/hero.js.map +1 -1
- package/dist/components/layout/page-sections/one-half-one-half-section/one-half-one-half-section.d.ts.map +1 -1
- package/dist/components/layout/page-sections/one-half-one-half-section/one-half-one-half-section.js +2 -1
- package/dist/components/layout/page-sections/one-half-one-half-section/one-half-one-half-section.js.map +1 -1
- package/dist/components/layout/page-sections/one-third-two-thirds-section/one-third-two-thirds-section.d.ts.map +1 -1
- package/dist/components/layout/page-sections/one-third-two-thirds-section/one-third-two-thirds-section.js +2 -1
- package/dist/components/layout/page-sections/one-third-two-thirds-section/one-third-two-thirds-section.js.map +1 -1
- package/dist/components/layout/page-sections/sidebar-section/sidebar-section.d.ts.map +1 -1
- package/dist/components/layout/page-sections/sidebar-section/sidebar-section.js +2 -1
- package/dist/components/layout/page-sections/sidebar-section/sidebar-section.js.map +1 -1
- package/dist/components/layout/page-sections/simple-section/simple-section.d.ts.map +1 -1
- package/dist/components/layout/page-sections/simple-section/simple-section.js +2 -1
- package/dist/components/layout/page-sections/simple-section/simple-section.js.map +1 -1
- package/dist/components/layout/page-sections/two-thirds-one-third-section/two-thirds-one-third-section.d.ts.map +1 -1
- package/dist/components/layout/page-sections/two-thirds-one-third-section/two-thirds-one-third-section.js +2 -1
- package/dist/components/layout/page-sections/two-thirds-one-third-section/two-thirds-one-third-section.js.map +1 -1
- package/dist/components/layout/popover/popover.d.ts +0 -2
- package/dist/components/layout/popover/popover.d.ts.map +1 -1
- package/dist/components/layout/popover/popover.js +6 -25
- package/dist/components/layout/popover/popover.js.map +1 -1
- package/dist/components/layout/sheet/sheet.d.ts +0 -2
- package/dist/components/layout/sheet/sheet.d.ts.map +1 -1
- package/dist/components/layout/sheet/sheet.js +9 -20
- package/dist/components/layout/sheet/sheet.js.map +1 -1
- package/dist/components/layout/shell/shell.d.ts.map +1 -1
- package/dist/components/layout/shell/shell.js +2 -1
- package/dist/components/layout/shell/shell.js.map +1 -1
- package/dist/components/layout/spacer/spacer.d.ts.map +1 -1
- package/dist/components/layout/spacer/spacer.js +2 -1
- package/dist/components/layout/spacer/spacer.js.map +1 -1
- package/dist/components/layout/split-views/bar-split-view/bar-split-view.d.ts +6 -6
- package/dist/components/layout/split-views/bar-split-view/bar-split-view.d.ts.map +1 -1
- package/dist/components/layout/split-views/bar-split-view/bar-split-view.js +9 -12
- package/dist/components/layout/split-views/bar-split-view/bar-split-view.js.map +1 -1
- package/dist/components/layout/split-views/navigation-split-view/navigation-split-view.d.ts.map +1 -1
- package/dist/components/layout/split-views/navigation-split-view/navigation-split-view.js +2 -1
- package/dist/components/layout/split-views/navigation-split-view/navigation-split-view.js.map +1 -1
- package/dist/components/layout/split-views/side-by-side-split-view/side-by-side-split-view.d.ts.map +1 -1
- package/dist/components/layout/split-views/side-by-side-split-view/side-by-side-split-view.js +2 -1
- package/dist/components/layout/split-views/side-by-side-split-view/side-by-side-split-view.js.map +1 -1
- package/dist/components/layout/split-views/split-view-divider/split-view-divider.d.ts.map +1 -1
- package/dist/components/layout/split-views/split-view-divider/split-view-divider.js +2 -1
- package/dist/components/layout/split-views/split-view-divider/split-view-divider.js.map +1 -1
- package/dist/components/layout/split-views/split-view-pane/split-view-pane.d.ts.map +1 -1
- package/dist/components/layout/split-views/split-view-pane/split-view-pane.js +2 -1
- package/dist/components/layout/split-views/split-view-pane/split-view-pane.js.map +1 -1
- package/dist/components/layout/split-views/stacked-split-view/stacked-split-view.d.ts.map +1 -1
- package/dist/components/layout/split-views/stacked-split-view/stacked-split-view.js +2 -1
- package/dist/components/layout/split-views/stacked-split-view/stacked-split-view.js.map +1 -1
- package/dist/components/layout/task-board/task-board-column.d.ts.map +1 -1
- package/dist/components/layout/task-board/task-board-column.js +2 -4
- package/dist/components/layout/task-board/task-board-column.js.map +1 -1
- package/dist/components/layout/task-board/task-board.d.ts.map +1 -1
- package/dist/components/layout/task-board/task-board.js +4 -3
- package/dist/components/layout/task-board/task-board.js.map +1 -1
- package/dist/components/layout/window/window.d.ts +0 -1
- package/dist/components/layout/window/window.d.ts.map +1 -1
- package/dist/components/layout/window/window.js +4 -6
- package/dist/components/layout/window/window.js.map +1 -1
- package/dist/components/list-item.i18n-89uqlBMK.js +8 -0
- package/dist/components/list.i18n-nFB6dZpc.js +13 -0
- package/dist/components/lists-and-tables/cells/cell/cell.d.ts.map +1 -1
- package/dist/components/lists-and-tables/cells/cell/cell.js +2 -1
- package/dist/components/lists-and-tables/cells/cell/cell.js.map +1 -1
- package/dist/components/lists-and-tables/cells/description-cell/description-cell.d.ts.map +1 -1
- package/dist/components/lists-and-tables/cells/description-cell/description-cell.js +2 -1
- package/dist/components/lists-and-tables/cells/description-cell/description-cell.js.map +1 -1
- package/dist/components/lists-and-tables/cells/drag-handle-cell/drag-handle-cell.d.ts.map +1 -1
- package/dist/components/lists-and-tables/cells/drag-handle-cell/drag-handle-cell.js +2 -1
- package/dist/components/lists-and-tables/cells/drag-handle-cell/drag-handle-cell.js.map +1 -1
- package/dist/components/lists-and-tables/cells/icon-cell/icon-cell.d.ts +1 -0
- package/dist/components/lists-and-tables/cells/icon-cell/icon-cell.d.ts.map +1 -1
- package/dist/components/lists-and-tables/cells/icon-cell/icon-cell.js +3 -1
- package/dist/components/lists-and-tables/cells/icon-cell/icon-cell.js.map +1 -1
- package/dist/components/lists-and-tables/cells/spacer-cell/spacer-cell.d.ts.map +1 -1
- package/dist/components/lists-and-tables/cells/spacer-cell/spacer-cell.js +2 -1
- package/dist/components/lists-and-tables/cells/spacer-cell/spacer-cell.js.map +1 -1
- package/dist/components/lists-and-tables/cells/step-cell/step-cell.d.ts +0 -1
- package/dist/components/lists-and-tables/cells/step-cell/step-cell.d.ts.map +1 -1
- package/dist/components/lists-and-tables/cells/step-cell/step-cell.js +5 -15
- package/dist/components/lists-and-tables/cells/step-cell/step-cell.js.map +1 -1
- package/dist/components/lists-and-tables/cells/text-cell/text-cell.d.ts.map +1 -1
- package/dist/components/lists-and-tables/cells/text-cell/text-cell.js +2 -1
- package/dist/components/lists-and-tables/cells/text-cell/text-cell.js.map +1 -1
- package/dist/components/lists-and-tables/cells/title-cell/title-cell.d.ts.map +1 -1
- package/dist/components/lists-and-tables/cells/title-cell/title-cell.js +2 -1
- package/dist/components/lists-and-tables/cells/title-cell/title-cell.js.map +1 -1
- package/dist/components/lists-and-tables/list/list.d.ts +5 -23
- package/dist/components/lists-and-tables/list/list.d.ts.map +1 -1
- package/dist/components/lists-and-tables/list/list.js +53 -98
- package/dist/components/lists-and-tables/list/list.js.map +1 -1
- package/dist/components/lists-and-tables/list-item/list-item.d.ts +10 -15
- package/dist/components/lists-and-tables/list-item/list-item.d.ts.map +1 -1
- package/dist/components/lists-and-tables/list-item/list-item.js +40 -87
- package/dist/components/lists-and-tables/list-item/list-item.js.map +1 -1
- package/dist/components/lists-and-tables/list-item-segment/list-item-segment.d.ts +2 -2
- package/dist/components/lists-and-tables/list-item-segment/list-item-segment.d.ts.map +1 -1
- package/dist/components/lists-and-tables/list-item-segment/list-item-segment.js +6 -11
- package/dist/components/lists-and-tables/list-item-segment/list-item-segment.js.map +1 -1
- package/dist/components/lists-and-tables/table/table.d.ts +0 -13
- package/dist/components/lists-and-tables/table/table.d.ts.map +1 -1
- package/dist/components/lists-and-tables/table/table.js +6 -41
- package/dist/components/lists-and-tables/table/table.js.map +1 -1
- package/dist/components/navigation/breadcrumbs/breadcrumbs.d.ts.map +1 -1
- package/dist/components/navigation/breadcrumbs/breadcrumbs.js +2 -1
- package/dist/components/navigation/breadcrumbs/breadcrumbs.js.map +1 -1
- package/dist/components/navigation/document-tab-bar/document-tab-bar.d.ts.map +1 -1
- package/dist/components/navigation/document-tab-bar/document-tab-bar.js +2 -4
- package/dist/components/navigation/document-tab-bar/document-tab-bar.js.map +1 -1
- package/dist/components/navigation/link/link.d.ts.map +1 -1
- package/dist/components/navigation/link/link.js +2 -1
- package/dist/components/navigation/link/link.js.map +1 -1
- package/dist/components/navigation/link/link.template.js +2 -2
- package/dist/components/navigation/menu-bar/menu-bar.d.ts +4 -0
- package/dist/components/navigation/menu-bar/menu-bar.d.ts.map +1 -1
- package/dist/components/navigation/menu-bar/menu-bar.js +13 -10
- package/dist/components/navigation/menu-bar/menu-bar.js.map +1 -1
- package/dist/components/navigation/menu-bar-item/menu-bar-item.d.ts.map +1 -1
- package/dist/components/navigation/menu-bar-item/menu-bar-item.js +2 -1
- package/dist/components/navigation/menu-bar-item/menu-bar-item.js.map +1 -1
- package/dist/components/navigation/pagination/pagination.d.ts.map +1 -1
- package/dist/components/navigation/pagination/pagination.js +2 -1
- package/dist/components/navigation/pagination/pagination.js.map +1 -1
- package/dist/components/navigation/skip-link/skip-link.d.ts.map +1 -1
- package/dist/components/navigation/skip-link/skip-link.js +6 -8
- package/dist/components/navigation/skip-link/skip-link.js.map +1 -1
- package/dist/components/navigation/tab-bar/tab-bar.d.ts +1 -1
- package/dist/components/navigation/tab-bar/tab-bar.d.ts.map +1 -1
- package/dist/components/navigation/tab-bar/tab-bar.js +5 -15
- package/dist/components/navigation/tab-bar/tab-bar.js.map +1 -1
- package/dist/components/navigation/top-navigation-bar/top-navigation-bar.d.ts +0 -1
- package/dist/components/navigation/top-navigation-bar/top-navigation-bar.d.ts.map +1 -1
- package/dist/components/navigation/top-navigation-bar/top-navigation-bar.js +6 -6
- package/dist/components/navigation/top-navigation-bar/top-navigation-bar.js.map +1 -1
- package/dist/components/navigation/top-title-bar/top-title-bar.d.ts.map +1 -1
- package/dist/components/navigation/top-title-bar/top-title-bar.js +7 -6
- package/dist/components/navigation/top-title-bar/top-title-bar.js.map +1 -1
- package/dist/components/nl.generated-Ny3Kwppu.js +61 -0
- package/dist/components/status-and-feedback/activity-indicator/activity-indicator.d.ts.map +1 -1
- package/dist/components/status-and-feedback/activity-indicator/activity-indicator.js +2 -1
- package/dist/components/status-and-feedback/activity-indicator/activity-indicator.js.map +1 -1
- package/dist/components/status-and-feedback/badge/badge.d.ts.map +1 -1
- package/dist/components/status-and-feedback/badge/badge.js +3 -6
- package/dist/components/status-and-feedback/badge/badge.js.map +1 -1
- package/dist/components/status-and-feedback/banner/banner.d.ts.map +1 -1
- package/dist/components/status-and-feedback/banner/banner.js +2 -1
- package/dist/components/status-and-feedback/banner/banner.js.map +1 -1
- package/dist/components/status-and-feedback/inline-dialog/inline-dialog.d.ts.map +1 -1
- package/dist/components/status-and-feedback/inline-dialog/inline-dialog.js +2 -1
- package/dist/components/status-and-feedback/inline-dialog/inline-dialog.js.map +1 -1
- package/dist/components/status-and-feedback/just-in-time-education/just-in-time-education.d.ts.map +1 -1
- package/dist/components/status-and-feedback/just-in-time-education/just-in-time-education.js +2 -1
- package/dist/components/status-and-feedback/just-in-time-education/just-in-time-education.js.map +1 -1
- package/dist/components/status-and-feedback/modal-dialog/modal-dialog.d.ts +0 -3
- package/dist/components/status-and-feedback/modal-dialog/modal-dialog.d.ts.map +1 -1
- package/dist/components/status-and-feedback/modal-dialog/modal-dialog.js +2 -14
- package/dist/components/status-and-feedback/modal-dialog/modal-dialog.js.map +1 -1
- package/dist/components/status-and-feedback/notification/notification.d.ts.map +1 -1
- package/dist/components/status-and-feedback/notification/notification.js +3 -7
- package/dist/components/status-and-feedback/notification/notification.js.map +1 -1
- package/dist/components/status-and-feedback/progress-bar/progress-bar.d.ts.map +1 -1
- package/dist/components/status-and-feedback/progress-bar/progress-bar.js +4 -5
- package/dist/components/status-and-feedback/progress-bar/progress-bar.js.map +1 -1
- package/dist/components/status-and-feedback/progress-circle/progress-circle.d.ts.map +1 -1
- package/dist/components/status-and-feedback/progress-circle/progress-circle.js +2 -1
- package/dist/components/status-and-feedback/progress-circle/progress-circle.js.map +1 -1
- package/dist/components/status-and-feedback/status-bar/status-bar.d.ts +1 -1
- package/dist/components/status-and-feedback/status-bar/status-bar.d.ts.map +1 -1
- package/dist/components/status-and-feedback/status-bar/status-bar.js +8 -7
- package/dist/components/status-and-feedback/status-bar/status-bar.js.map +1 -1
- package/dist/components/status-and-feedback/step-bar/step-bar.d.ts +0 -7
- package/dist/components/status-and-feedback/step-bar/step-bar.d.ts.map +1 -1
- package/dist/components/status-and-feedback/step-bar/step-bar.js +2 -24
- package/dist/components/status-and-feedback/step-bar/step-bar.js.map +1 -1
- package/dist/components/{visibility-mixin-C-K7ho5Q.js → visibility-mixin-DcwzF0_a.js} +1 -7
- package/dist/components/{with-translations-DRuOq3QK.js → with-translations-DLzmBSkU.js} +26 -5
- package/dist/nldd.min.js +775 -775
- package/dist/types/vue.d.ts +76 -6
- package/dist/utilities/codemirror/codemirror-input.d.ts +0 -2
- package/dist/utilities/codemirror/codemirror-input.d.ts.map +1 -1
- package/dist/utilities/codemirror/codemirror-input.js +0 -14
- package/dist/utilities/codemirror/codemirror-input.js.map +1 -1
- package/dist/utilities/custom-element.d.ts +7 -0
- package/dist/utilities/custom-element.d.ts.map +1 -0
- package/dist/utilities/custom-element.js +7 -0
- package/dist/utilities/custom-element.js.map +1 -0
- package/dist/utilities/dev-checks-trigger.d.ts +2 -0
- package/dist/utilities/dev-checks-trigger.d.ts.map +1 -0
- package/dist/utilities/dev-checks-trigger.js +10 -0
- package/dist/utilities/dev-checks-trigger.js.map +1 -0
- package/dist/utilities/dev-checks.d.ts +40 -0
- package/dist/utilities/dev-checks.d.ts.map +1 -0
- package/dist/utilities/dev-checks.js +115 -0
- package/dist/utilities/dev-checks.js.map +1 -0
- package/dist/utilities/dev-rules.generated.d.ts +3 -0
- package/dist/utilities/dev-rules.generated.d.ts.map +1 -0
- package/dist/utilities/dev-rules.generated.js +2472 -0
- package/dist/utilities/dev-rules.generated.js.map +1 -0
- package/dist/utilities/element-state.d.ts +19 -0
- package/dist/utilities/element-state.d.ts.map +1 -0
- package/dist/utilities/element-state.js +49 -0
- package/dist/utilities/element-state.js.map +1 -0
- package/dist/utilities/form-associated-mixin.d.ts.map +1 -1
- package/dist/utilities/form-associated-mixin.js +2 -1
- package/dist/utilities/form-associated-mixin.js.map +1 -1
- package/dist/utilities/link-hint.d.ts +2 -21
- package/dist/utilities/link-hint.d.ts.map +1 -1
- package/dist/utilities/link-hint.js +22 -8
- package/dist/utilities/link-hint.js.map +1 -1
- package/dist/utilities/spacing-scale.d.ts +4 -5
- package/dist/utilities/spacing-scale.d.ts.map +1 -1
- package/dist/utilities/spacing-scale.js +4 -23
- package/dist/utilities/spacing-scale.js.map +1 -1
- package/dist/utilities/translations.d.ts.map +1 -1
- package/dist/utilities/translations.js +3 -15
- package/dist/utilities/translations.js.map +1 -1
- package/dist/utilities/visibility-mixin.d.ts +7 -0
- package/dist/utilities/visibility-mixin.d.ts.map +1 -1
- package/dist/utilities/visibility-mixin.js +0 -10
- package/dist/utilities/visibility-mixin.js.map +1 -1
- package/lint/cli.js +18 -0
- package/lint/data.generated.json +1 -0
- package/lint/engine.js +191 -0
- package/lint/fix.js +293 -0
- package/lint/format.js +133 -0
- package/lint/frontends.js +483 -0
- package/lint/linter.js +262 -0
- package/lint/main.js +279 -0
- package/lint/project.js +143 -0
- package/lint/rule-data.js +83 -0
- package/lint/rule-index.js +20 -0
- package/lint/rule.schema.json +65 -0
- package/lint/tree.js +131 -0
- package/package.json +21 -4
package/lint/engine.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluates rules against a tree.
|
|
3
|
+
*
|
|
4
|
+
* Every rule runs in two worlds. In W+ whatever is unknown turns out in favour of
|
|
5
|
+
* presence: a bound attribute is set to any value, unknown content matches
|
|
6
|
+
* anything. In W- it all turns out absent. A violation in both worlds is
|
|
7
|
+
* `failed`, in neither `passed`, and anything else is `cantTell`, the W3C ACT
|
|
8
|
+
* outcome for a result that cannot be determined. Only `failed` is reported, so
|
|
9
|
+
* a rule never fires on something that might be fine at runtime.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { compile } from 'css-select';
|
|
13
|
+
import { parse } from 'css-what';
|
|
14
|
+
import { BOUND, adapter, walk } from './tree.js';
|
|
15
|
+
|
|
16
|
+
/** In W+ a sibling behind a condition might not show, as with `v-if`, `v-else` and tabs on `v-show`. */
|
|
17
|
+
const favorableAdapter = {
|
|
18
|
+
...adapter,
|
|
19
|
+
getSiblings: (node) =>
|
|
20
|
+
adapter.getSiblings(node).filter((each) => each === node || (!each.conditional && !each.repeated && !each.toggled)),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const BUILT_IN_PSEUDOS = new Set(['is', 'not', 'has', 'where', 'matches']);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether a field hands its label to `target`, as _findInput in nldd-form-field does:
|
|
27
|
+
* the first input in document order, helper text left out. The answer is `maybe` when
|
|
28
|
+
* something before it may or may not be an input that renders.
|
|
29
|
+
*/
|
|
30
|
+
function findsInput(node, target, isInput, uncertain = false) {
|
|
31
|
+
let maybe = uncertain;
|
|
32
|
+
for (const child of node.children) {
|
|
33
|
+
if (child.name === 'nldd-form-field-help-text') continue;
|
|
34
|
+
const unsure = maybe || child.conditional || child.repeated;
|
|
35
|
+
if (child === target) return maybe ? 'maybe' : 'yes';
|
|
36
|
+
if (isInput(child)) {
|
|
37
|
+
if (!unsure) return 'no';
|
|
38
|
+
maybe = true;
|
|
39
|
+
}
|
|
40
|
+
if (child.opaque) maybe = true;
|
|
41
|
+
const inside = findsInput(child, target, isInput, unsure);
|
|
42
|
+
if (inside !== 'absent') return inside;
|
|
43
|
+
}
|
|
44
|
+
return 'absent';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* On a running page the attribute is simply there, so the browser checks leave this
|
|
49
|
+
* out. In source it has to be worked out.
|
|
50
|
+
*/
|
|
51
|
+
function createFieldLabelCheck(isInput, allowMaybe) {
|
|
52
|
+
return (node) => {
|
|
53
|
+
for (let parent = node.parent; parent; parent = parent.parent) {
|
|
54
|
+
if (parent.name === 'nldd-form-field') {
|
|
55
|
+
const label = parent.attrs.get('label');
|
|
56
|
+
const unknownLabel = label === BOUND || parent.spread;
|
|
57
|
+
if (!unknownLabel && !label) return false;
|
|
58
|
+
const found = findsInput(parent, node, isInput);
|
|
59
|
+
if (found === 'yes' && !unknownLabel) return true;
|
|
60
|
+
return allowMaybe && found !== 'no';
|
|
61
|
+
}
|
|
62
|
+
if (parent.opaque) return allowMaybe;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function classPseudos(classes) {
|
|
69
|
+
return Object.fromEntries(
|
|
70
|
+
Object.entries(classes).map(([name, tags]) => {
|
|
71
|
+
const members = new Set(tags);
|
|
72
|
+
return [name, (node) => members.has(node.name)];
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Rewrites a selector for one world. W+ lets what is unknown match, W- does not, and
|
|
79
|
+
* `:not()` turns that around: unknown content that might be `x` makes `:not(x)` true
|
|
80
|
+
* in W+ only because there it is not taken for an `x`.
|
|
81
|
+
*/
|
|
82
|
+
function forWorld(tokens, classes, widen) {
|
|
83
|
+
const unknown = { type: 'pseudo', name: 'unknown', data: null };
|
|
84
|
+
return tokens.map((token) => {
|
|
85
|
+
if (token.type === 'pseudo' && BUILT_IN_PSEUDOS.has(token.name) && Array.isArray(token.data)) {
|
|
86
|
+
const inner = token.name === 'not' ? !widen : widen;
|
|
87
|
+
return { ...token, data: token.data.map((each) => forWorld(each, classes, inner)) };
|
|
88
|
+
}
|
|
89
|
+
if (!widen) return token;
|
|
90
|
+
if (token.type === 'pseudo' && token.name === 'named-by-field') return { ...token, name: 'may-be-named-by-field' };
|
|
91
|
+
if (token.type === 'tag' || (token.type === 'pseudo' && token.name in classes)) {
|
|
92
|
+
return { type: 'pseudo', name: 'is', data: [[token], [unknown]] };
|
|
93
|
+
}
|
|
94
|
+
// "Not empty" is about a value we have, and a bound value is not empty.
|
|
95
|
+
if (token.type === 'attribute' && token.action === 'equals' && token.value === '') return token;
|
|
96
|
+
if (token.type === 'attribute') {
|
|
97
|
+
const bound = { type: 'pseudo', name: 'bound', data: token.name };
|
|
98
|
+
return { type: 'pseudo', name: 'is', data: [[token], [bound]] };
|
|
99
|
+
}
|
|
100
|
+
return token;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function createEngine({ classes = {} } = {}) {
|
|
105
|
+
const shared = classPseudos(classes);
|
|
106
|
+
const pseudos = {
|
|
107
|
+
...shared,
|
|
108
|
+
'named-by-field': createFieldLabelCheck(shared['form-input'] ?? (() => false), false),
|
|
109
|
+
'may-be-named-by-field': createFieldLabelCheck(shared['form-input'] ?? (() => false), true),
|
|
110
|
+
// Only exists on a running page, so in source it is never true.
|
|
111
|
+
state: () => false,
|
|
112
|
+
unknown: (node) => node.opaque,
|
|
113
|
+
bound: (node, name) => node.opaque || node.spread || node.attrs.get(name) === BOUND,
|
|
114
|
+
};
|
|
115
|
+
const cache = new Map();
|
|
116
|
+
|
|
117
|
+
function matches(node, selector, world) {
|
|
118
|
+
const key = world + selector;
|
|
119
|
+
let test = cache.get(key);
|
|
120
|
+
if (!test) {
|
|
121
|
+
const query = parse(selector).map((tokens) => forWorld(tokens, classes, world === '+'));
|
|
122
|
+
test = compile(query, { adapter: world === '+' ? favorableAdapter : adapter, pseudos, xmlMode: true });
|
|
123
|
+
cache.set(key, test);
|
|
124
|
+
}
|
|
125
|
+
return test(node);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* W- counts what certainly renders, W+ whatever might. So `v-if` and `v-else` do
|
|
130
|
+
* not add up, and four static buttons are too many, whatever a `v-for` adds.
|
|
131
|
+
*/
|
|
132
|
+
function countViolated(rule, node, world) {
|
|
133
|
+
const { of, min, max } = rule.count;
|
|
134
|
+
const counted = node.children.filter((child) => matches(child, of, world));
|
|
135
|
+
if (world === '-') {
|
|
136
|
+
const certain = counted.filter((child) => !child.conditional && !child.repeated && !child.toggled && !child.opaque).length;
|
|
137
|
+
return (max !== undefined && certain > max) || (min !== undefined && certain < min);
|
|
138
|
+
}
|
|
139
|
+
const open = counted.some((child) => child.repeated) || node.children.some((child) => child.opaque);
|
|
140
|
+
return (max !== undefined && counted.length > max) || (min !== undefined && !open && counted.length < min);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function isViolated(rule, node, world) {
|
|
144
|
+
if (rule.assert) return !matches(node, rule.assert, world);
|
|
145
|
+
if (rule.report) return matches(node, rule.report, world);
|
|
146
|
+
if (rule.count) return countViolated(rule, node, world);
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function refOutcome(rule, node, root) {
|
|
151
|
+
const { attr, target, equal } = rule.ref;
|
|
152
|
+
const value = node.attrs.get(attr);
|
|
153
|
+
if (value === undefined) return 'passed';
|
|
154
|
+
if (value === BOUND || node.spread) return 'cantTell';
|
|
155
|
+
const found = [];
|
|
156
|
+
walk(root, (candidate) => {
|
|
157
|
+
if (candidate.attrs.get('id') === value && matches(candidate, target, '-')) {
|
|
158
|
+
found.push(candidate);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
// The target may be rendered by another file, unless this is a whole document.
|
|
162
|
+
if (found.length === 0) return root.opaque ? 'cantTell' : 'failed';
|
|
163
|
+
if (!equal) return 'passed';
|
|
164
|
+
const expected = node.attrs.get(equal);
|
|
165
|
+
const actual = found[0].attrs.get(equal);
|
|
166
|
+
if (expected === BOUND || actual === BOUND) return 'cantTell';
|
|
167
|
+
return expected === actual ? 'passed' : 'failed';
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** @returns {{ node: object, outcome: 'passed' | 'failed' | 'cantTell' }[]} */
|
|
171
|
+
function evaluate(rule, root) {
|
|
172
|
+
const results = [];
|
|
173
|
+
walk(root, (node) => {
|
|
174
|
+
if (node.opaque) return;
|
|
175
|
+
const inMinus = matches(node, rule.context, '-');
|
|
176
|
+
const inPlus = matches(node, rule.context, '+');
|
|
177
|
+
if (!inMinus && !inPlus) return;
|
|
178
|
+
if (rule.ref) {
|
|
179
|
+
results.push({ node, outcome: refOutcome(rule, node, root) });
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const minus = inMinus && isViolated(rule, node, '-');
|
|
183
|
+
const plus = inPlus && isViolated(rule, node, '+');
|
|
184
|
+
const outcome = minus && plus ? 'failed' : !minus && !plus ? 'passed' : 'cantTell';
|
|
185
|
+
results.push({ node, outcome });
|
|
186
|
+
});
|
|
187
|
+
return results;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return { evaluate };
|
|
191
|
+
}
|
package/lint/fix.js
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies what `--fix` may do without anyone looking. A rule says what changes, in
|
|
3
|
+
* its `fix`; this file knows how that is written in each framework. A fix works on
|
|
4
|
+
* the text of the file, so the rest of it stays exactly as it was.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const toCamelCase = (name) => name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
8
|
+
|
|
9
|
+
/** Where a template language opens a hole in a string: `${ }`, `{{ }}` or `{% %}`. */
|
|
10
|
+
const isHole = (source, at) => source.startsWith('${', at) || source.startsWith('{{', at) || source.startsWith('{%', at);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The closing quote of the string at `start`, past the holes in it, which hold
|
|
14
|
+
* quotes of their own. A backslash escapes only in code: HTML has no such thing.
|
|
15
|
+
*/
|
|
16
|
+
function endOfString(source, start, inCode = false) {
|
|
17
|
+
for (let at = start + 1; at < source.length; at++) {
|
|
18
|
+
if (inCode && source[at] === '\\') at += 1;
|
|
19
|
+
else if (source[at] === source[start]) return at;
|
|
20
|
+
else if (isHole(source, at)) {
|
|
21
|
+
at = endOfBraces(source, source.indexOf('{', at));
|
|
22
|
+
if (at === undefined) return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The last `}` of the braces at `start`. */
|
|
29
|
+
function endOfBraces(source, start) {
|
|
30
|
+
let depth = 0;
|
|
31
|
+
for (let at = start; at < source.length; at++) {
|
|
32
|
+
const char = source[at];
|
|
33
|
+
if (source.startsWith('/*', at)) {
|
|
34
|
+
at = source.indexOf('*/', at) + 1;
|
|
35
|
+
if (at === 0) return undefined;
|
|
36
|
+
} else if (source.startsWith('//', at)) {
|
|
37
|
+
at = source.indexOf('\n', at);
|
|
38
|
+
if (at === -1) return undefined;
|
|
39
|
+
} else if (/["'`]/.test(char)) {
|
|
40
|
+
at = endOfString(source, at, true);
|
|
41
|
+
if (at === undefined) return undefined;
|
|
42
|
+
} else if (char === '{') depth += 1;
|
|
43
|
+
else if (char === '}' && --depth === 0) return at;
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The start tag from `start`, with strings and `{ }` blanked: a value can hold anything. */
|
|
49
|
+
function maskedTag(source, start) {
|
|
50
|
+
let masked = '';
|
|
51
|
+
for (let at = start; at < source.length; at++) {
|
|
52
|
+
const char = source[at];
|
|
53
|
+
const quoted = /["'`]/.test(char);
|
|
54
|
+
if (char === '>') return masked;
|
|
55
|
+
if (quoted || char === '{') {
|
|
56
|
+
const end = quoted ? endOfString(source, at) : endOfBraces(source, at);
|
|
57
|
+
if (end === undefined) return masked;
|
|
58
|
+
masked += ' '.repeat(end - at + 1);
|
|
59
|
+
at = end;
|
|
60
|
+
} else masked += char;
|
|
61
|
+
}
|
|
62
|
+
return masked;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Vue, Alpine, Lit and Angular write a name with a prefix, and JSX bare. */
|
|
66
|
+
function attributePattern(name) {
|
|
67
|
+
const names = [...new Set([name, toCamelCase(name)])].join('|');
|
|
68
|
+
return new RegExp(`(?<=\\s)(:|v-bind:|x-bind:|\\.|\\?|\\[attr\\.|\\[\\(?)?(${names})(?=[\\s=/\\])]|$)`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Where the attribute stands in the start tag at `offset`, if it does. */
|
|
72
|
+
function findAttribute(source, offset, name) {
|
|
73
|
+
const masked = maskedTag(source, offset);
|
|
74
|
+
// A comment in a tag can hold anything, and a line comment takes what follows it.
|
|
75
|
+
if (/\/[*/]/.test(masked)) return undefined;
|
|
76
|
+
const match = attributePattern(name).exec(masked);
|
|
77
|
+
if (!match) return undefined;
|
|
78
|
+
const [, prefix = '', written] = match;
|
|
79
|
+
const start = offset + match.index + prefix.length;
|
|
80
|
+
return { prefix, written, start, end: start + written.length };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function renameEdits(source, offset, from, to) {
|
|
84
|
+
const found = findAttribute(source, offset, from);
|
|
85
|
+
if (!found || findAttribute(source, offset, to)) return [];
|
|
86
|
+
const { prefix, written, start, end } = found;
|
|
87
|
+
const isProperty = prefix === '.' || (prefix.startsWith('[') && prefix !== '[attr.');
|
|
88
|
+
return [{ from: start, to: end, text: isProperty || written !== from ? toCamelCase(to) : to }];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Only a value written out in the markup: a bound one can hold anything. */
|
|
92
|
+
function valueEdits(source, offset, name, values) {
|
|
93
|
+
const found = findAttribute(source, offset, name);
|
|
94
|
+
if (!found || found.prefix) return [];
|
|
95
|
+
const opening = /^\s*=\s*(["']?)/.exec(source.slice(found.end));
|
|
96
|
+
if (!opening) return [];
|
|
97
|
+
const at = found.end + opening[0].length;
|
|
98
|
+
return Object.entries(values).flatMap(([from, to]) => {
|
|
99
|
+
const after = source[at + from.length];
|
|
100
|
+
const whole = opening[1] ? after === opening[1] : /[\s/>]/.test(after ?? ' ');
|
|
101
|
+
return source.startsWith(from, at) && whole ? [{ from: at, to: at + from.length, text: to }] : [];
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const endsValue = (source, at) => at >= source.length || /[\s>]/.test(source[at]) || source.startsWith('/>', at);
|
|
106
|
+
|
|
107
|
+
/** The end of an attribute's value, or undefined when it does not end where a value ends. */
|
|
108
|
+
function endOfValue(source, name) {
|
|
109
|
+
const closers = /^[\])]*/.exec(source.slice(name))[0].length;
|
|
110
|
+
const equals = /^\s*=\s*/.exec(source.slice(name + closers));
|
|
111
|
+
if (!equals) return name + closers;
|
|
112
|
+
const start = name + closers + equals[0].length;
|
|
113
|
+
if (source.startsWith('{%', start)) return undefined;
|
|
114
|
+
let at = start;
|
|
115
|
+
while (at !== undefined && !endsValue(source, at)) {
|
|
116
|
+
if (/["'`]/.test(source[at])) at = endOfString(source, at);
|
|
117
|
+
else if (source[at] === '{') at = endOfBraces(source, at);
|
|
118
|
+
if (at !== undefined) at += 1;
|
|
119
|
+
}
|
|
120
|
+
return at;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function removeEdits(source, offset, name) {
|
|
124
|
+
const found = findAttribute(source, offset, name);
|
|
125
|
+
const end = found && endOfValue(source, found.end);
|
|
126
|
+
if (end === undefined) return [];
|
|
127
|
+
let from = found.start - found.prefix.length;
|
|
128
|
+
while (/\s/.test(source[from - 1])) from -= 1;
|
|
129
|
+
return [{ from, to: end, text: '' }];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The parser says where an element ends: a comment or a string that looks like its
|
|
134
|
+
* closing tag does not count. Without a closing tag of its own it stays as it is.
|
|
135
|
+
*/
|
|
136
|
+
function tagEdits(source, offset, endOffset, name, to) {
|
|
137
|
+
// An element the file never closes ends past the last character.
|
|
138
|
+
if (endOffset === undefined || endOffset >= source.length || !source.startsWith(`<${name}`, offset)) return [];
|
|
139
|
+
const open = { from: offset + 1, to: offset + 1 + name.length, text: to };
|
|
140
|
+
const startTag = maskedTag(source, offset);
|
|
141
|
+
if (startTag.trimEnd().endsWith('/') && offset + startTag.length === endOffset) return [open];
|
|
142
|
+
const closing = source.lastIndexOf('</', endOffset);
|
|
143
|
+
if (closing <= offset || !new RegExp(`^</${name}\\s*>$`).test(source.slice(closing, endOffset + 1))) return [];
|
|
144
|
+
return [open, { from: closing + 2, to: closing + 2 + name.length, text: to, closing: true }];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** An edit is `{ from, to, text }` in the source. What is not certain makes none. */
|
|
148
|
+
function editsOf(source, { fix, offset, endOffset, tag }) {
|
|
149
|
+
return [
|
|
150
|
+
...Object.entries(fix.rename ?? {}).flatMap(([from, to]) => renameEdits(source, offset, from, to)),
|
|
151
|
+
...Object.entries(fix.value ?? {}).flatMap(([name, values]) => valueEdits(source, offset, name, values)),
|
|
152
|
+
...(fix.remove ?? []).flatMap((name) => removeEdits(source, offset, name)),
|
|
153
|
+
...(fix.tag ? tagEdits(source, offset, endOffset, tag, fix.tag) : []),
|
|
154
|
+
];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** False when a finding has a fix that does not apply here, such as with both names present. */
|
|
158
|
+
export const canFix = (source, finding) => editsOf(source, finding).length > 0;
|
|
159
|
+
|
|
160
|
+
const withoutComments = (source) => source.replace(/<!--[^]*?-->|\{#[^]*?#\}|\{%\s*comment\s*%\}[^]*?\{%\s*endcomment\s*%\}/g, '');
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Half a rename breaks a template, so a tag goes everywhere in a file or nowhere.
|
|
164
|
+
* Control flow in text is invisible to the parser, which sees one element in
|
|
165
|
+
* `{% if a %}<x>{% else %}<x>{% endif %}</x>` and in the reverse with two closers.
|
|
166
|
+
* JSX has no such thing: there the parser is enough.
|
|
167
|
+
* @returns {Set<string>} Tags that stay as they are.
|
|
168
|
+
*/
|
|
169
|
+
export function stuckTags(source, findings, isJsx) {
|
|
170
|
+
const stuck = new Set();
|
|
171
|
+
const renamed = findings.filter(({ fix }) => fix?.tag);
|
|
172
|
+
for (const tag of new Set(renamed.map((finding) => finding.tag))) {
|
|
173
|
+
const edits = renamed.filter((finding) => finding.tag === tag).map((finding) => editsOf(source, finding));
|
|
174
|
+
const closers = withoutComments(source).match(new RegExp(`</${tag}\\s*>`, 'g'))?.length ?? 0;
|
|
175
|
+
const paired = edits.filter((list) => list.length === 2).length;
|
|
176
|
+
if (edits.some((list) => list.length === 0) || (!isJsx && closers !== paired)) stuck.add(tag);
|
|
177
|
+
}
|
|
178
|
+
return stuck;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const toClass = (tag) => `NLDD${toCamelCase(tag.replace(/^nldd-/, '-'))}`;
|
|
182
|
+
const entryPoint = (tag) => `@nldd/design-system/${tag.replace(/^nldd-/, '')}`;
|
|
183
|
+
const translationKey = (tag) => `components.${tag.replace(/^nldd-/, '')}`;
|
|
184
|
+
|
|
185
|
+
const escaped = (name) => name.replace(/[/@.-]/g, '\\$&');
|
|
186
|
+
const nameIn = (name) => new RegExp(`(?<![\\w-])${escaped(name)}(?![\\w-])`, 'g');
|
|
187
|
+
|
|
188
|
+
/** Not `.nldd-x`, `#nldd-x` or a path: those are a class, an id and a file of the app. */
|
|
189
|
+
const tagName = (tag) => `(?<![\\w.#/-])${escaped(tag)}(?![\\w-])`;
|
|
190
|
+
|
|
191
|
+
/** In a selector, a tag stands free: `[a="nldd-x"]` and `[a=nldd-x]` are values. */
|
|
192
|
+
const selectorName = (tag) => `(?<!["'=])${tagName(tag)}(?!["'])`;
|
|
193
|
+
|
|
194
|
+
/** The arguments that can only be a selector or a tag. */
|
|
195
|
+
const SELECTOR_CALL = /((?:querySelector(?:All)?|closest|matches|locator|createElement|getElementsByTagName)\(\s*)(["'`])([^"'`\n]*)\2/g;
|
|
196
|
+
|
|
197
|
+
function renameInScript(source, tag, to) {
|
|
198
|
+
let count = 0;
|
|
199
|
+
const inMarkup = source.replace(new RegExp(`(<\\\\?/?)${escaped(tag)}(?=[\\s/>])`, 'g'), (_, opening) => {
|
|
200
|
+
count += 1;
|
|
201
|
+
return opening + to;
|
|
202
|
+
});
|
|
203
|
+
const text = inMarkup.replace(SELECTOR_CALL, (call, name, quote, selector) => {
|
|
204
|
+
const renamed = selector.replace(new RegExp(selectorName(tag), 'g'), () => {
|
|
205
|
+
count += 1;
|
|
206
|
+
return to;
|
|
207
|
+
});
|
|
208
|
+
return `${name}${quote}${renamed}${quote}`;
|
|
209
|
+
});
|
|
210
|
+
return { text, count };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** A selector stands before the brace of a rule, or on a line of a list that ends in a comma. */
|
|
214
|
+
function renameInStyles(source, tag, to) {
|
|
215
|
+
let count = 0;
|
|
216
|
+
const text = source
|
|
217
|
+
.split('\n')
|
|
218
|
+
.map((line) => {
|
|
219
|
+
const brace = line.indexOf('{');
|
|
220
|
+
const selector = brace === -1 ? line : line.slice(0, brace);
|
|
221
|
+
const opensRule = brace !== -1 || /,\s*$/.test(line);
|
|
222
|
+
if (!opensRule || /^\s*@|:\s|url\(|image-set\(/.test(selector)) return line;
|
|
223
|
+
const renamed = selector.replace(new RegExp(selectorName(tag), 'g'), () => {
|
|
224
|
+
count += 1;
|
|
225
|
+
return to;
|
|
226
|
+
});
|
|
227
|
+
return renamed + line.slice(selector.length);
|
|
228
|
+
})
|
|
229
|
+
.join('\n');
|
|
230
|
+
return { text, count };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function replaceAll(source, pattern, to) {
|
|
234
|
+
let count = 0;
|
|
235
|
+
const text = source.replace(pattern, () => {
|
|
236
|
+
count += 1;
|
|
237
|
+
return to;
|
|
238
|
+
});
|
|
239
|
+
return { text, count };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Renames what names a renamed tag outside its markup, where that is certain: an
|
|
244
|
+
* import and a class anywhere, a tag in a stylesheet, in a selector call or in
|
|
245
|
+
* markup in a script. Not in a file with a suppression, which may be about that
|
|
246
|
+
* tag, or one that defines the old tag. The rest, `linesNaming` points at.
|
|
247
|
+
* @param {'markup' | 'script' | 'styles'} kind
|
|
248
|
+
* @returns {{ source: string, fixed: number }}
|
|
249
|
+
*/
|
|
250
|
+
export function renameReferences(source, renamedTags, kind) {
|
|
251
|
+
let text = source;
|
|
252
|
+
let fixed = 0;
|
|
253
|
+
const apply = ({ text: changed, count }) => {
|
|
254
|
+
text = changed;
|
|
255
|
+
fixed += count;
|
|
256
|
+
};
|
|
257
|
+
for (const [from, to] of renamedTags) {
|
|
258
|
+
if (new RegExp(`(define|customElement)\\(\\s*["'\`]${from}["'\`]`).test(source)) continue;
|
|
259
|
+
apply(replaceAll(text, nameIn(entryPoint(from)), entryPoint(to)));
|
|
260
|
+
apply(replaceAll(text, nameIn(toClass(from)), toClass(to)));
|
|
261
|
+
if (source.includes('nldd-lint-disable')) continue;
|
|
262
|
+
if (kind === 'script') apply(renameInScript(text, from, to));
|
|
263
|
+
if (kind === 'styles') apply(renameInStyles(text, from, to));
|
|
264
|
+
}
|
|
265
|
+
return { source: text, fixed };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** Lines that still name a renamed tag or its translation keys, for someone to look at. */
|
|
269
|
+
export function linesNaming(source, renamedTags) {
|
|
270
|
+
const names = [...renamedTags.keys()].flatMap((tag) => [new RegExp(tagName(tag)), nameIn(translationKey(tag))]);
|
|
271
|
+
return source.split('\n').flatMap((line, index) => (names.some((name) => line.search(name) !== -1) ? [index + 1] : []));
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* @returns {{ source: string, fixed: number, renamedTags: Map<string, string> }}
|
|
276
|
+
*/
|
|
277
|
+
export function applyFixes(source, findings) {
|
|
278
|
+
const renamedTags = new Map();
|
|
279
|
+
const edits = findings
|
|
280
|
+
.filter(({ fix }) => fix)
|
|
281
|
+
.flatMap((finding) => {
|
|
282
|
+
const found = editsOf(source, finding);
|
|
283
|
+
if (found.length > 0 && finding.fix.tag) renamedTags.set(finding.tag, finding.fix.tag);
|
|
284
|
+
return found;
|
|
285
|
+
});
|
|
286
|
+
const seen = new Set();
|
|
287
|
+
const unique = edits.filter(({ from }) => !seen.has(from) && seen.add(from));
|
|
288
|
+
let fixed = source;
|
|
289
|
+
for (const { from, to, text } of unique.sort((a, b) => b.from - a.from)) {
|
|
290
|
+
fixed = fixed.slice(0, from) + text + fixed.slice(to);
|
|
291
|
+
}
|
|
292
|
+
return { source: fixed, fixed: unique.filter(({ closing }) => !closing).length, renamedTags };
|
|
293
|
+
}
|
package/lint/format.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/** Renders findings. `text` is for people, `json` for agents and tools, `github` for CI. */
|
|
2
|
+
|
|
3
|
+
import { relative } from 'node:path';
|
|
4
|
+
|
|
5
|
+
const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
6
|
+
const paint = (code) => (text) => (useColor ? `\u001b[${code}m${text}\u001b[0m` : text);
|
|
7
|
+
const red = paint(31);
|
|
8
|
+
const yellow = paint(33);
|
|
9
|
+
const dim = paint(2);
|
|
10
|
+
const blue = paint(34);
|
|
11
|
+
const bold = paint(1);
|
|
12
|
+
|
|
13
|
+
function codeFrame(sourceLine, line, column, tag) {
|
|
14
|
+
const gutter = String(line);
|
|
15
|
+
const pointer = '^'.repeat(Math.max(1, tag.length + 1));
|
|
16
|
+
const lead = sourceLine.slice(0, column - 1).replace(/[^\t]/g, ' ');
|
|
17
|
+
return [
|
|
18
|
+
` ${dim(`${gutter} │`)} ${sourceLine}`,
|
|
19
|
+
` ${' '.repeat(gutter.length)} ${dim('│')} ${lead}${red(pointer)}`,
|
|
20
|
+
].join('\n');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const plural = (count, word) => `${count} ${word}${count === 1 ? '' : 's'}`;
|
|
24
|
+
|
|
25
|
+
/** A hint is advice, so it gets one entry however often it applies. */
|
|
26
|
+
function hintSummary(results, root, explainRule) {
|
|
27
|
+
const grouped = new Map();
|
|
28
|
+
for (const { filename, findings } of results) {
|
|
29
|
+
for (const { severity, rule, message, line } of findings) {
|
|
30
|
+
if (severity !== 'hint') continue;
|
|
31
|
+
const key = `${rule}\n${message}`;
|
|
32
|
+
const entry = grouped.get(key) ?? { rule, message, places: [] };
|
|
33
|
+
entry.places.push(`${relative(root, filename)}:${line}`);
|
|
34
|
+
grouped.set(key, entry);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const lines = [];
|
|
38
|
+
for (const { rule, message, places } of grouped.values()) {
|
|
39
|
+
const shown = places.slice(0, 2).join(', ');
|
|
40
|
+
const more = places.length > 2 ? `, +${places.length - 2}` : '';
|
|
41
|
+
lines.push(` ${rule} ${dim(`${places.length}× ${shown}${more}`)}`, ` ${message}`);
|
|
42
|
+
const see = explainRule?.(rule)?.url;
|
|
43
|
+
if (see) lines.push(dim(` → ${see}`));
|
|
44
|
+
}
|
|
45
|
+
return lines;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function formatText(results, { root, files, ms, skipped, explainRule }) {
|
|
49
|
+
const lines = [];
|
|
50
|
+
for (const { filename, source, findings } of results) {
|
|
51
|
+
const sourceLines = source.split('\n');
|
|
52
|
+
for (const finding of findings.filter(({ severity }) => severity !== 'hint')) {
|
|
53
|
+
const { line, column, severity, rule, message, tag } = finding;
|
|
54
|
+
const location = `${relative(root, filename)}:${line}:${column}`;
|
|
55
|
+
const label = severity === 'error' ? red('error') : yellow('warn');
|
|
56
|
+
lines.push(`${bold(location)} ${label} ${rule}`, ` ${message}`);
|
|
57
|
+
if (tag) lines.push(codeFrame(sourceLines[line - 1] ?? '', line, column, tag));
|
|
58
|
+
lines.push(dim(` → nldd explain ${rule}`), '');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const all = results.flatMap((result) => result.findings);
|
|
62
|
+
const advice = hintSummary(results, root, explainRule);
|
|
63
|
+
if (advice.length > 0) lines.push(blue('Hints'), ...advice, '');
|
|
64
|
+
const count = (level) => all.filter((finding) => finding.severity === level).length;
|
|
65
|
+
const errors = count('error');
|
|
66
|
+
const warnings = count('warn');
|
|
67
|
+
const hints = count('hint') ? `, ${plural(count('hint'), 'hint')}` : '';
|
|
68
|
+
const known = skipped ? dim(` (${skipped} in baseline)`) : '';
|
|
69
|
+
const summary = `${plural(errors, 'error')}, ${plural(warnings, 'warning')}${hints} in ${plural(files, 'file')} (${ms} ms)`;
|
|
70
|
+
const fixable = all.filter(({ fix }) => fix).length;
|
|
71
|
+
const canFix = fixable ? `, ${fixable} fixable with --fix` : '';
|
|
72
|
+
lines.push(`${errors + warnings ? red('✖') : '✔'} ${summary}${known}${canFix}`);
|
|
73
|
+
return lines.join('\n');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A count per rule, most first: where to start when a project has hundreds. */
|
|
77
|
+
export function formatStatistics(results, { files, ms, skipped }) {
|
|
78
|
+
const counts = new Map();
|
|
79
|
+
for (const { rule, severity, fix } of results.flatMap(({ findings }) => findings)) {
|
|
80
|
+
const entry = counts.get(rule) ?? { rule, severity, count: 0 };
|
|
81
|
+
entry.count += 1;
|
|
82
|
+
entry.fixable = Boolean(fix);
|
|
83
|
+
counts.set(rule, entry);
|
|
84
|
+
}
|
|
85
|
+
const rows = [...counts.values()].sort((a, b) => b.count - a.count || a.rule.localeCompare(b.rule));
|
|
86
|
+
const width = String(rows[0]?.count ?? 0).length;
|
|
87
|
+
const total = rows.reduce((sum, { count }) => sum + count, 0);
|
|
88
|
+
return [
|
|
89
|
+
...rows.map(({ count, severity, rule, fixable }) => `${String(count).padStart(width)} ${severity.padEnd(5)} ${rule}${fixable ? ' [--fix]' : ''}`),
|
|
90
|
+
...(rows.length > 0 ? [''] : []),
|
|
91
|
+
`${plural(total, 'finding')} in ${plural(files, 'file')} (${ms} ms)${skipped ? ` (${skipped} in baseline)` : ''}`,
|
|
92
|
+
].join('\n');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Everything an agent needs to fix a finding without opening the docs. */
|
|
96
|
+
export function formatJson(results, { root, explainRule }) {
|
|
97
|
+
const findings = results.flatMap(({ filename, findings: list }) =>
|
|
98
|
+
list.map((finding) => {
|
|
99
|
+
const detail = explainRule(finding.rule);
|
|
100
|
+
return {
|
|
101
|
+
file: relative(root, filename),
|
|
102
|
+
line: finding.line,
|
|
103
|
+
column: finding.column,
|
|
104
|
+
severity: finding.severity,
|
|
105
|
+
rule: finding.rule,
|
|
106
|
+
message: finding.message,
|
|
107
|
+
see: detail?.see,
|
|
108
|
+
url: detail?.url,
|
|
109
|
+
fixable: Boolean(finding.fix),
|
|
110
|
+
example: detail?.examples?.passed?.[0],
|
|
111
|
+
};
|
|
112
|
+
}),
|
|
113
|
+
);
|
|
114
|
+
return JSON.stringify({ findings }, null, 2);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function escapeGithub(text) {
|
|
118
|
+
return text.replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const escapeProperty = (text) => escapeGithub(text).replace(/:/g, '%3A').replace(/,/g, '%2C');
|
|
122
|
+
|
|
123
|
+
export function formatGithub(results, { root }) {
|
|
124
|
+
const lines = [];
|
|
125
|
+
for (const { filename, findings } of results) {
|
|
126
|
+
for (const { severity, line, column, rule, message } of findings) {
|
|
127
|
+
const level = { error: 'error', warn: 'warning', hint: 'notice' }[severity];
|
|
128
|
+
const file = relative(root, filename);
|
|
129
|
+
lines.push(`::${level} file=${escapeProperty(file)},line=${line},col=${column},title=${rule}::${escapeGithub(message)}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return lines.join('\n');
|
|
133
|
+
}
|