Skip to main content

declaration-property-unit-allowed-list

在声明中指定允许的属性和单元对的列表。

¥Specify a list of allowed property and unit pairs within declarations.

a { width: 100px; }
/** ↑ ↑

* These properties and these units */

message 次要选项 可以接受该规则的参数。

¥The message secondary option can accept the arguments of this rule.

选项

¥Options

Object<string, Array<string>>

{ "unprefixed-property-name": ["array", "of", "units"] }

您可以为属性名称指定正则表达式,例如 { "/^animation/": [] }

¥You can specify a regex for a property name, such as { "/^animation/": [] }.

鉴于:

¥Given:

{
"declaration-property-unit-allowed-list": {
"font-size": ["em", "px"],
"/^animation/": ["s"],
"line-height": []
}
}

以下模式被视为问题:

¥The following patterns are considered problems:

a { font-size: 1.2rem; }
a { animation: animation-name 500ms ease; }
a { -webkit-animation: animation-name 500ms ease; }
a { animation-duration: 500ms; }
a { line-height: 13px; }

以下模式不被视为问题:

¥The following patterns are not considered problems:

a { font-size: 1em; }
a { height: 100px; }
a { animation: animation-name 5s ease; }
a { -webkit-animation: animation-name 5s ease; }
a { animation-duration: 5s; }
a { line-height: 1; }

可选的辅助选项

¥Optional secondary options

ignore

{ "ignore": ["array", "of", "options"] }

"inside-function"

忽略函数内部的单位。

¥Ignore units that are inside a function.

鉴于:

¥Given:

{
"declaration-property-unit-allowed-list": [
{
"/^border/": ["px"],
"/^background/": ["%"]
},
{
"ignore": ["inside-function"]
}
]
}

以下模式不被视为问题:

¥The following patterns are not considered problems:

a {
border: 1px solid hsla(162deg, 51%, 35%, 0.8);
}
a {
background-image: linear-gradient(hsla(162deg, 51%, 35%, 0.8), hsla(62deg, 51%, 35%, 0.8));
}