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

Invalid using directives code fix with partially disabled warnings #2026

Closed
sharwell opened this issue Jan 6, 2016 · 1 comment
Closed
Assignees
Milestone

Comments

@sharwell
Copy link
Member

sharwell commented Jan 6, 2016

Sample code

// Copyright (c) 2015 ACME, Inc. All rights reserved worldwide.

#if !VS2012

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Forms.Integration;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;

#if VS2008
using Microsoft.Windows.Controls;
#elif VS2010
using System.Windows.Media;
#endif

using Forms = System.Windows.Forms;
using IWin32Window = System.Windows.Forms.IWin32Window;

namespace Microsoft.VisualStudio.Shell
{
#pragma warning disable SA1200 // Using directives must be placed correctly
    // This is required to work around accessibility issues in documentation comments.
    using NativeMethods = MyApplication.Namespace.NativeMethods;
#pragma warning restore SA1200 // Using directives must be placed correctly
}

#endif

Configuration

{
  "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
  "settings": {
    "documentationRules": {
      "fileNamingConvention": "metadata",
      "companyName": "ACME, Inc",
      "copyrightText": "Copyright (c) {year} {companyName}. All rights reserved worldwide.",
      "xmlHeader": false,
      "variables": {
        "year": "2015"
      }
    },
    "orderingRules": {
      "usingDirectivesPlacement": "outsideNamespace"
    }
  }
}

Operation

Run an Organize using directives code fix for the SA1210 warning.

Expected result

📝 This bug report does not concern the blank lines which are removed from the result. Those are merely an accuracy issue, where I'm more concerned about the correctness issue.

// Copyright (c) 2015 ACME, Inc. All rights reserved worldwide.

#if !VS2012

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms.Integration;
using System.Windows.Input;
using System.Windows.Interop;

#if VS2008
using Microsoft.Windows.Controls;
#elif VS2010
using System.Windows.Media;
#endif

using Forms = System.Windows.Forms;
using IWin32Window = System.Windows.Forms.IWin32Window;

namespace Microsoft.VisualStudio.Shell
{
#pragma warning disable SA1200 // Using directives must be placed correctly
    // This is required to work around accessibility issues in documentation comments.
    using NativeMethods = MyApplication.Namespace.NativeMethods;
#pragma warning restore SA1200 // Using directives must be placed correctly
}

#endif

Actual result

// Copyright (c) 2015 ACME, Inc. All rights reserved worldwide.

#if !VS2012
#endif
#pragma warning disable SA1200 // Using directives must be placed correctly
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms.Integration;
using System.Windows.Input;
using System.Windows.Interop;

#if VS2008
using Microsoft.Windows.Controls;
#elif VS2010
using System.Windows.Media;
using Forms = System.Windows.Forms;
using IWin32Window = System.Windows.Forms.IWin32Window;

namespace Microsoft.VisualStudio.Shell
{
// This is required to work around accessibility issues in documentation comments.
using NativeMethods = MyApplication.Namespace.NativeMethods;
#pragma warning restore SA1200 // Using directives must be placed correctly
}

#endif
@sharwell sharwell added the bug label Jan 6, 2016
@vweijsters
Copy link
Contributor

Grabbing this

vweijsters added a commit to vweijsters/StyleCopAnalyzers that referenced this issue Jan 20, 2016
vweijsters added a commit to vweijsters/StyleCopAnalyzers that referenced this issue Jan 31, 2016
vweijsters added a commit to vweijsters/StyleCopAnalyzers that referenced this issue May 18, 2016
@vweijsters vweijsters added this to the 1.1.0 Beta 1 milestone May 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants