diff --git a/rules/S7198/java/metadata.json b/rules/S7198/java/metadata.json new file mode 100644 index 0000000000..8c3a1ea511 --- /dev/null +++ b/rules/S7198/java/metadata.json @@ -0,0 +1,26 @@ +{ + "title": "\"Path.of\" should be preferred to \"Paths.get\"", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "tags": [ + "java11" + ], + "defaultSeverity": "Minor", + "ruleSpecification": "RSPEC-7198", + "sqKey": "S7198", + "scope": "All", + "defaultQualityProfiles": ["Sonar way"], + "quickfix": "targeted", + "code": { + "impacts": { + "MAINTAINABILITY": "MEDIUM", + "RELIABILITY": "LOW", + "SECURITY": "LOW" + }, + "attribute": "CONVENTIONAL" + } +} diff --git a/rules/S7198/java/rule.adoc b/rules/S7198/java/rule.adoc new file mode 100644 index 0000000000..508b43bda1 --- /dev/null +++ b/rules/S7198/java/rule.adoc @@ -0,0 +1,29 @@ +== Why is this an issue? + +`Path.of()` provides a modern and consistent approach to creating Path instances, aligning with factory methods such as `List.of()` and `Set.of()`. +Additionally, `Paths.get()` may be deprecated in future versions of Java. + +== How to fix it + +Replace `Paths.get()` with `Path.of()`. + +=== Code examples + +==== Noncompliant code example + + +[source,java,diff-id=1,diff-type=noncompliant] +---- +Path path = Paths.get("my/file.txt"); // non compliant +---- + +==== Compliant solution + +[source,java,diff-id=1,diff-type=compliant] +---- +Path path = Path.of("my/file.txt"); // compliant +---- + +== Resources +=== Documentation +- Java Documentation - https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Paths.html[Paths] diff --git a/rules/S7198/metadata.json b/rules/S7198/metadata.json new file mode 100644 index 0000000000..2c63c08510 --- /dev/null +++ b/rules/S7198/metadata.json @@ -0,0 +1,2 @@ +{ +}