有没有办法强制使用制表符而不是空格?

发布于 2024-08-22 06:08:27 字数 90 浏览 3 评论 0原文

StyleCop 提供检查空格使用的一致性,但遗憾的是缺乏相反的想法:强制源代码使用制表符。有什么方法可以添加这个功能吗?不一定是 StyleCop,其他工具也可以。

StyleCop offers to check for consistent use of spaces, but sadly lacks the opposite idea: Force source code to use tabs. Is there some way to add this functionality? It does not have to be StyleCop, other tools are welcome as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

寂寞花火° 2024-08-29 06:08:27

我也是一个不使用制表符而不是空格的人,尽管有很多理由使用其中任何一种,并且还有其他地方可以解释您为什么认为其中一种比另一种更好。 :)

我实际上想要同样的东西 - 一个检查制表符缩进的规则 - 所以我根据 StyleCop 的 SpacingRules 源代码编写了它。它似乎工作得相当好,尽管到目前为止我只在几个项目中使用过它。它可能可以优化或其他什么......但它有效。

using System;
using System.Text.RegularExpressions;
using Microsoft.StyleCop;
using Microsoft.StyleCop.CSharp;

namespace CustomRules.StyleCop.CSharp
{
  [SourceAnalyzer(typeof(CsParser))]
  public class SpacingRules : SourceAnalyzer
  {
    public SpacingRules()
    {
    }

    public override void AnalyzeDocument(CodeDocument document)
    {
      Param.RequireNotNull(document, "document");

      CsDocument csdocument = (CsDocument)document;
      if (csdocument.RootElement != null && !csdocument.RootElement.Generated)
      {
        this.CheckSpacing(csdocument.Tokens);
      }
    }

    private void CheckSpacing(MasterList<CsToken> tokens)
    {
      Param.AssertNotNull(tokens, "tokens");

      foreach (var token in tokens)
      {
        if (this.Cancel)
        {
          break;
        }

        if (token.Generated)
        {
          continue;
        }

        switch (token.CsTokenType)
        {
          case CsTokenType.WhiteSpace:
            this.CheckWhitespace(token as Whitespace);
            break;

          case CsTokenType.XmlHeader:
            XmlHeader header = (XmlHeader)token;
            foreach (var xmlChild in header.ChildTokens)
            {
              this.CheckTabsInComment(xmlChild);
            }
            break;

          case CsTokenType.SingleLineComment:
          case CsTokenType.MultiLineComment:
            this.CheckTabsInComment(token);
            break;
        }

        switch (token.CsTokenClass)
        {
          case CsTokenClass.ConstructorConstraint:
            this.CheckSpacing(((ConstructorConstraint)token).ChildTokens);
            break;

          case CsTokenClass.GenericType:
            this.CheckGenericSpacing((GenericType)token);
            this.CheckSpacing(((TypeToken)token).ChildTokens);
            break;

          case CsTokenClass.Type:
            this.CheckSpacing(((TypeToken)token).ChildTokens);
            break;
        }
      }
    }

    private void CheckGenericSpacing(GenericType generic)
    {
      Param.AssertNotNull(generic, "generic");
      if (generic.ChildTokens.Count == 0)
      {
        return;
      }

      foreach (var token in generic.ChildTokens)
      {
        if (this.Cancel)
        {
          break;
        }

        if (token.CsTokenClass == CsTokenClass.GenericType)
        {
          this.CheckGenericSpacing(token as GenericType);
        }

        if (!token.Generated && token.CsTokenType == CsTokenType.WhiteSpace)
        {
          this.CheckWhitespace(token as Whitespace);
        }
      }
    }

    private void CheckWhitespace(Whitespace whitespace)
    {
      Param.AssertNotNull(whitespace, "whitespace");

      if (whitespace.Location.StartPoint.IndexOnLine == 0 && Regex.IsMatch(whitespace.Text, "^ +"))
      {
        this.AddViolation(whitespace.FindParentElement(), whitespace.LineNumber, "TabsMustBeUsed");
      }
    }

    private void CheckTabsInComment(CsToken comment)
    {
      Param.AssertNotNull(comment, "comment");

      var lines = comment.Text.Split('\n');
      for (int i = 0; i < lines.Length; i++)
      {
        if (Regex.IsMatch(lines[i], "^ +"))
        {
          this.AddViolation(comment.FindParentElement(), comment.LineNumber + i, "TabsMustBeUsed");
        }
      }
    }
  }
}

请注意,您还必须在程序集中将嵌入的 XML 文件“SpacingRules.xml”与该文件一起放置。 (有关更多信息,请阅读 StyleCop SDK 文档。)

<?xml version="1.0" encoding="utf-8" ?>
<SourceAnalyzer Name="Custom Spacing Rules">
  <Description>
    Rules which verify the spacing placed between keywords and symbols in the code.
  </Description>
  <Rules>
    <Rule Name="TabsMustBeUsed" CheckId="MY1027">
      <Context>Spaces are not allowed. Use tabs instead.</Context>
      <Description>Verifies that the code does not contain spaces.</Description>
    </Rule>
  </Rules>
</SourceAnalyzer>

I'm a tabs-not-spaces person, too, though there are plenty of reasons to use either one and there are other places to get into why you think one is better than the other. :)

I actually wanted the same thing - a rule to check for tab indents - so I wrote it based on the SpacingRules source from StyleCop. It seems to work reasonably well, though I've only used it on a few projects so far. It could probably be optimized or whatever... but it works.

using System;
using System.Text.RegularExpressions;
using Microsoft.StyleCop;
using Microsoft.StyleCop.CSharp;

namespace CustomRules.StyleCop.CSharp
{
  [SourceAnalyzer(typeof(CsParser))]
  public class SpacingRules : SourceAnalyzer
  {
    public SpacingRules()
    {
    }

    public override void AnalyzeDocument(CodeDocument document)
    {
      Param.RequireNotNull(document, "document");

      CsDocument csdocument = (CsDocument)document;
      if (csdocument.RootElement != null && !csdocument.RootElement.Generated)
      {
        this.CheckSpacing(csdocument.Tokens);
      }
    }

    private void CheckSpacing(MasterList<CsToken> tokens)
    {
      Param.AssertNotNull(tokens, "tokens");

      foreach (var token in tokens)
      {
        if (this.Cancel)
        {
          break;
        }

        if (token.Generated)
        {
          continue;
        }

        switch (token.CsTokenType)
        {
          case CsTokenType.WhiteSpace:
            this.CheckWhitespace(token as Whitespace);
            break;

          case CsTokenType.XmlHeader:
            XmlHeader header = (XmlHeader)token;
            foreach (var xmlChild in header.ChildTokens)
            {
              this.CheckTabsInComment(xmlChild);
            }
            break;

          case CsTokenType.SingleLineComment:
          case CsTokenType.MultiLineComment:
            this.CheckTabsInComment(token);
            break;
        }

        switch (token.CsTokenClass)
        {
          case CsTokenClass.ConstructorConstraint:
            this.CheckSpacing(((ConstructorConstraint)token).ChildTokens);
            break;

          case CsTokenClass.GenericType:
            this.CheckGenericSpacing((GenericType)token);
            this.CheckSpacing(((TypeToken)token).ChildTokens);
            break;

          case CsTokenClass.Type:
            this.CheckSpacing(((TypeToken)token).ChildTokens);
            break;
        }
      }
    }

    private void CheckGenericSpacing(GenericType generic)
    {
      Param.AssertNotNull(generic, "generic");
      if (generic.ChildTokens.Count == 0)
      {
        return;
      }

      foreach (var token in generic.ChildTokens)
      {
        if (this.Cancel)
        {
          break;
        }

        if (token.CsTokenClass == CsTokenClass.GenericType)
        {
          this.CheckGenericSpacing(token as GenericType);
        }

        if (!token.Generated && token.CsTokenType == CsTokenType.WhiteSpace)
        {
          this.CheckWhitespace(token as Whitespace);
        }
      }
    }

    private void CheckWhitespace(Whitespace whitespace)
    {
      Param.AssertNotNull(whitespace, "whitespace");

      if (whitespace.Location.StartPoint.IndexOnLine == 0 && Regex.IsMatch(whitespace.Text, "^ +"))
      {
        this.AddViolation(whitespace.FindParentElement(), whitespace.LineNumber, "TabsMustBeUsed");
      }
    }

    private void CheckTabsInComment(CsToken comment)
    {
      Param.AssertNotNull(comment, "comment");

      var lines = comment.Text.Split('\n');
      for (int i = 0; i < lines.Length; i++)
      {
        if (Regex.IsMatch(lines[i], "^ +"))
        {
          this.AddViolation(comment.FindParentElement(), comment.LineNumber + i, "TabsMustBeUsed");
        }
      }
    }
  }
}

Note that you also have to have the embedded XML file "SpacingRules.xml" in the assembly alongside this thing. (Read the StyleCop SDK doc for more on that.)

<?xml version="1.0" encoding="utf-8" ?>
<SourceAnalyzer Name="Custom Spacing Rules">
  <Description>
    Rules which verify the spacing placed between keywords and symbols in the code.
  </Description>
  <Rules>
    <Rule Name="TabsMustBeUsed" CheckId="MY1027">
      <Context>Spaces are not allowed. Use tabs instead.</Context>
      <Description>Verifies that the code does not contain spaces.</Description>
    </Rule>
  </Rules>
</SourceAnalyzer>
悲歌长辞 2024-08-29 06:08:27

您可以使用 StyleCop+ 插件强制使用选项卡。

下载 StyleCopPlus.dll 后,将其放入 StyleCop 主文件夹 C:\Program Files (x86)\StyleCop 4.7\Custom Rules 内的 Custom Rules 文件夹中> 或直接在主文件夹中。

现在,当使用 StyleCopSettingsEditor 打开 Settings.StyleCop 时,您将能够设置规则 SP2001:CheckAllowedIndentationCharacters

此规则可以在 StyleCop+ 选项卡下的 更多自定义规则 子选项卡下的 Formatting 标题下找到:

规则选项

You can use StyleCop+ plugin to enforce usage of tabs.

After downloading StyleCopPlus.dll place it in Custom Rules folder inside the main StyleCop folder C:\Program Files (x86)\StyleCop 4.7\Custom Rules or directly in the main folder.

Now, when opening a Settings.StyleCop with StyleCopSettingsEditor you will be able to set rule SP2001: CheckAllowedIndentationCharacters.

This rule can be found under the StyleCop+ tab, under the More Custom Rules subtab, under the Formatting heading:

Rule Options

爱的十字路口 2024-08-29 06:08:27

假设您使用 Visual Studio 作为 IDE,并且您的队友接受这个想法,您可以做的一件事是将 VS 设置为使用制表符而不是空格,导出并共享设置文件。

该设置可以在“工具”>“工具”下找到。选项>文本编辑器>所有语言(或您希望使用的语言)>选项卡,然后在右侧您可以选择“插入空格”或“保留选项卡”。

要从视觉工作室导出设置:工具>导入和导出设置>导出选定的环境设置>选择“选项”

只是一个想法 - 但说实话,真正的问题似乎是队友的支持。否则他们总是可以恢复到他们的设置。或者,按照 Sam 的建议,在办理入住手续时,您可以进行一些自动重新格式化。

华泰

One thing you could do, assuming you are using Visual Studio as your IDE, and that your team-mates buy-in to this idea, would be to set VS to use tabs instead of spaces, export and share the settings file.

The setting can be found under Tools > Options > Text Editor > All Languages (or the language you wish to use) > Tabs and then on the right hand side you can pick to 'Insert Spaces' or 'Keep Tabs'.

To export the settings from your visual studio: Tools > Import and Export Settings > Export selected environment settings > select the 'Options'

Just a thought - but to be honest the real problem seems to be the buy-in from your team-mates. They can always revert back to their settings otherwise. Alternatively, upon check-in, as Sam suggested, you can do some automated re-formatting.

HTH

沐歌 2024-08-29 06:08:27

包方法:

目前的趋势似乎是通过 nuget 包来做到这一点(并且经典的 StyleCop 可能会在某个时候被淘汰)。因此,要对包执行此操作,请执行以下操作:

通过 nuget:

Install-Package Microsoft.CodeAnalysis.FxCopAnalyzers
Install-Package StyleCop.Analyzers -Version 1.1.0-beta006

请注意对预发行版的引用(此时),选项卡的设置仅在测试版中可用。

将以下代码作为 ca.ruleset 添加到您的项目中:

<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Custom Rulset" Description="Custom Rulset" ToolsVersion="14.0">
    <Rules AnalyzerId="AsyncUsageAnalyzers" RuleNamespace="AsyncUsageAnalyzers">
        <Rule Id="UseConfigureAwait" Action="Warning" />
    </Rules>
    <Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
        <Rule Id="CA1001" Action="Warning" />
        <Rule Id="CA1009" Action="Warning" />
        <Rule Id="CA1016" Action="Warning" />
        <Rule Id="CA1033" Action="Warning" />
        <Rule Id="CA1049" Action="Warning" />
        <Rule Id="CA1060" Action="Warning" />
        <Rule Id="CA1061" Action="Warning" />
        <Rule Id="CA1063" Action="Warning" />
        <Rule Id="CA1065" Action="Warning" />
        <Rule Id="CA1301" Action="Warning" />
        <Rule Id="CA1400" Action="Warning" />
        <Rule Id="CA1401" Action="Warning" />
        <Rule Id="CA1403" Action="Warning" />
        <Rule Id="CA1404" Action="Warning" />
        <Rule Id="CA1405" Action="Warning" />
        <Rule Id="CA1410" Action="Warning" />
        <Rule Id="CA1415" Action="Warning" />
        <Rule Id="CA1821" Action="Warning" />
        <Rule Id="CA1900" Action="Warning" />
        <Rule Id="CA1901" Action="Warning" />
        <Rule Id="CA2002" Action="Warning" />
        <Rule Id="CA2100" Action="Warning" />
        <Rule Id="CA2101" Action="Warning" />
        <Rule Id="CA2108" Action="Warning" />
        <Rule Id="CA2111" Action="Warning" />
        <Rule Id="CA2112" Action="Warning" />
        <Rule Id="CA2114" Action="Warning" />
        <Rule Id="CA2116" Action="Warning" />
        <Rule Id="CA2117" Action="Warning" />
        <Rule Id="CA2122" Action="Warning" />
        <Rule Id="CA2123" Action="Warning" />
        <Rule Id="CA2124" Action="Warning" />
        <Rule Id="CA2126" Action="Warning" />
        <Rule Id="CA2131" Action="Warning" />
        <Rule Id="CA2132" Action="Warning" />
        <Rule Id="CA2133" Action="Warning" />
        <Rule Id="CA2134" Action="Warning" />
        <Rule Id="CA2137" Action="Warning" />
        <Rule Id="CA2138" Action="Warning" />
        <Rule Id="CA2140" Action="Warning" />
        <Rule Id="CA2141" Action="Warning" />
        <Rule Id="CA2146" Action="Warning" />
        <Rule Id="CA2147" Action="Warning" />
        <Rule Id="CA2149" Action="Warning" />
        <Rule Id="CA2200" Action="Warning" />
        <Rule Id="CA2202" Action="Warning" />
        <Rule Id="CA2207" Action="Warning" />
        <Rule Id="CA2212" Action="Warning" />
        <Rule Id="CA2213" Action="Warning" />
        <Rule Id="CA2214" Action="Warning" />
        <Rule Id="CA2216" Action="Warning" />
        <Rule Id="CA2220" Action="Warning" />
        <Rule Id="CA2229" Action="Warning" />
        <Rule Id="CA2231" Action="Warning" />
        <Rule Id="CA2232" Action="Warning" />
        <Rule Id="CA2235" Action="Warning" />
        <Rule Id="CA2236" Action="Warning" />
        <Rule Id="CA2237" Action="Warning" />
        <Rule Id="CA2238" Action="Warning" />
        <Rule Id="CA2240" Action="Warning" />
        <Rule Id="CA2241" Action="Warning" />
        <Rule Id="CA2242" Action="Warning" />
        <Rule Id="CA1012" Action="Warning" />
    </Rules>
    <Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
        <Rule Id="SA1305" Action="Warning" />
        <Rule Id="SA1412" Action="Warning" />
        <Rule Id="SA1600" Action="None" />
        <Rule Id="SA1609" Action="Warning" />
    </Rules>
</RuleSet>

通过编辑 .csproj 文件并添加以下内容,将其添加到您的项目文件中:

<PropertyGroup>
    <CodeAnalysisRuleSet>ca.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

要覆盖选项卡(和其他)设置,您需要将 stylecop.json 文件添加到您的项目中。在文件属性中,将构建操作设置为“(分析器)附加文件”。根据项目类型,实际的“分析器”一词可能不存在。

将 stylecop.json 文件编辑为如下所示:

{
  "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
  "settings": {
    "documentationRules": {
      "companyName": "YourCompanyName",
      "copyrightText": "Copyright (c) {companyName}. All Rights Reserved.\r\nLicensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.",
      "xmlHeader": false,
      "fileNamingConvention": "metadata"
    },
    "indentation": {
      "useTabs": true
    }
  }
}

至少对于 .NET 标准项目,您需要确保 csproj 文件中包含以下内容(并且没有对文件的其他引用):

<ItemGroup>
  <AdditionalFiles Include="stylecop.json" />
</ItemGroup>

您可能必须重新加载项目和包以使它们识别 stylecop.json 文件。

参考文献:

DotNetAnalyzers/StyleCopAnalyzers

.NET Core、代码分析和 StyleCop

The package approach:

It seems that the current trend is to do this through nuget packages (and that the classic StyleCop may be phased out at some point). So, to do this with the packages, do the following:

via nuget:

Install-Package Microsoft.CodeAnalysis.FxCopAnalyzers
Install-Package StyleCop.Analyzers -Version 1.1.0-beta006

Notice the reference to the pre-releaset (at this time), the settings for tabs are only available in the beta.

add the following code to your project as ca.ruleset:

<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Custom Rulset" Description="Custom Rulset" ToolsVersion="14.0">
    <Rules AnalyzerId="AsyncUsageAnalyzers" RuleNamespace="AsyncUsageAnalyzers">
        <Rule Id="UseConfigureAwait" Action="Warning" />
    </Rules>
    <Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
        <Rule Id="CA1001" Action="Warning" />
        <Rule Id="CA1009" Action="Warning" />
        <Rule Id="CA1016" Action="Warning" />
        <Rule Id="CA1033" Action="Warning" />
        <Rule Id="CA1049" Action="Warning" />
        <Rule Id="CA1060" Action="Warning" />
        <Rule Id="CA1061" Action="Warning" />
        <Rule Id="CA1063" Action="Warning" />
        <Rule Id="CA1065" Action="Warning" />
        <Rule Id="CA1301" Action="Warning" />
        <Rule Id="CA1400" Action="Warning" />
        <Rule Id="CA1401" Action="Warning" />
        <Rule Id="CA1403" Action="Warning" />
        <Rule Id="CA1404" Action="Warning" />
        <Rule Id="CA1405" Action="Warning" />
        <Rule Id="CA1410" Action="Warning" />
        <Rule Id="CA1415" Action="Warning" />
        <Rule Id="CA1821" Action="Warning" />
        <Rule Id="CA1900" Action="Warning" />
        <Rule Id="CA1901" Action="Warning" />
        <Rule Id="CA2002" Action="Warning" />
        <Rule Id="CA2100" Action="Warning" />
        <Rule Id="CA2101" Action="Warning" />
        <Rule Id="CA2108" Action="Warning" />
        <Rule Id="CA2111" Action="Warning" />
        <Rule Id="CA2112" Action="Warning" />
        <Rule Id="CA2114" Action="Warning" />
        <Rule Id="CA2116" Action="Warning" />
        <Rule Id="CA2117" Action="Warning" />
        <Rule Id="CA2122" Action="Warning" />
        <Rule Id="CA2123" Action="Warning" />
        <Rule Id="CA2124" Action="Warning" />
        <Rule Id="CA2126" Action="Warning" />
        <Rule Id="CA2131" Action="Warning" />
        <Rule Id="CA2132" Action="Warning" />
        <Rule Id="CA2133" Action="Warning" />
        <Rule Id="CA2134" Action="Warning" />
        <Rule Id="CA2137" Action="Warning" />
        <Rule Id="CA2138" Action="Warning" />
        <Rule Id="CA2140" Action="Warning" />
        <Rule Id="CA2141" Action="Warning" />
        <Rule Id="CA2146" Action="Warning" />
        <Rule Id="CA2147" Action="Warning" />
        <Rule Id="CA2149" Action="Warning" />
        <Rule Id="CA2200" Action="Warning" />
        <Rule Id="CA2202" Action="Warning" />
        <Rule Id="CA2207" Action="Warning" />
        <Rule Id="CA2212" Action="Warning" />
        <Rule Id="CA2213" Action="Warning" />
        <Rule Id="CA2214" Action="Warning" />
        <Rule Id="CA2216" Action="Warning" />
        <Rule Id="CA2220" Action="Warning" />
        <Rule Id="CA2229" Action="Warning" />
        <Rule Id="CA2231" Action="Warning" />
        <Rule Id="CA2232" Action="Warning" />
        <Rule Id="CA2235" Action="Warning" />
        <Rule Id="CA2236" Action="Warning" />
        <Rule Id="CA2237" Action="Warning" />
        <Rule Id="CA2238" Action="Warning" />
        <Rule Id="CA2240" Action="Warning" />
        <Rule Id="CA2241" Action="Warning" />
        <Rule Id="CA2242" Action="Warning" />
        <Rule Id="CA1012" Action="Warning" />
    </Rules>
    <Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
        <Rule Id="SA1305" Action="Warning" />
        <Rule Id="SA1412" Action="Warning" />
        <Rule Id="SA1600" Action="None" />
        <Rule Id="SA1609" Action="Warning" />
    </Rules>
</RuleSet>

Add it to your project file by editing the .csproj file and adding:

<PropertyGroup>
    <CodeAnalysisRuleSet>ca.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

To override the tab (and other) settings, you will need to add a stylecop.json file to your project. In the file properties, set the Build Action to '(analyzer) additional file'. Depending on the project type, the actual word 'analyzer' may not be present.

Edit the stylecop.json file to something like the following:

{
  "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
  "settings": {
    "documentationRules": {
      "companyName": "YourCompanyName",
      "copyrightText": "Copyright (c) {companyName}. All Rights Reserved.\r\nLicensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.",
      "xmlHeader": false,
      "fileNamingConvention": "metadata"
    },
    "indentation": {
      "useTabs": true
    }
  }
}

At least for .NET standard projects, you need to insure that the following is in the csproj file (and no other references to file):

<ItemGroup>
  <AdditionalFiles Include="stylecop.json" />
</ItemGroup>

You may have to reload the project and the packages to get them to recognize the stylecop.json file.

References:

DotNetAnalyzers/StyleCopAnalyzers

.NET Core, Code Analysis and StyleCop

冷血 2024-08-29 06:08:27

StyleCop 支持创建自定义规则,因此您可以添加自己的“使用前导制表符而不是空格”规则。如果您不想尝试开发自己的规则,则可以在 http://stylecopcontrib 获取现有规则。 codeplex.com/http://github.com/AArnott/nerdbank.stylecop .规则

StyleCop supports creation of custom rules, so you can add your own "use leading tabs instead of spaces" rule. If you don't feel like trying to develop your own, you can get an existing rule at either http://stylecopcontrib.codeplex.com/ or http://github.com/AArnott/nerdbank.stylecop.rules.

岁吢 2024-08-29 06:08:27

好的,我设法找出问题所在,因为出现此警告的原因是,

如果您使用的是 VS2010, 开发人员有时会复制并粘贴代码
转到解决方案资源管理器
检查设置风格警察
然后修改 Cop 样式内的设置,例如禁用或取消选中设置[Spacing.....]

Ok I managed to figure out the problem because the reason why this warning appear, It appear because the developer sometimes copy and paste the code

if you are using VS2010
Go to solution explorer
Check in Setting Style Cop
then modify the setting inside the style Cop e.g disable or uncheck the setting[Spacing.....]

宫墨修音 2024-08-29 06:08:27

在源代码控制服务器中执行此操作。使用预提交脚本检查文件中是否存在以多个空格开头的行并阻止提交。

我同意制表符比空格更好。这是个人喜好,但团队的一致性非常重要。

Do it within your source control server. Use a pre-commit script to check the file for lines starting with multiple spaces and prevent the commit.

I agree tabs are better than spaces. It's a personal preference, but team consistency is very important.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文