feat(LC0095, LC0099): split unreferenced-parameter rule into LC0095 and LC0099 - #425
Conversation
…nd LC0099 Separate unreferenced parameter diagnostics by procedure kind: - Keep LC0095 for regular non-local procedures (internal/public) - Introduce LC0099 for event subscribers (Info severity) Implement a shared code fix provider for both diagnostics: - Keep scoped equivalence keys for regular procedures and event subscribers - Use custom Fix All with one-pass RemoveNodes on separated parameter lists - Keep fallback behavior when fixAllSpans is empty in document scope Improve maintainability and consistency: - Align naming in tests and fix-all scenarios - Keep netstandard2.1 compatibility behavior intact Expand and update test coverage: - Add and adjust diagnostic, single-fix, and fix-all cases for both scopes - Verify focused ParameterNotReferenced test suite passes
Code reviewReviewed the LC0095/LC0099 split, the CodeFix changes, and the new FixAll implementation. No significant issues found in the core implementation. Summary of what was verified: Builds & tests
FixAll correctness
Plumbing
Question: is deleting the adjacent comment intentional? In Was this a deliberate choice? Our view is that a code fix shouldn't silently delete user comments; the developer should decide whether a comment is still relevant. If you agree, this needs a change (e.g., Related: directive trivia (
|
|
I'll need some days for internal stull. I'll come back to this in a couple of days. |
Remove balanced pragma pairs only when they exclusively enclose removed parameters. Preserve broader, unbalanced, and mismatched directives, transferring them with immediately preceding comments when necessary. Add Fix All coverage for comment and pragma ownership, mixed retained and removed parameter scopes, and descriptive LC0095 fixture names.
|
Thanks for raising this. I revisited both the comment and pragma handling as part of this PR. For the original example, deleting The important nuance is that parser trivia ownership is not the same as semantic ownership. A comment may be attached to the removed parameter by the syntax tree even though it actually describes a nearby pragma directive. I now handle that explicitly:
I considered I also addressed the pragma concern in this PR. The behavior is intentionally conservative:
The Fix All tests now cover line and block comments around transferred pragmas, comments before and after the removed parameter, balanced pragma pairs around only removed parameters, pairs spanning removed and retained parameters, cross-procedure pairs, and unbalanced or mismatched directives. |
|
@MODUSCarstenScholling Did you close this PR on purpose (to maybe create a new PR) or is this a mistake? |
|
@Arthurvdv Sorry. I accidently deleted the branch ❌ It is back now and PR reopened. |
Code Review —
|
|
Thanks, I've let the Code Review run and it comes with some remarks. If I can help and/or create a PR based on this into your branch let me know, happy to help! |
- Use structured pragma directive APIs to pair disable and restore scopes by a canonical, case-insensitive set of warning IDs. - Preserve directive semantics for inactive conditional branches, unbalanced and mismatched scopes, pairs extending outside parameter lists, nested pairs, and mixed retained/removed parameter scopes. - Restrict removal to balanced pairs wholly contained in a single parameter list. - Preserve adjacent directives, comments belonging to transferred pragmas, source order when multiple directives move to a closing parenthesis, and formatting around closing parentheses. - Do not offer a code fix for parameters owning conditional directive trivia, since removing them can modify inactive branch text. - Add focused single-fix, Fix All, subscriber, mixed LC0095/LC0099, conditional, nested, multi-code, duplicate-code, empty-list, partial restore, cross-method, and no-fix coverage. - Update LC0095 and LC0099 implementation instructions to document the final behavior.
|
Trivia is not trivial after all, especially when it can carry an entire inactive conditional branch. Thanks for the detailed review. I addressed the findings and expanded the coverage around the directive-handling edge cases. Correctness1. Greedy pragma trivia removal Confirmed. The previous cleanup could consume an adjacent preserved pragma directive when both directives were attached to the same token trivia list. The cleanup now removes only the targeted pragma directive and its associated whitespace. A dedicated regression case covers an immediately adjacent removable pair followed by a preserved pair. 2. String-based warning-code comparison Confirmed. I replaced the raw substring-based comparison with the structured
This handles reordered IDs, whitespace differences, and duplicate IDs. The tests cover reordered multi-code pragmas and duplicate warning-code entries. 3. Structured directive handling Confirmed. Inactive directives are also filtered via 4. Semantic-model wrapper Confirmed. The unused 5. Repeated full-document allocations Confirmed. Parameter indentation is now derived from the parameter's leading trivia rather than from Additional robustness workI also found and addressed a few related cases while extending the matrix:
Test coverageThe updated tests cover:
|
|
Thanks for look into the feedback, it looks ready now. Let's get this merged for the upcoming v1.1.0 release. |
Summary
This PR splits the previous unreferenced-parameter behavior into two diagnostics with clear scope boundaries:
It also keeps a shared code fix implementation and updates tests and documentation accordingly.
What changed
Analyzer:
Code fix:
Tests:
Why
AA0137 does not cover this full space:
Splitting the diagnostics improves clarity, allows better policy tuning, and keeps fix behavior deterministic.
Validation
Breaking changes
No runtime breaking changes.
Diagnostic behavior changes:
Implements #426