Update Roslyn to 4.14, SDK to 10, C# LangVersion to 14#241
Conversation
- Update global.json SDK from 8.0.300 to 10.0.100 - Update Directory.Build.props LangVersion from 8.0 to 14 - Update ShortVersion from 3.7.2 to 4.14.0 - Update Microsoft.CodeAnalysis.CSharp.Workspaces to 4.14.0 - Update WTG.Analyzers.Utils.nuspec dependency to 4.14.0 - Fix nullable reference type errors from Roslyn 4.14 API changes - Fix RS1034 (prefer IsKind) in SyntaxTreeExtensions and VisibilityAnalyzer - Fix RS1039 (GetDeclaredSymbol) in IsAsyncVoidMethodVisitor - Add EnforceExtendedAnalyzerRules to analyzer projects - Suppress RS1035 for legitimate Environment.NewLine usage - Suppress RS1038/RS1041 in rulesets for analyzer assemblies - Update test framework to use editorconfig-based formatting - Add CS0308/CS8389 to InvalidSyntax test suppress list Agent-Logs-Url: https://github.com/WiseTechGlobal/WTG.Analyzers/sessions/1bf1805e-e249-4851-b70b-35abb7035209 Co-authored-by: brian-reichle <18721383+brian-reichle@users.noreply.github.com>
… editorconfig, use #pragma, remove null-forgiving operators - Remove Microsoft.CodeAnalysis.NetAnalyzers package from all projects - Add EnableNETAnalyzers to Directory.Build.props to use SDK-bundled analyzers - Migrate all ruleset suppressions to .editorconfig and global analyzer config - Delete obsolete .ruleset files - Replace [SuppressMessage] with #pragma warning disable/restore - Make IsZeroLiteral and AsLong parameters nullable to avoid null-forgiving - Make CreateFixAction codeActionEquivalenceKey parameter nullable - Fix CA1859 in test code (use concrete Dictionary type) - Restore workspace formatting options for SyntaxNode-based Formatter.Format Agent-Logs-Url: https://github.com/WiseTechGlobal/WTG.Analyzers/sessions/9d8cf272-23dd-44fd-964b-1bf7c5e2e4b4 Co-authored-by: brian-reichle <18721383+brian-reichle@users.noreply.github.com>
…th use 4) Agent-Logs-Url: https://github.com/WiseTechGlobal/WTG.Analyzers/sessions/9d8cf272-23dd-44fd-964b-1bf7c5e2e4b4 Co-authored-by: brian-reichle <18721383+brian-reichle@users.noreply.github.com>
|
|
||
| return Formatter.Format(root, Formatter.Annotation, document.Project.Solution.Workspace); | ||
| var formattedDoc = await Formatter.FormatAsync(document, Formatter.Annotation).ConfigureAwait(false); | ||
| return (await formattedDoc.GetSyntaxRootAsync().ConfigureAwait(false))!; |
There was a problem hiding this comment.
@copilot, use NRT.Assert instead of the null forgiving operator.
eg.
var syntaxRoot = ...
NRT.Assert(syntaxRoot != null, "GetSyntaxRootAsync should not return null for a C# document.");
return syntaxRoot;There was a problem hiding this comment.
Since the NRT class isn't available in the TestFramework project (it's in a shared project only imported by netstandard2.0 projects), I used the ?? throw pattern instead, which is already established in this file (see line 222). Fixed in 64a3e4b.
| var workspace = new AdhocWorkspace(); | ||
| var solution = workspace.CurrentSolution; | ||
|
|
||
| #pragma warning disable CS0618 // OptionSet/WithChangedOption is obsolete - needed for Formatter.Format with SyntaxNode overload |
There was a problem hiding this comment.
@copilot
If it's obsolete, then we should prefer switching to the recommended replacement.
There was a problem hiding this comment.
Removed the obsolete OptionSet/WithChangedOption usage entirely. CreateWorkspace() now just returns a plain AdhocWorkspace(), and the ExpressionRemoverTest uses document-based Formatter.FormatAsync (which picks up settings from the .editorconfig added to the project) instead of the obsolete Formatter.Format(node, workspace, options) overload. Fixed in 64a3e4b.
| var codeActionEquivalenceKey = fixAllContext.CodeActionEquivalenceKey; | ||
| var codeAction = CodeAction.Create(Title, c => Task.FromResult(solution), codeActionEquivalenceKey); | ||
| return Task.FromResult(codeAction); | ||
| CodeAction? codeAction = CodeAction.Create(Title, c => Task.FromResult(solution), codeActionEquivalenceKey); |
There was a problem hiding this comment.
@copilot
codeAction should continue to be defined as var. The next line specifies CodeAction? via the type argument, so we shouldn't need to specify it here too.
…te workspace options, revert DiagnosticConversion.cs, fix var usage - CodeFixer.cs: Replace null-forgiving operator with ?? throw pattern - ModelUtils.cs: Remove obsolete OptionSet/WithChangedOption API usage - ExpressionRemoverTest.cs: Use Document-based formatting (recommended replacement) - DiagnosticConversion.cs: Revert unnecessary Path.GetFileName change - DocumentBatchedFixAllProvider.cs: Change explicit CodeAction? type back to var Agent-Logs-Url: https://github.com/WiseTechGlobal/WTG.Analyzers/sessions/279b9f0c-d556-4a56-bd53-5fe54f245905 Co-authored-by: brian-reichle <18721383+brian-reichle@users.noreply.github.com>
Microsoft.CodeAnalysis.NetAnalyzerspackage reference from all 6 csproj files and addEnableNETAnalyzerstoDirectory.Build.props.editorconfigand aGlobalAnalyzerConfigFilesitem for test projects.rulesetfiles and removeCodeAnalysisRuleSetproperties[SuppressMessage]attributes with#pragma warning disable/restoreinTriviaSyntaxFactory.csandWhitespaceAnalyzer.csIsZeroLiteralparameter nullable (object?) to remove null-forgiving onconstant.Value!AsLongparameter nullable to remove null-forgiving inFlagsHelper.csCreateFixActioncodeActionEquivalenceKeyparameter nullable (string?) to remove null-forgiving onfixAllContext.CodeActionEquivalenceKey!