UNPKG

stylelint

Version:

A mighty CSS linter that helps you avoid errors and enforce conventions.

962 lines (925 loc) • 18 kB
/** @type {ReadonlySet<string>} */ export const deprecatedHtmlTypeSelectors = new Set([ 'acronym', 'applet', 'basefont', 'big', 'bgsound', 'blink', 'center', 'content', 'dir', 'font', 'frame', 'frameset', 'isindex', 'keygen', 'listing', 'marquee', 'menuitem', 'multicol', 'nextid', 'nobr', 'noembed', 'noframes', 'plaintext', 'param', 'popup', 'rb', 'rtc', 'selectmenu', 'shadow', 'spacer', 'strike', 'tt', 'xmp', ]); /** * Includes `math` and `svg`, the elements that embed MathML and SVG in HTML * * @see https://html.spec.whatwg.org/multipage/indices.html#elements-3 * @type {ReadonlySet<string>} */ const standardHtmlTypeSelectors = new Set([ 'a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdi', 'bdo', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'link', 'main', 'map', 'mark', 'math', 'menu', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'search', 'section', 'select', 'selectedcontent', 'slot', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'svg', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr', ]); /** @type {ReadonlySet<string>} */ const experimentalHtmlTypeSelectors = new Set([ 'fencedframe', 'listbox', 'model', 'portal', 'selectlist', 'geolocation', 'usermedia', 'install', ]); /** @type {ReadonlySet<string>} */ export const htmlTypeSelectors = deprecatedHtmlTypeSelectors .union(standardHtmlTypeSelectors) .union(experimentalHtmlTypeSelectors); /** @type {ReadonlySet<string>} */ export const deprecatedSvgTypeSelectors = new Set([ 'altGlyph', 'altGlyphDef', 'altGlyphItem', 'animateColor', 'color-profile', 'cursor', 'font', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'glyph', 'glyphRef', 'hatchPath', 'hkern', 'missing-glyph', 'tref', 'vkern', ]); /** * @see https://svgwg.org/svg2-draft/eltindex.html * @type {ReadonlySet<string>} */ const standardSvgTypeSelectors = new Set([ 'a', 'animate', 'animateMotion', 'animateTransform', 'circle', 'clipPath', 'defs', 'desc', 'ellipse', 'feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence', 'filter', 'foreignObject', 'g', 'image', 'line', 'linearGradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialGradient', 'rect', 'script', 'set', 'stop', 'style', 'svg', 'switch', 'symbol', 'text', 'textPath', 'title', 'tspan', 'use', 'view', ]); /** * Hatches were removed from SVG 2 after the 2016 Candidate Recommendation, * so they are known but not deprecated * * @see https://www.w3.org/TR/2016/CR-SVG2-20160915/pservers.html#Hatches * @type {ReadonlySet<string>} */ const experimentalSvgTypeSelectors = new Set(['hatch', 'hatchpath']); /** @type {ReadonlySet<string>} */ export const svgTypeSelectors = deprecatedSvgTypeSelectors .union(standardSvgTypeSelectors) .union(experimentalSvgTypeSelectors); /** @param {string} name */ function isMixedCase(name) { return name !== name.toLowerCase(); } /** @type {ReadonlySet<string>} */ export const mixedCaseSvgTypeSelectors = new Set([...svgTypeSelectors].filter(isMixedCase)); /** * Presentation and content elements from MathML 1 to 3 * * @see https://www.w3.org/TR/MathML3/ * @see https://www.w3.org/TR/mathml-core/#mathml-elements * @type {ReadonlySet<string>} */ export const mathmlTypeSelectors = new Set([ 'abs', 'and', 'annotation', 'annotation-xml', 'apply', 'approx', 'arccos', 'arccosh', 'arccot', 'arccoth', 'arccsc', 'arccsch', 'arcsec', 'arcsech', 'arcsin', 'arcsinh', 'arctan', 'arctanh', 'arg', 'bind', 'bvar', 'card', 'cartesianproduct', 'cbytes', 'ceiling', 'cerror', 'ci', 'cn', 'codomain', 'complexes', 'compose', 'condition', 'conjugate', 'cos', 'cosh', 'cot', 'coth', 'cs', 'csc', 'csch', 'csymbol', 'curl', 'declare', 'degree', 'determinant', 'diff', 'divergence', 'divide', 'domain', 'domainofapplication', 'emptyset', 'encoding', 'eq', 'equivalent', 'eulergamma', 'exists', 'exp', 'exponentiale', 'factorial', 'factorof', 'false', 'floor', 'fn', 'forall', 'function', 'gcd', 'geq', 'grad', 'gt', 'ident', 'image', 'imaginary', 'imaginaryi', 'implies', 'in', 'infinity', 'int', 'integers', 'intersect', 'interval', 'inverse', 'lambda', 'laplacian', 'lcm', 'leq', 'limit', 'list', 'ln', 'log', 'logbase', 'lowlimit', 'lt', 'maction', 'malign', 'maligngroup', 'malignmark', 'malignscope', 'math', 'matrix', 'matrixrow', 'max', 'mean', 'median', 'menclose', 'merror', 'mfenced', 'mfrac', 'mfraction', 'mglyph', 'mi', 'min', 'minus', 'mlabeledtr', 'mlongdiv', 'mmultiscripts', 'mn', 'mo', 'mode', 'moment', 'momentabout', 'mover', 'mpadded', 'mphantom', 'mprescripts', 'mroot', 'mrow', 'ms', 'mscarries', 'mscarry', 'msgroup', 'msline', 'mspace', 'msqrt', 'msrow', 'mstack', 'mstyle', 'msub', 'msubsup', 'msup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'naturalnumbers', 'neq', 'none', 'not', 'notanumber', 'notin', 'notprsubset', 'notsubset', 'or', 'otherwise', 'outerproduct', 'partialdiff', 'pi', 'piece', 'piecewise', 'plus', 'power', 'primes', 'product', 'prsubset', 'quotient', 'rationals', 'real', 'reals', 'reln', 'rem', 'root', 'scalarproduct', 'sdev', 'sec', 'sech', 'select', 'selector', 'semantics', 'sep', 'set', 'setdiff', 'share', 'sin', 'sinh', 'subset', 'sum', 'tan', 'tanh', 'tendsto', 'times', 'transpose', 'true', 'union', 'uplimit', 'var', 'variance', 'vector', 'vectorproduct', 'xor', ]); /** * Hyphen-containing element names from SVG 2 and MathML, which are not valid custom element names * * @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name * @type {ReadonlySet<string>} */ export const hyphenContainingTypeSelectors = new Set([ 'annotation-xml', 'color-profile', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'missing-glyph', ]); /** * These are the ones that can have single-colon notation * * @type {ReadonlySet<string>} */ export const levelOneAndTwoPseudoElements = new Set([ 'before', 'after', 'first-line', 'first-letter', ]); /** @type {ReadonlySet<string>} */ export const shadowTreePseudoElements = new Set(['part']); /** * @see https://drafts.csswg.org/css-pseudo/#element-backed * @type {ReadonlySet<string>} */ export const elementBackedPseudoElements = shadowTreePseudoElements.union( new Set([ // alphabetically 'details-content', 'file-selector-button', ]), ); /** * Pseudo-elements that are defined as sub-pseudo-elements of another * pseudo-element, e.g. `::before::marker` * * @see https://drafts.csswg.org/selectors/#sub-pseudo-elements * @type {ReadonlySet<string>} */ export const subPseudoElements = new Set(['marker', 'scroll-marker']); /** * Pseudo-elements that represent real elements * * @see https://drafts.csswg.org/css-pseudo/#element-backed * @see https://drafts.csswg.org/css-shadow/#slotted-pseudo * @type {ReadonlySet<string>} */ export const elementRepresentingPseudoElements = elementBackedPseudoElements.union( new Set(['slotted']), ); /** @type {ReadonlySet<string>} */ export const webkitScrollbarPseudoElements = new Set([ '-webkit-resizer', '-webkit-scrollbar', '-webkit-scrollbar-button', '-webkit-scrollbar-corner', '-webkit-scrollbar-thumb', '-webkit-scrollbar-track', '-webkit-scrollbar-track-piece', ]); /** @type {ReadonlySet<string>} */ const vendorSpecificPseudoElements = webkitScrollbarPseudoElements.union( new Set([ // alphabetically '-moz-focus-inner', '-moz-focus-outer', '-moz-list-bullet', '-moz-meter-bar', '-moz-placeholder', '-moz-progress-bar', '-moz-range-progress', '-moz-range-thumb', '-moz-range-track', '-ms-browse', '-ms-check', '-ms-clear', '-ms-expand', '-ms-fill', '-ms-fill-lower', '-ms-fill-upper', '-ms-reveal', '-ms-thumb', '-ms-ticks-after', '-ms-ticks-before', '-ms-tooltip', '-ms-track', '-ms-value', '-webkit-calendar-picker-indicator', '-webkit-clear-button', '-webkit-color-swatch', '-webkit-color-swatch-wrapper', '-webkit-date-and-time-value', '-webkit-datetime-edit', '-webkit-datetime-edit-ampm-field', '-webkit-datetime-edit-day-field', '-webkit-datetime-edit-fields-wrapper', '-webkit-datetime-edit-hour-field', '-webkit-datetime-edit-millisecond-field', '-webkit-datetime-edit-minute-field', '-webkit-datetime-edit-month-field', '-webkit-datetime-edit-second-field', '-webkit-datetime-edit-text', '-webkit-datetime-edit-week-field', '-webkit-datetime-edit-year-field', '-webkit-details-marker', '-webkit-distributed', '-webkit-file-upload-button', '-webkit-input-placeholder', '-webkit-keygen-select', '-webkit-meter-bar', '-webkit-meter-even-less-good-value', '-webkit-meter-horizontal-bar', '-webkit-meter-horizontal-even-less-good-value', '-webkit-meter-horizontal-optimum-value', '-webkit-meter-horizontal-suboptimal-value', '-webkit-meter-inner-element', '-webkit-meter-optimum-value', '-webkit-meter-suboptimum-value', '-webkit-meter-vertical-bar', '-webkit-meter-vertical-even-less-good-value', '-webkit-meter-vertical-optimum-value', '-webkit-meter-vertical-suboptimal-value', '-webkit-progress-bar', '-webkit-progress-inner-element', '-webkit-progress-value', '-webkit-search-cancel-button', '-webkit-search-decoration', '-webkit-search-results-button', '-webkit-search-results-decoration', '-webkit-slider-runnable-track', '-webkit-slider-thumb', '-webkit-textfield-decoration-container', '-webkit-validation-bubble', '-webkit-validation-bubble-arrow', '-webkit-validation-bubble-arrow-clipper', '-webkit-validation-bubble-heading', '-webkit-validation-bubble-message', '-webkit-validation-bubble-text-block', ]), ); /** @type {ReadonlySet<string>} */ export const deprecatedPseudoElements = new Set(['content', 'shadow']); /** @type {ReadonlySet<string>} */ export const pseudoElements = levelOneAndTwoPseudoElements .union(vendorSpecificPseudoElements) .union(elementBackedPseudoElements) .union(subPseudoElements) .union(elementRepresentingPseudoElements) .union(deprecatedPseudoElements) .union( new Set([ // alphabetically 'backdrop', 'checkmark', 'clear-icon', 'color-swatch', 'cue', 'field-component', 'field-separator', 'field-text', 'grammar-error', 'highlight', 'picker', 'picker-icon', 'placeholder', 'scroll-button', 'scroll-marker-group', 'search-text', 'selection', 'slider-fill', 'slider-thumb', 'slider-track', 'spelling-error', 'step-control', 'step-down', 'step-up', 'target-text', 'view-transition', 'view-transition-group', 'view-transition-image-pair', 'view-transition-new', 'view-transition-old', ]), ); /** @type {ReadonlySet<string>} */ export const percentageKeyframeWithNamedEquivalent = new Set(['0%', '100%']); /** @type {ReadonlySet<string>} */ export const aNPlusBNotationPseudoClasses = new Set([ 'nth-column', 'nth-last-column', 'nth-last-of-type', 'nth-of-type', ]); /** @type {ReadonlySet<string>} */ export const aNPlusBOfSNotationPseudoClasses = new Set(['nth-child', 'nth-last-child']); /** * @see https://drafts.csswg.org/selectors/#structural-pseudos * @type {ReadonlySet<string>} */ export const treeStructuralPseudoClasses = aNPlusBOfSNotationPseudoClasses.union( new Set([ // alphabetically 'empty', 'first-child', 'first-of-type', 'last-child', 'last-of-type', 'nth-last-of-type', 'nth-of-type', 'only-child', 'only-of-type', 'root', ]), ); /** @type {ReadonlySet<string>} */ export const atRulePagePseudoClasses = new Set([ 'first', 'right', 'left', 'blank', 'recto', 'verso', 'nth', ]); /** @type {ReadonlySet<string>} */ export const linguisticPseudoClasses = new Set(['dir', 'lang']); /** @type {ReadonlySet<string>} */ export const dirIdentifiers = new Set(['ltr', 'rtl']); /** * @see https://drafts.csswg.org/selectors/#typedef-forgiving-selector-list * @type {ReadonlySet<string>} */ export const forgivingPseudoClasses = new Set(['is', 'where']); /** @type {ReadonlySet<string>} */ export const logicalCombinationsPseudoClasses = new Set(['has', 'is', 'matches', 'not', 'where']); /** @type {ReadonlySet<string>} */ export const deprecatedPseudoClasses = new Set([ '-moz-any', '-webkit-any', 'contains', 'drop', 'focus-ring', 'fullscreen-ancestor', 'matches', 'popup-open', 'top-layer', 'user-error', ]); /** @type {ReadonlySet<string>} */ const vendorSpecificPseudoClasses = new Set([ '-khtml-drag', '-moz-any', '-moz-any-link', '-moz-bound-element', '-moz-broken', '-moz-dir', '-moz-drag-over', '-moz-empty-except-children-with-localname', '-moz-first-node', '-moz-focusring', '-moz-full-screen', '-moz-full-screen-ancestor', '-moz-is-html', '-moz-last-node', '-moz-loading', '-moz-meter-optimum', '-moz-meter-sub-optimum', '-moz-meter-sub-sub-optimum', '-moz-only-whitespace', '-moz-placeholder', '-moz-read-only', '-moz-read-write', '-moz-submit-invalid', '-moz-suppressed', '-moz-table-border-nonzero', '-moz-ui-invalid', '-moz-ui-valid', '-moz-user-disabled', '-moz-window-inactive', '-ms-fullscreen', '-ms-input-placeholder', '-webkit-drag', '-webkit-any', '-webkit-any-link', '-webkit-autofill', '-webkit-full-screen', '-webkit-full-screen-ancestor', ]); /** * @see https://webkit.org/blog/363/styling-scrollbars/ * @type {ReadonlySet<string>} */ export const webkitScrollbarPseudoClasses = new Set([ 'horizontal', 'vertical', 'decrement', 'increment', 'start', 'end', 'double-button', 'single-button', 'no-button', 'corner-present', 'window-inactive', ]); /** * @see https://www.w3.org/TR/selectors-4/#resource-pseudos * @type {ReadonlySet<string>} */ const resourceStatePseudoClasses = new Set([ 'buffering', 'muted', 'paused', 'playing', 'seeking', 'stalled', 'volume-locked', ]); /** @type {ReadonlySet<string>} */ export const pseudoClasses = aNPlusBNotationPseudoClasses .union(linguisticPseudoClasses) .union(logicalCombinationsPseudoClasses) .union(treeStructuralPseudoClasses) .union(resourceStatePseudoClasses) .union(vendorSpecificPseudoClasses) .union(deprecatedPseudoClasses) .union( new Set([ 'active-view-transition-type', 'active-view-transition', 'active', 'any-link', 'autofill', // introduced the 10/05/2016 by 8c808d0 // as of 2024 it is still not supported by any browser 'blank', 'checked', 'current', 'default', 'defined', 'disabled', 'enabled', 'even-less-good-value', 'focus-visible', 'focus-within', 'focus', 'fullscreen', 'future', 'has-slotted', 'heading', 'high-value', 'host-context', 'host', 'hover', 'in-range', 'indeterminate', 'invalid', 'link', 'low-value', 'modal', 'open', 'optimal-value', 'optional', 'out-of-range', 'past', 'picture-in-picture', 'placeholder-shown', 'popover-open', 'read-only', 'read-write', 'required', 'scope', 'state', 'suboptimal-value', 'target', 'unchecked', 'unresolved', 'user-invalid', 'user-valid', 'valid', 'visited', 'window-inactive', // for ::selection (chrome) ]), ); const disableableElements = new Set([ 'button', 'fieldset', 'input', 'optgroup', 'option', 'select', 'textarea', ]); const checkableElements = new Set(['input', 'option']); const requirableElements = new Set(['input', 'select', 'textarea']); const validatableElements = new Set(['button', 'fieldset', 'form', 'input', 'select', 'textarea']); const rangeableElements = new Set(['input']); const placeholderShowableElements = new Set(['input', 'textarea']); const defaultableElements = new Set(['button', 'input', 'option']); const autofillableElements = new Set(['input', 'select', 'textarea']); const linkElements = new Set(['a', 'area']); /** * @see https://html.spec.whatwg.org/multipage/semantics-other.html#pseudo-classes * @see https://drafts.csswg.org/selectors/#useraction-pseudos * @type {ReadonlyMap<string, ReadonlySet<string>>} */ export const applicableElementsByPseudoClass = new Map([ ['any-link', linkElements], ['autofill', autofillableElements], ['checked', checkableElements], ['default', defaultableElements], ['disabled', disableableElements], ['enabled', disableableElements], ['in-range', rangeableElements], ['invalid', validatableElements], ['link', linkElements], ['optional', requirableElements], ['out-of-range', rangeableElements], ['placeholder-shown', placeholderShowableElements], ['required', requirableElements], ['user-invalid', validatableElements], ['user-valid', validatableElements], ['valid', validatableElements], ['visited', linkElements], ]);