【问题标题】:CodeNarc supress JdbcREsultSetReference seems not workingCodeNarc 抑制 JdbcREsultSetReference 似乎不起作用
【发布时间】:2017-10-26 07:56:07
【问题描述】:

我有类似的课程:

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 移至班级,但它仍然告诉我我违反了规则。所以问题是:如何让这种抑制发挥作用?

【问题讨论】:

    标签: groovy codenarc


    【解决方案1】:

    不幸的是,这些规则着眼于 import 语句,而 @SuppressWarnings 不适用于这些。

    一种选择是为您的 Mapper 类禁用该规则: 例如在您的 codenarc.properties 中:

        JdbcResultSetReference.doNotApplyToClassNames = *Mapper
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-03
      • 1970-01-01
      • 2016-11-29
      • 2016-02-01
      • 2020-09-23
      • 2010-12-05
      • 2011-06-14
      • 2015-01-10
      相关资源
      最近更新 更多