Skip to content

Instantly share code, notes, and snippets.

@aaronzirbes
Last active July 16, 2018 11:37
Show Gist options
  • Save aaronzirbes/6fb53f4fe6a6bf0b03102faab373accc to your computer and use it in GitHub Desktop.
Save aaronzirbes/6fb53f4fe6a6bf0b03102faab373accc to your computer and use it in GitHub Desktop.
Example Codenarc.groovy
apply plugin: 'groovy'
apply plugin: 'codenarc'
codenarc {
configFile = file("${project.projectDir}/gradle/codenarc.groovy")
}
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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
EmptyStaticInitializer
EmptySwitchStatement
EmptySynchronizedStatement
EmptyTryBlock
EmptyWhileStatement
EqualsAndHashCode
EqualsOverloaded
ExplicitGarbageCollection
ForLoopShouldBeWhileLoop
HardCodedWindowsFileSeparator
HardCodedWindowsRootDirectory
IntegerGetInteger
MultipleUnaryOperators
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
NoDef
ParameterReassignment
TernaryCouldBeElvis
VectorIsObsolete
// rulesets/design.xml
AbstractClassWithPublicConstructor
AbstractClassWithoutAbstractMethod
BooleanMethodReturnsNull
// BuilderMethodWithSideEffects
CloneableWithoutClone
CloseWithoutCloseable
CompareToWithoutComparable
ConstantsOnlyInterface
EmptyMethodInAbstractClass
FinalClassWithProtectedMember
ImplementationAsType
Instanceof
LocaleSetDefault
NestedForLoop
PrivateFieldCouldBeFinal
PublicInstanceField
ReturnsNullInsteadOfEmptyArray
ReturnsNullInsteadOfEmptyCollection
SimpleDateFormatMissingLocale
StatelessSingleton
ToStringReturnsNull
// rulesets/dry.xml
/*
DuplicateListLiteral
DuplicateMapLiteral
DuplicateNumberLiteral
DuplicateStringLiteral
*/
// rulesets/enhanced.xml
/*
CloneWithoutCloneable
JUnitAssertEqualsConstantActualValue
UnsafeImplementationAsMap
*/
// rulesets/exceptions.xml
CatchArrayIndexOutOfBoundsException
CatchError
CatchException
CatchIllegalMonitorStateException
CatchIndexOutOfBoundsException
CatchNullPointerException
CatchRuntimeException
CatchThrowable
ConfusingClassNamedException
ExceptionExtendsError
ExceptionExtendsThrowable
ExceptionNotThrown
MissingNewInThrowStatement
ReturnNullFromCatchBlock
SwallowThreadDeath
ThrowError
ThrowException
ThrowNullPointerException
ThrowRuntimeException
ThrowThrowable
// rulesets/formatting.xml
BlankLineBeforePackage
BracesForClass
BracesForForLoop
BracesForIfElse
BracesForMethod
BracesForTryCatchFinally
// ClassJavadoc
ClosureStatementOnOpeningLineOfMultipleLineClosure
ConsecutiveBlankLines
FileEndsWithoutNewline
LineLength
MissingBlankLineAfterImports
MissingBlankLineAfterPackage
SpaceAfterCatch
SpaceAfterClosingBrace
SpaceAfterComma
SpaceAfterFor
SpaceAfterIf
SpaceAfterOpeningBrace
SpaceAfterSemicolon
SpaceAfterSwitch
SpaceAfterWhile
SpaceAroundClosureArrow
SpaceAroundMapEntryColon(characterAfterColonRegex: /\s/)
SpaceAroundOperator
SpaceBeforeClosingBrace
SpaceBeforeOpeningBrace
TrailingWhitespace
// rulesets/generic.xml
IllegalClassMember
IllegalClassReference
IllegalPackageReference
IllegalRegex
IllegalString
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
NoWildcardImports
// rulesets/jdbc.xml
DirectConnectionManagement
JdbcConnectionReference
JdbcResultSetReference
JdbcStatementReference
// rulesets/junit.xml
// ChainedTest
// CoupledTestCase
// JUnitAssertAlwaysFails
// JUnitAssertAlwaysSucceeds
// JUnitFailWithoutMessage
// JUnitLostTest
// JUnitPublicField
// JUnitPublicNonTestMethod
// JUnitPublicProperty
// 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 {
regex = '^[A-Z][\\$a-zA-Z0-9]*$'
}
ClassNameSameAsFilename
ConfusingMethodName
// FactoryMethodName
FieldName {
regex = '^_?[a-z][a-zA-Z0-9]*$'
finalRegex = '^_?[a-z][a-zA-Z0-9]*$'
staticFinalRegex = '^logger$|^[A-Z][A-Z_0-9]*$|^serialVersionUID$'
}
InterfaceName
MethodName {
regex = '^[a-z][\\$_a-zA-Z0-9]*$|^.*\\s.*$'
}
ObjectOverrideMisspelledMethodName
PackageName
ParameterName
PropertyName
VariableName {
finalRegex = '^[a-z][a-zA-Z0-9]*$'
}
// rulesets/security.xml
FileCreateTempFile
InsecureRandom
// JavaIoPackageAccess
NonFinalPublicField
NonFinalSubclassOfSensitiveInterface
ObjectFinalize
PublicFinalizeMethod
SystemExit
UnsafeArrayDeclaration
// rulesets/serialization.xml
EnumCustomSerializationIgnored
SerialPersistentFields
SerialVersionUID
SerializableClassMustDefineSerialVersionUID
// rulesets/size.xml
AbcMetric // Requires the GMetrics jar
ClassSize
// CrapMetric // Requires the GMetrics jar and a Cobertura coverage file
CyclomaticComplexity // Requires the GMetrics jar
MethodCount
MethodSize
NestedBlockDepth
ParameterCount
// rulesets/unnecessary.xml
AddEmptyString
ConsecutiveLiteralAppends
ConsecutiveStringConcatenation
UnnecessaryBigDecimalInstantiation
UnnecessaryBigIntegerInstantiation
UnnecessaryBooleanExpression
UnnecessaryBooleanInstantiation
UnnecessaryCallForLastElement
UnnecessaryCallToSubstring
UnnecessaryCast
UnnecessaryCatchBlock
UnnecessaryCollectCall
UnnecessaryCollectionCall
UnnecessaryConstructor
UnnecessaryDefInFieldDeclaration
UnnecessaryDefInMethodDeclaration
UnnecessaryDefInVariableDeclaration
UnnecessaryDotClass
UnnecessaryDoubleInstantiation
UnnecessaryElseStatement
UnnecessaryFinalOnPrivateMethod
UnnecessaryFloatInstantiation
UnnecessaryGString
UnnecessaryGetter
UnnecessaryIfStatement
UnnecessaryInstanceOfCheck
UnnecessaryInstantiationToGetClass
UnnecessaryIntegerInstantiation
UnnecessaryLongInstantiation
UnnecessaryModOne
UnnecessaryNullCheck
UnnecessaryNullCheckBeforeInstanceOf
UnnecessaryObjectReferences
UnnecessaryOverridingMethod
UnnecessaryPackageReference
UnnecessaryParenthesesForMethodCallWithClosure
UnnecessaryPublicModifier
// UnnecessaryReturnKeyword
UnnecessarySelfAssignment
UnnecessarySemicolon
UnnecessaryStringInstantiation
UnnecessarySubstring
UnnecessaryTernaryExpression
// UnnecessaryToString
UnnecessaryTransientModifier
// rulesets/unused.xml
UnusedArray
UnusedMethodParameter
UnusedObject
UnusedPrivateField
UnusedPrivateMethod
UnusedPrivateMethodParameter
UnusedVariable
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment