Skip to main content

declaration-property-value-no-unknown

不允许声明中的属性值未知。

¥Disallow unknown values for properties within declarations.

a { top: unknown; }
/** ↑ ↑

* property and value pairs like these */

此规则认为 CSS 规范中定义的属性值是已知的。你可以使用 propertiesSyntaxtypesSyntax 辅助选项来扩展语法。

¥This rule considers values for properties defined within the CSS specifications to be known. You can use the propertiesSyntax and typesSyntax secondary options to extend the syntax.

你可以过滤 CSSTree 语法参考 以找出属性已知的值语法。

¥You can filter the CSSTree Syntax Reference to find out what value syntax is known for a property.

此规则仅适用于 CSS。你不应该为类似 CSS 的语言(例如 SCSS 或 Less)启用它。

¥This rule is only appropriate for CSS. You should not turn it on for CSS-like languages, such as SCSS or Less.

此规则检查属性值。你可以使用 at-rule-descriptor-value-no-unknown 禁止 at-rules 中的描述符的未知值。

¥This rule checks property values. You can use at-rule-descriptor-value-no-unknown to disallow unknown values for descriptors within at-rules.

此规则与以下内容重叠:

¥This rule overlaps with:

你可以关闭规则或将其配置为忽略重叠。

¥You can either turn off the rules or configure them to ignore the overlaps.

message 次要选项 可以接受参数。

¥The message secondary option can accept arguments.

现有技术:

¥Prior art:

选项

¥Options

true

以下模式被视为问题:

¥The following patterns are considered problems:

a { top: red; }
a { top: unknown; }

以下模式不被视为问题:

¥The following patterns are not considered problems:

a { top: 0; }
a { top: var(--foo); }

可选的辅助选项

¥Optional secondary options

ignoreProperties: { "property": ["/regex/", /regex/, "non-regex"]|"/regex/"|/regex/|"non-regex" }

忽略指定的属性和值对。对象中的键表示属性名称。如果对象中的字符串被 "/" 包围,则它被解释为正则表达式。例如,"/.+/" 匹配任何字符串。

¥Ignore the specified property and value pairs. Keys in the object indicate property names. If a string in the object is surrounded with "/", it's interpreted as a regular expression. For example, "/.+/" matches any strings.

鉴于:

¥Given:

{
"top": ["unknown"],
"/^margin-/": "/^--foo/",
"padding": "/.+/",
"/.+/": "--unknown-value"
}

以下模式不被视为问题:

¥The following patterns are not considered problems:

a { top: unknown; }
a { margin-top: --foo-bar; }
a { padding: invalid; }
a { width: --unknown-value; }

propertiesSyntax: { property: syntax }

扩展或更改属性语法字典。CSS 值定义语法 用于定义值的语法。如果定义以 | 开头,则将其添加到 现有定义值(如果有)。

¥Extend or alter the properties syntax dictionary. CSS Value Definition Syntax is used to define a value's syntax. If a definition starts with | it is added to the existing definition value if any.

鉴于:

¥Given:

{ "size": "<length-percentage>" }

以下模式不被视为问题:

¥The following patterns are not considered problems:

a { size: 0; }
a { size: 10px }

typesSyntax: { type: syntax }

扩展或更改类型语法字典。CSS 值定义语法 用于定义值的语法。如果定义以 | 开头,则将其添加到 现有定义值(如果有)。

¥Extend or alter the types syntax dictionary. CSS Value Definition Syntax is used to define a value's syntax. If a definition starts with | it is added to the existing definition value if any.

类型类似于预设,允许你在其他定义中重用一个定义。因此,在使用此选项时你可能还想使用 propertiesSyntax 选项。

¥Types are something like a preset which allows you to reuse a definition across other definitions. So, you'll likely want to also use the propertiesSyntax option when using this option.

鉴于:

¥Given:

{
"propertiesSyntax": { "top": "| <--foo()>" },
"typesSyntax": { "--foo()": "--foo( <length-percentage> )" }
}

以下模式不被视为问题:

¥The following patterns are not considered problems:

a { top: --foo(0); }
a { top: --foo(10px); }