SonarQube Java
  1. SonarQube Java
  2. SONARJAVA-130

Rule S109: Magic numbers should not be used

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.3
    • Component/s: Squid
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Annotations should not be taken into account

        Issue Links

          Activity

          Hide
          Nicolas Peru added a comment -

          Implemented.

          Some remarks :

          • We expect the numbers to be refactored as constants (spec updated)
          • In the case of anonymous class defined as a constant we might have some false negative :
            public static final MyClass = new MyClass {
              int magicNb = 42; //false negative
            }
            

            I tend to think we should be fine with that but feel free to correct me.

          Show
          Nicolas Peru added a comment - Implemented. Some remarks : We expect the numbers to be refactored as constants (spec updated) In the case of anonymous class defined as a constant we might have some false negative : public static final MyClass = new MyClass { int magicNb = 42; // false negative } I tend to think we should be fine with that but feel free to correct me.
          Hide
          G. Ann Campbell added a comment -

          Tiny problem in description: "clearly named (variables|constants) before "

          For Java, either would be appropriate, so please edit to: "clearly named variables or constants before "

          Implementation looks fine.

          Show
          G. Ann Campbell added a comment - Tiny problem in description: "clearly named (variables|constants) before " For Java, either would be appropriate, so please edit to: "clearly named variables or constants before " Implementation looks fine.
          Hide
          Nicolas Peru added a comment -

          For java, only constants matters. Description updated.

          Show
          Nicolas Peru added a comment - For java, only constants matters. Description updated.
          Hide
          G. Ann Campbell added a comment -

          looks good

          Show
          G. Ann Campbell added a comment - looks good

            People

            • Assignee:
              Nicolas Peru
              Reporter:
              Freddy Mallet
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Due:
                Created:
                Updated:
                Resolved: