Skip to content

Commit

Permalink
Fix false positives for x unit within vendor-prefixed image-set in un…
Browse files Browse the repository at this point in the history
…it-no-unknown (#4654)
  • Loading branch information
srawlins committed Apr 3, 2020
1 parent 9c564e4 commit fa24482
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/rules/unit-no-unknown/__tests__/index.js
Expand Up @@ -224,6 +224,10 @@ testRule(rule, {
code: "a { background-image: image-set('img-1x.jpg' 1x, 'img-2x.jpg' 2x, 'img-3x.jpg' 3x) }",
description: 'ignore `x` unit in image-set',
},
{
code: "a { background-image: -webkit-image-set('img-1x.jpg' 1x, 'img-2x.jpg' 2x) }",
description: 'ignore `x` unit in vendor-prefixd image-set',
},
{
code: '@media (resolution: 2x) {}',
description: 'ignore `x` unit in @media with `resolution`',
Expand Down
7 changes: 5 additions & 2 deletions lib/rules/unit-no-unknown/index.js
Expand Up @@ -8,6 +8,7 @@ const isMap = require('../../utils/isMap');
const keywordSets = require('../../reference/keywordSets');
const mediaParser = require('postcss-media-query-parser').default;
const optionsMatches = require('../../utils/optionsMatches');
const postcss = require('postcss');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
Expand Down Expand Up @@ -116,8 +117,10 @@ function rule(actual, options) {
return;
}

if (/^image-set/i.test(value)) {
const imageSet = parsedValue.nodes.find((node) => node.value === 'image-set');
if (/^(?:-webkit-)?image-set[\s(]/i.test(value)) {
const imageSet = parsedValue.nodes.find(
(node) => postcss.vendor.unprefixed(node.value) === 'image-set',
);
const imageSetValueLastIndex = _.last(imageSet.nodes).sourceIndex;

if (imageSetValueLastIndex >= valueNode.sourceIndex) {
Expand Down

0 comments on commit fa24482

Please sign in to comment.