Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S107 FPs: Don't count base constructor parameter in the threshold #3727

Closed
pavel-mikula-sonarsource opened this issue Nov 6, 2020 · 0 comments · Fixed by #3847
Closed
Assignees
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@pavel-mikula-sonarsource
Copy link
Contributor

As reported by @DAud-IcI here #1015 (comment):

When base class has parameter count close to the limit, the inheriting class adding few more parameters raises issue. We should substract the base class constructor parameter count from the treshold.

public class BaseService
{
    public string HttpContextAccessor { get; }
    public string LinkGenerator { get; }
    public string ServiceProvider { get; }
    public string MemoryCache { get; }
    public string Hca { get; }
    public string Settings { get; }

    public BaseService(string httpContextAccessor, string linkGenerator, string serviceProvider, string memoryCache, string hca, string settings)
    {
        HttpContextAccessor = httpContextAccessor;
        LinkGenerator = linkGenerator;
        ServiceProvider = serviceProvider;
        MemoryCache = memoryCache;
        Hca = hca;
        Settings = settings;
    }
}

public class DescendantService : BaseService
{
    private readonly string _stringLocalizer;
    private readonly string _logger;

    public DescendantService(string httpContextAccessor, string linkGenerator, string serviceProvider, string memoryCache, string hca, string settings,
        string stringLocalizer,
        string logger) // <-- S107 triggers on this constructor.
        : base(httpContextAccessor, linkGenerator, serviceProvider, memoryCache, hca, settings)
    {
        _stringLocalizer = stringLocalizer;
        _logger = logger;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants