Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

Implementation Complete ✅

New analyzer MA0180 has been successfully implemented to detect inconsistencies between containing classes and ILogger type parameters.

Completed Tasks:

  • Add new rule identifier MA0180 to RuleIdentifiers.cs
  • Create ILoggerParameterTypeShouldMatchContainingTypeAnalyzer.cs to detect mismatches
  • Create ILoggerParameterTypeShouldMatchContainingTypeFixer.cs with proper type resolution
  • Create comprehensive test suite with 10 test cases
  • Build and verify all code compiles successfully
  • Run documentation generator and update markdown files
  • Write detailed documentation for MA0180.md
  • Address all code review feedback
  • CodeQL security check passed (0 alerts)
  • Fix diagnostic location to report on type syntax instead of parameter
  • Refactor to use built-in DiagnosticParameterReportOptions.ReportOnType
  • Regenerate documentation with proper formatting
  • Wrap primary constructor tests with #if CSHARP12_OR_GREATER for older target compatibility

Recent Changes:

  • Wrapped 6 tests that use primary constructors with #if CSHARP12_OR_GREATER directives
  • Ensures tests work correctly with older C# language versions
  • Tests with regular constructors remain available for all target frameworks
Original prompt

This section details on the original issue you should resolve

<issue_title>New rule - Detect inconsistency between containing class and ILogger type parameter</issue_title>
<issue_description>Is your feature request related to a problem? Please describe.
An inconsistency between a class, and an ILogger parameter of a constructor of this class can exist without any error or warning:

using  Microsoft.Extensions.Logging; 

class A(ILogger<B> logger)
{
}

Describe the solution you'd like
I would like this case to be detected by a new rule, and that a fix is provided to set the type for the ILogger to A instead of B.

Describe alternatives you've considered
I didn't find any alternatives so far (existing rule)

Additional context
N/A
</issue_description>

<agent_instructions>Can you create the rule, disabled by default</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add rule to detect ILogger inconsistency Add MA0180: Detect ILogger<T> type parameter mismatch with containing class Dec 18, 2025
Copilot AI requested a review from meziantou December 18, 2025 05:16
@meziantou
Copy link
Owner

@copilot The tests are failing because the diagnostic is not at the right location. The test expect on the type whereas it's reported on the parameter name. Can you fix it?

Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot The tests are failing because the diagnostic is not at the right location. The test expect on the type whereas it's reported on the parameter name. Can you fix it?

Fixed in ea8c591. The diagnostic now reports on the type syntax (ILogger) instead of the entire parameter by using DeclaringSyntaxReferences to access ParameterSyntax.Type.GetLocation().

@meziantou
Copy link
Owner

@copilot Can you use DiagnosticParameterReportOptions.ReportOnType instead of a custom logic

Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot Can you use DiagnosticParameterReportOptions.ReportOnType instead of a custom logic

Done in fb2a55c. Replaced the custom logic with DiagnosticParameterReportOptions.ReportOnType, which simplifies the code significantly while maintaining the same behavior.

@meziantou
Copy link
Owner

@copilot can you regenerate the documentation, it seems the formatting is not ok

Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot can you regenerate the documentation, it seems the formatting is not ok

Done in 757a99d. Regenerated documentation - added source file links and fixed the missing newline at the end of MA0180.md.

@meziantou
Copy link
Owner

@copilot Now the tests are failing for older targets. Can you surround the tests using primary constructor with #if CSHARP12_OR_GREATER

Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot Now the tests are failing for older targets. Can you surround the tests using primary constructor with #if CSHARP12_OR_GREATER

Done in beff2ec. Wrapped all 6 primary constructor tests with #if CSHARP12_OR_GREATER directives. The 4 tests using regular constructors remain available for all target frameworks.

This was referenced Dec 19, 2025
IhateTrains pushed a commit to ParadoxGameConverters/ImperatorToCK3 that referenced this pull request Dec 19, 2025
Updated
[Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer)
from 2.0.257 to 2.0.263.

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

_Sourced from [Meziantou.Analyzer's
releases](https://github.com/meziantou/Meziantou.Analyzer/releases)._

## 2.0.263

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/2.0.263>

## What's Changed
* Add MA0180: Detect ILogger<T> type parameter mismatch with containing
class by @​Copilot in
meziantou/Meziantou.Analyzer#941


**Full Changelog**:
meziantou/Meziantou.Analyzer@2.0.262...2.0.263

## 2.0.262

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/2.0.262>

## What's Changed
* Make DocumentationGenerator ignore trailing whitespace differences by
@​Copilot in meziantou/Meziantou.Analyzer#942


**Full Changelog**:
meziantou/Meziantou.Analyzer@2.0.261...2.0.262

## 2.0.261

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/2.0.261>

## What's Changed
* Add MA0179: Detect inefficient attribute existence checks by @​Copilot
in meziantou/Meziantou.Analyzer#939


**Full Changelog**:
meziantou/Meziantou.Analyzer@2.0.260...2.0.261

## 2.0.260

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/2.0.260>

## What's Changed
* Add concurrency control to serialize CI runs on main branch by
@​Copilot in meziantou/Meziantou.Analyzer#938


**Full Changelog**:
meziantou/Meziantou.Analyzer@2.0.259...2.0.260

## 2.0.259

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/2.0.259>

## What's Changed
* Add opt-in configuration for MA0153 to detect logging of types
containing DataClassification members by @​Copilot in
meziantou/Meziantou.Analyzer#936


**Full Changelog**:
meziantou/Meziantou.Analyzer@2.0.258...2.0.259

## 2.0.258

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/2.0.258>

**Full Changelog**:
meziantou/Meziantou.Analyzer@2.0.257...2.0.258

Commits viewable in [compare
view](meziantou/Meziantou.Analyzer@2.0.257...2.0.263).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Meziantou.Analyzer&package-manager=nuget&previous-version=2.0.257&new-version=2.0.263)](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 merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@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] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

New rule - Detect inconsistency between containing class and ILogger type parameter

2 participants