StyleCop



設定

  • SA1027が、いつの間にかOFFにできるようになった(@@
SA1027をOFFにしたいが、それはできないようだ。つまりタブは使えず、すべてスペースにしろってことらしい。
  • SA1630はOFFにしないと不都合がある。これは、「summaryタグ内の文字列にスペースがない」というエラーで、英文は区切りがスペースであり、それがないということは、ドキュメントがちゃんと書かれていないかも、ということを示している。日本語は句読点で区切ることができるため、ちゃんと書いてあってもこのエラーに引っかかる。
  • SA1631はOFFにしないと不都合がある。これは、「summaryタグ内が、適切な文法構造に従うようには見えない」というエラーで、シンボルと非英字の割合で算出される。つまり、日本語とは関係ない。


ヘッダーの例

<copyright file="AssemblyInfo.cs" company="J-FACTORY">(C)2012</copyright>

ファイルを除外

プロジェクトファイル(.csproj)に細工をする
<ItemGroup>
  <Compile Include="Properties\AssemblyInfo.cs">
    <ExcludeFromStyleCop>true</ExcludeFromStyleCop>
  </Compile>
</ItemGroup>
ファイル先頭に下記を追加する(こっちのが簡単)
// <auto-generated />

行やブロックを除外

[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented",
		Justification = "抑制する理由を書く")]

参考

http://stylecop.soyuz5.com/StyleCop%20Rules.html


1000 Spacing Rules

Microsoft.StyleCop.CSharp.SpacingRules
SA1000 SA1000:KeywordsMustBeSpacedCorrectly
A violation of this rule occurs when the spacing around a keyword is incorrect.
SA1001:CommasMustBeSpaceCorrectly The spacing around a comma is incorrect, within a C# code file.
SA1002:SemicolonsMustBeSpaceCorrectly Invalid spacing around the semicolon.
セミコロンの前後の間隔が無効です。
SA1003:SymbolsMustBeSpaceCorrectly The spacing around the symbol '+' is invalid.
'+'というシンボルの周りのスペースは無効です。
SA1004:DocumentationLinesMustBeginWithSingleSpace The documentation header line must start with a single space.
ドキュメンテーションヘッダーの行は、シングルスペースから始まらなければなりません。
SA1005:SingleLineCommentsMustBeginWithSingleSpace The comment must start with a single space. To ignore this error when commenting out a line of code, begin the comment with '////' rather than '//'.
コメントはシングルスペースから始まらなければなりません。コードの行をコメントアウトするときこのエラーを無視するには、'//'よりむしろ'////'でコメントを始めてください。
SA1006:PreprocessorKeywordsMustNotBePrecededBySpace A violation of this rule occurs when the preprocessor-type keyword in a preprocessor directive is preceded by space.
SA1007:OperatorKeywordMustBeFollowedBySpace A violation of this rule occurs when the operator keyword within an operator overload method is not followed by any whitespace. The operator keyword should always be followed by a single space.
SA1008:OpeningParenthesisMustBeSpacedCorrectly A violation of this rule occurs when the opening parenthesis within a statement is not spaced correctly.
SA1009:ClosingParenthesisMustBeSpacedCorrectly Invalid spacing around the closing parenthesis.
閉じ括弧の周りの無効のスペース
SA1010:OpeningSquareBracketsMustBeSpacedCorrectly A violation of this rule occurs when an opening square bracket within a statement is preceded or followed by whitespace.
SA1011:ClosingSquareBracketsMustBeSpacedCorrectly A violation of this rule occurs when the spacing around a closing square bracket is not correct.
SA1012:OpeningCurlyBracketsMustBeSpacedCorrectly Invalid spacing around the opening curly bracket.
初めの中括弧の周りの無効のスペース。
SA1025:CodeMustNotContainMultipleWhitespaceInARow The code contains multiple spaces in a row. Only one space is needed.
このコード行で複数のスペースが含まれています。唯一の1つのスペースが必要です。
SA1027:TabsMustNotBeUsed Tabs are not allowed. Use spaces instead.
タブは許容されていません。 代わりにスペースを使用してください。

1100 Readability Rules

[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "*", Justification = "")]
SA1100 SA1100:DoNotPrefixCallsWithBaseUnlessLocalImplementationExists
継承されたクラスのメンバーへの呼び出しはbaseで始まらなくてはならない。
SA1101 The call to components must begin with the 'this.' prefix to indicate that the item is a member of the class.
アイテムがクラスの一員であることを示すために、コンポーネントへの呼び出しは'this'接頭語で始めなければなりません。
SA1108 SA1108:BlockStatementsMustNotContainEmbeddedComments
コメントは括弧の中に置かなければなりません。
SA1115 The parameter must begin on the line after the previous parameter.
パラメタは前のパラメタの後の行の上で始まらなければなりません。
SA1116 If the method parameters are on separate lines, the first parameter must begin on the line beneath the name of the method.
メソッドパラメタが別々の行にあるなら、最初のパラメタはメソッド名の下の位置で始まらなければなりません。
SA1117 All method parameters must be placed on the same line, or each parameter must be placed on a separate line.
すべてのメソッドのパラメータは同じ行に配置するか、各パラメータごとに別の行に配置する必要があります。
SA1119 The line contains unnecessary parenthesis.
不必要な括弧の行を含んでいます。
SA1120 The comment is empty. Add text to the comment or remove it.
コメントは空です。コメントにテキストを追加または削除してください。
SA1121 Use the built-in type alias 'byte' rather than Byte or System.Byte.
ByteやSystem.Byteよりむしろ内蔵型別名'byte'を使用してください。
int,uint,short,ushort...
SA1122 Use string.Empty rather than "".
""よりstring.Emptyを使用してください。
SA1123 The use of regions is not allowed within code elements. Remove the #region and #endregion tags.
regionの使用はコード要素の中で許されていません。 #regionと#endregionタグを取り除いてください。

1200 Ordering Rules

Microsoft.StyleCop.CSharp.OrderingRules
SA1200 All "using directives" must be placed inside of the namespace.
すべてのusingディレクティブは名前空間の内部に置かなければなりません。
SA1201 All constructors must be placed after all fields.
すべてのフィールドの後にすべてのコンストラクタを置かなければなりません。
●ファイル内の順番
Extern Alias
Directives
Using Directives
名前空間(Namespaces)
デリゲート(Delegates)
列挙型(Enums)
インターフェイス(Interfaces)
構造体(Structs)
クラス(Classes)
●クラスか構造体かインターフェイス内の順番
メンバ(Fields)
コンストラクタ(Constructors)
デストラクタ(Finalizers (Destructors))
デリゲート(Delegates)
イベント(Events)
列挙型(Enums)
インターフェイス(Interfaces)
プロパティ(Properties)
インデクサ(Indexers)
メソッド(Methods)
構造体(Structs)
クラス(Classes)
SA1202 All protected methods must be placed after all public methods.
すべてのprotectedメソッドはpublicメソッドの後ろに置かなければなりません。
SA1203 All constant and readonly private fields must be placed before all non-constant, non-readonly private fields.
すべての定数と読み取り専用プライベートフィールドは、非定数と非読み取り専用プライベートフィールドよりも前に配置する必要があります。
SA1204 All static private fields must be placed before all non-static private fields.
すべての静的なプライベートフィールドの前に全ての非静的プライベートフィールドを配置する必要があります。
SA1205 SA1205:PartialElementsMustDeclareAccess
The partial element does not have an access modifier defined.
部分的な要素は、アクセス修飾子を定めておきません。
SA1206 SA1206:DeclarationKeywordsMustFollowOrder
The access modifier keyword must come before the 'static' keyword in the element declaration.
アクセス修飾子キーワードは、要素宣言において『静的』キーワードの前に来なければなりません。
SA1210 Using directives must be sorted alphabetically by the namespaces.
using は名前空間のアルファベット順にソートされていなければなりません。


1300 Naming Rules

Microsoft.StyleCop.CSharp.NamingRules
SA1300 method names begin with an upper-case letter: XXX
メソッド名は大文字アルファベットで始まります
SA1305 The variable name 'hByte2' begins with a prefix that looks like Hungarian notation. Remove the prefix or add it to the list of allowed prefixes.
変数名'hByte2'はハンガリーの記法に似ている接頭語で始まります。 接頭語を移すか、または許容接頭語のリストにそれを追加してください。
SA1306 Variable names must start with a lower-case letter: 変数名.
変数名は小文字アルファベットから始まらなければなりません
SA1307 Public and internal fields must start with an upper-case letter.
public、そして、internalのフィールドは大文字アルファベットから始まらなければなりません


1400 Maintainability Rules

Microsoft.StyleCop.CSharp.MaintainabilityRules
SA1400 The class must have an access modifier.
クラスには、アクセス修飾語がなければなりません。
SA1401 SA1401:SA1401:FieldsMustBePrivate
Fields must be declared with private access. Use properties to expose fields.
プライベートでフィールドを申告しなければなりません。 プロパティを使用でフィールドを公開してください。
SA1402 SA1402:FileMayOnlyContainASingleClass
A violation of this rule occurs when a C# file contains more than one class.
ファイルはクラスをひとつだけ含むべきである
SA1404 A Code Analysis suppression must contain a non-empty justification describing the reason for the suppression.
コード解析の抑制、非空の正当性を抑制するための理由を記述する必要があります。
SA1405 A call to Debug.Assert must provide a message in the second parameter describing the reason for the assert.
Debug.Assertの呼び出しは、2番目のパラメータにassertの理由を表すメッセージを記述する必要があります。
SA1407 Insert parenthesis within the arithmetic expression to declare the operator precedence.
算術式の中に丸括弧を挿入して、演算子の優先順位を明確にしてください。



1500 Layout Rules

Microsoft.StyleCop.CSharp.LayoutRules
SA1500 If a statement spans multiple lines, the opening curly bracket must be placed on its own line.
ステートメントが複数の行にかかっているなら、初めの中括弧をそれ自身の行に置かなければなりません。
SA1501 A statement containing curly brackets must not be placed on a single line. The opening and closing curly brackets must each be placed on their own line.
SA1501: 中括弧を含むステートメントを一行に置いてはいけません。 それぞれそれら自身の線に中括弧を置かなければなりません。
SA1502 SA1502:ElementMustNotBeOnASingleLine
The constructor must not be placed on a single line. The opening and closing curly brackets must each be placed on their own line.
コンストラクタを一行に置いてはいけません。 それぞれ初めの、そして、終わりの中括弧をそれら自身の線に置かなければなりません。
SA1503 The body of the if statement must be wrapped in opening and closing curly brackets.
本体は、中括弧でステートメントを包装しなければならない。
SA1505 An opening curly bracket must not be followed by a blank line.
空白行は初めの中括弧のあとに続いてはいけません。
SA1506 A documentation header line must not be followed by a blank line.
空白行はドキュメンテーションヘッダー行のあとに続いてはいけません。
SA1507 The code must not contain multiple blank lines in a row.
このコード行で、複数の空白行を含めることはできません。
SA1508 The code must not contain blank lines at the end of the file.
ファイル最後に空行を含んではなりません。
SA1510 An else, catch, or finally statement must not be preceded by a blank line.
else、catch、finallyステートメントは、空白行が先行することはできません。
SA1512 A single-line comment must not be followed by a blank line. To ignore this error when commenting out a line of code, begin the comment with '////' rather than '//'.
空白行は一行コメントのあとに続いてはいけません。コメントはシングルスペースから始まらなければなりません。コードの行をコメントアウトするときこのエラーを無視するには、'//'よりむしろ'////'でコメントを始めてください。
SA1513 Statements or elements wrapped in curly brackets must be followed by a blank line.
中括弧で囲まれたステートメントかエレメントは、空白行が続かなければなりません。
SA1514 A documentation header must be preceded by a blank line or must be the first item in its scope.
ドキュメンテーションヘッダーは、空白行が先行しなければならない、さもなければ、範囲で最初の項目であるに違いありません。
SA1515 A single-line comment must be preceded by a blank line or another single-line comment, or must be the first item in its scope. To ignore this error when commenting out a line of code, begin the comment with '////' rather than '//'.
SA1515: 1行のコメントは、空白行か別の単線コメントで先行しなければならないか、または範囲で最初の項目であるに違いありません。コメントはシングルスペースから始まらなければなりません。コードの行をコメントアウトするときこのエラーを無視するには、'//'よりむしろ'////'でコメントを始めてください。
SA1516 Adjacent elements must be separated by a blank line.
隣接するエレメントは、空白行で切り離さなければなりません。


1600 Documentation Rules

Microsoft.StyleCop.CSharp.DocumentationRules
SA1600 The class must have a documentation header.
The method must have a documentation header.
クラス(メソッド)には、ドキュメンテーションヘッダーがなければなりません。
SA1601 The partial class element must have a documentation header containing either a summary tag or a content tag.
partial class要素には、summaryタグかcontentタグのどちらかを含むドキュメンテーションヘッダーがなければなりません。
SA1606 The summary section in the documentation header must not be empty.
ドキュメントヘッダーの概要のセクションを空にすることはできません。
SA1611 The documentation header must contain param tags matching the element's parameter list.
ドキュメンテーションヘッダーは要素のパラメータ・リストに合っているparamタグを含まなければなりません。
SA1612 The param tags in the documentation header must match the element's parameter list.
ドキュメンテーションヘッダーのparamタグは要素のパラメータ・リストに合わなければなりません
SA1614 The documentation text within the param tag for the '<param name="hdr"></param>' parameter must not be empty.
ドキュメントのテキストのparamタグの'<param name="xxx"></param>'が空であってはならない。
SA1615 The documentation header must contain a returns tag since the element has a return value.
戻り値を持っているエレメントのドキュメンテーションヘッダは、リターンタグを含める必要があります。
SA1623 The property's documentation summary text must begin with: Gets
プロパティの<summary>は以下で始まらなければなりません。 Gets ...
SA1625 The documentation header contains two or more identical documentation strings. The only documentation text which may be duplicated is 'The parameter is not used.'.
ドキュメンテーションヘッダーは2個以上の同じドキュメンテーションストリングを含んでいます。 コピーされるかもしれない唯一のドキュメンテーションテキストは'parameter is not used.'。
SA1630 The documentation text within the summary tag does not contain any whitespace between words, indicating that it most likely does not follow a proper grammatical structure required for documentation text.
summaryタグの中のドキュメンテーションテキストは単語の間のどんな空白も含んでいません、たぶん適切な文法構造がドキュメンテーションテキストに必要であるということにならないのを示しています。
SA1631 The documentation text within the summary tag does not appear to follow a proper grammatical structure required for documentation text.
summaryタグの中のドキュメンテーションテキストはドキュメンテーションテキストに必要である適切な文法構造に従うように見えません。
SA1632 The documentation text within the summary tag must be at least 10 characters in length. Documentation failing to meet this guideline most likely does not follow a proper grammatical structure required for documentation text.
summaryタグの中のドキュメンテーションテキストは少なくとも10文字の長さでなければなりません。 このガイドラインを満たさないドキュメンテーションがたぶんドキュメンテーションテキストに必要である適切な文法構造に従いません。
SA1633 The file has no header, the header Xml is invalid, or the header is not located at the top of the file.
ファイルには、ヘッダーが全くないか、ヘッダーXmlが無効であるか、またはヘッダーはファイルの先頭に位置していません。
SA1634 The file header must contain a copyright tag.
ファイル先頭には、<copyright>タグがなくてはならない
SA1638 The file attribute in the file header's copyright tag must contain the name of the file.
ファイルヘッダーのファイル属性のcopyrightタグは、ファイル名を含まなければなりません。
SA1642 The documentation text within the constructor's summary tag must begin with the text:Initializes a new instance of the Form1 class.
コンストラクタのsummaryタグの中のドキュメンテーションテキストは"Initializes a new instance of the **** class"テキストで始まらなければなりません。
SA1643 The documentation text within the destructor's summary tag must begin with the text: Finalizes an instance of the **** class.
デストラクタのsummaryタグの中のドキュメンテーションテキストは"Finalizes an instance of the **** class"テキストで始まらなければなりません。
SA1644 The documentation header must not contain blank lines. Use the 'para' tag to insert line breaks within documentation text.
空白行は、ドキュメントヘッダーに含めることはできません。ドキュメントのテキストに改行を挿入するには'para'タグを使用してください。
SA1649 SA1649:FileHeaderFileNameDocumentationMustMatchTypeName
A violation of this rule occurs when the file tag within the file header at the top of a C# file does not contain the name of the first type in the file.
ファイルヘッダのファイルタグに、ファイル内の最初の名前が含まれていない


VisualStudioのエディタ設定

オプションダイアログ => テキストエディタ => C#
  • タブ
    • インデント
      ( ) なし
      ( ) ブロック
      (O) スマート
    • タブ
      タブサイズ = 4
      インデントサイズ = 4
      (O) 空白の保持
      ( ) タブの保持
  • 書式設定
    • 全般
      [V]‘;'を入力しステートメントを終了したときにオートフォーマットする
      [V]‘}'を入力しブロックを終了したときにオートフォーマットする
      [V] 貼り付け時にオートフォーマットする
    • インデント
      [V] ブロックの内容をインデントする
      [ ] 初めと終わりのかっこをインデントする
      [V] caseの内容をインデントする
      [ ] caseのラベルをインデントする
      • ラベルインデント
        ( ) gotoラベルを左端の列に配置する(O) gotoラベルを現在より1インデントだけ下げて配置する
        ( ) ラベルを標準にインデントする
    • 改行
      • 中かっこの改行オプション
        [V] 新しい行に始めかっこを配置する
        [V] 新しい行にメソッドの始めかっこを配置する
        [V] 新しい行に匿名メソッドの始めかっこを配置する
        [V] 新しい行にコントロールブロックの始めかっこを配置する
        [V] 新しい行に匿名型の始めかっこを配置する
        [V] 新しい行にオブジェクト初期化子の始めかっこを配置する
        [V] 新しい行にラムダ式の始めかっこを配置する
      • キーワードの改行オプション
        [V] 新しい行に"else"を配置する
        [V] 新しい行に"catch"を配置する
        [V] 新しい行に"finally"を配置する
      • 式の改行オプション
        [V] 新しい行にオブジェクト初期化子のメンバを配置する
        [V] 新しい行に匿名型のメンバを配置する
        [V] 新しい行にクエリ式の句を配置する
    • 行間
      • メソッド宣言子のスペースを設定する
        [ ] メソッド名と初めのかっこの間にスペースを挿入する
        [ ] 引数リストのかっこ内にスペースを挿入する[ ] 空の引数リストのかっこ内にスペースを挿入する
      • メソッド呼び出しのスペースを設定する
        [ ] メソッド名と初めかっこの間にスペースを挿入する
        [ ] 引数リストのかっこ内にスペースを挿入する
        [ ] 空の引数リストのかっこ内にスペースを挿入する
      • その他のスペースオプションを設定する
        [V] 制御フローステートメント内のキーワードの後にスペースを挿入する
        [ ] 式のかっこ内にスペースを挿入する
        [ ] 型キャストのかっこ内にスペースを挿入する
        [ ] 制御フローステートメントのかっこ内にスペースを挿入する
        [ ] キャストの後にスペースを追加する
        [V] 宣言ステートメント内のスペースを無視する
      • 大かっこのスペースを設定する
        [ ] 初め角かっこの前にスペースを挿入する
        [ ] 空の角かっこ内にスペースを挿入する
        [ ] 角かっこ内にスペースを挿入する
      • 区切り記号のスペースを設定する
        [V] 型宣言で、基本またはインターフェイス用のコロンの後にスペースを配置する
        [V] コンマの後にスペースを追加する
        [ ] ピリオドの後にスペースを追加する
        [V] "for"ステートメントでセミコロンの後にスペースを挿入する
        [V] 型宣言で、基本またはインターフェイス用のコロンの前にスペースを挿入する
        [ ] コンマの前にスペースを挿入する
        [ ] ピリオドの前にスペースを挿入する
        [ ] "for"ステートメントの前にスペースを挿入する
      • 演算子のスペースを設定する
        (O) バイナリ演算子の前後にスペースを挿入する
        ( ) バイナリ演算子の前後のスペースを無視する
        ( ) バイナリ演算子の前後のスペースを削除する
      • 折り返し
        [V] ブロックを単一行に配置する
        [V] 1行に複数のステートメントとメンバ宣言を表示する
最終更新:2014年06月09日 15:54