CodeNarc 抑制 JdbcREsultSetReference 似乎不起作用

CodeNarc supress JdbcREsultSetReference seems not working

我有 class 个类似的:

import org.springframework.jdbc.core.RowMapper
import java.sql.ResultSet

class DataMapper implements RowMapper<Data> {

    @Override
    @SupressWarnings('JdbcResultSetReference')
    Data mapRow(ResultSet resultSet, int rowNum) throws SQLException {
        // get some values from resultSet and return desired Data
    }
}

这是使用 groovy 迁移一些数据的一次性脚本,所以我想抑制 codenarc 规则。在 ruleSet 中包含 jdbc 规则,我不想禁用它们,因为它们会扫描所有项目。

<ruleset xmlns="http://codenarc.org/ruleset/1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://codenarc.org/ruleset/1.0 
    http://codenarc.org/ruleset-schema.xsd"
    xsi:noNamespaceSchemaLocation="http://codenarc.org/ruleset-schema.xsd">

    <description>Static analysis rule set for Groovy sources</description>

    <!-- not related rules -->
    <ruleset-ref path='rulesets/jdbc.xml>
</ruleset>

我 运行 在 junit 测试中进行静态分析并得到这个错误:

[codenarc] File: com/example/migrate/DataMapper.groovy
[codenarc]     Violation: Rule=JdbcResultSetReference P=2 Line=5 Msg=[Found reference to java.sql.ResultSet] Src=[import java.sql.ResultSet]
[codenarc]     Violation: Rule=JdbcResultSetReference P=2 Line=5 Msg=[Found reference to java.sql.ResultSet] Src=[import java.sql.ResultSet]
[codenarc] [CodeNarc (http://www.codenarc.org) v1.0]
[codenarc] CodeNarc completed: (p1=0; p2=2; p3=0) 5929ms

我尝试将 @SupressWarnings 移动到 class,但它仍然告诉我我违反了规则。所以问题是:如何使这种抑制起作用?

不幸的是,这些规则着眼于导入语句,@SuppressWarnings 对这些语句不起作用。

一个选项是为您的映射器禁用该规则类: 例如在你的 codenarc.properties:

    JdbcResultSetReference.doNotApplyToClassNames = *Mapper

或在规则集文件中的规则上设置相同的 属性。