Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-1107

Close curly brace and the next "else", "catch" and "finally" keywords should be located on the same line

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Move this ["else"|"catch"|"finally"] to the same line as the previous closing curly brace.
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Legacy Key:
      RightCurlyBraceSameLineAsNextBlockCheck
    • Targeted languages:
      C#, C++, Flex, JavaScript, PHP, TypeScript
    • Covered Languages:
      Java
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      1min
    • Analysis Scope:
      Main Sources, Test Sources
    • Checkstyle:
      RightCurly
    • ESLint:
      brace-style
    • TSLint:
      one-line

      Description

      Shared coding conventions make it possible for a team to collaborate efficiently.
      This rule makes it mandatory to place closing curly braces on the same line as the next else, catch or finally keywords.

      Noncompliant Code Example

      public void myMethod() {
        if(something) {
          executeTask();
        } else if (somethingElse) {
          doSomethingElse();
        }
        else {                               // Noncompliant
           generateError();
        }
      
        try {
          generateOrder();
        } catch (Exception e) {
          log(e);
        }
        finally {                            // Noncompliant
          closeConnection();
        }
      }
      

      Compliant Solution

      public void myMethod() {
        if(something) {
          executeTask();
        } else if (somethingElse) {
          doSomethingElse();
        } else {
           generateError();
        }
      
        try {
          generateOrder();
        } catch (Exception e) {
          log(e);
        } finally {
          closeConnection();
        }
      }
      

        Attachments

          Issue Links

          1.
          Java RSPEC-4767 Language-Specification Active Unassigned

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              freddy.mallet Freddy Mallet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: