Skip to content

style: wrap switch-case const declarations in curly braces; enforce no-case-declarations#406

Merged
askpt merged 2 commits into
mainfrom
repo-assist/improve-switch-case-scoping-20260623-bfb9fd519ecefbe4
Jun 23, 2026
Merged

style: wrap switch-case const declarations in curly braces; enforce no-case-declarations#406
askpt merged 2 commits into
mainfrom
repo-assist/improve-switch-case-scoping-20260623-bfb9fd519ecefbe4

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Fixes four instances of bare lexical declarations (const) inside switch case clauses in csharpAnalyzer.ts and goAnalyzer.ts, and enforces the no-case-declarations ESLint rule to prevent future occurrences.

Problem

In both files the binary_expression cases in getComplexityIncrement and getComplexityReason used:

case "binary_expression":
  const operator = this.getBinaryOperator(node);
  ...

A bare const (or let) directly inside a case clause is scoped to the entire switch block, not to that individual case. This means:

  • The variable is visible to every other case in the same switch, which can cause confusing linter errors if the same name is reused.
  • ESLint's [no-case-declarations]((eslint.org/redacted) rule flags this as an error.
  • The pattern is inconsistent with the codebase's own convention — rustAnalyzer.ts already wraps these in {}.

Fix

Wrap each such case body in curly braces to give the const its own block scope:

case "binary_expression": {
  const operator = this.getBinaryOperator(node);
  ...
}

Also adds "no-case-declarations": "error" to eslint.config.mjs so any future bare declarations are caught at lint time.

Files Changed

File Change
src/metricsAnalyzer/languages/csharpAnalyzer.ts Wrapped 2 bare const in switch cases with {}
src/metricsAnalyzer/languages/goAnalyzer.ts Wrapped 2 bare const in switch cases with {}
eslint.config.mjs Added "no-case-declarations": "error"

Test Status

npm run compile  ✅  (0 errors)
npm run lint     ✅  (0 warnings/errors)
npm run test:unit  ✅  137 passing, 0 failing

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.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@d63b34de41bc0dc052096e094c732cf28eafc659

…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>
@askpt askpt changed the title [repo-assist] style: wrap switch-case const declarations in curly braces; enforce no-case-declarations style: wrap switch-case const declarations in curly braces; enforce no-case-declarations Jun 23, 2026
@askpt askpt marked this pull request as ready for review June 23, 2026 19:32
@askpt askpt self-requested a review as a code owner June 23, 2026 19:32
Copilot AI review requested due to automatic review settings June 23, 2026 19:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_expression switch cases in {} blocks in the Go and C# analyzers to properly scope const declarations.
  • 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.

@askpt askpt enabled auto-merge (squash) June 23, 2026 19:34
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.37%. Comparing base (e52ffd0) to head (01b7d17).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@askpt askpt merged commit ecea03f into main Jun 23, 2026
10 checks passed
@askpt askpt deleted the repo-assist/improve-switch-case-scoping-20260623-bfb9fd519ecefbe4 branch June 23, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants