-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
{ | ||
"title": "FIXME", | ||
"title": "Do not escape quotes in code snippet’s attributes values", | ||
"type": "CODE_SMELL", | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant\/Issue", | ||
"constantCost": "5min" | ||
}, | ||
"tags": [ | ||
"javadoc" | ||
], | ||
"defaultSeverity": "Major", | ||
"ruleSpecification": "RSPEC-6451", | ||
"sqKey": "S6451", | ||
"scope": "All", | ||
"defaultQualityProfiles": ["Sonar way"], | ||
"quickfix": "unknown" | ||
"quickfix": "partial" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,77 @@ | ||
FIXME: add a description | ||
In Javadoc code snippets introduced with Java 18, attributes' values can be quoted with single-quote (') characters or double-quote (") characters. Simple values, such as identifiers or numbers need not be quoted. According to Javadoc's specification, escape sequences are not supported in attribute value. Using them will therefore lead to unpredictable behaviors when parsing the snippet, at best, and "spurious markup" warnings being reported. | ||
// If you want to factorize the description uncomment the following line and create the file. | ||
//include::../description.adoc[] | ||
If there is a need to use double-quotes within the attribute already using double-quotes, consider using single-quotes to delimit the value instead of escaping quotes. Proceed the other way around in case of single-quote need. | ||
== Noncompliant Code Example | ||
[source,java] | ||
---- | ||
FIXME | ||
/** | ||
* {@snippet : | ||
* public static void main(String... args) { | ||
* System.out.println("Hello World!"); // @link regex="\".+\"" target="java.lang.String" | ||
* } | ||
* } | ||
*/ | ||
void foo(); | ||
/** | ||
* {@snippet : | ||
* public static void main(String... args) { | ||
* System.out.println('c'); // @link regex='\'.+\'' target="java.lang.Character" | ||
* } | ||
* } | ||
*/ | ||
void bar(); | ||
---- | ||
== Compliant Solution | ||
[source,java] | ||
---- | ||
FIXME | ||
/** | ||
* {@snippet : | ||
* public static void main(String... args) { | ||
* System.out.println("Hello World!"); // @link regex='".+"' target="java.lang.String" | ||
* } | ||
* } | ||
*/ | ||
void foo(); | ||
/** | ||
* {@snippet : | ||
* public static void main(String... args) { | ||
* System.out.println('c'); // @link regex="'.+'" target="java.lang.Character" | ||
* } | ||
* } | ||
*/ | ||
void bar(); | ||
---- | ||
== See | ||
FIXME: A list of links | ||
Oracle’s Programmer's Guide to Snippets: https://docs.oracle.com/en/java/javase/18/code-snippet/index.html[https://docs.oracle.com/en/java/javase/18/code-snippet/index.html] | ||
ifdef::env-github,rspecator-view[] | ||
''' | ||
== Implementation Specification | ||
(visible only on this page) | ||
=== Message | ||
* In case of escaped double quotes: Use single-quotes to delimit the value instead of escaping double-quotes. | ||
* In case of escaped single quotes: Use double-quotes to delimit the value instead of escaping single-quotes. | ||
=== Highlighting | ||
* Primary: attribute value including the quotes | ||
=== Quickfix | ||
Only possible if there is no mix of quotes and double quotes within the value (this should not compile on javadoc side anyway) | ||
* In case of escaped double quotes: Replace starting and ending double-quotes by single-quotes, and remove escapes from double-quotes within the value. | ||
* In case of escaped single quotes: Replace starting and ending single-quotes by double-quotes, and remove escapes from single-quotes within the value. | ||
endif::env-github,rspecator-view[] |