font-weight-notation
Require numeric or named (where possible) font-weight values.
a { font-weight: bold; }/** ↑ * This notation */
a { font: italic small-caps 600 16px/3 cursive; }/** ↑ * And this notation, too */
@font-face { font-weight: normal bold; }/** ↑ * Multiple notations are available in @font-face */Use this rule to enforce a convention. normal and bold are names for 400 and 700.
Choose:
"numeric"for one scale across every weight, including the fine steps of variable fonts"named-where-possible"for clarity
This rule ignores $sass, @less, and var(--custom-property) variable syntaxes.
The fix option can automatically fix all of the problems reported by this rule.
This rule supports up to 2 message arguments: the notation type, or the actual and expected font-weight values.
Options
Section titled “Options”"numeric"
Section titled “"numeric"”font-weight values must always be numbers.
{ "font-weight-notation": "numeric"}The following patterns are considered problems:
a { font-weight: bold; }a { font: italic normal 20px sans-serif; }@font-face { font-weight: normal bold; }The following patterns are not considered problems:
a { font-weight: 700; }a { font: italic 400 20px; }@font-face { font-weight: 400 700; }"named-where-possible"
Section titled “"named-where-possible"”font-weight values must always be keywords when an appropriate keyword is available.
{ "font-weight-notation": "named-where-possible"}This means that only 400 and 700 will be rejected, because those are the only numbers with keyword equivalents (normal and bold).
The following patterns are considered problems:
a { font-weight: 700; }a { font: italic 400 20px sans-serif; }The following patterns are not considered problems:
a { font-weight: bold; }a { font: italic normal 20px sans-serif; }Optional secondary options
Section titled “Optional secondary options”ignore
Section titled “ignore”{ "ignore": ["array", "of", "options"] }"relative"
Section titled “"relative"”Ignore the relative keyword names of bolder and lighter.
Given:
{ "font-weight-notation": ["numeric", { "ignore": ["relative"] }]}The following patterns are not considered problems:
a { font-weight: 400; }a b { font-weight: lighter; }