Skip to content

Commit

Permalink
Update metadata and description
Browse files Browse the repository at this point in the history
  • Loading branch information
Wohops committed Sep 12, 2022
1 parent 2db7807 commit d83e7b3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
5 changes: 3 additions & 2 deletions rules/S6451/java/metadata.json
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"
}
67 changes: 61 additions & 6 deletions rules/S6451/java/rule.adoc
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[]

0 comments on commit d83e7b3

Please sign in to comment.