简体   繁体   中英

CodeNarc failing on DuplicateStringLiteral rule for strings included in ignoreStrings

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?

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 (ie, 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'
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM