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

SA1516 doesn't report missing blank line after file scoped namespace #3512

Closed
JakubLinhart opened this issue May 20, 2022 · 9 comments · Fixed by #3513
Closed

SA1516 doesn't report missing blank line after file scoped namespace #3512

JakubLinhart opened this issue May 20, 2022 · 9 comments · Fixed by #3513

Comments

@JakubLinhart
Copy link
Contributor

This code:

namespace MyNamespace;
public class MyClass
{
}

doesn't show SA1516 and SA1513 cannot workaround it.

I would expect that SA1516 is reported for public class MyClass like it is for namespace MyNamespace; here:

using System;
namespace MyNamespace;

Tested with StyleCop.Analyzers 1.2.0-beta.435.

@martynas1266
Copy link

martynas1266 commented Aug 30, 2022

Any plans to merge PR and close this issue?
We are using file-scoped namespaces in our project and it would be nice to enforce this rule.

@ldeluigi
Copy link

ldeluigi commented Feb 25, 2023

Us too

@prlcutting
Copy link

Ditto.

@symbiogenesis
Copy link

bump

@guillemurano
Copy link

guillemurano commented May 30, 2023

I have the same issue with SA1402 with scoped namespace

@bjornhellander
Copy link
Contributor

@guillemurano I don't see any strange behaviour with SA1402. Could you describe the problem you are having?

@guillemurano
Copy link

guillemurano commented May 30, 2023

I'm getting the correct SA1402 with this code

`
namespace EamReportingMicroservice.Core.Models
{
///


/// Paginated Reports
///

public class PaginatedReports
{
///
/// Total
///

public int Total { get; set; }

/// <summary>
/// Page
/// </summary>
public int Page { get; set; }

/// <summary>
/// Page Size
/// </summary>
public int PageSize { get; set; }

/// <summary>
/// Items
/// </summary>
public List<ReportItem> Items { get; set; } = new();

}

/// <summary>
/// My Test
/// </summary>
public class MyTest
{
    /// <summary>
    /// Abc
    /// </summary>
    public int Abc { get; set; }
}

}
`

image

But when I stick to scoped namespace it's not shown

`
namespace EamReportingMicroservice.Core.Models;

///


/// Paginated Reports
///

public class PaginatedReports
{
///
/// Total
///

public int Total { get; set; }

/// <summary>
/// Page
/// </summary>
public int Page { get; set; }

/// <summary>
/// Page Size
/// </summary>
public int PageSize { get; set; }

/// <summary>
/// Items
/// </summary>
public List<ReportItem> Items { get; set; } = new();

}

///


/// My Test
///

public class MyTest
{
///
/// Abc
///

public int Abc { get; set; }
}
`

image

This is the ruleset I'm using:

<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers.MaintainabilityRules"> <Rule Id="SA1119" Action="Warning" /> <!-- Statement should not use unnecessary parenthesis --> <Rule Id="SA1400" Action="Warning" /> <!-- Access modifier should be declared --> <Rule Id="SA1401" Action="Warning" /> <!-- Fields should be private --> <Rule Id="SA1402" Action="Warning" /> <!-- File may only contain a single type --> <Rule Id="SA1403" Action="Warning" /> <!-- File may only contain a single namespace --> <Rule Id="SA1404" Action="Warning" />

@bjornhellander
Copy link
Contributor

@guillemurano SA1402 was updated to handle this last year. It was included in 1.2.0-beta.406. What version are you using?

@guillemurano
Copy link

@guillemurano SA1402 was updated to handle this last year. It was included in 1.2.0-beta.406. What version are you using?

Excellent, I was on the latest version, works fine with the prerelease

@sharwell sharwell added this to the 1.2-beta.next milestone Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants