Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brown-olives-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `media-feature-range-notation` false positives for multiple queries and `except: exact-value`
38 changes: 38 additions & 0 deletions lib/rules/media-feature-range-notation/__tests__/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ testRule({
{
code: '@media (color) {}',
},
{
code: '@media (width = 1px) {} @media (width = 2px) {}',
description: 'multiple media queries',
},
{
code: '@media (width = 1px), (width = 2px) {}',
description: 'multiple features',
},
],
reject: [
{
Expand All @@ -360,5 +368,35 @@ testRule({
endLine: 1,
endColumn: 20,
},
{
code: '@media (width: 1px), (width: 2px) {}',
fixed: '@media (width = 1px), (width = 2px) {}',
fix: {
range: [13, 14],
text: ' =',
},
message: messages.expected('context'),
warnings: [
{
message: messages.expected('context'),
line: 1,
column: 8,
endLine: 1,
endColumn: 20,
fix: {
range: [13, 14],
text: ' =',
},
},
{
message: messages.expected('context'),
line: 1,
column: 22,
endLine: 1,
endColumn: 34,
fix: undefined,
},
],
},
],
});
12 changes: 7 additions & 5 deletions lib/rules/media-feature-range-notation/index.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions lib/rules/media-feature-range-notation/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const rule = (primary, secondaryOptions) => {

if (!rangeTypeMediaFeatureNames.has(unprefixedMediaFeature)) return;

let expected = primary;

if (exceptExactValue) {
const isMediaFeatureRangeWithExactOperator =
(isMediaFeatureRangeNameValue(node) || isMediaFeatureRangeValueName(node)) &&
Expand All @@ -83,15 +85,15 @@ const rule = (primary, secondaryOptions) => {
isMediaFeaturePlain(node) && featureName.length === unprefixedMediaFeature.length;

if (isMediaFeatureRangeWithExactOperator || isMediaFeaturePlainUnprefixed) {
primary = primary === 'prefix' ? 'context' : 'prefix';
expected = primary === 'prefix' ? 'context' : 'prefix';
}
}

// Expected plain notation and received plain notation
if (primary === 'prefix' && isMediaFeaturePlain(node)) return;
if (expected === 'prefix' && isMediaFeaturePlain(node)) return;

// Expected range notation and received range notation
if (primary === 'context' && isMediaFeatureRange(node)) return;
if (expected === 'context' && isMediaFeatureRange(node)) return;

/**
* @param {object} entry
Expand Down Expand Up @@ -142,14 +144,14 @@ const rule = (primary, secondaryOptions) => {
};

const hasFix =
primary === 'context' && isMediaFeaturePlain(node) && isMediaFeature(parent);
expected === 'context' && isMediaFeaturePlain(node) && isMediaFeature(parent);
const fix = hasFix ? contextFixer({ node, parent }) : undefined;
const [startIndex, endIndex] = sourceIndices(node);
const atRuleIndex = atRuleParamIndex(atRule);

report({
message: messages.expected,
messageArgs: [primary],
messageArgs: [expected],
node: atRule,
index: atRuleIndex + startIndex - 1,
endIndex: atRuleIndex + endIndex + 1 + 1,
Expand Down
Loading