Checking the following code snippet:
public function isTopDomain(part: string): boolean {
return /^([^\x00-\x7F]|[a-z])+$/.test(part); // FP, the (negative) range matches all ASCII characters
}
reported by SonarQube IDE for VS Code v4.15.0
Rule S6324 states that use of control characters in a regex is most likely a mistake, which is likely true. In this case, however, I think the use of [^\x00-\x7F]
, is the most common (if not the only) way to describe any non-ASCII character and [\x00-\x7F]
for any ASCII character.
I’m not sure if I think the rule should ignore all ranges including control characters, or this particular one, or (if there is an alternative way to describe either of the groups) describe what to do in this case.