Since CodeNarc 0.15
Checks the location of the opening brace ({) for classes. By default, requires them on the same line, but the sameLine property can be set to false to override this.
NOTE: This rule ignores annotation types, e.g. @interface MyAnnotation .
Since CodeNarc 0.15
Checks the location of the opening brace ({) for for loops. By default, requires them on the same line, but the sameLine property can be set to false to override this.
Since CodeNarc 0.15
Checks the location of the opening brace ({) for if statements. By default, requires them on the same line, but the sameLine property can be set to false to override this.
Since CodeNarc 0.15
Checks the location of the opening brace ({) for constructors and methods. By default, requires them on the same line, but the sameLine property can be set to false to override this.
Since CodeNarc 0.15
Checks the location of the opening brace ({) for try statements. By default, requires them on the line, but the sameLine property can be set to false to override this.
Since CodeNarc 0.15
Makes sure each class and interface definition is preceded by javadoc. Enum definitions are not checked, due to strange behavior in the Groovy AST. By default, only the main class in a file is checked for Javadoc. The main class is defined as the class that has the same name as the source file, for instance MyClass is the main class in MyClass.groovy but the class MyOtherClass defined in the same source file is not the main class. To check all the classes in the file set the rule property applyToNonMainClasses to true.
Since CodeNarc 0.15
Checks the maximum length for each line of source code. It checks for number of characters, so lines that include tabs may appear longer than the allowed number when viewing the file. The maximum line length can be configured by setting the length property, which defaults to 120.
NOTE: This rule does not support the @SuppressAnnotations annotation or the classname-based rule properties (applyToClassNames, doNotApplyToClassNames) to enable/disable the rule. If you want to specify or restrict where this rule is applied, you must use the file-based rule properties: applyToFileNames, doNotApplyToFileNames, applyToFilesMatching and doNotApplyToFilesMatching.
Since CodeNarc 0.18
Check that there is exactly one space (blank) after the catch keyword and before the opening parenthesis.
Examples of violations:
try { } catch(Exception e) { } // violation
try { } catch (Exception e) { } // violation
Since CodeNarc 0.18
Checks that there is at least one space or whitespace following each comma. That includes checks for method and closure declaration parameter lists, method call parameter lists, Map literals and List literals.
Known limitations:
Examples of violations:
def value = calculate(1,399, 'abc') // violation on parameter 399
def method1(int a,String b) { } // violation on parameter b
def closure1 = { int a,String b -> } // violation on parameter b
def list1 = [a,b, c] // violation on list element b
def map1 = [a:1,b:2, c:3] // violation on map element b:2
Since CodeNarc 0.18
Check that there is at least one space (blank) or whitespace after each closing brace ("{") for method/class/interface declarations, closure expressions and block statements.
A closure expression followed by a dot operator (.), a comma, a closing parenthesis, the spread-dot operator (*.) or the null-safe operator (?.) does not cause a violation.
| Property | Description | Default Value |
| checkClosureMapEntryValue | If false, then do not check for whitespace after closing braces for closure expressions that are literal Map values, e.g. [abc:doStuff()]. |
true |
Known limitations:
Examples of violations and exceptions:
if (ready) { return 9 }else { } // violation
try { doStuff() }finally { } // violation
def matching = list.find { it.isReady() }.filter() // no violation for dot operator
assert list.every { it.isReady() }, "Error" // no violation for comma
def m = [a:123, b:{ println 7 },c:99] // no violation for comma
processItems(list.select { it.isReady() }) // no violation for closing parenthesis
def names = records.findAll { it.age > 1 }*.name // no violation for spread operator
list?.collect { it?.type }?.join(',') // no violation for null-safe operator
Since CodeNarc 0.18
Check that there is exactly one space (blank) after the for keyword and before the opening parenthesis.
Examples of violations:
for(name in names) { } // violation
for (int i=0; i < 10; i++) { } // violation
Since CodeNarc 0.18
Check that there is exactly one space (blank) after the if keyword and before the opening parenthesis.
Examples of violations:
if(true) { } // violation
if (true) { } // violation
Since CodeNarc 0.18
Check that there is at least one space (blank) or whitespace after each opening brace ("{") for method/class/interface declarations, closure expressions and block statements.
| Property | Description | Default Value |
| checkClosureMapEntryValue | If false, then do not check for whitespace after opening braces for closure expressions that are literal Map values, e.g. [abc:doStuff()]. |
true |
Examples of violations:
class MyClass{int count } // violation
interface MyInterface {static final OK = 1 }// violation
enum MyEnum {OK, BAD } // violation
def myMethod() {int count } // violation
if (ready) {println 9 } // violation
if (ready) {
} else {println 99} // violation
for (int i=0; i<10; i++) {println i } // violation
for (String name in names) {println name } // violation
for (String name: names) {println name } // violation
while (ready) {println time } // violation
try {doStuff() // violation
} catch(Exception e) {x=77 } // violation
} finally {println 'error' } // violation
list.each {name -> } // violation
shouldFail(Exception) {doStuff() } // violation
Since CodeNarc 0.18
Check that there is at least one space (blank) or whitespace following a semicolon that separates:
Examples of violations:
def myMethod() {
println 1;println 2 // violation
def closure = { x -> doStuff();x = 23; } // violation
for (int i=0;i < 10;i++) { // violations (2)
for (int j=0; j < 10;j++) { } // violation
}
}
Since CodeNarc 0.18
Check that there is exactly one space (blank) after the switch keyword and before the opening parenthesis.
Examples of violations:
switch(x) { // violation
case 1: println 'one'
}
switch (x) { // violation
case 1: println 'one'
}
Since CodeNarc 0.18
Check that there is exactly one space (blank) after the while keyword and before the opening parenthesis.
Examples of violations:
while(true) { } // violation
while (true) { } // violation
Since CodeNarc 0.18
Check that there is at least one space (blank) or whitespace around each binary operator, including: +, -, *, /, >>, <<, &&, ||, &, |, ?:, =.
Do not check dot ('.') operator. Do not check unary operators (!, +, -, ++, --, ?.). Do not check array ('[') operator.
Known limitations:
Examples of violations:
def myMethod() {
3+ 5-x*23/ 100 // violation
list \<\<123 // violation
other\>\> writer // violation
x=99 // violation
x&& y // violation
x ||y // violation
x &y // violation
x| y // violation
}
Since CodeNarc 0.18
Check that there is at least one space (blank) or whitespace before each closing brace ("}") for method/class/interface declarations, closure expressions and block statements.
| Property | Description | Default Value |
| checkClosureMapEntryValue | If false, then do not check for whitespace before closing braces for closure expressions that are literal Map values, e.g. [abc:doStuff()]. |
true |
Known limitations:
Examples of violations:
class MyClass { int count} // violation
interface MyInterface { void doStuff()} // violation
enum MyEnum { OK, BAD} // violation
def myMethod() { return 9} // violation
if (ready) { doStuff()} // violation
if (ready) {
} else { return 9} // violation
for (int i=0; i<10; i++) { println i} // violation
for (String name in names) { println name} // violation
for (String name: names) { println name} // violation
while (ready) { doStuff()} // violation
try { doStuff()} // violation
catch(Exception e) { logError(e)} // violation
finally { cleanUp()} // violation
list.each { name -> println name} // violation
shouldFail(Exception) { doStuff()} // violation
Since CodeNarc 0.18
Check that there is at least one space (blank) or whitespace before each opening brace ("{") for method/class/interface declarations, closure expressions and block statements.
| Property | Description | Default Value |
| checkClosureMapEntryValue | If false, then do not check for whitespace before opening braces for closure expressions that are literal Map values, e.g. [abc:doStuff()]. |
true |
Known limitations:
Examples of violations:
class MyClass{ } // violation
class MyOtherClass extends AbstractClass{ } // violation
interface MyInterface{ } // violation
enum MyEnum{ OK, BAD } // violation
def myMethod(){ } // violation
if (ready){ } // violation
if (ready) {
} else{} // violation
for (int i=0; i<10; i++){ } // violation
for (String name in names){ } // violation
for (String name: names){ } // violation
while (ready){ } // violation
try{
} finally { } // violation
try {
} catch(Exception e){ } // violation
try {
} finally{ } // violation
list.each{ name -> } // violation
shouldFail(Exception){ doStuff() } // violation