Skip to main content

color-named

要求(如果可能)或不允许命名颜色。

¥Require (where possible) or disallow named colors.

a { color: black }
/** ↑

* This named color */

此规则忽略 $sass@less 变量语法。

¥This rule ignores $sass and @less variable syntaxes.

选项

¥Options

string"always-where-possible"|"never"

"always-where-possible"

在可能的情况下,颜色必须始终被命名。

¥Colors must always, where possible, be named.

如果十六进制(3、4、6 和 8 位数字)、rgb()rgba()hsl()hsla()hwb()gray() 颜色可以表示为命名颜色,则会报错。

¥This will complain if a hex (3, 4, 6 and 8 digit), rgb(), rgba(), hsl(), hsla(), hwb() or gray() color can be represented as a named color.

以下模式被视为问题:

¥The following patterns are considered problems:

a { color: #000; }
a { color: #f000; }
a { color: #ff000000; }
a { color: rgb(0, 0, 0); }
a { color: rgb(0%, 0%, 0%); }
a { color: rgba(0, 0, 0, 0); }
a { color: hsl(0, 0%, 0%); }
a { color: hwb(0, 0%, 100%); }
a { color: gray(0); }

以下模式不被视为问题:

¥The following patterns are not considered problems:

a { color: black; }
a { color: rgb(10, 0, 0); }
a { color: rgb(0, 0, 0, 0.5); }

"never"

颜色绝不能被命名。

¥Colors must never be named.

以下模式被视为问题:

¥The following patterns are considered problems:

a { color: black; }
a { color: white; }

以下模式不被视为问题:

¥The following patterns are not considered problems:

a { color: #000; }
a { color: rgb(0, 0, 0); }
a { color: var(--white); }

可选的辅助选项

¥Optional secondary options

ignore: ["inside-function"]

忽略函数内部的颜色。

¥Ignore colors that are inside a function.

例如,"never"

¥For example, with "never".

以下模式不被视为问题:

¥The following patterns are not considered problems:

a {
color: map-get($color, blue);
}
a {
background-image: url(red);
}

ignoreProperties: ["/regex/", /regex/, "string"]

例如 "never"

¥For example with "never".

鉴于:

¥Given:

["/^my-/", "composes"]

以下模式不被视为问题:

¥The following patterns are not considered problems:

a {
my-property: red;
}
a {
my-other-property: red;
}
a {
composes: red from './index.css';
}