All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.py.rules.python.S5860.html Maven / Gradle / Ivy

There is a newer version: 4.23.0.17664
Show newest version

Why is this an issue?

Why use named groups only to never use any of them later on in the code?

This rule raises issues every time named groups are:

  • referenced while not defined;
  • defined but called elsewhere in the code by their number instead.

Noncompliant code example

import re

def foo():
    pattern = re.compile(r"(?P<a>.)")
    matches = pattern.match("abc")
    g1 = matches.group("b") # Noncompliant - group "b" is not defined
    g2 = matches.group(1) # Noncompliant - Directly use 'a' instead of its group number.

Compliant solution

import re

def foo():
    pattern = re.compile(r"(?P<a>.)")
    matches = pattern.match("abc")
    g = matches.group("a")




© 2015 - 2024 Weber Informatics LLC | Privacy Policy