stylelint: Add `ignore: ["consecutive-duplicates-with-different-syntaxes"]` to `declaration-block-no-duplicate-properties`
What is the problem you’re trying to solve?
I would like to have errors on duplicate declarations with different values only if the different values have the same syntax.
A different syntax is most likely a fallback/progressive enhancement.
Error :
.foo {
width: 100px;
width: 150px;
}
.foo {
width: calc(10px * 2);
width: calc(20px * 2);
}
Ok :
.foo {
width: 100px;
width: 10ch;
}
.foo {
width: calc(10px * 2);
width: 2vi;
}
What solution would you like to see?
It is possible to analyse the value by tokenizing and checking if the token streams of both are the same.
When comparing the token streams the actual values must be ignored and only the type and unit must be considered.
If the token streams differ the syntax is not the same.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 21 (21 by maintainers)
@carlosjeurissen I’ve created a new issue to track this : https://github.com/stylelint/stylelint/issues/6796
@jeddy3 I start implementing this issue.
I think the new option name better be
consecutive-duplicates-with-different-syntax. Duplicatedignore, and there is already an optionconsecutive-duplicates-with-different-values.@ybiquitous Do you prefer to discuss this further in this issue or in a new one?
In hindsight I should have taken the time to provide more examples to explain what I had in mind for this option.
I think it can be interpreted in two ways :
These are related, but not the same. You can have differing AST shapes while also using the same syntax features, and you can have the same AST shape while using different features.
I think that what exists know checks if the AST shape is similar, but doesn’t actually check for similar syntax features.
For example
These have different AST shapes, but they use the same syntax features.
The vague idea I had when proposing this option was to do these steps :
Set’s for :token_typesfunction_namesident_namesdimension_unitsdelimstoken_typesfunction_names--foo) -> continue / skipident_namesdimension_unitsdelimnsI might have forgotten a token type, writing this from memory
If all sets have the same contents for both values then the syntax is similar.
The false positive is things like this :
These do not have the same syntax. One has a double position stop.
@ybiquitous Thanks for your reply!
For stylelint-config-recommended, something like:
Seems to tricky for being recommended. Potentially something for
stylelint-config-standard, but even then personally seems too much of an interference.For now seems like the best option considering the potential issues as specified. We can then follow up with determining what keywords should be considered the same group. In which case
min-contentandmax-contentcan be put in the same group, whilefit-contentandautocan be in different groups.This is used to override
width: 100px;which is set with a different className.This seems like a good idea. When using
initialinstead ofauto, this is also removed in favor offit-content.initialfor sure should be seen as a different category asfit-content.I’ve opened https://github.com/stylelint/stylelint-config-recommended/issues/186
I think changing to
consecutive-duplicates-with-different-syntaxesis better because it can more strictly check fallback.@kimulaco Thanks for the pull request. We will release this new option with the next version.
So, let me ask a question about our recommended config. The current config turns on the rule with
ignore: ['consecutive-duplicates-with-different-values']. Should we change it toconsecutive-duplicates-with-different-syntaxes? What do you think, guys?https://github.com/stylelint/stylelint-config-recommended/blob/e6c852041a7c030c5763b3eca0deddc9fad852a9/index.js#L12-L17
Good. I just updated the issue title again. 👍🏼
@ybiquitous Thanks. I agree.
consecutive-duplicates-with-different-syntaxesis better!