-
-
Notifications
You must be signed in to change notification settings - Fork 928
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
Add checkAgainstRule util #2173
Conversation
SGTM 👍 |
SGTM too. The CI is failing because of a couple of flow warnings. |
I don't know what callback to use in order to push warning where they belong, so I've used stylelint.checkAgainstRule(
{
ruleName: 'declaration-block-properties-order',
ruleSettings: [ cleanedConfig, options ],
root,
},
(warning) => console.log(warning)
); I've used code above instead of https://github.com/hudochenkov/stylelint-order/blob/master/rules/declaration-block-property-groups-structure/index.js#L32-L40 It shows this warning on setup as in #2139:
Problem with severity lays some where else :( |
@hudochenkov Here's how you'd use this: function myPluginRule(root, result) {
/* ... */
stylelint.checkAgainstRule({
ruleName: 'declaration-block-properties-order',
ruleSettings: someAppropriateSettings,
root,
}, (warning) => {
stylelint.utils.report({
result,
ruleName: myPluginRuleName,
message: myMessage,
node: warning.node,
line: warning.line,
column: warning.column
})
});
} The idea is that you'd actually Does this make sense? |
Sounds reasonable. I've changed
|
@hudochenkov If I were using that plugin, I think I'd find it confusing to see a rule mentioned that I did not deliberately turn on — so I'd suggest using a regex or something to replace the name with that of the rule that is reporting. |
It sounds like this approach is working out well. I'll label this up as "needs docs". |
45943cf
to
3c54a2d
Compare
Added some documentation in |
Excellent. That example really highlights the power of this addition! |
@davidtheclark Those flow errors have resurfaced. Should we fix those before merging? |
75679c0
to
e605058
Compare
Got the tests passing! Please take another look sometime :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks very good 👍
Changelog
As an aside, I think with new features like this the next release is shaping up as a good one :) |
* Add checkAgainstRule util
Here's an idea to solve #2139.
It exposes another function
stylelint.checkAgainstRule
, which you can use to run a PostCSSRoot
object through a rule, and invoke a callback with every warning that is created.What I'd like to see in a situation liked #2139 is that the plugin rule that uses a core rule is the only one that calls
report()
. It is the reporting rule, and its severity should be used.I have not yet added documentation, but did add some tests.
@hudochenkov would you please try this branch out and see if it works for your use-case?
@stylelint/core any input on this?