Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3867

S2479 Add a flag to allow tabs in string literals

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.3
    • Component/s: Rules
    • Labels:

      Description

      S2479 does not raise issues when a text block contains tab characters in its left margin:

      public String template() {
      ↦   ↦   return """
      ↦   ↦   ↦   ↦   <html>
      ↦   ↦   ↦   ↦   \t<head>
      ↦   ↦   ↦   ↦   \t\t<title>Main</title>
      ↦   ↦   ↦   ↦   \t</head>
      ↦   ↦   ↦   ↦   \t<body>
      ↦   ↦   ↦   ↦   \t</body>
      ↦   ↦   ↦   ↦   </html>
      ↦   ↦   ↦   """;
      ↦   }
      

      But S2479 raises issues when a text block contains tab characters after its left margin:

      public String template() {
      ↦   ↦   return """
      ↦   ↦   ↦   ↦   <html>
      ↦   ↦   ↦   ↦   ↦   <head>
      ↦   ↦   ↦   ↦   ↦   ↦   <title>Main</title>
      ↦   ↦   ↦   ↦   ↦   </head>
      ↦   ↦   ↦   ↦   ↦   <body>
      ↦   ↦   ↦   ↦   ↦   </body>
      ↦   ↦   ↦   ↦   </html>
      ↦   ↦   ↦   """;
      ↦   }
      

      Historically, S2479 changes several times its way of raising issues with tabs in text blocks, and we can not find a non-controversial solution:

      • some users want to detect unintentional tab character coming from a copy and past
      • some users want to format html/json/java code inside text blocks using tabulations like all their java code.

      Because it's not possible to make everybody happy, the rule S2479 should have a parameter to allow tabulations in the string literal content.

      (Possible idea: allow tabs only when the java file itself is also indented using tabs)

      And the rule description states in its 'Exceptions' paragraph:

      • Text Blocks string literals (java 13 three double-quote marks) can contain tabulations to allow indentation using tabulations.
        This statement does not match exactly the rule implementation and should be updated.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dorian.burihabwa Dorian Burihabwa
              Reporter:
              alban.auzeill Alban Auzeill
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: