style: wrap switch-case const declarations in curly braces; enforce no-case-declarations#406
Merged
askpt merged 2 commits intoJun 23, 2026
Conversation
…o-case-declarations
Add no-case-declarations ESLint rule and fix the four existing violations in
csharpAnalyzer.ts and goAnalyzer.ts where bare const declarations appeared
inside switch case clauses without a scoping block.
Bare lexical declarations (const/let) directly inside a case clause share the
enclosing switch block's scope, which can cause confusing cross-case variable
aliasing. Wrapping each such case in {} ensures variables are scoped to the
individual case, makes the intent explicit, and is consistent with how other
switch cases in the codebase are already written (e.g. rustAnalyzer.ts).
The no-case-declarations rule is promoted to 'error' so future violations are
caught at lint time rather than discovered in review.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…0623-bfb9fd519ecefbe4
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens switch-case scoping in the language analyzers by block-wrapping case bodies that contain lexical declarations, and enforces ESLint’s no-case-declarations rule to prevent regressions. This aligns Go/C# analyzers with the existing pattern already used in the Rust analyzer.
Changes:
- Wrap
binary_expressionswitch cases in{}blocks in the Go and C# analyzers to properly scopeconstdeclarations. - Add ESLint rule
"no-case-declarations": "error"to enforce this pattern at lint time.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/metricsAnalyzer/languages/goAnalyzer.ts | Adds block scopes around binary_expression switch cases that declare const. |
| src/metricsAnalyzer/languages/csharpAnalyzer.ts | Adds block scopes around binary_expression switch cases that declare const. |
| eslint.config.mjs | Enables no-case-declarations as an error to prevent future bare lexical declarations in switch cases. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #406 +/- ##
==========================================
+ Coverage 77.25% 77.37% +0.11%
==========================================
Files 13 13
Lines 4120 4124 +4
Branches 442 438 -4
==========================================
+ Hits 3183 3191 +8
+ Misses 934 930 -4
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Fixes four instances of bare lexical declarations (
const) insideswitch caseclauses incsharpAnalyzer.tsandgoAnalyzer.ts, and enforces theno-case-declarationsESLint rule to prevent future occurrences.Problem
In both files the
binary_expressioncases ingetComplexityIncrementandgetComplexityReasonused:A bare
const(orlet) directly inside acaseclause is scoped to the entireswitchblock, not to that individual case. This means:no-case-declarations]((eslint.org/redacted) rule flags this as an error.rustAnalyzer.tsalready wraps these in{}.Fix
Wrap each such
casebody in curly braces to give theconstits own block scope:Also adds
"no-case-declarations": "error"toeslint.config.mjsso any future bare declarations are caught at lint time.Files Changed
src/metricsAnalyzer/languages/csharpAnalyzer.tsconstin switch cases with{}src/metricsAnalyzer/languages/goAnalyzer.tsconstin switch cases with{}eslint.config.mjs"no-case-declarations": "error"Test Status
No behaviour changes — purely a code style / scoping fix.
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
releaseassets.githubusercontent.comSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run