Skip to content

Commit

Permalink
feat: implement no_unknown_type_selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazuhiro-Mimaki committed Jun 24, 2024
1 parent e4f8ae4 commit 4deab92
Show file tree
Hide file tree
Showing 8 changed files with 673 additions and 6 deletions.
302 changes: 299 additions & 3 deletions crates/biome_css_analyze/src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5433,17 +5433,292 @@ pub const RESET_TO_INITIAL_PROPERTIES_BY_FONT: [&str; 13] = [
"font-variation-settings",
];

// https://developer.mozilla.org/ja/docs/Web/HTML/Element
// https://github.com/sindresorhus/html-tags/blob/main/html-tags.json
pub const HTML_TAGS: [&str; 148] = [
"a",
"abbr",
"acronym",
"address",
"applet",
"area",
"article",
"aside",
"audio",
"b",
"base",
"basefont",
"bdi",
"bdo",
"bgsound",
"big",
"blink",
"blockquote",
"body",
"br",
"button",
"canvas",
"caption",
"center",
"cite",
"code",
"col",
"colgroup",
"content",
"data",
"datalist",
"dd",
"del",
"details",
"dfn",
"dir",
"div",
"dl",
"dt",
"em",
"embed",
"fencedframe",
"fieldset",
"figcaption",
"figure",
"font",
"footer",
"form",
"frame",
"frameset",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"head",
"header",
"hgroup",
"hr",
"html",
"i",
"iframe",
"img",
"input",
"ins",
"isindex",
"kbd",
"keygen",
"label",
"legend",
"li",
"link",
"listbox",
"listing",
"main",
"map",
"mark",
"marquee",
"math",
"menu",
"menuitem",
"meta",
"meter",
"model",
"multicol",
"nav",
"nextid",
"nobr",
"noembed",
"noframes",
"noscript",
"object",
"ol",
"optgroup",
"option",
"output",
"p",
"param",
"picture",
"plaintext",
"portal",
"pre",
"progress",
"q",
"rb",
"rp",
"rt",
"rtc",
"ruby",
"s",
"samp",
"script",
"search",
"section",
"select",
"selectlist",
"slot",
"small",
"source",
"spacer",
"span",
"strike",
"strong",
"style",
"sub",
"summary",
"sup",
"svg",
"table",
"tbody",
"td",
"template",
"textarea",
"tfoot",
"th",
"thead",
"time",
"title",
"tr",
"track",
"tt",
"u",
"ul",
"var",
"video",
"wbr",
"xmp",
];

// https://developer.mozilla.org/ja/docs/Web/SVG/Element
// https://github.com/element-io/svg-tags/blob/master/lib/svg-tags.json
pub const SVG_TAGS: [&str; 81] = [
"a",
"altGlyph",
"altGlyphDef",
"altGlyphItem",
"animate",
"animateColor",
"animateMotion",
"animateTransform",
"circle",
"clipPath",
"color-profile",
"cursor",
"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",
"font",
"font-face",
"font-face-format",
"font-face-name",
"font-face-src",
"font-face-uri",
"foreignObject",
"g",
"glyph",
"glyphRef",
"hatchpath",
"hkern",
"image",
"line",
"linearGradient",
"marker",
"mask",
"metadata",
"missing-glyph",
"mpath",
"path",
"pattern",
"polygon",
"polyline",
"radialGradient",
"rect",
"script",
"set",
"stop",
"style",
"svg",
"switch",
"symbol",
"text",
"textPath",
"title",
"tspan",
"use",
"view",
"vkern",
];

// https://developer.mozilla.org/ja/docs/Web/MathML/Element
pub const MATH_ML_TAGS: [&str; 32] = [
"annotation",
"annotation-xml",
"maction",
"math",
"menclose",
"merror",
"mfenced",
"mfrac",
"mi",
"mmultiscripts",
"mn",
"mo",
"mover",
"mpadded",
"mphantom",
"mprescripts",
"mroot",
"mrow",
"ms",
"mspace",
"msqrt",
"mstyle",
"msub",
"msubsup",
"msup",
"mtable",
"mtd",
"mtext",
"mtr",
"munder",
"munderover",
"semantics",
];

#[cfg(test)]
mod tests {
use std::collections::HashSet;

use super::{
FUNCTION_KEYWORDS, KNOWN_EDGE_PROPERTIES, KNOWN_EXPLORER_PROPERTIES,
FUNCTION_KEYWORDS, HTML_TAGS, KNOWN_EDGE_PROPERTIES, KNOWN_EXPLORER_PROPERTIES,
KNOWN_FIREFOX_PROPERTIES, KNOWN_PROPERTIES, KNOWN_SAFARI_PROPERTIES,
KNOWN_SAMSUNG_INTERNET_PROPERTIES, KNOWN_US_BROWSER_PROPERTIES,
LONGHAND_SUB_PROPERTIES_OF_SHORTHAND_PROPERTIES, MEDIA_FEATURE_NAMES,
LONGHAND_SUB_PROPERTIES_OF_SHORTHAND_PROPERTIES, MATH_ML_TAGS, MEDIA_FEATURE_NAMES,
RESET_TO_INITIAL_PROPERTIES_BY_BORDER, RESET_TO_INITIAL_PROPERTIES_BY_FONT,
SHORTHAND_PROPERTIES,
SHORTHAND_PROPERTIES, SVG_TAGS,
};

#[test]
Expand Down Expand Up @@ -5635,4 +5910,25 @@ mod tests {
.any(|&x| !set.insert(x));
assert!(!has_duplicates);
}

#[test]
fn test_selector_types() {
for items in HTML_TAGS.windows(2) {
assert!(items[0] < items[1], "{} < {}", items[0], items[1]);
}
}

#[test]
fn test_svg_tags() {
for items in SVG_TAGS.windows(2) {
assert!(items[0] < items[1], "{} < {}", items[0], items[1]);
}
}

#[test]
fn test_math_ml_tags() {
for items in MATH_ML_TAGS.windows(2) {
assert!(items[0] < items[1], "{} < {}", items[0], items[1]);
}
}
}
Loading

0 comments on commit 4deab92

Please sign in to comment.