Skip to content

Commit

Permalink
Fix declaration-property-value-no-unknown parse error for `alpha(op…
Browse files Browse the repository at this point in the history
…acity=n)` to report as violation (#6650)

* Fix `declaration-property-value-no-unknown` parseError even when a file starts with `/* stylelint-disable */`

* reuse values

* Create clean-snakes-cheat.md

* Update lib/rules/declaration-property-value-no-unknown/__tests__/index.js

Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>

* Update .changeset/clean-snakes-cheat.md

Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>

---------

Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
  • Loading branch information
romainmenke and ybiquitous committed Feb 12, 2023
1 parent 11064f7 commit 6df74eb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
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

0 comments on commit 6df74eb

Please sign in to comment.