Add semantic functions to the XPath queries of MA0240 - #1548
Merged
Merged
Conversation
Add implements, inherits-from, is-assignable-to, has-attribute, attributes, containing-assembly and is-from-current-assembly, so a query can select a type by what it derives from, and a symbol by its attributes or by its assembly, including the symbols declared in another assembly.
Add file-path, overrides, implements-member, containing-namespace, is-externally-visible and is-captured, so an entry can be scoped to some files, and a query can select a member by what it overrides or implements, a symbol by its namespace or its visibility, and the locals captured by a closure.
The ImmutableArray of Roslyn 4.8 cannot be created with a collection expression.
This was referenced Sep 23, 2026
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.283
Analogy-LogViewer/Analogy.LogViewer.NLog.Targets#582
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.283
Analogy-LogViewer/Analogy.AspNetCore.LogProvider#563
Closed
Closed
Closed
Closed
This was referenced Sep 26, 2026
IhateTrains
pushed a commit
to ParadoxGameConverters/ImperatorToCK3
that referenced
this pull request
Sep 26, 2026
Updated [Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer) from 3.0.266 to 3.0.290. <details> <summary>Release notes</summary> _Sourced from [Meziantou.Analyzer's releases](https://github.com/meziantou/Meziantou.Analyzer/releases)._ ## 3.0.290 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.290> ## What's Changed * Use IsAssignableTo where IsOrInheritsFrom was meant to check assignability by @meziantou in meziantou/Meziantou.Analyzer#1616 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.289...3.0.290 ## 3.0.289 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.289> ## What's Changed * Fix code fix crash when adding an argument to a conditional access invocation by @meziantou in meziantou/Meziantou.Analyzer#1617 * Share the search of available CancellationToken and TimeProvider values by @meziantou in meziantou/Meziantou.Analyzer#1612 * Use IOperation instead of SyntaxNode in MA0050 by @meziantou in meziantou/Meziantou.Analyzer#1613 * Remove MA0212 by @meziantou in meziantou/Meziantou.Analyzer#1615 * Skip every special type when searching for CancellationToken/TimeProvider members by @meziantou in meziantou/Meziantou.Analyzer#1614 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.288...3.0.289 ## 3.0.288 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.288> ## What's Changed * Add MA0242: Use a value factory with ConcurrentDictionary.GetOrAdd/AddOrUpdate when the value is expensive by @meziantou in meziantou/Meziantou.Analyzer#1611 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.287...3.0.288 ## 3.0.287 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.287> ## What's Changed * Test and document the records in MA0197, MA0198 and MA0199 by @meziantou in meziantou/Meziantou.Analyzer#1555 * Fix MA0042 false positives, false negatives and code fix crashes by @meziantou in meziantou/Meziantou.Analyzer#1560 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.286...3.0.287 ## 3.0.286 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.286> ## What's Changed * Fix MA0171 false positives in nameof and conditional access by @meziantou in meziantou/Meziantou.Analyzer#1562 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.285...3.0.286 ## 3.0.285 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.285> ## What's Changed * Fix MA0071 code fix when the locals of the else clause conflict with other identifiers by @meziantou in meziantou/Meziantou.Analyzer#1565 * Fix MA0150 false positive on user-defined operators returning a string by @meziantou in meziantou/Meziantou.Analyzer#1596 * Fix MA0214 false positives in unsafe contexts and after using declarations by @meziantou in meziantou/Meziantou.Analyzer#1602 * Fix MA0028 code fixes for AppendLine with a one-char interpolated string, no-op calls, and char[].ToString() by @meziantou in meziantou/Meziantou.Analyzer#1603 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.284...3.0.285 ## 3.0.284 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.284> ## What's Changed * Fix MA0003 code fix not applied to the arguments of indexers by @meziantou in meziantou/Meziantou.Analyzer#1609 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.283...3.0.284 ## 3.0.283 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.283> ## What's Changed * Do not offer the MA0202 code fix to merge non-adjacent branches by @meziantou in meziantou/Meziantou.Analyzer#1580 * Fix the LINQ optimization rules on predicates, casts, ordering and collection interfaces by @meziantou in meziantou/Meziantou.Analyzer#1585 * Fix MA0003 exclusions applied to the arguments of target-typed new expressions by @meziantou in meziantou/Meziantou.Analyzer#1594 * Fix MA0123 checking the wrong argument when the arguments are named by @meziantou in meziantou/Meziantou.Analyzer#1564 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.282...3.0.283 ## 3.0.282 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.282> ## What's Changed * Fix MA0070 not reported on field-targeted attributes of auto-properties by @meziantou in meziantou/Meziantou.Analyzer#1601 * Fix MA0090 code fix changing the if statement an outer else belongs to by @meziantou in meziantou/Meziantou.Analyzer#1574 * Fix MA0096 code fix when CompareTo is implemented explicitly by @meziantou in meziantou/Meziantou.Analyzer#1579 * Fix MA0145 on non-static accessors and MA0146 on constructor accessors by @meziantou in meziantou/Meziantou.Analyzer#1575 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.281...3.0.282 ## 3.0.281 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.281> ## What's Changed * Fix MA0061 code fix for default values declared in a referenced assembly by @meziantou in meziantou/Meziantou.Analyzer#1605 * Fix MA0137 false positive on user-defined operators and conversions by @meziantou in meziantou/Meziantou.Analyzer#1606 * Fix MA0139 false positive when the Serilog params array is passed as an array by @meziantou in meziantou/Meziantou.Analyzer#1607 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.280...3.0.281 ## 3.0.280 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.280> ## What's Changed * Fix MA0004 using the ConfigureAwait of nested functions to detect the context by @meziantou in meziantou/Meziantou.Analyzer#1593 * Fix MA0172 false positive on operands with side effects by @meziantou in meziantou/Meziantou.Analyzer#1578 * Fix MA0151 false positive on members of containing types and namespaces by @meziantou in meziantou/Meziantou.Analyzer#1592 * Fix MA0128 behavior change when a string span is compared to an empty string by @meziantou in meziantou/Meziantou.Analyzer#1591 * Fix MA0040 suggesting static, write-only, and indexer members as cancellation tokens by @meziantou in meziantou/Meziantou.Analyzer#1577 * Fix MA0036 false positive on classes used as a type in declarations by @meziantou in meziantou/Meziantou.Analyzer#1576 * Fix MA0163 false positive when the ProcessStartInfo is assigned to Process.StartInfo by @meziantou in meziantou/Meziantou.Analyzer#1586 * Fix MA0048 only_validate_first_type when the first type is a delegate by @meziantou in meziantou/Meziantou.Analyzer#1595 * Fix MA0194 merging is expressions on values converted by a cast by @meziantou in meziantou/Meziantou.Analyzer#1608 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.279...3.0.280 ## 3.0.279 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.279> ## What's Changed * Fix MA0100 false positive on returns nested before a using declaration by @meziantou in meziantou/Meziantou.Analyzer#1572 * Fix MA0056 false positive on members accessed with base by @meziantou in meziantou/Meziantou.Analyzer#1584 * Fix MA0091 false positive on instance events raised from a static context by @meziantou in meziantou/Meziantou.Analyzer#1588 * Fix MA0054 false negative on exceptions of a derived type by @meziantou in meziantou/Meziantou.Analyzer#1590 * Fix MA0102 code fix copying the modifiers of the reported accessor to the other accessor by @meziantou in meziantou/Meziantou.Analyzer#1598 * Fix MA0046 reporting override events by @meziantou in meziantou/Meziantou.Analyzer#1599 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.278...3.0.279 ## 3.0.278 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.278> ## What's Changed * Fix the MA0082 code fix for operands of another type or nullable operands by @meziantou in meziantou/Meziantou.Analyzer#1570 * Fix MA0103 code fix when the left operand is implicitly converted to a span by @meziantou in meziantou/Meziantou.Analyzer#1566 * Fix MA0141, MA0142, MA0148 and MA0149 false positives on dynamic operands by @meziantou in meziantou/Meziantou.Analyzer#1567 * Fix MA0037 code fix crash on embedded empty statements by @meziantou in meziantou/Meziantou.Analyzer#1568 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.277...3.0.278 ## 3.0.277 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.277> ## What's Changed * Fix MA0170 on non-public setters and System.Enum parameters by @meziantou in meziantou/Meziantou.Analyzer#1571 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.276...3.0.277 ## 3.0.276 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.276> ## What's Changed * Fix MA0022 code fix dropping non-null branches and false positive in async methods by @meziantou in meziantou/Meziantou.Analyzer#1558 * Fix MA0204 false positive on types with partial members by @meziantou in meziantou/Meziantou.Analyzer#1559 * Fix MA0109 false positive on generic methods with a Span overload by @meziantou in meziantou/Meziantou.Analyzer#1561 * Fix MA0173 when the value contains an await or an out variable declaration by @meziantou in meziantou/Meziantou.Analyzer#1563 * Fix MA0050 when an await precedes the argument validation by @meziantou in meziantou/Meziantou.Analyzer#1583 * Fix MA0166 on types that derive from TimeProvider and on non-readable members by @meziantou in meziantou/Meziantou.Analyzer#1582 * Fix MA0110 code fix referencing local constants in the GeneratedRegex attribute by @meziantou in meziantou/Meziantou.Analyzer#1581 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.275...3.0.276 ## 3.0.275 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.275> ## What's Changed * chore(deps): update dependency microsoft.bcl.asyncinterfaces to 10.0.12 by @renovate[bot] in meziantou/Meziantou.Analyzer#1546 * Fix MA0182 false positives on types used in nested patterns, events and self-referencing types by @meziantou in meziantou/Meziantou.Analyzer#1549 * Fix MA0215 false positives on await foreach, await using, and top-level statements by @meziantou in meziantou/Meziantou.Analyzer#1550 * Fix MA0009 and MA0023 with named arguments and GeneratedRegex culture name by @meziantou in meziantou/Meziantou.Analyzer#1552 * Fix MA0067 false positive on default parameter values by @meziantou in meziantou/Meziantou.Analyzer#1553 * Fix duplicate diagnostics of the XML comment rules on shared documentation comments by @meziantou in meziantou/Meziantou.Analyzer#1554 * Fix MA0073 false positive on user-defined equality operators by @meziantou in meziantou/Meziantou.Analyzer#1556 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.274...3.0.275 ## 3.0.274 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.274> ## What's Changed * Add semantic functions to the XPath queries of MA0240 by @meziantou in meziantou/Meziantou.Analyzer#1548 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.273...3.0.274 ## 3.0.273 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.273> ## What's Changed * Expose the kind-specific modifiers of the symbols in the XPath queries of MA0240 by @meziantou in meziantou/Meziantou.Analyzer#1547 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.272...3.0.273 ## 3.0.272 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.272> ## What's Changed * Query the symbols with the XPath queries of MA0240 by @meziantou in meziantou/Meziantou.Analyzer#1545 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.271...3.0.272 ## 3.0.271 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.271> ## What's Changed * Expose more of Roslyn to the XPath queries of MA0240 by @meziantou in meziantou/Meziantou.Analyzer#1544 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.270...3.0.271 ## 3.0.270 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.270> ## What's Changed * Reduce the CPU and the memory used by the rules by @meziantou in meziantou/Meziantou.Analyzer#1542 * chore(deps): update dependency dotnet-sdk to v10.0.401 by @renovate[bot] in meziantou/Meziantou.Analyzer#1543 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.269...3.0.270 ## 3.0.269 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.269> ## What's Changed * Reduce the cost of the XPath queries of MA0240 by @meziantou in meziantou/Meziantou.Analyzer#1541 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.268...3.0.269 ## 3.0.268 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.268> ## What's Changed * Query the operations with the XPath queries of MA0240 by @meziantou in meziantou/Meziantou.Analyzer#1540 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.267...3.0.268 ## 3.0.267 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.267> ## What's Changed * Support a custom severity in the banned syntax entries of MA0240 by @meziantou in meziantou/Meziantou.Analyzer#1539 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.266...3.0.267 Commits viewable in [compare view](meziantou/Meziantou.Analyzer@3.0.266...3.0.290). </details> [](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 Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
This PR adds thirteen functions to the XPath queries of MA0240. Each one works on the node it is evaluated on, whether that node is a syntax node, an operation, or a symbol:
implements(type[, format])truewhen the type of the node implements the interface. The type itself is excluded.inherits-from(type[, format])truewhentypeis one of the base classes of the node's typeis-assignable-to(type[, format])truewhen the node's type istype, derives from it, or implements ithas-attribute(type[, format])truewhen the symbol has an attribute whose class istypeor derives from itattributes()/attributes(nodes)AttributeDataelements withConstructorArgument,NamedArgumentandItemchildrencontaining-assembly()/containing-assembly(name)is-from-current-assembly()truewhen the symbol is declared in the analyzed projectcontaining-namespace()/containing-namespace(name)overrides(member)truewhen the symbol overridesmember, directly or transitivelyimplements-member(member)truewhen the symbol implements that interface member, implicitly or explicitlyis-externally-visible()truewhen the symbol and all its containing types arepublic,protectedorprotected internalis-captured()truefor a local or a parameter used by a lambda or a local functionfile-path()/separators. It does not need the semantic modelThe
typeargument accepts three formats:MetadataName,DocumentationDeclarationId, andDocumentationReferenceId. The format is detected from the name: aT:prefix means a declaration ID, and a{means a reference ID. An optional second argument overrides the detection. Only reference IDs match specific type arguments. Variance is not considered.The
memberargument ofoverridesandimplements-memberis either a documentation ID (M:System.Object.Equals(System.Object), which selects one overload) or a qualified name (System.Object.Equals, which selects every overload). The format is detected from theM:prefix.Why
Until now, a query could only match a type by its exact name. It could not test the inheritance chain, the interfaces, or the attributes of a type. Also, the
symbol()function only reaches the symbols declared in the file, so a query could not tell where a referenced symbol comes from.Notes for reviewers
syntax()returns in operation and symbol queries.SemanticSyntax, so it gets the semantic model.Minargs/Maxargsfor context functions.ResolveFunctionnow checks the argument count itself, so MA0241 reports a call with the wrong number of arguments. This also applies tosyntax()andsymbol(), which previously matched nothing when called with the wrong count.attributes(nodes)makes it possible to report the attributes themselves. They are reported on the attribute syntax asAttributeData. Attributes that come from metadata can be tested, but they are not reported.file-path()lets an entry apply to some files only. An.editorconfigseverity applies to every entry at once. Plain syntax queries now get a context that holds only the syntax tree, sofile-path()works in them without requesting the semantic model.is-captured()usesSemanticModel.AnalyzeDataFlowon the body that declares the symbol. The result is cached per body. The parameters of a primary constructor are not considered.docs/Rules/MA0240.mdhas a new "Semantic functions" section, anddocs/Rules/MA0241.mdis updated.Testing
DoNotUseBannedSyntaxAnalyzerTests. All 270 tests in that class pass on roslyn 4.8, 4.14, 5.0, 5.6 and 5.9.dotnet run --project src/DocumentationGeneratorexits with code 0.