These rules check for duplicate code, enforcing the DRY (Don't Repeat Yourself) principle.
Since CodeNarc 0.11
This rule checks for duplicate number literals within the current class.
Code containing duplicate Number literals can usually be improved by declaring the Number as a constant field.
By default, the rule does not analyze test files. This rule sets the default value of the doNotApplyToClassNames property to only match class names that do not end in 'Test', 'Tests' or 'TestCase'.
Property | Description | Default Value |
ignoreNumbers | The optional comma-separated list of numbers that should be ignored (i.e., not cause a violation). |
0,1 |
Since CodeNarc 0.11
This rule checks for duplicate String literals within the current class.
Code containing duplicate String literals can usually be improved by declaring the String as a constant field.
By default, the rule does not analyze test files. This rule sets the default value of the doNotApplyToClassNames property to only match class names that do not end in 'Test', 'Tests' or 'TestCase'.
Property | Description | Default Value |
ignoreStrings | The optional comma-separated list of Strings that should be ignored (i.e., not cause a violation). |
'' (empty string) |