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:
-
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
- is implemented by
-
SONARJAVA-473 Rule improvement: Add the threshold parameter to the rule "String literals should not be duplicated"
-
- Closed
-
-
CPP-1051 Rule: String literals should not be duplicated
-
- Open
-
-
SONARFLEX-108 Rule: String literals should not be duplicated
-
- Open
-
-
SONARVBSIX-248 Rule: String literals should not be duplicated
-
- Open
-
-
SONARABAP-64 Rule: String literals should not be duplicated
-
- Closed
-
-
SONARCOBOL-956 String literals should not be duplicated
-
- Closed
-
-
SONARPY-269 Rule S1192: String literals should not be duplicated
-
- Closed
-
-
SONARRPG-65 Rule: String literals should not be duplicated
-
- Closed
-
-
SONARSLANG-11 Rule S1192: String literals should not be duplicated
-
- Closed
-
-
SONARSLANG-214 [Scala] Enable Rule: S1192 String literals should not be duplicated
-
- Closed
-
-
SONARSLANG-295 [Apex] Enable Rule: S1192 String literals should not be duplicated
-
- Closed
-
-
SONARSWIFT-353 Rule: String literals should not be duplicated
-
- Closed
-
-
SONARTSQL-37 Rule: String literals should not be duplicated
-
- Closed
-
-
SONARCOBOL-1580 S1192: Add a message on the secondary location
-
- Closed
-
-
SONARJAVA-1231 FP on S1192: Should ignore string literals used in body of interface default methods
-
- Closed
-
-
SONARPLSQL-486 Rule: String literals should not be duplicated
-
- Closed
-
-
SONARPLSQL-752 S1192: Add a message on the secondary location
-
- Closed
-
-
SONARTSQL-257 S1192: Add a message on the secondary location
-
- Closed
-
-
SONARPY-665 FP raised by S1192 on type hints
-
- Closed
-
- is related to
-
SONARJAVA-3671 Improve rule S1192 to Support Text blocks
-
- Closed
-
-
SONARPY-750 S1192 (StringLiteralDuplicationCheck) shouldn't exclude capitalized strings
-
- Open
-
-
SONARSLANG-33 Kotlin: False negative related to strings
-
- Closed
-
-
SONARSLANG-486 [GO] FP in S1192: struct tags should not be considered as String literals
-
- Closed
-
- relates to
-
SONARPHP-1090 S1192: Add a message on the secondary location
-
- Closed
-
- links to
1.
|
Java | RSPEC-1889 |
|
Active | Unassigned | |
2.
|
PHP | RSPEC-1890 |
|
Active | Unassigned | |
3.
|
COBOL | RSPEC-1891 |
|
Active | Unassigned | |
4.
|
ABAP | RSPEC-1892 |
|
Active | Unassigned | |
5.
|
PL/SQL | RSPEC-1893 |
|
Active | Unassigned | |
6.
|
RPG | RSPEC-1894 |
|
Active | Unassigned | |
7.
|
T-SQL | RSPEC-4101 |
|
Active | Unassigned | |
8.
|
C# | RSPEC-4522 |
|
Active | Unassigned | |
9.
|
Go | RSPEC-4574 |
|
Active | Unassigned | |
10.
|
Swift | RSPEC-4618 |
|
Active | Unassigned | |
11.
|
Kotlin | RSPEC-4680 |
|
Active | Unassigned | |
12.
|
JavaScript | RSPEC-4872 |
|
Active | Unassigned | |
13.
|
Apex | RSPEC-4989 |
|
Active | Unassigned | |
14.
|
Scala | RSPEC-5406 |
|
Active | Unassigned | |
15.
|
Ruby | RSPEC-5407 |
|
Active | Unassigned | |
16.
|
Python | RSPEC-5587 |
|
Active | Unassigned | |
17.
|
VB.NET | RSPEC-6125 |
|
Active | Unassigned |