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

!important without whitespace considered invalid in some cases #18

Closed
ArgonAlex opened this issue Mar 30, 2021 · 3 comments
Closed

!important without whitespace considered invalid in some cases #18

ArgonAlex opened this issue Mar 30, 2021 · 3 comments

Comments

@ArgonAlex
Copy link

Related to csstree/csstree/issues/155

Should we be using matchDeclaration() instead of matchProperty()?

const { validate } = require('csstree-validator');
console.log(validate('a { width: calc(100% - 10px)!important }'));
[
	SyntaxError [SyntaxMatchError]: Mismatch
		at matchSyntax (node_modules\css-tree\lib\lexer\Lexer.js:87:17)
		at Lexer.matchProperty (node_modules\css-tree\lib\lexer\Lexer.js:331:16)
		at validateDeclaration (node_modules\csstree-validator\lib\validate.js:103:45)
		at List.<anonymous> (node_modules\csstree-validator\lib\validate.js:120:32)
		at List.each (node_modules\css-tree\lib\common\List.js:158:12)
		at validateRule (node_modules\csstree-validator\lib\validate.js:118:29)
		at Object.enter (node_modules\csstree-validator\lib\validate.js:158:28)
		at Object.<anonymous> (node_modules\css-tree\lib\walker\create.js:11:16) {
	  message: 'Invalid value for `width` property',
	  rawMessage: 'Mismatch',
	  syntax: 'auto | <length> | <percentage> | min-content | max-content | fit-content( <length-percentage> )',
	  css: 'calc(100% - 10px)!important',
	  mismatchOffset: 17,
	  mismatchLength: 1,
	  offset: 28,
	  line: 1,
	  column: 29,
	  loc: { source: '<unknown>', start: [Object], end: [Object] },
	  property: 'width',
	  details: 'Mismatch\n' +
		'  syntax: auto | <length> | <percentage> | min-content | max-content | fit-content( <length-percentage> )\n' +
		'   value: calc(100% - 10px)!important\n' +
		'  -------------------------^'
	}
  ]
@lahmatiy
Copy link
Member

Thank you for the report! Now I see the origin of the issue and able to reproduce it.
I found that this is a bug in CSSTree's parser when parseValue option is set to false (it set to false in csstree-validator to speed up parsing since it not needed for a detailed AST for values). In this case !important is included into a value but must not. I will address a fix for this ASAP. The status can be tracked in csstree/csstree#155 (original report about the problem). But this issue is also useful since the bug affects csstree-validator and will indicate when fix will come into csstree-validator.

@ArgonAlex
Copy link
Author

Thanks!

@lahmatiy
Copy link
Member

Fixed in 2.0.1.

@ArgonAlex Thank you for the report once again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants