检查未使用的成员变量的样式?

问题描述 投票:0回答:1

需要对未使用的成员变量进行checkstyle配置。

存在如下所示的检查样式,但仅适用于局部变量。

<module name="UnusedParameterCheck"/>

(需要对成员变量进行类似的检查)例如

class MyService {
    private String foo;
    private String unusedBar; // violation, should fail    
    public String getFoo() {         
        return foo;     
    } 
}

我正在使用最新版本的checkstyle

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>3.3.0</version>
    <executions>
        <execution>
            <id>checkstyle</id>
            <phase>compile</phase>
            <goals>
                <goal>check</goal>
            </goals>
            <configuration>
                <failOnViolation>true</failOnViolation>
                <configLocation>checkstyle.xml</configLocation>
                <consoleOutput>true</consoleOutput>
                <sourceDirectories>
                    <sourceDirectory>src</sourceDirectory>
                </sourceDirectories>
            </configuration>
        </execution>
    </executions>
</plugin>

无法在线获得正确的解决方案!

请帮忙!

尝试网上搜索但没有找到解决方案!

java refactoring checkstyle code-cleanup maven-checkstyle-plugin
1个回答
0
投票

目前没有此类检查(8/2023)。已在 https://github.com/checkstyle/checkstyle/issues/12596 提出请求,仍在寻求批准和实施。

© www.soinside.com 2019 - 2024. All rights reserved.