This rule detects assignments where a variable is assigned to itself, such as foo = foo;. Such statements are redundant and have no effect on the program’s state. They can indicate a mistake or misunderstanding in the code logic.
To comply with this rule, review assignments and ensure that each variable is assigned a meaningful or updated value. If the intent is to update a variable, use expressions that modify or transform its value, for example, foo = foo + 1;. If you are performing self-assignment to avoid leaving a parameter unused, you should be more explicit and assign it to a new variable, for example String ignore = unusedParameter.
Non-Compliant Code Examples
class Class {
public void myFunction(){
Integer foo;
foo = foo;
}
}
Compliant Code Examples
class Class {
public void myFunction(){
Integer foo;
foo = foo + 1;
}
}
シームレスな統合。 Datadog Code Security をお試しください
Datadog Code Security
このルールを試し、Datadog Code Security でコードを解析する
このルールの使用方法
1
2
rulesets:- apex-code-style # Rules to enforce Apex code style.