CodeNarc failing on DuplicateStringLiteral rule for strings included in ignoreStrings

1k views Asked by At

I'm using the CodeNarc plug for Gradle with CodeNarc 1.1. I am using the DuplicateStringLiteral rule and passing in ignoreStrings: ['1', '2'] in the config file but the rule is not respecting the values I'm passing in. It's a groovy config file, section looks like:

DuplicateStringLiteral (
        ignoreStrings: ['1', '2']
)

I am also using DuplicateNumberLiteral and defined the ignoreNumbers property the same way and that seems to be working fine, so I don't think I have the syntax wrong. The report seems to pick up the ignored values as well as it shows this line in the definition for the rule:

The ignoreStrings property ([1, 2]) can optionally specify a comma-separated list of Strings to ignore.

Anyone see what I'm doing wrong here?

1

There are 1 answers

2
billjamesdev On BEST ANSWER

The documentation shows the default value of ignoreStrings to be an empty String... not an empty List. This makes me think that when it says The optional comma-separated list of Strings that should be ignored (i.e., not cause a violation)., it means to put the list (note lack of capitalization) of comma-separated strings in a single String value for the property.

TL;DR Try:

DuplicateStringLiteral (
        ignoreStrings: '1,2'
)