-
Notifications
You must be signed in to change notification settings - Fork 61
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
Improved error message for properties in groups #72
Comments
I believe you can use it if you use stylelint without
Sounds good! I checked your code and I think it should be located in the other file, but I can't say for sure. (Which indicates, that I'm probably need to refactor my code :)) I'll dig into it, and tell you later next week (I'm traveling right now). If you participating in Hacktoberfest, then feel free to open “work in progress” pull request, so your contribution will count. |
Whilst it's on my mind, I'll just add a suggestion for the message itself. How's about?:
It'll be more aligned with the messages of the built-in rules because they follow the convention of making sense regardless of what goes in the quotes. For example:
Would give:
Whereas the current implementation would give:
Which, arguably, makes less sense as '"one" properties' isn't a thing. |
Great - thank you, no rush.
Good catch. I was aiming for a message that would make sense both in this case: padding: 10px;
right: 0; And in this one, where the property is already in the correct group but not in the right order within that group: right: 0;
position: 10px; I'm not sure if the |
Also: I'm not participating in Hacktoberfest, but I went ahead and created a PR labeled "WIP": |
I just looked into this...thanks, but it looks like you need a processor of some sort to enable this:
And stylelint does not currently support autofixes for processors. See: Autofixing would be a great feature, but I don't think it would be possible without stylelint adding support for this to the processor API. And it could be complex for styled-components because it the template string can also contain JS functions. |
This is my bad. I missed this bit about processors in the configuration doc when I deemphasised processors elsewhere in the docs after the I've created a quick PR to fix the configuration doc: stylelint/stylelint#3747. As @hudochenkov said, linting and fixing of styled-components is supported out-of-the-box now. |
Currently, when using property groups, you'll get an error message like this if your code doesn't match the specified order:
It would be nice if the error message mentioned the fact that the property is also expected to be part of a group.
Here's an example use case...at my company we are using styled-components, so we can't use the
--fix
option. So we want to require an order for properties that only requires remembering a few rules and is also readable. This is what we want to use:Given these rules, if a new developer starts working on a project and puts a rule, e.g.
position
orright
in alphabetical order instead of at the top:They'll get errors like this:
It would be great if the error message wouldn't just say that
right
should go abovepadding
, but that it belongs in the positioning group.I created a fork of this repo that achieves this (note: I didn't add a Jest test for it yet):
https://github.com/mbrowne/stylelint-order/tree/group-error-message
mbrowne@6ba7e43
It allows property groups to have an optional
name
property:And if a group name is present, the error includes it, e.g.:
I think that would be much more helpful for developers new to our rules than the current error.
Does this sound like a good solution? Should I submit a PR? Thanks.
The text was updated successfully, but these errors were encountered: