Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify rule S1075: Add more exceptions (SONARJAVA-5149) #4570

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions rules/S1075/java/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
include::../description.adoc[]

=== Exceptions

This rule does not raise an issue when:

* A constant path is relative and contains at most two parts.
* A constant path is used in an annotation
* A path is annotated

== How to fix it

=== Code examples
Expand All @@ -9,6 +17,8 @@ include::../description.adoc[]
[source,java,diff-id=1,diff-type=noncompliant]
----
public class Foo {
public static final String FRIENDS_ENDPOINT = "/user/friends"; // Compliant path is relative and has only two parts

public Collection<User> listUsers() {
File userList = new File("/home/mylogin/Dev/users.txt"); // Noncompliant
Collection<User> users = parse(userList);
Expand Down Expand Up @@ -38,6 +48,24 @@ public class Foo {
}
----

==== Exceptions

[source,java]
----
public class Foo {
public static final String FRIENDS_ENDPOINT = "/user/friends"; // Compliant path is relative and has only two parts

public static final String ACCOUNT = "/account/group/list.html"; // Compliant path is used in an annotation

@Value("${base.url}" + ACCOUNT)
private String groupUrl;

@MyAnnotation()
String path = "/default/url/for/site"; // Compliant path is annotated

}
----

ifdef::env-github,rspecator-view[]

'''
Expand Down
Loading