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

String literals should not be duplicated

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Define a constant instead of duplicating this literal "{string}" {number} times.
    • Highlighting:
      • Primary: The first occurrence
      • Secondary: the following occurrences
        • message: 'Duplication.'
    • List of parameters:
      Hide

      Key: threshold
      Description: Number of times a literal must be duplicated to trigger an issue
      Default: 3

      Show
      Key: threshold Description: Number of times a literal must be duplicated to trigger an issue Default: 3
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      C++, Flex, VB6
    • Covered Languages:
      ABAP, C#, Cobol, Go, Java, JavaScript, Kotlin, PHP, PL/SQL, Python, RPG, Ruby, Scala, Swift, T-SQL, TypeScript, VB.Net
    • Irrelevant for Languages:
      C, HTML, Objective-C, PL/I, XML
    • Remediation Function:
      Linear with offset
    • Linear Argument Description:
      per duplicate instance
    • Linear Factor:
      2min
    • Linear Offset:
      2min
    • Analysis Level:
      Syntactic Analysis
    • Analysis Scope:
      Main Sources
    • Common Rule:
      Yes
    • Checkstyle:
      MultipleStringLiterals
    • PMD:
      AvoidDuplicateLiterals
    • TSLint-SonarTS:
      no-duplicate-string

      Description

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

        Attachments

          Issue Links

          1.
          Java RSPEC-1889 Language-Specification Active Unassigned
          2.
          PHP RSPEC-1890 Language-Specification Active Unassigned
          3.
          COBOL RSPEC-1891 Language-Specification Active Unassigned
          4.
          ABAP RSPEC-1892 Language-Specification Active Unassigned
          5.
          PL/SQL RSPEC-1893 Language-Specification Active Unassigned
          6.
          RPG RSPEC-1894 Language-Specification Active Unassigned
          7.
          T-SQL RSPEC-4101 Language-Specification Active Unassigned
          8.
          C# RSPEC-4522 Language-Specification Active Unassigned
          9.
          Go RSPEC-4574 Language-Specification Active Unassigned
          10.
          Swift RSPEC-4618 Language-Specification Active Unassigned
          11.
          Kotlin RSPEC-4680 Language-Specification Active Unassigned
          12.
          JavaScript RSPEC-4872 Language-Specification Active Unassigned
          13.
          Apex RSPEC-4989 Language-Specification Active Unassigned
          14.
          Scala RSPEC-5406 Language-Specification Active Unassigned
          15.
          Ruby RSPEC-5407 Language-Specification Active Unassigned
          16.
          Python RSPEC-5587 Language-Specification Active Unassigned
          17.
          VB.NET RSPEC-6125 Language-Specification Active Unassigned

            Activity

              People

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

                Dates

                Created:
                Updated: