Skip to content

fix(generators): ContainsOrdinal to satisfy MA0074 after Meziantou 3.0.114 bump#182

Merged
ANcpLua merged 1 commit into
mainfrom
fix/ma0074-contains-ordinal-generators
Jun 30, 2026
Merged

fix(generators): ContainsOrdinal to satisfy MA0074 after Meziantou 3.0.114 bump#182
ANcpLua merged 1 commit into
mainfrom
fix/ma0074-contains-ordinal-generators

Conversation

@ANcpLua

@ANcpLua ANcpLua commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Root cause

main is red on AOT Publish Smoke (run 28442562600). PR #181 bumped Meziantou.Analyzer 3.0.98 → 3.0.114, and the newer analyzer enforces MA0074 (Use an overload of 'Contains' that has a StringComparison parameter) on the five bare string.Contains(string) call sites in ErrorOrX.Generators. Under the repo-wide TreatWarningsAsErrors, that fails the build (5 Error(s)), skipping the AOT publish steps.

Why MA0074 only started firing now: ErrorOrX.Generators targets netstandard2.0, whose BCL string has no Contains(string, StringComparison). The ANcpLua.Roslyn.Utilities.Sources polyfill supplies that overload as an extension — and MA0074 reports precisely because a StringComparison overload is now reachable.

Fix

Switch the 5 sites to the package's ContainsOrdinal helper — the same ordinal-explicit idiom already used right alongside them (StartsWithOrdinal, EndsWithOrdinal, EqualsOrdinal), in global-usings scope. Behavior is unchanged: the default string.Contains(string) is already ordinal, so this is a pure rule-satisfying rename, not a semantic change.

File Line
Core/ErrorOrEndpointGenerator.ParameterBinding.TypeAnalysis.cs 25
Validation/RouteValidator.cs 138
Analyzers/ErrorOrEndpointAnalyzer.cs 242
Analyzers/ErrorOrEndpointAnalyzer.RouteValidation.cs 154
Core/ErrorOrEndpointGenerator.Initialize.EndpointFlow.cs 309

Tests already use the net10.0 BCL Contains(x, StringComparison.Ordinal) overload and were unaffected.

Verification — complete & verified

  • dotnet build src/ErrorOrX.Generators -c Release0 Warning(s), 0 Error(s) (MA0074 cleared, restores Meziantou 3.0.114)
  • dotnet build ErrorOrX.slnx -c Release0 / 0
  • dotnet test tests/ErrorOrX.Generators.Tests156 passed, 0 failed

🤖 Generated with Claude Code

…u 3.0.114 bump

Meziantou.Analyzer 3.0.98 -> 3.0.114 (#181) newly enforces MA0074 on the
five `string.Contains(string)` call sites in ErrorOrX.Generators, which
under TreatWarningsAsErrors broke `main` (AOT Publish Smoke, run 28442562600).

The netstandard2.0 BCL lacks `Contains(string, StringComparison)`; the
ANcpLua.Roslyn.Utilities.Sources polyfill supplies it (that overload's
existence is precisely what made MA0074 start firing). Rather than the BCL
overload, switch to the package's `ContainsOrdinal` helper — the same
ordinal-explicit idiom already used alongside (`StartsWithOrdinal`,
`EndsWithOrdinal`). Behavior is identical (default string.Contains is already
ordinal); the rule is satisfied by construction.

Verified: `dotnet build -c Release` of the generator project and full slnx
both 0 warnings / 0 errors; 156 generator tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f748fa2a-92ea-4052-ac40-bbff03b17321

📥 Commits

Reviewing files that changed from the base of the PR and between f04606c and 81615b5.

📒 Files selected for processing (5)
  • src/ErrorOrX.Generators/Analyzers/ErrorOrEndpointAnalyzer.RouteValidation.cs
  • src/ErrorOrX.Generators/Analyzers/ErrorOrEndpointAnalyzer.cs
  • src/ErrorOrX.Generators/Core/ErrorOrEndpointGenerator.Initialize.EndpointFlow.cs
  • src/ErrorOrX.Generators/Core/ErrorOrEndpointGenerator.ParameterBinding.TypeAnalysis.cs
  • src/ErrorOrX.Generators/Validation/RouteValidator.cs

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting


Summary by CodeRabbit

  • Bug Fixes
    • Improved route and endpoint pattern handling to more reliably detect empty placeholders and attribute patterns.
    • Made type and attribute matching more consistent across different locales, reducing incorrect detection in edge cases.

Walkthrough

Five string-comparison calls across analyzer, generator, and validator source files are changed from culture-sensitive Contains() to ordinal ContainsOrdinal() equivalents. The changes affect empty route-parameter detection, ErrorOrEndpoint attribute-name matching, and DbContext type-name matching. No public API signatures are altered.

Changes

Ordinal Comparison Fix

Layer / File(s) Summary
Empty route parameter detection
src/ErrorOrX.Generators/Analyzers/ErrorOrEndpointAnalyzer.RouteValidation.cs, src/ErrorOrX.Generators/Validation/RouteValidator.cs
Both route pattern validation paths switch the "{}" empty-parameter-name check from Contains to ContainsOrdinal.
ErrorOrEndpoint attribute detection
src/ErrorOrX.Generators/Analyzers/ErrorOrEndpointAnalyzer.cs, src/ErrorOrX.Generators/Core/ErrorOrEndpointGenerator.Initialize.EndpointFlow.cs
Constructor-argument index selection and HTTP-method/pattern extraction both switch attrName.Contains("ErrorOrEndpoint") to ContainsOrdinal.
DbContext type matcher
src/ErrorOrX.Generators/Core/ErrorOrEndpointGenerator.ParameterBinding.TypeAnalysis.cs
The s_dbContextMatcher predicate's "Db" substring check switches to ordinal comparison.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes


Comment @coderabbitai help to get the list of available commands.

@ANcpLua ANcpLua merged commit a9537b4 into main Jun 30, 2026
4 of 5 checks passed
@ANcpLua ANcpLua deleted the fix/ma0074-contains-ordinal-generators branch June 30, 2026 21:12
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.

2 participants