Skip to main content

declaration-block-no-duplicate-properties

禁止声明块内出现重复的属性。

¥Disallow duplicate properties within declaration blocks.

a { color: pink; color: orange; }
/** ↑ ↑

* These duplicated properties */

该规则忽略变量($sass@less--custom-property)。

¥This rule ignores variables ($sass, @less, --custom-property).

fix 选项 可以自动修复此规则报告的所有问题。

¥The fix option can automatically fix all of the problems reported by this rule.

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

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

选项

¥Options

true

以下模式被视为问题:

¥The following patterns are considered problems:

a { color: pink; color: orange; }
a { color: pink; background: orange; color: orange }

以下模式不被视为问题:

¥The following patterns are not considered problems:

a { color: pink; }
a { color: pink; background: orange; }

可选的辅助选项

¥Optional secondary options

ignore: ["consecutive-duplicates"]

忽略连续重复的属性。

¥Ignore consecutive duplicated properties.

事实证明,它们对于旧版浏览器来说是有用的后备方案。

¥They can prove to be useful fallbacks for older browsers.

以下模式被视为问题:

¥The following patterns are considered problems:

p {
font-size: 16px;
font-weight: 400;
font-size: 1rem;
}

以下模式不被视为问题:

¥The following patterns are not considered problems:

p {
font-size: 16px;
font-size: 1rem;
font-weight: 400;
}

ignore: ["consecutive-duplicates-with-different-values"]

忽略具有不同值的连续重复属性。

¥Ignore consecutive duplicated properties with different values.

包含重复属性(后备)对于处理旧版浏览器对 CSS 属性的支持非常有用。例如。当 rem 不可用时使用 px 单位。

¥Including duplicate properties (fallbacks) is useful to deal with older browsers support for CSS properties. E.g. using px units when rem isn't available.

以下模式被视为问题:

¥The following patterns are considered problems:

/* properties with the same value */
p {
font-size: 16px;
font-size: 16px;
font-weight: 400;
}
/* nonconsecutive duplicates */
p {
font-size: 16px;
font-weight: 400;
font-size: 1rem;
}

以下模式不被视为问题:

¥The following patterns are not considered problems:

p {
font-size: 16px;
font-size: 1rem;
font-weight: 400;
}

ignore: ["consecutive-duplicates-with-different-syntaxes"]

忽略具有不同值语法(类型和值单位)的连续重复属性。

¥Ignore consecutive duplicated properties with different value syntaxes (type and unit of value).

以下模式被视为问题:

¥The following patterns are considered problems:

/* properties with the same value syntax */
p {
font-size: 16px;
font-size: 14px;
font-weight: 400;
}

以下模式不被视为问题:

¥The following patterns are not considered problems:

p {
font-size: 16px;
font-size: 16rem;
font-weight: 400;
}

ignore: ["consecutive-duplicates-with-same-prefixless-values"]

忽略前缀时,忽略具有相同值的连续重复属性。

¥Ignore consecutive duplicated properties with identical values, when ignoring their prefix.

此选项对于处理草稿 CSS 值非常有用,同时仍然面向未来。例如。使用 fit-content-moz-fit-content

¥This option is useful to deal with draft CSS values while still being future proof. E.g. using fit-content and -moz-fit-content.

以下模式被视为问题:

¥The following patterns are considered problems:

/* nonconsecutive duplicates */
p {
width: fit-content;
height: 32px;
width: -moz-fit-content;
}
/* properties with different prefixless values */
p {
width: -moz-fit-content;
width: 100%;
}

以下模式不被视为问题:

¥The following patterns are not considered problems:

p {
width: -moz-fit-content;
width: fit-content;
}

ignoreProperties: ["/regex/", /regex/, "non-regex"]

忽略特定属性的重复项。

¥Ignore duplicates of specific properties.

鉴于:

¥Given:

["color", "/background-/"]

以下模式被视为问题:

¥The following patterns are considered problems:

a { color: pink; background: orange; background: white; }
a { background: orange; color: pink; background: white; }

以下模式不被视为问题:

¥The following patterns are not considered problems:

a { color: pink; color: orange; background-color: orange; background-color: white; }
a { color: pink; background-color: orange; color: orange; background-color: white; }