swift:S1451: False Positive with Regex

swift

(Simon Hartmann) #1

versions
Sonar Version 6.7.3 (build 38370)
SonarQube Scanner 3.2.0.1227
Swift Plugin 4.1

Sample
We have a single line header with the copyright, which matches this regex:

[\+\*!,\.-a-zA-Z0-9_\s&\w]* Copyright (©|\(C\)) \d{4} COMPANYNAME [&a-zA-Z0-9_\s,\.]*

Applied to this header gives an false positive, since it should match the regex:
// Copyright © 2017 COMPANYNAME All rights reserved.

Example match: https://regex101.com/r/egc2qM/3

When we add an empty line before the header it works. Also if we add another comment line with // it works. However it stops working this line is the first in the file.


(Andrei Epure) #4

Thank you, Simon, for reporting to us this FP. I’ve opened SONARSWIFT-423 to track it.

I expect you meant 4.1 (the latest released version).

Cheers,
Andrei


(Simon Hartmann) #5

Sure, 4.1, thanks! I changed it.