Skip to content

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

Closed

Description

@JakubLinhart

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.

Activity

  1. martynas1266 commented on Aug 30, 2022

    @martynas1266

    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.

  2. ldeluigi commented on Feb 25, 2023

    @ldeluigi

    Us too

  3. prlcutting commented on Mar 10, 2023

    @prlcutting

    Ditto.

  4. symbiogenesis commented on May 4, 2023

    @symbiogenesis

    bump

  5. guillemurano commented on May 30, 2023

    @guillemurano

    I have the same issue with SA1402 with scoped namespace

  6. bjornhellander commented on May 30, 2023

    @bjornhellander
    Contributor

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

  7. guillemurano commented on May 30, 2023

    @guillemurano

    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" />

  8. bjornhellander commented on May 30, 2023

    @bjornhellander
    Contributor

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

  9. guillemurano commented on May 30, 2023

    @guillemurano

    @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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions