Skip to content

fix(analyzers): skip RCS1231 for sync Task-returning methods - #1802

Merged
josefpihrt merged 3 commits into
mainfrom
fix/analyzers/rcs1231-sync-task-cancellationtoken
Aug 14, 2026
Merged

fix(analyzers): skip RCS1231 for sync Task-returning methods#1802
josefpihrt merged 3 commits into
mainfrom
fix/analyzers/rcs1231-sync-task-cancellationtoken

Conversation

@josefpihrt

Copy link
Copy Markdown
Collaborator

Summary

  • Align RCS1231 with the existing async exemption by skipping sync methods and local functions that return well-known task types (Task, Task<T>, ValueTask, ValueTask<T>)
  • Fixes false positive on CancellationToken in sync methods like return Task.FromCanceled(cancellationToken)

Fixes #1702

Test plan

  • dotnet test src/Tests/Analyzers.Tests/Analyzers.Tests.csproj --filter "FullyQualifiedName~RCS1231"

Made with Cursor

josefpihrt and others added 2 commits August 9, 2026 17:37
Fixes #1702

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

@josefpihrt josefpihrt left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review notes for skipping RCS1231 on sync Task-returning methods. Fixes the #1702 pattern, but the gate may be broader than intended. Also likely conflicts with #1807 on the same analyzer.

Comment thread src/Analyzers/CSharp/Analysis/RefReadOnlyParameterAnalyzer.cs Outdated
Comment thread src/Analyzers/CSharp/Analysis/RefReadOnlyParameterAnalyzer.cs Outdated
…methods

Keep suggesting `in` for other readonly structs on Task-returning methods, and reuse the existing GetDeclaredSymbol lookup in Analyze.

Co-authored-by: Cursor <cursoragent@cursor.com>
@josefpihrt
josefpihrt merged commit 028176d into main Aug 14, 2026
17 checks passed
@josefpihrt
josefpihrt deleted the fix/analyzers/rcs1231-sync-task-cancellationtoken branch August 14, 2026 19:23
This was referenced Aug 16, 2026
SonnyRR pushed a commit to SonnyRR/stacked-deck-templates that referenced this pull request Aug 18, 2026
Updated [Roslynator.Analyzers](https://github.com/dotnet/roslynator)
from 4.16.0 to 4.16.1.

<details>
<summary>Release notes</summary>

_Sourced from [Roslynator.Analyzers's
releases](https://github.com/dotnet/roslynator/releases)._

## 4.16.1

### Fixed

- Fix analyzer
[RCS1060](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1060)
to not report a file that contains only multiple partial declarations of
the same type ([PR](dotnet/roslynator#1798))
- Fix analyzer
[RCS1231](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1231)
to not suggest `in` for `ref struct` parameters
([#​1725](dotnet/roslynator#1725))
([PR](dotnet/roslynator#1807))
- Fix analyzer
[RCS1260](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1260)
false positive for `omit_when_single_line` on multi-line
object/collection initializers
([#​1439](dotnet/roslynator#1439))
([PR](dotnet/roslynator#1808))
- Fix analyzer
[RCS0036](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0036)
to report blank lines between single-line declarations in records
([PR](dotnet/roslynator#1813))
- Fix analyzer
[RCS1046](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1046)
to report `async void` methods without `Async` suffix
([PR](dotnet/roslynator#1790))
- Fix analyzer
[RCS1265](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1265)
to not report catch clauses with a `when` filter
([PR](dotnet/roslynator#1789))
- Fix analyzer
[RCS0034](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0034)
for types with a primary constructor and multiple constraint clauses
([PR](dotnet/roslynator#1791))
- Fix analyzer
[RCS1231](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1231)
to not report `CancellationToken` in sync methods returning `Task`
([PR](dotnet/roslynator#1802))
- [CLI] Fix GitLab output format to use relative paths, forward slashes,
and 1-based line numbers
([PR](dotnet/roslynator#1792))
- [CLI] Fix `generate-doc` to omit internal interfaces from type
declarations and the Implements section
([PR](dotnet/roslynator#1801))

Commits viewable in [compare
view](dotnet/roslynator@v4.16.0...v4.16.1).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Roslynator.Analyzers&package-manager=nuget&previous-version=4.16.0&new-version=4.16.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Aug 18, 2026
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.

RCS1231 is triggered for CancellationToken in non-async method

1 participant