ReturnCount: special option for methods with void return type #3143

Closed
romani opened this Issue Apr 28, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@romani
Member

romani commented Apr 28, 2016

http://checkstyle.sourceforge.net/config_coding.html#ReturnCount

validation for methods which return void should have separate limit - maxForVoid. By default should be the same as default of max property.

This code does not give a violation, but with maxForVoid=1 should fire violation.

    private void checkThrows() {
        final DetailAST throwsAst = getMainAst().findFirstToken(TokenTypes.LITERAL_THROWS);
        if (throwsAst == null) {
            return; /// should be violation with maxForVoid=1, as one return is at end of method
        }

        if (isOnStartOfLine(throwsAst)) {
            final int columnNo = expandedTabsColumnNo(throwsAst);
            final IndentLevel expectedColumnNo = new IndentLevel(getIndent(), getIndentCheck()
                    .getThrowsIndent());

            if (!expectedColumnNo.isAcceptable(columnNo)) {
                logError(throwsAst, "throws", columnNo, expectedColumnNo);
            }
        }

        checkWrappingIndentation(throwsAst, throwsAst.getNextSibling(),
                expandedTabsColumnNo(getMainAst()), getIndentCheck().getThrowsIndent());
    }

@romani romani added the approved label Apr 28, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue May 15, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue May 15, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue May 15, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue May 16, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue May 16, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue May 16, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue May 16, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue May 16, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue May 16, 2016

rnveach added a commit to rnveach/xwiki-commons that referenced this issue May 22, 2016

[Misc] Fix violation for new property 'maxForVoid' for 'ReturnCountCh…
…eck'

This PR is being created because of a new violation found in CheckStyle's regression of XWiki.
Issue: checkstyle/checkstyle#3143
PR: checkstyle/checkstyle#3180 (comment)

A new property for `ReturnCountCheck` was added, 'maxForVoid'. This property allows users to count `return;` statements separately from `return expression;` statements. The default value of this property is 1 and this caused only the following violation in XWiki:
````[ERROR] [src/main/java/org/xwiki/job/internal/DefaultJobProgress.java:180,5](https://github.com/xwiki/xwiki-commons/blob/master/xwiki-commons-core/xwiki-commons-job/src/main/java/org/xwiki/job/internal/DefaultJobProgress.java#L180-L206) (coding) ReturnCount: Return count is 2 (max allowed is 1).````

You can either accept this PR and not have an issue when you upgrade CS with this new feature in the future,
or make your own change, suppression, or add a different property value later when you do upgrade CS.

Feel free to ask any other questions or propose any additional changes.

rnveach added a commit to rnveach/checkstyle that referenced this issue May 27, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue May 27, 2016

@romani romani added the new feature label May 27, 2016

@romani romani added this to the 6.19 milestone May 27, 2016

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani May 27, 2016

Member

fix is merged.

Member

romani commented May 27, 2016

fix is merged.

@romani romani closed this May 27, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment