forked from phoedos/pmd
[apex] AvoidNonRestrictiveQueries fix FP with multiline queries
This commit is contained in:
@ -24,8 +24,8 @@ import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
|
|||||||
import net.sourceforge.pmd.reporting.RuleContext;
|
import net.sourceforge.pmd.reporting.RuleContext;
|
||||||
|
|
||||||
public class AvoidNonRestrictiveQueriesRule extends AbstractApexRule {
|
public class AvoidNonRestrictiveQueriesRule extends AbstractApexRule {
|
||||||
private static final Pattern RESTRICTIVE_PATTERN = Pattern.compile("(where )|(limit )", Pattern.CASE_INSENSITIVE);
|
private static final Pattern RESTRICTIVE_PATTERN = Pattern.compile("(where\\s+)|(limit\\s+)", Pattern.CASE_INSENSITIVE);
|
||||||
private static final Pattern SELECT_OR_FIND_PATTERN = Pattern.compile("(select|find )", Pattern.CASE_INSENSITIVE);
|
private static final Pattern SELECT_OR_FIND_PATTERN = Pattern.compile("(select\\s+|find\\s+)", Pattern.CASE_INSENSITIVE);
|
||||||
private static final Pattern SUB_QUERY_PATTERN = Pattern.compile("(?i)\\(\\s*select\\s+[^)]+\\)");
|
private static final Pattern SUB_QUERY_PATTERN = Pattern.compile("(?i)\\(\\s*select\\s+[^)]+\\)");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -237,6 +237,29 @@ public class Something {
|
|||||||
List<List<SObject>> searchList = [FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name WHERE Name like 'test'), Contact, Opportunity, Lead];
|
List<List<SObject>> searchList = [FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name WHERE Name like 'test'), Contact, Opportunity, Lead];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
|
|
||||||
|
<test-code>
|
||||||
|
<description>False positives for SOQL queries with WHERE on multiple lines</description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class Something {
|
||||||
|
private static final String NAMESPACE_PREFIX = 'some_prefix';
|
||||||
|
private static final String PERMISSION_SET = 'some_permission';
|
||||||
|
|
||||||
|
public static Boolean hasPermission(Id userId) {
|
||||||
|
return ![
|
||||||
|
SELECT Id
|
||||||
|
FROM PermissionSetAssignment
|
||||||
|
WHERE
|
||||||
|
AssigneeId = :userId
|
||||||
|
AND PermissionSet.Name = :PERMISSION_SET
|
||||||
|
AND PermissionSet.NamespacePrefix = :NAMESPACE_PREFIX
|
||||||
|
]
|
||||||
|
.isEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
</test-data>
|
</test-data>
|
||||||
|
Reference in New Issue
Block a user