length-zero-no-unit
不允许使用零长度单位。
¥Disallow units for zero lengths.
a { top: 0px; }
/** ↑↑
* This zero and this type of length unit */
长度是指距离测量。长度是一个维度,是一个紧跟单位标识符的数字。然而,对于零长度,单元标识符是可选的。长度单位是:em
、ex
、ch
、vw
、vh
、cm
、mm
、in
、pt
、pc
、px
、rem
、vmin
和 vmax
。
¥Lengths refer to distance measurements. A length is a dimension, which is a number immediately followed by a unit identifier. However, for zero lengths the unit identifier is optional. The length units are: em
, ex
, ch
, vw
, vh
, cm
, mm
, in
, pt
, pc
, px
, rem
, vmin
, and vmax
.
该规则忽略数学函数中的长度(例如 calc
)。
¥This rule ignores lengths within math functions (e.g. calc
).
fix
选项 可以自动修复此规则报告的所有问题。
¥The fix
option can automatically fix all of the problems reported by this rule.
选项
¥Options
true
{
"length-zero-no-unit": true
}
以下模式被视为问题:
¥The following patterns are considered problems:
a { top: 0px }
a { top: 0.000em }
以下模式不被视为问题:
¥The following patterns are not considered problems:
a { top: 0 } /* no unit */
a { transition-delay: 0s; } /* dimension */
a { top: 2in; }
a { top: 1.001vh }
可选的辅助选项
¥Optional secondary options
ignore
{ "ignore": ["array", "of", "options"] }
"custom-properties"
忽略自定义属性中零长度的单位。
¥Ignore units for zero lengths in custom properties.
{
"length-zero-no-unit": [true, { "ignore": ["custom-properties"] }]
}
以下模式不被视为问题:
¥The following pattern is not considered a problem:
a { --x: 0px; }
ignoreFunctions
{ "ignoreFunctions": ["array", "of", "functions", "/regex/"] }
忽略指定函数中零长度的单位。
¥Ignore units for zero lengths within the specified functions.
鉴于:
¥Given:
{
"length-zero-no-unit": [true, { "ignoreFunctions": ["var", "/^--/"] }]
}
以下模式不被视为问题:
¥The following patterns are not considered problems:
a { top: var(--foo, 0px); }
a { top: --bar(0px); }
ignorePreludeOfAtRules
{
"ignorePreludeOfAtRules": ["array", "of", "at-rules", "/regex/"]
}
忽略指定 at-rules 前奏中的零长度单位。
¥Ignore units for zero lengths within the preludes of the specified at-rules.
鉴于:
¥Given:
{
"length-zero-no-unit": [
true,
{ "ignorePreludeOfAtRules": ["media", "/^--bar/"] }
]
}
以下模式不被视为问题:
¥The following patterns are not considered problems:
@media (height > 0px) {}
@--bar-baz 0px;