简体   繁体   English

CodeNarc抑制JdbcREsultSetReference似乎不起作用

[英]CodeNarc supress JdbcREsultSetReference seems not working

I have class similar to this one: 我有与此课程相似的课程:

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
    }
}

This is one time script to migrate some data using groovy, so I want to suppress codenarc rule. 这是一次使用groovy迁移某些数据的脚本,因此我想取消Codenarc规则。 In the ruleSet jdbc rules are included and I don't want to disable them, as they scanning all the project. 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>

I'm running static analysis within junit tests and get this error: 我正在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 

I tried moving @SupressWarnings to the class, but it still tells me that I'm violating the rule. 我尝试将@SupressWarnings移到该类上,但是它仍然告诉我我违反了规则。 So the question is: how to make that suppression to work? 所以问题是:如何使抑制作用起作用?

Unfortunately those rules look at import statements, and the @SuppressWarnings does not work on those. 不幸的是,这些规则会查看导入语句,而@SuppressWarnings不适用于这些语句。

One option is to disable that rule for your Mapper classes: eg in your codenarc.properties: 一种选择是为您的Mapper类禁用该规则:例如,在codenarc.properties中:

    JdbcResultSetReference.doNotApplyToClassNames = *Mapper

or set that same property on the rule in your ruleset file. 或在您的规则集文件中的规则上设置相同的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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