View on GitHub

Scalastyle: Implemented Rules

There are 37 rules which are currently implemented:

org.scalastyle.file.FileLengthChecker - Check the number of lines in a file

Justification

Files which are too long can be hard to read and understand.

Parameters

ParameterDescriptionTypeDefault Value
maxFileLength Maximum file length integer 1500

Example configuration

<check enabled="true" class="org.scalastyle.file.FileLengthChecker" level="warning">
 <parameters>
  <parameter name="maxFileLength">800</parameter>
 </parameters>
</check>

org.scalastyle.file.FileLineLengthChecker - Check the number of characters in a line

Parameters

ParameterDescriptionTypeDefault Value
maxLineLength Maximum line length integer 160
tabSize Tab size integer 4

Example configuration

TBD

org.scalastyle.file.FileTabChecker - Check that there are no tabs in a file

Parameters

No parameters

Example configuration

TBD

org.scalastyle.file.HeaderMatchesChecker - Check the first lines of each file matches the text

Parameters

ParameterDescriptionTypeDefault Value
header Header string

Example configuration

TBD

org.scalastyle.file.NewLineAtEofChecker - Checks that a file ends with a newline character

Justification

Some version control systems don’t cope well with files which don’t end with a newline character.

Parameters

No parameters

Example configuration

<check enabled="true" class="org.scalastyle.file.NewlineAtEofChecker" level="warning"></check>

org.scalastyle.file.NoNewLineAtEofChecker - Checks that a file does not end with a newline character

Justification

Because Mirco Dotta wanted it.

Parameters

No parameters

Example configuration

<check enabled="true" class="org.scalastyle.file.NoNewlineAtEofChecker" level="warning"></check>

org.scalastyle.file.RegexChecker - Checks that a regular expression cannot be matched, if found reports this

Parameters

ParameterDescriptionTypeDefault Value
regex Regular expression string

Example configuration

<check enabled="true" class="org.scalastyle.file.RegexChecker" level="warning">
 <parameters>
  <parameter name="regex">(?m)^\s\*$(\r|)\n^\s*$(\r|)\n</parameter>
 </parameters>
 <customMessage>No double blank lines</customMessage>
</check>

org.scalastyle.file.WhitespaceEndOfLineChecker - Check that there is no trailing whitespace at the end of lines

Parameters

No parameters

Example configuration

TBD

org.scalastyle.scalariform.ClassNamesChecker - Check that class names match a regular expression

Parameters

ParameterDescriptionTypeDefault Value
regex Regular expression string ^[A-Z][A-Za-z]*$

Example configuration

TBD

org.scalastyle.scalariform.CovariantEqualsChecker - Check that classes and objects do not define equals without overriding equals(java.lang.Object).

Parameters

No parameters

Example configuration

TBD

org.scalastyle.scalariform.CyclomaticComplexityChecker - Checks that the cyclomatic complexity of a method does exceed a value

Justification

If the code is too complex, then this can make code hard to read.

Parameters

ParameterDescriptionTypeDefault Value
maximum Maximum integer 10

Example configuration

<check enabled="true" class="org.scalastyle.scalariform.CyclomaticComplexityChecker" level="warning">
 <parameters>
  <parameter name="maximum">10</parameter>
 </parameters>
</check>

org.scalastyle.scalariform.EqualsHashCodeChecker - Check that if a class implements either equals or hashCode, it should implement the other

Parameters

No parameters

Example configuration

TBD

org.scalastyle.scalariform.IfBraceChecker - Checks that if statement have braces

Justification

A lowercase L (l) can look similar to a number 1 with some fonts.

Parameters

ParameterDescriptionTypeDefault Value
singleLineAllowed Single Line Allowed boolean true
doubleLineAllowed Double Line Allowed boolean false

Example configuration

<check enabled="true" class="org.scalastyle.scalariform.IfBraceChecker" level="warning">
 <parameters>
  <parameter name="singleLineAllowed">true</parameter>
  <parameter name="doubleLineAllowed">false</parameter>
 </parameters>
</check>

org.scalastyle.scalariform.IllegalImportsChecker - Check that a class does not import certain classes

Parameters

ParameterDescriptionTypeDefault Value
illegalImports Illegal Imports string sun._,java.awt._

Example configuration

TBD

org.scalastyle.scalariform.MagicNumberChecker - Checks for use of magic numbers

Justification

Replacing a magic number with a named constant can make code easier to read and understand, and can avoid some subtle bugs.

Description

A simple assignment to a val is not considered to be a magic number, for example:

val foo = 4

is not a magic number, but

var foo = 4

is considered to be a magic number.

Parameters

ParameterDescriptionTypeDefault Value
ignore Ignore string -1,0,1,2

Example configuration

<check enabled="true" class="org.scalastyle.scalariform.MagicNumberChecker" level="warning">
 <parameters>
  <parameter name="ignore">-1,0,1,2,3</parameter>
 </parameters>
</check>

org.scalastyle.scalariform.MethodLengthChecker - Checks that methods do not exceed a maximum length

Justification

Long methods can be hard to read and understand.

Parameters

ParameterDescriptionTypeDefault Value
maxLength Maximum length integer 50

Example configuration

<check enabled="true" class="org.scalastyle.scalariform.MethodLengthChecker" level="warning">
 <parameters>
  <parameter name="maxLength">50</parameter>
 </parameters>
</check>

org.scalastyle.scalariform.MethodNamesChecker - Check that method names match a regular expression

Justification

The Scala style guide recommends that method names conform to certain standards.

Parameters

ParameterDescriptionTypeDefault Value
regex Regular expression string ^[a-z][A-Za-z0-9]*$

Example configuration

<check enabled="true" class="org.scalastyle.scalariform.MethodNamesChecker" level="warning">
 <parameters>
  <parameter name="regex">^[A-Za-z]*$</parameter>
 </parameters>
</check>

org.scalastyle.scalariform.NoCloneChecker - Check that classes and objects do not define the clone() method

Parameters

No parameters

Example configuration

TBD

org.scalastyle.scalariform.NoFinalizeChecker - Check that classes and objects do not define the finalize() method

Parameters

No parameters

Example configuration

TBD

org.scalastyle.scalariform.NoWhitespaceAfterLeftBracketChecker - No whitespace after left bracket ‘[’

Parameters

No parameters

Example configuration

TBD

org.scalastyle.scalariform.NoWhitespaceBeforeLeftBracketChecker - No whitespace before left bracket ‘[’

Parameters

No parameters

Example configuration

TBD

org.scalastyle.scalariform.NullChecker - Check that null is not used

Parameters

No parameters

Example configuration

TBD

org.scalastyle.scalariform.NumberOfMethodsInTypeChecker - Check that a class / trait / object does not have too many methods

Justification

If a type declares too many methods, this can be an indication of bad design.

Parameters

ParameterDescriptionTypeDefault Value
maxMethods Maximum methods integer 30

Example configuration

<check enabled="true" class="org.scalastyle.scalariform.NumberOfMethodsInTypeChecker" level="warning">
 <parameters>
  <parameter name="maxMethods">30</parameter>
 </parameters>
</check>

org.scalastyle.scalariform.NumberOfTypesChecker - Checks that there are not too many types declared in a file

Justification

If there are too many classes/objects defined in a single file, this can cause the code to be difficult to understand.

Parameters

ParameterDescriptionTypeDefault Value
maxTypes Maximum Number integer 20

Example configuration

<check enabled="true" class="org.scalastyle.scalariform.NumberOfTypesChecker" level="warning">
 <parameters>
  <parameter name="maxTypes">20</parameter>
 </parameters>
</check>

org.scalastyle.scalariform.ObjectNamesChecker - Check that object names match a regular expression

Parameters

ParameterDescriptionTypeDefault Value
regex Regular expression string ^[A-Z][A-Za-z]*$

Example configuration

TBD

org.scalastyle.scalariform.PackageObjectNamesChecker - Check that package object names match a regular expression

Parameters

ParameterDescriptionTypeDefault Value
regex Regular expression string ^[a-z][A-Za-z]*$

Example configuration

TBD

org.scalastyle.scalariform.ParameterNumberChecker - Maximum number of parameters for a method

Parameters

ParameterDescriptionTypeDefault Value
maxParameters Maximum Number integer 8

Example configuration

TBD

org.scalastyle.scalariform.PublicMethodsHaveTypeChecker - Check that a method has an explicit return type, it is not inferred

Justification

A public method declared on a type is effectively an API declaration. Explicitly declaring a return type means that other code which depends on that type won’t break unexpectedly.

Parameters

No parameters

Example configuration

<check enabled="true" class="org.scalastyle.scalariform.PublicMethodsHaveTypeChecker" level="warning"></check>

org.scalastyle.scalariform.ReturnChecker - Check that return is not used

Parameters

No parameters

Example configuration

TBD

org.scalastyle.scalariform.SimplifyBooleanExpressionChecker - Boolean expression can be simplified

Parameters

No parameters

Example configuration

TBD

org.scalastyle.scalariform.SpacesAfterPlusChecker - Check that the plus sign is followed by a space

Parameters

No parameters

Example configuration

TBD

org.scalastyle.scalariform.SpacesBeforePlusChecker - Check that the plus sign is preceded by a space

Parameters

No parameters

Example configuration

TBD

org.scalastyle.scalariform.StructuralTypeChecker - Check that structural types are not used.

Parameters

No parameters

Example configuration

TBD

org.scalastyle.scalariform.UppercaseLChecker - Checks that if a long literal is used, then an uppercase L is used

Justification

A lowercase L (l) can look similar to a number 1 with some fonts.

Parameters

No parameters

Example configuration

<check enabled="true" class="org.scalastyle.scalariform.UppercaseLChecker" level="warning"></check>

org.scalastyle.scalariform.VarFieldChecker - Checks that classes and objects do not define mutable fields

Justification

var (mutable fields) are deprecated if you’re using a strict functional style

Parameters

No parameters

Example configuration

<check enabled="true" class="org.scalastyle.scalariform.VarFieldChecker" level="warning"></check>

org.scalastyle.scalariform.VarLocalChecker - Checks that functions do not define mutable variables

Justification

vars (mutable local variables) loops are deprecated if you’re using a strict functional style

Parameters

No parameters

Example configuration

<check enabled="true" class="org.scalastyle.scalariform.VarLocalChecker" level="warning"></check>

org.scalastyle.scalariform.WhileChecker - Checks that while is not used

Justification

while loops are deprecated if you’re using a strict functional style

Parameters

No parameters

Example configuration

<check enabled="true" class="org.scalastyle.scalariform.WhileChecker" level="warning"></check>