我有类似于这一课的课程:
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迁移某些数据的一次脚本,所以我想禁止代码弧规则。在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测试中运行静态分析,并得到以下错误:
代码弧文件:com/示例/迁移/DataMapper.groovy代码违背: Rule=JdbcResultSetReference P=2 Line=5 Msg=Found引用java.sql.ResultSet Src=import java.sql.ResultSet违章: Rule=JdbcResultSetReference P=2 Line=5 Msg=Found对java.sql.ResultSet Src=import java.sql.ResultSet codenarc的引用(P=2 v1.0CodeNarc已完成:(p1=0;java.sql.ResultSet;) 5929ms
我尝试将@SupressWarnings移到类中,但它仍然告诉我我违反了规则。所以问题是:怎样才能使这种压制发挥作用?
发布于 2017-10-26 22:54:45
不幸的是,这些规则查看import语句,@SuppressWarnings对这些语句不起作用。
一个选项是禁用Mapper类的规则:例如在您的codenarc.properties中:
JdbcResultSetReference.doNotApplyToClassNames = *Mapper或者在规则集文件中对规则设置相同的属性。
https://stackoverflow.com/questions/46948726
复制相似问题