【问题标题】:How to make the code compliant with: Move this variable to comply with Java Code Conventions如何使代码符合:移动此变量以符合 Java 代码约定
【发布时间】:2020-12-21 22:56:51
【问题描述】:

我有以下课程:

public final class AppConst {
    private AppConst() {}
        
    public static final String READ_ERROR = "READ";
    public static final String PROCESS_ERROR = "PROCESS";
    public static final String WRITE_ERROR = "WRITE";
}

SonarQube 用变量标记所有三行上的错误:

移动此变量以符合 Java 代码约定。

如何使代码与 SonarQube 兼容?

我正在使用 SonarLint for Eclipse v2.6.0。

【问题讨论】:

  • 帖子中没有问题,所以我添加了它。我希望这是你想问的问题。

标签: sonarqube sonarlint


【解决方案1】:

问题由RSPEC-1213 The members of an interface or class declaration should appear in a pre-defined order 规则发现。描述说:

根据 Oracle 定义的 Java 代码约定,类或接口声明的成员应按以下顺序出现在源文件中:

  • 类和实例变量
  • 构造函数
  • 方法

您的代码在变量之前包含一个构造函数。有效代码:

public final class AppConst {   
    public static final String READ_ERROR = "READ";
    public static final String PROCESS_ERROR = "PROCESS";
    public static final String WRITE_ERROR = "WRITE";

    private AppConst() {}
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-27
    • 2016-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多