New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore x
unit in some cases
#4427
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ const atRuleParamIndex = require('../../utils/atRuleParamIndex'); | |
const declarationValueIndex = require('../../utils/declarationValueIndex'); | ||
const getUnitFromValueNode = require('../../utils/getUnitFromValueNode'); | ||
const keywordSets = require('../../reference/keywordSets'); | ||
const mediaParser = require('postcss-media-query-parser').default; | ||
const optionsMatches = require('../../utils/optionsMatches'); | ||
const report = require('../../utils/report'); | ||
const ruleMessages = require('../../utils/ruleMessages'); | ||
|
@@ -62,10 +63,42 @@ const rule = function(actual, options) { | |
return; | ||
} | ||
|
||
if (keywordSets.units.has(unit.toLowerCase())) { | ||
if (keywordSets.units.has(unit.toLowerCase()) && unit.toLowerCase() !== 'x') { | ||
return; | ||
} | ||
|
||
if (unit.toLowerCase() === 'x') { | ||
if ( | ||
node.type === 'atrule' && | ||
node.name === 'media' && | ||
node.params.toLowerCase().includes('resolution') | ||
) { | ||
let ignoreUnit = false; | ||
|
||
mediaParser(node.params).walk((mediaNode, i, mediaNodes) => { | ||
if ( | ||
mediaNode.value.toLowerCase().includes('resolution') && | ||
_.last(mediaNodes).sourceIndex === valueNode.sourceIndex | ||
) { | ||
ignoreUnit = true; | ||
|
||
return false; | ||
} | ||
}); | ||
|
||
if (ignoreUnit) { | ||
return; | ||
} | ||
} | ||
|
||
if ( | ||
node.type === 'decl' && | ||
(node.prop.toLowerCase() === 'image-resolution' || /^image-set/i.test(node.value)) | ||
) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can parse decl here too, because you can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice case. Updated the logic. |
||
return; | ||
} | ||
} | ||
|
||
report({ | ||
index: getIndex(node) + valueNode.sourceIndex, | ||
message: messages.rejected(unit), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add test with
@media (resolution: 2x) and (min-width: 200x) {}
, second should be rejectedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to update logic so that such a case could be handled properly.
Not sure about implementation though.
Any suggestions are welcome.