Skip to content

Commit

Permalink
Add support for font-weight ranges in @font-face (#4372)
Browse files Browse the repository at this point in the history
* Fix #4327

* Replace regexp with list.space + update tests

* Add reject cases

* Fix lint error
  • Loading branch information
fanich37 authored and hudochenkov committed Oct 24, 2019
1 parent e1a4011 commit 783c876
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
63 changes: 63 additions & 0 deletions lib/rules/font-weight-notation/__tests__/index.js
Expand Up @@ -84,6 +84,33 @@ testRule(rule, {
code: 'a { font-weight: INITIAL; }',
description: 'ignore initial value',
},
{
code: '@font-face { font-weight: 400; }',
},
{
code: '@font-face { font-weight: 400.5; }',
},
{
code: '@font-face { font-weight: 400 700; }',
},
{
code: '@font-face { font-weight: 100.5 400; }',
},
{
code: '@font-face { font-weight: 400.5 700.5; }',
},
{
code: '@font-face { font-weight: 400.5 /* 700 */ 700.5; }',
},
{
code: '@font-face { font-weight: 400.5 /* 700 */700.5; }',
},
{
code: '@font-face { font-weight: 400 /*700*/700; }',
},
{
code: '@font-face { font-weight: 400.5/*700*/ 700.5; }',
},
],

reject: [
Expand Down Expand Up @@ -144,6 +171,42 @@ testRule(rule, {
line: 1,
column: 11,
},
{
code: '@font-face { font-weight: normal bold; }',
message: messages.expected('numeric'),
line: 1,
column: 27,
},
{
code: '@font-face { font-weight: 400 bold; }',
message: messages.expected('numeric'),
line: 1,
column: 27,
},
{
code: '@font-face { font-weight: normal 700; }',
message: messages.expected('numeric'),
line: 1,
column: 27,
},
{
code: '@font-face { font-weight: /* 400 */ normal 700; }',
message: messages.expected('numeric'),
line: 1,
column: 37,
},
{
code: '@font-face { font-weight: normal /* 400 */700; }',
message: messages.expected('numeric'),
line: 1,
column: 27,
},
{
code: '@font-face { font-weight: normal/* 400 */ 700; }',
message: messages.expected('numeric'),
line: 1,
column: 27,
},
],
});

Expand Down
10 changes: 10 additions & 0 deletions lib/rules/font-weight-notation/index.js
Expand Up @@ -103,6 +103,16 @@ const rule = function(expectation, options) {
const weightValueOffset = decl.value.indexOf(weightValue);

if (expectation === 'numeric') {
if (decl.parent.type === 'atrule' && decl.parent.name.toLowerCase() === 'font-face') {
const weightValueNumbers = postcss.list.space(weightValue);

if (!weightValueNumbers.every(isNumbery)) {
return complain(messages.expected('numeric'));
}

return;
}

if (!isNumbery(weightValue)) {
return complain(messages.expected('numeric'));
}
Expand Down

0 comments on commit 783c876

Please sign in to comment.