Avoid undefined type on data or routines declaration

Why you should care

Groovy support dynamic types, that is declarations where the type is def or unspecified.

How we detect

CAST Highlight counts one occurrence each time a function, method, field member, variable or parameter has no explicit type defined. def is not an explicit type.


    void functionWithDynamicParameter(def parameter) {              // violation
    void functionWithParameterWithoutTypeDeclaration(parameter, def param2) {   // + 2 violations
    void functionWithObjectParameter(Object parameter)              // OK
    def functionWithDynamicReturnType() {                         // + 1 VIOLATION
   def variableWithDynamicType = "yoooo"                       // +1 VIOLATION
    class toto {
              def fieldWithDynamicType = 0       // +1 VIOLATION
              def int fieldWithExplicitType        // OK
              def void methodWithExplicitReturnType() {   // OK
              def methodWithDynamicType() {              // +1 VIOLATION
                       def localVarWithDynamicType = 0   // +1 VIOLATION


https://codenarc.org/codenarc-rules-convention.html (FieldTypeRequired, MethodParameterTypeRequired, MethodReturnTypeRequired, VariableTypeRequired)

About CAST and Highlight’s Code Insights

Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.