wagtail / stylelint-config-wagtail

Shareable stylelint config for CSS and SCSS, following Wagtail’s code style.
https://www.npmjs.com/package/@wagtail/stylelint-config-wagtail
MIT License
11 stars 4 forks source link

Add ability to block selectors that select data attributes #28

Closed lb- closed 2 years ago

lb- commented 2 years ago

Overview

Proposed solution

Add 'selector-max-attribute': [0, { ignoreAttributes: ['/^(?!data-).*/'] }], - which only blocks the use of data-* attributes when applying styles to components.

All other usage should still be allowed, such as hidden, aria-hidden, disabled, type etc.

Additional details

Issues in Wagtail Core

The following 11 issues will be flagged in Wagtail core if this rule is applied.

client/scss/components/_tabs.scss
 69:3  ✖  Expected ".w-tabs[data-tabs-animate] .w-tabs__panel" to have no more than 0 attribute selectors             selector-max-attribute
 72:5  ✖  Expected ".w-tabs[data-tabs-animate] .w-tabs__panel.animate-in" to have no more than 0 attribute selectors  selector-max-attribute

client/scss/overrides/_vendor.tippy.scss
  8:1  ✖  Expected ".tippy-box[data-placement^='top'] > .tippy-arrow::before" to have no more than 0 attribute selectors     selector-max-attribute
 12:1  ✖  Expected ".tippy-box[data-placement^='bottom'] > .tippy-arrow::before" to have no more than 0 attribute selectors  selector-max-attribute
 16:1  ✖  Expected ".tippy-box[data-placement^='left'] > .tippy-arrow::before" to have no more than 0 attribute selectors    selector-max-attribute
 20:1  ✖  Expected ".tippy-box[data-placement^='right'] > .tippy-arrow::before" to have no more than 0 attribute selectors   selector-max-attribute
 25:1  ✖  Expected ".tippy-box[data-theme='dropdown']" to have no more than 0 attribute selectors                            selector-max-attribute
 28:3  ✖  Expected ".tippy-box[data-theme='dropdown'] .tippy-content" to have no more than 0 attribute selectors             selector-max-attribute

client/src/components/Sidebar/modules/WagtailBranding.scss
 54:7  ✖  Expected ".sidebar-wagtail-branding--wagging:hover [data-part='tail']" to have no more than 0 attribute selectors         selector-max-attribute
 60:7  ✖  Expected ".sidebar-wagtail-branding--wagging:hover [data-part='eye--open']" to have no more than 0 attribute selectors    selector-max-attribute
 64:7  ✖  Expected ".sidebar-wagtail-branding--wagging:hover [data-part='eye--closed']" to have no more than 0 attribute selectors  selector-max-attribute
lb- commented 2 years ago

This recently came up when reviewing a PR - see comment - https://github.com/wagtail/wagtail/pull/8671#discussion_r897822527

Scotchester commented 2 years ago

Makes sense to me!

thibaudcolas commented 2 years ago

I’m not 100% convinced data- attributes don’t have a place in stylesheets, but in my mind if they did have a place it’d only be in a few specific cases – so I quite like the idea of outright enforcing they aren’t used ever.

If we did this, I think we could use selector-attribute-disallowed-list? "selector-attribute-name-disallowed-list": ["/^data-/"],

lb- commented 2 years ago

Thanks Thibaud. selector-attribute-name-disallowed-list is way better! Don't know what I was thinking haha.