-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
New Check YieldCount #15052
Comments
It can be used. <?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<module name="TreeWalker">
<module name="DescendantToken">
<property name="tokens" value="SWITCH_RULE, CASE_GROUP"/>
<property name="limitedTokens" value="LITERAL_YIELD"/>
<property name="maximumNumber" value="2"/>
</module>
</module>
</module>
does this mean we don't need this check? note that we can also use |
@nrmancuso will do decision |
At least we should extend our examples to let users to have ready to use config for such use case . Additionally I would update summary of this Check to have word "nested" somewhere and maybe some other words to let all find this Check easier at https://checkstyle.org/checks.html It is not first time even I can not find this Check, even I know it exists. |
Awesome idea, @mahfouz72 let's update this issue to reflect a documentation update in DescendantToken for the yield example and to jazz up the description a bit as @romani suggested above. |
It looks like Here is a rough example (may not be a completely accurate code example, but it should provide the point):
Technically the first switch has a count of 2, and the inner switch has a count of 1. The violation is combining them and saying it is 3. To me this seems like it still needs to be a new check. @nrmancuso Please decide. |
Excellent counterexample. Looks like we may not be able to avoid a new check for this, DescendantToken will not support various scenarios like @rnveach illustrated above. Also - this should be a simple check to implement. We could also consider MatchXpathCheck. I am going to assign this to myself and see if I can come up with some reasonable expression before we do any work here. |
I was not able to come up with an XPath for this, but I have been thinking more about this check and believe that we should wait to see some interest from the community before we begin implementation. I could see a few different ways to approach this check (counting yields per switch, or yields for an individual case), plus how we should consider nested switches with yields, etc, and we should get some feedback from actual users on our ideas before we start any work. |
child of #14961
Restricts the number of yield statements in switch expression case block.
Config
Example
Expected Output
The text was updated successfully, but these errors were encountered: