Please provide
- Operating system: MacOS Sequoia 15.0.1
- Visual Studio version: 1.94.1
- SonarLint plugin version: 4.11.1
- Programming language you’re coding in: python 3.12.4
- Is connected mode used:
- Connected to SonarCloud or SonarQube (and which version): No
- settings.json statement: “sonarlint.connectedMode.connections.sonarqube”: ,
And a thorough description of the problem / question:
I am receiving this message twice but I believe inQuotes can change based on the prior passes through the match on codepoints in the string. The intent is to mark when we’ve encountered our first double quote and when we’ve found its matching double quote (skipping escaped quotes in between). I think the rule needs to take into consideration the outer loop that can allow multiple passes through the match block:
Replace this expression; used as a condition it will always be constant. [+1 location]
For the inQuotes variable in the code below for the if/elif inQuotes tests:
inQuotes = False
for i in range(0, len(codePoints)):
chPrior = ch # save prior character
ch = codePoints[i]
match (ch):
case 0x2C:
if inQuotes:
sb += str(ch)
else:
# don't save the comma
strList.append(sb)
sb = ""
break
case 0x22:
# check if this quote is escaped
if chPrior == 0x5C:
# just keep as is
sb = sb + str(ch)
elif inQuotes:
if i < len(codePoints) - 1:
# check if this is an escaped quote
if codePoints[i + 1] == 0x22:
sb = sb + str(ch)
break
else:
# if prior is a quote this is escaped
if chPrior == 0x22:
sb += str(ch)
break
# else this is ending the quoted field
inQuotes = False
else:
inQuotes = True
break
case _:
sb += str(ch)
break