[ 
https://issues.apache.org/jira/browse/CASSANDRA-20038?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17894230#comment-17894230
 ] 

Stefan Miklosovic commented on CASSANDRA-20038:
-----------------------------------------------

We could do something like this

{code}
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;

public class ForbidVarCheck extends AbstractCheck {

    @Override
    public int[] getDefaultTokens() {
        return new int[] { TokenTypes.VARIABLE_DEF };
    }

    @Override
    public void visitToken(DetailAST ast) {
        DetailAST typeAST = ast.findFirstToken(TokenTypes.TYPE);
        if (typeAST != null && "var".equals(typeAST.getFirstChild().getText())) 
{
            log(ast.getLineNo(), "Usage of 'var' is forbidden. Please use 
explicit types.");
        }
    }
}
{code}

but the question is where to put this, how to have that compiled and on the 
class path so we can reference it in checkstyle.

Maybe it would be better to implement this in checkstyle directly, wait for the 
release, bump the version we are using and we would just reference it from 
there.

> Investigate how to ban usages of "var" in production code.
> ----------------------------------------------------------
>
>                 Key: CASSANDRA-20038
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-20038
>             Project: Cassandra
>          Issue Type: Task
>          Components: Build
>            Reporter: Stefan Miklosovic
>            Priority: Normal
>
> In this thread (1) we reached the consensus of banning usages of "var" in the 
> production code but allowing it in tests. We should investigate how to handle 
> this robustly, e.g. by a checkstyle rule. The investigation how to do this 
> should be conducted.
> Upon delivery, that probably means that the existing usages of "var" in the 
> production code will need to be fixed and converted to have it all on types 
> again because such rule would fail the compilation of the production code 
> otherwise.
> (1) https://lists.apache.org/thread/jfgj8lh1llp9zrodmfqyq22kvtlodyk6



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to