You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Steve Amerige <St...@sas.com> on 2015/06/12 21:46:49 UTC

Default Ruleset for CodeNarc Sought as Default

For Groovy programming, we're looking to establish a default ruleset for 
CodeNarc.  CodeNarc shows the following rules index:

     http://codenarc.sourceforge.net/codenarc-rule-index.html

We're looking to establish a corporate default for CodeNarc that can be 
overridden and is a good default for Groovy programming.

I'm guessing the the Groovy core team use some custom ruleset.  What do 
other Groovy programmers use... and, more importantly, would you be 
willing to share?

Thanks,
Steve Amerige
Principal Software Developer, Fraud and Compliance Solutions Development
SAS Institute, 100 SAS Campus Dr, Room U3050, Cary, NC 27513-8617



Re: Default Ruleset for CodeNarc Sought as Default

Posted by Kyle Boon <ky...@gmail.com>.
Generally I am an advocate to use the defaults. You can nitpick a lot of
rules, but in the end I'd rather have a standard than argue.

This is what I'm using currently:

ruleset {

      description 'SmartThings ruleset'

      // rulesets/basic.xml
      AssertWithinFinallyBlock
      AssignmentInConditional
      BigDecimalInstantiation
      BitwiseOperatorInConditional
      BooleanGetBoolean
      BrokenNullCheck
      BrokenOddnessCheck
      ClassForName
      ComparisonOfTwoConstants
      ComparisonWithSelf
      ConstantAssertExpression
      ConstantIfExpression
      ConstantTernaryExpression
      DeadCode
      DoubleNegative
      DuplicateCaseStatement
      DuplicateMapKey
      DuplicateSetValue
      EmptyCatchBlock
      EmptyClass
      EmptyElseBlock
      EmptyFinallyBlock
      EmptyForStatement
      EmptyIfStatement
      EmptyInstanceInitializer
      EmptyMethod{
         doNotApplyToClassNames = "*Controller"
      }
      EmptyStaticInitializer
      EmptySwitchStatement
      EmptySynchronizedStatement
      EmptyTryBlock
      EmptyWhileStatement
      EqualsAndHashCode
      EqualsOverloaded
      ExplicitGarbageCollection
      ForLoopShouldBeWhileLoop
      HardCodedWindowsFileSeparator
      HardCodedWindowsRootDirectory
      IntegerGetInteger
      RandomDoubleCoercedToZero
      RemoveAllOnSelf
      ReturnFromFinallyBlock
      ThrowExceptionFromFinallyBlock

      // rulesets/braces.xml
      ElseBlockBraces
      ForStatementBraces
      IfStatementBraces
      WhileStatementBraces

      // rulesets/concurrency.xml
      BusyWait
      DoubleCheckedLocking
      InconsistentPropertyLocking
      InconsistentPropertySynchronization
      NestedSynchronization
      StaticCalendarField
      StaticConnection
      StaticDateFormatField
      StaticMatcherField
      StaticSimpleDateFormatField
      SynchronizedMethod
      SynchronizedOnBoxedPrimitive
      SynchronizedOnGetClass
      SynchronizedOnReentrantLock
      SynchronizedOnString
      SynchronizedOnThis
      SynchronizedReadObjectMethod
      SystemRunFinalizersOnExit
      ThisReferenceEscapesConstructor
      ThreadGroup
      ThreadLocalNotStaticFinal
      ThreadYield
      UseOfNotifyMethod
      VolatileArrayField
      VolatileLongOrDoubleField
      WaitOutsideOfWhileLoop

      // rulesets/convention.xml
      ConfusingTernary
      CouldBeElvis
      HashtableIsObsolete
      IfStatementCouldBeTernary
      InvertedIfElse
      LongLiteralWithLowerCaseL
      ParameterReassignment
      TernaryCouldBeElvis
      VectorIsObsolete

      // rulesets/design.xml
      AbstractClassWithPublicConstructor
      AbstractClassWithoutAbstractMethod
      BooleanMethodReturnsNull
      BuilderMethodWithSideEffects
      CloneableWithoutClone
      CloseWithoutCloseable
      CompareToWithoutComparable
      ConstantsOnlyInterface
      EmptyMethodInAbstractClass
      FinalClassWithProtectedMember
      ImplementationAsType
      PrivateFieldCouldBeFinal
      PublicInstanceField
      ReturnsNullInsteadOfEmptyArray
      ReturnsNullInsteadOfEmptyCollection
      SimpleDateFormatMissingLocale
      StatelessSingleton

      // rulesets/dry.xml
      DuplicateListLiteral
      DuplicateMapLiteral

      // rulesets/enhanced.xml
      CloneWithoutCloneable
      JUnitAssertEqualsConstantActualValue
      UnsafeImplementationAsMap

      // rulesets/exceptions.xml
      CatchArrayIndexOutOfBoundsException
      CatchError
      CatchException
      CatchIllegalMonitorStateException
      CatchIndexOutOfBoundsException
      CatchNullPointerException
      CatchRuntimeException
      CatchThrowable
      ConfusingClassNamedException
      ExceptionExtendsError
      ExceptionNotThrown
      MissingNewInThrowStatement
      ReturnNullFromCatchBlock
      SwallowThreadDeath
      ThrowError
      ThrowException
      ThrowNullPointerException
      ThrowRuntimeException
      ThrowThrowable

      // rulesets/formatting.xml
      BracesForClass
      BracesForForLoop
      BracesForIfElse
      BracesForMethod
      BracesForTryCatchFinally
      ClassJavadoc {
         enabled = false
      }
      SpaceAfterCatch
      SpaceAfterClosingBrace
      SpaceAfterComma
      SpaceAfterFor
      SpaceAfterIf
      SpaceAfterOpeningBrace
      SpaceAfterSemicolon
      SpaceAfterSwitch
      SpaceAfterWhile
      SpaceAroundClosureArrow
      SpaceAroundOperator
      SpaceBeforeClosingBrace
      SpaceBeforeOpeningBrace

      // rulesets/generic.xml
      IllegalClassMember
      IllegalClassReference
      IllegalPackageReference
      IllegalRegex
      RequiredRegex
      RequiredString
      StatelessClass

      // rulesets/groovyism.xml
      AssignCollectionSort
      AssignCollectionUnique
//    ClosureAsLastMethodParameter
      CollectAllIsDeprecated
      ConfusingMultipleReturns
      ExplicitArrayListInstantiation
      ExplicitCallToAndMethod
      ExplicitCallToCompareToMethod
      ExplicitCallToDivMethod
      ExplicitCallToEqualsMethod
      ExplicitCallToGetAtMethod
      ExplicitCallToLeftShiftMethod
      ExplicitCallToMinusMethod
      ExplicitCallToModMethod
      ExplicitCallToMultiplyMethod
      ExplicitCallToOrMethod
      ExplicitCallToPlusMethod
      ExplicitCallToPowerMethod
      ExplicitCallToRightShiftMethod
      ExplicitCallToXorMethod
      ExplicitHashMapInstantiation
      ExplicitHashSetInstantiation
      ExplicitLinkedHashMapInstantiation
      ExplicitLinkedListInstantiation
      ExplicitStackInstantiation
      ExplicitTreeSetInstantiation
      GStringAsMapKey
      GStringExpressionWithinString
      GetterMethodCouldBeProperty
      GroovyLangImmutable
      UseCollectMany
      UseCollectNested

      // rulesets/imports.xml
      DuplicateImport
      ImportFromSamePackage
      ImportFromSunPackages
      MisorderedStaticImports
      UnnecessaryGroovyImport
      UnusedImport

      // rulesets/jdbc.xml
      DirectConnectionManagement
      JdbcConnectionReference
      JdbcResultSetReference
      JdbcStatementReference

      // rulesets/junit.xml
      ChainedTest
      CoupledTestCase
      JUnitAssertAlwaysFails
      JUnitAssertAlwaysSucceeds
      JUnitFailWithoutMessage
      JUnitLostTest
      JUnitPublicField
      JUnitPublicNonTestMethod
      JUnitSetUpCallsSuper
      JUnitStyleAssertions
      JUnitTearDownCallsSuper
      JUnitTestMethodWithoutAssert
      JUnitUnnecessarySetUp
      JUnitUnnecessaryTearDown
      JUnitUnnecessaryThrowsException
      SpockIgnoreRestUsed
      UnnecessaryFail
      UseAssertEqualsInsteadOfAssertTrue
      UseAssertFalseInsteadOfNegation
      UseAssertNullInsteadOfAssertEquals
      UseAssertSameInsteadOfAssertTrue
      UseAssertTrueInsteadOfAssertEquals
      UseAssertTrueInsteadOfNegation

      // rulesets/logging.xml
      LoggerForDifferentClass
      LoggerWithWrongModifiers
      LoggingSwallowsStacktrace
      MultipleLoggers
      PrintStackTrace
      Println
      SystemErrPrint
      SystemOutPrint

      // rulesets/naming.xml
      AbstractClassName
      ClassName
      ClassNameSameAsFilename
      ConfusingMethodName
      FactoryMethodName {
         enabled = false
      }
      FieldName
      InterfaceName
      MethodName
      ObjectOverrideMisspelledMethodName
      PackageName
      ParameterName
      PropertyName
      VariableName

      // rulesets/security.xml
      FileCreateTempFile
      InsecureRandom
      NonFinalPublicField
      NonFinalSubclassOfSensitiveInterface
      ObjectFinalize
      PublicFinalizeMethod
      SystemExit
      UnsafeArrayDeclaration

      // rulesets/serialization.xml
      EnumCustomSerializationIgnored
      SerialPersistentFields
      SerialVersionUID
      SerializableClassMustDefineSerialVersionUID {
         enabled = false
      }

      // rulesets/size.xml
      AbcComplexity   // DEPRECATED: Use the AbcMetric rule instead.
Requires the GMetrics jar
      AbcMetric   // Requires the GMetrics jar
      ClassSize
      CrapMetric   // Requires the GMetrics jar and a Cobertura coverage file
      CyclomaticComplexity   // Requires the GMetrics jar
      MethodCount
      MethodSize
      NestedBlockDepth

      // rulesets/unnecessary.xml
      AddEmptyString
      ConsecutiveLiteralAppends
      ConsecutiveStringConcatenation
      UnnecessaryBigDecimalInstantiation
      UnnecessaryBigIntegerInstantiation
      UnnecessaryBooleanExpression
      UnnecessaryBooleanInstantiation
      UnnecessaryCallForLastElement
      UnnecessaryCallToSubstring
      UnnecessaryCatchBlock
      UnnecessaryCollectCall
      UnnecessaryCollectionCall
      UnnecessaryConstructor
      UnnecessaryDefInFieldDeclaration
      UnnecessaryDefInMethodDeclaration
      UnnecessaryDefInVariableDeclaration
      UnnecessaryDotClass
      UnnecessaryDoubleInstantiation
      UnnecessaryFinalOnPrivateMethod
      UnnecessaryFloatInstantiation
      UnnecessaryGString{
         enabled = false
      }
      UnnecessaryGetter
      UnnecessaryIfStatement
      UnnecessaryInstanceOfCheck
      UnnecessaryInstantiationToGetClass
      UnnecessaryIntegerInstantiation
      UnnecessaryLongInstantiation
      UnnecessaryModOne
      UnnecessaryNullCheck
      UnnecessaryNullCheckBeforeInstanceOf
      UnnecessaryObjectReferences
      UnnecessaryOverridingMethod
      UnnecessaryPackageReference
      UnnecessaryParenthesesForMethodCallWithClosure
      UnnecessaryPublicModifier
      UnnecessaryReturnKeyword{
         enabled = false
      }
      UnnecessarySelfAssignment
      UnnecessarySemicolon
      UnnecessaryStringInstantiation
      UnnecessarySubstring
      UnnecessaryTernaryExpression
      UnnecessaryTransientModifier

      // rulesets/unused.xml
      UnusedArray
      UnusedMethodParameter
      UnusedObject
      UnusedPrivateField
      UnusedPrivateMethod
      UnusedPrivateMethodParameter
      UnusedVariable
   }


On Fri, Jun 12, 2015 at 2:46 PM, Steve Amerige <St...@sas.com>
wrote:

>  For Groovy programming, we're looking to establish a default ruleset for
> CodeNarc.  CodeNarc shows the following rules index:
>
>     http://codenarc.sourceforge.net/codenarc-rule-index.html
>
> We're looking to establish a corporate default for CodeNarc that can be
> overridden and is a good default for Groovy programming.
>
> I'm guessing the the Groovy core team use some custom ruleset.  What do
> other Groovy programmers use... and, more importantly, would you be willing
> to share?
>
> Thanks,
> Steve Amerige
>  Principal Software Developer, Fraud and Compliance Solutions Development
> SAS Institute, 100 SAS Campus Dr, Room U3050, Cary, NC 27513-8617
>
>
>