Skip to content
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

Fix declaration-property-value-no-unknown parse error for alpha(opacity=n) to report as violation #6650

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clean-snakes-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `declaration-property-value-no-unknown` parse error for `alpha(opacity=n)` to report as violation
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ testRule({
endLine: 1,
endColumn: 17,
},
{
code: 'a { filter: alpha(opacity=30); }',
message: messages.rejectedParseError('filter', 'alpha(opacity=30)'),
line: 1,
column: 13,
endLine: 1,
endColumn: 30,
},
],
});

Expand Down
13 changes: 11 additions & 2 deletions lib/rules/declaration-property-value-no-unknown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const ruleName = 'declaration-property-value-no-unknown';

const messages = ruleMessages(ruleName, {
rejected: (property, value) => `Unexpected unknown value "${value}" for property "${property}"`,
rejectedParseError: (property, value) =>
`Cannot parse property value "${value}" for property "${property}"`,
});

const meta = {
Expand Down Expand Up @@ -91,9 +93,16 @@ const rule = (primary, secondaryOptions) => {

if (containsUnsupportedFunction(cssTreeValueNode)) return;
} catch (e) {
result.warn(`Cannot parse property value "${value}"`, {
const index = declarationValueIndex(decl);
const endIndex = index + value.length;

report({
message: messages.rejectedParseError(prop, value),
node: decl,
stylelintType: 'parseError',
index,
endIndex,
result,
ruleName,
});

return;
Expand Down