Skip to content

Commit 01f328c

Browse files
sonar-nigel[bot]Vibe Bot
authored andcommitted
SONARPY-3987 Fix S117 false positive for UPPERCASE params in marimo cell functions (#1030)
Co-authored-by: Vibe Bot <vibe-bot@sonarsource.com> GitOrigin-RevId: a779359a4b9af41c23550f4d479b3b94070fb65e
1 parent 3690627 commit 01f328c

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

python-checks/src/main/java/org/sonar/python/checks/LocalVariableAndParameterNameConventionCheck.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.sonar.plugins.python.api.tree.SubscriptionExpression;
4141
import org.sonar.plugins.python.api.tree.Tree;
4242
import org.sonar.plugins.python.api.types.v2.PythonType;
43+
import org.sonar.python.checks.utils.MarimoUtils;
4344
import org.sonar.python.semantic.SymbolUtils;
4445
import org.sonar.python.tree.TreeUtils;
4546
import org.sonar.python.types.v2.TypeCheckBuilder;
@@ -170,7 +171,7 @@ private void raiseIssueForNameAndUsage(SubscriptionContext ctx, String name, Usa
170171
if (name.length() <= 1) {
171172
return;
172173
}
173-
} else if (kind == UsageV2.Kind.PARAMETER && isParameterNameFromOverriddenMethod(usage, name)) {
174+
} else if (kind == UsageV2.Kind.PARAMETER && (isParameterNameFromOverriddenMethod(usage, name) || MarimoUtils.isTreeInMarimoDecoratedFunction(usage.tree(), ctx))) {
174175
return;
175176
}
176177
ctx.addIssue(usage.tree(), String.format(MESSAGE, type, name, format));

python-checks/src/test/resources/checks/localVariableAndParameterNameIncompatibility.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,31 @@ def execute(self):
145145
class DerivedLongerSignature(BaseShortSignature):
146146
def execute(self, ExtraParam): # Noncompliant
147147
pass
148+
149+
150+
import marimo
151+
152+
app = marimo.App()
153+
154+
155+
@app.cell
156+
def _():
157+
TSHIRT_ORDER = ["XS", "S", "M", "L", "XL", "XXL"]
158+
return TSHIRT_ORDER,
159+
160+
161+
@app.cell
162+
def _(TSHIRT_ORDER):
163+
filtered = [size for size in TSHIRT_ORDER if size != "XXL"]
164+
return filtered,
165+
166+
167+
@app.cell(hide_code=True)
168+
def _(API_KEY, DB_CONFIG):
169+
connection_string = f"host={DB_CONFIG['host']}?key={API_KEY}"
170+
return connection_string,
171+
172+
173+
@app.function
174+
def helper(INPUT_DATA):
175+
return INPUT_DATA

0 commit comments

Comments
 (0)