Skip to content

Add S52 lint rule for detecting duplicate cases in switch statements - #1322

Draft
BrettMayson with Copilot wants to merge 2 commits into
mainfrom
copilot/suggestion-lint-detect-duplicated-cases
Draft

Add S52 lint rule for detecting duplicate cases in switch statements#1322
BrettMayson with Copilot wants to merge 2 commits into
mainfrom
copilot/suggestion-lint-detect-duplicated-cases

Conversation

Copilot AI commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Implement a new lint rule (S52) to detect duplicate case values within switch statements, addressing the request to identify unreachable duplicate case branches.

Changes

  • New S52 Lint Rule: Detects when the same value appears as multiple cases in a switch statement, with diagnostics pointing to the first occurrence
  • Syntax Support: Handles both SQF case syntaxes (case VALUE : EXPR and case VALUE do EXPR)
  • Test Coverage: Comprehensive test file covering simple duplicates, multiple duplicates, variable cases, and default cases

Example

The lint now correctly identifies this common issue:

switch (_minDist) do {
    case _distLeft:   { [  0,         _y ] };
    case _distRight:  { [ _worldSize, _y ] };
    case _distBottom: { [ _x,          0 ] };
    case _distBottom: { [ _x, _worldSize ] };  // L-S52: Duplicate case
};

All existing lint tests pass with no regressions.

Co-authored-by: BrettMayson <3946739+BrettMayson@users.noreply.github.com>
Copilot AI changed the title [WIP] Add lint detection for duplicated cases in switch statements Add S52 lint rule for detecting duplicate cases in switch statements Aug 30, 2026
Copilot AI requested a review from BrettMayson August 30, 2026 17:55
@codecov

codecov Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.85714% with 65 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.0%. Comparing base (c2fd31b) to head (39b9683).

Files with missing lines Patch % Lines
libs/sqf/src/analyze/lints/s52_duplicate_case.rs 62.8% 65 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
libs/sqf/src/analyze/lints/s52_duplicate_case.rs 62.8% <62.8%> (ø)

... and 2 files with indirect coverage changes

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

}

fn include(&self) -> bool {
true

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

no

switch (_value) do {
case 1: { "one" };
case 2: { "two" };
case default { "other" };

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

invalid syntax

Suggested change
case default { "other" };
default { "other" };

}
}

// Pattern 2: case VALUE do EXPR (where case is binary)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

case x do {} isn't a thing
I guess technically case returns "Switch Type"
but it just doesn't work

// Try to find case VALUE: EXPR pattern
// This is structured as: case VALUE : EXPR
// Where "case" is typically a unary command or binary command
// and ":" is an Associate operator

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should also think about single case expressions

switch test do {
    case 1;
    case 2: { "X" };
    case 1: { "Y"};
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion - Lint: Detect duplicated cases in switch statements

3 participants