ClangFormatスタイルオプション¶
| 概要: | インデントスタイル(ソースコード整形)ツールであるclang-formatの、スタイル(設定項目)の日本語の概要 |
|---|
ベーススタイル¶
| 概要: | 基本とするコーディングスタイル |
|---|
具体的な内容がよくわからない場合の参照先¶
参考
注釈
Artistic Style(AStyle) の スタイルオプション(Bracket Style) にも簡単なサンプルあり。
| スタイル | ClangFormat スタイルオプション | コーディング規約 |
|---|---|---|
| LLVM | BasedOnStyle: LLVM |
LLVM coding standards |
BasedOnStyle: Google |
Google’s C++ style guide | |
| Chromium | BasedOnStyle: Chromium |
Chromium’s style guide |
| Mozilla | BasedOnStyle: Mozilla |
Mozilla’s style guide |
| WebKit | BasedOnStyle: WebKit |
WebKit’s style guide |
| linux | BasedOnStyle:
LLVMIndentWidth:
8UseTab:
AlwaysBreakBeforeBraces:
LinuxAllowShortIfStatementsOnASingleLine:
falseIndentCaseLabels:
false |
Linux kernel coding style |
| Visual Studio | UseTab:
NeverIndentWidth:
4BreakBeforeBraces:
AllmanAllowShortIfStatementsOnASingleLine:
falseIndentCaseLabels:
falseColumnLimit:
0 |
スタイルオプション(設定項目)の概要¶
| 概要: | スタイルオプションの概要と ベーススタイル(LLVM Google Chromium Mozilla WebKit) の設定項目の初期値の一覧表 |
|---|---|
| 詳細: | 詳細は Clang ドキュメント の Clang の Clang-Format Style Options を参照 |
注釈
ベーススタイル名をクリックすると、その列を非表示にします。(JavaScript)
| # BasedOnStyle | LLVM | Chromium | Mozilla | WebKit | 概要 | |||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Language (LanguageKind) |
Cpp | 対象としているフォーマットスタイルの言語 注釈 設定ファイルでは、設定値のprefix
|
||||||||||||||||||||||
AccessModifierOffset (int) |
-2 | -1 | -1 | -2 | -4 | アクセス修飾子(
public: protected: private:)のインデント(
IndentWidth オプションと同じ値のマイナスでインデントなし) |
||||||||||||||||||
AlignAfterOpenBracket
(BracketAlignmentStyle) |
Align | Align | Align | Align | DontAlign |
注釈 設定ファイルでは、設定値のprefix
BAS_ は不要バージョン2.8で設定値の型が変更
|
||||||||||||||||||
AlignConsecutiveAssignments (bool) |
false |
注釈 バージョン 3.7 より追加 |
||||||||||||||||||||||
AlignConsecutiveDeclarations (bool) |
false |
注釈 バージョン 3.8 より追加 |
||||||||||||||||||||||
AlignEscapedNewlinesLeft (bool) |
false | true | true | false | false | エスケープされた改行の位置
|
||||||||||||||||||
AlignOperands (bool) |
true | true | true | true | false |
int aaa = bbbbbbbbbbbbbbb +
ccccccccccccccc;
|
||||||||||||||||||
AlignTrailingComments (bool) |
true | true | true | true | false | コメントを末尾に揃える | ||||||||||||||||||
AllowAllParametersOfDeclarationOnNextLine
(bool) |
true | true | false | false | true | BinPackParameters が false の場合でも、
次の行に関数宣言のすべてのパラメータを置く。 |
||||||||||||||||||
AllowShortBlocksOnASingleLine (bool) |
false | 単一の行に簡単なブレース文を収縮。
例えば、
if (a) { return; } を単一行に置く。 |
||||||||||||||||||||||
AllowShortCaseLabelsOnASingleLine (bool) |
false | true の場合、短いケースラベルを単一行に置く。 |
||||||||||||||||||||||
AllowShortFunctionsOnASingleLine
(ShortFunctionStyle) |
All | All | Inline | All | All |
注釈 設定ファイルでは、設定値のprefix
|
||||||||||||||||||
AllowShortIfStatementsOnASingleLine (bool) |
false | true | false | false | false | true の場合、単一行の if (a) return; をキープ |
||||||||||||||||||
AllowShortLoopsOnASingleLine (bool) |
false | true | false | false | false | true の場合、単一行の while (true) continue; をキープ |
||||||||||||||||||
AlwaysBreakAfterDefinitionReturnType
(DefinitionReturnTypeBreakingStyle) |
None | None | None | TopLevel | None | 関数定義の戻り値の型のスタイル。 より正確には「関数定義の型以下の識別子の前に改行」。 警告 このオプションは廃止されており、後方互換性のために残されています。
AlwaysBreakAfterReturnType を参照
注釈 バージョン 3.7 より追加 |
||||||||||||||||||
AlwaysBreakAfterReturnType
(ReturnTypeBreakingStyle) |
None | None | None | TopLevelDefinitions | None | 関数宣言の戻り値の型のスタイル。 より正確には「関数定義の型以下の識別子の前に改行」。
注釈 バージョン 3.8 より追加 |
||||||||||||||||||
AlwaysBreakBeforeMultilineStrings (bool) |
false | true | true | false | false | 複数行のリテラル文字列の前で改行する | ||||||||||||||||||
AlwaysBreakTemplateDeclarations (bool) |
false | true | true | false | false | true の場合、テンプレート宣言の template<...> の後に改行 |
||||||||||||||||||
BinPackArguments (bool) |
true | false の場合、関数呼び出しの引数は、全て同じ行か、1行ごとになる。 |
||||||||||||||||||||||
BinPackParameters (bool) |
true | true | false | true | true | 関数呼び出しや関数定義のパラメーターを、一行ごとにするか | ||||||||||||||||||
| BraceWrapping: | 波括弧{}のフォーマットスタイル(個々の設定はネストした設定フラグを参照)
注釈 バージョン 3.8 より追加 |
|||||||||||||||||||||||
BraceWrapping:AfterClass(bool) |
false | false | false | true | false | class の後 |
||||||||||||||||||
BraceWrapping:AfterControlStatement(bool) |
false | コントロールステートメント(if/for/while/switch/..)の後 | ||||||||||||||||||||||
BraceWrapping:AfterEnum(bool) |
false | false | false | true | false | enum の後 |
||||||||||||||||||
BraceWrapping:AfterFunction(bool) |
false | false | false | true | true | 関数の後 | ||||||||||||||||||
BraceWrapping:AfterNamespace(bool) |
false | namespace の後 |
||||||||||||||||||||||
BraceWrapping:AfterObjCDeclaration(bool) |
false | ObjC 宣言(@autoreleasepool, interfaces, ..)の後 | ||||||||||||||||||||||
BraceWrapping:AfterStruct(bool) |
false | false | false | true | false | struct の後 |
||||||||||||||||||
BraceWrapping:AfterUnion(bool) |
false | false | false | true | false | union の後 |
||||||||||||||||||
BraceWrapping:BeforeCatch(bool) |
false | catch の前 |
||||||||||||||||||||||
BraceWrapping:BeforeElse(bool) |
false | else の前 |
||||||||||||||||||||||
BraceWrapping:IndentBraces(bool) |
false | 関数呼び出しや関数定義のパラメーターを、一行ごとにするか | ||||||||||||||||||||||
BreakBeforeBinaryOperators
(BinaryOperatorStyle) |
None | None | None | None | All | 二項演算子の折り返し方法 注釈 設定ファイルでは、設定値のprefix
|
||||||||||||||||||
BreakBeforeBraces (BraceBreakingStyle) |
Attach | Attach | Attach | Mozilla (3.6 までは Attach) | WebKit (3.7 までは Stroustrup) | 波括弧{}のフォーマットスタイル
注釈 設定ファイルでは、設定値のprefix
|
||||||||||||||||||
BreakBeforeTernaryOperators (bool) |
true | 三項演算子を、改行の後に配置する | ||||||||||||||||||||||
BreakConstructorInitializersBeforeComma
(bool) |
false | false | false | false | true | コンストラクタ初期化子のコンマの前で改行し、コロンでカンマを揃えるか
|
||||||||||||||||||
| BreakAfterJavaFieldAnnotations | false | Javaファイル内のフィールドのアノテーションの後に改行。 注釈 バージョン 3.9 より追加 |
||||||||||||||||||||||
| BreakStringLiterals | true | フォーマット時に文字列リテラルを改行で調整。 注釈 バージョン 3.9 より追加 |
||||||||||||||||||||||
ColumnLimit (unsigned) |
80 | 80 | 80 | 80 | 0 | 最大列(行幅)数 | ||||||||||||||||||
CommentPragmas (std::string) |
‘^ IWYU pragma:’ | 行に分割または変更すべきでない、特別な意味を持つのコメントを記述する正規表現。
|
||||||||||||||||||||||
ConstructorInitializerAllOnOneLineOrOnePerLine
(bool) |
false | true | true | true | false | コンストラクターの初期化子が行に収まらない場合は、改行する | ||||||||||||||||||
ConstructorInitializerIndentWidth
(unsigned) |
4 | コンストラクタ初期化子リストのインデントに使用する文字数 | ||||||||||||||||||||||
ContinuationIndentWidth (unsigned) |
4 | 継続行のためのインデント幅 | ||||||||||||||||||||||
Cpp11BracedListStyle (bool) |
true | true | true | false | false | |||||||||||||||||||
DerivePointerAlignment (bool) |
false | true | false | true | false | true の場合、 * や & の位置を自動判定。PointerAlignment は、フォールバックとしてのみ使う |
||||||||||||||||||
DisableFormat (bool) |
false | 全ての書式設定を無効にする。 | ||||||||||||||||||||||
ExperimentalAutoDetectBinPacking (bool) |
false | |||||||||||||||||||||||
ForEachMacros (std::vector<std::string>) |
[ foreach, Q_FOREACH, BOOST_FOREACH ] | For example: BOOST_FOREACH. | ||||||||||||||||||||||
IncludeCategories
(std::vector<IncludeCategory>) |
(概要参照) |
LLVM, Mozilla, WebKit
Google, Chromium
注釈 バージョン 3.8 より追加 |
||||||||||||||||||||||
IncludeIsMainRegex (std::string) |
(概要参照) | file-to-main-include マッピングで許可されている サフィックスの正規表現を指定します。 LLVM, Mozilla, WebKit
Google, Chromium
注釈 バージョン 3.9 より追加 |
||||||||||||||||||||||
IndentCaseLabels (bool) |
false | true | true | true | false | switch ブロック内の case X: 文をインデント |
||||||||||||||||||
IndentWidth (unsigned) |
2 | 2 | 2 | 2 | 4 | インデントに使用する列数 | ||||||||||||||||||
IndentWrappedFunctionNames (bool) |
false | |||||||||||||||||||||||
JavaScriptQuotes (JavaScriptQuoteStyle) |
Leave | JavaScriptの文字列に使用します。 注釈 設定ファイルでは、設定値のprefix
注釈 バージョン 3.9 より追加 |
||||||||||||||||||||||
JavaScriptWrapImports (bool) |
true | |||||||||||||||||||||||
KeepEmptyLinesAtTheStartOfBlocks (bool) |
true | false | false | true | true | true の場合、ブロックの開始時の空行を保持する |
||||||||||||||||||
MacroBlockBegin (std::string) |
‘’ | ブロック開始マクロにマッチする正規表現 注釈 バージョン 3.7 より追加 |
||||||||||||||||||||||
MacroBlockEnd (std::string) |
‘’ | ブロック終了マクロにマッチする正規表現 注釈 バージョン 3.7 より追加 |
||||||||||||||||||||||
MaxEmptyLinesToKeep (unsigned) |
1 | 最大連続空行数 | ||||||||||||||||||||||
NamespaceIndentation
(NamespaceIndentationKind) |
None | None | None | None | Inner | namespace のインデント 注釈 設定ファイルでは、設定値のprefix
|
||||||||||||||||||
ObjCBlockIndentWidth (unsigned) |
2 | 2 | 2 | 2 | 4 | Objective-Cのインデントの文字数 | ||||||||||||||||||
ObjCSpaceAfterProperty (bool) |
false | false | false | true | true | Objective-Cで
@property の後にスペースを追加する。@property(readonly) の代わりに @property (readonly) を使用する。 |
||||||||||||||||||
ObjCSpaceBeforeProtocolList (bool) |
true | false | false | false | true | Objective-Cのプロトコルリストの前にスペースを追加。
Foo<Protocol> の代わりに Foo <Protocol> を使用する。 |
||||||||||||||||||
PenaltyBreakBeforeFirstCallParameter
(unsigned) |
19 | 1 | 1 | 19 | 19 | “call(” のペナルティー | ||||||||||||||||||
PenaltyBreakComment (unsigned) |
300 | コメントのペナルティー | ||||||||||||||||||||||
PenaltyBreakFirstLessLess (unsigned) |
120 | << のペナルティー |
||||||||||||||||||||||
PenaltyBreakString (unsigned) |
1000 | リテラル文字列のペナルティー | ||||||||||||||||||||||
PenaltyExcessCharacter (unsigned) |
1000000 | 文字のペナルティー | ||||||||||||||||||||||
PenaltyReturnTypeOnItsOwnLine (unsigned) |
60 | 200 | 200 | 200 | 60 | 独自の行に関数の戻り値の型を置くためのペナルティー | ||||||||||||||||||
PointerAlignment (PointerAlignmentStyle) |
Right | Left | Left | Left | Left |
注釈 設定ファイルでは、設定値のprefix
|
||||||||||||||||||
ReflowComments(bool) |
true |
注釈 バージョン 3.8 より追加 |
||||||||||||||||||||||
SortIncludes(bool) |
true | true | false | true | true |
注釈 バージョン 3.8 より追加 |
||||||||||||||||||
SpaceAfterCStyleCast (bool) |
false | Cスタイルのキャスト後のスペース
|
||||||||||||||||||||||
SpaceBeforeAssignmentOperators (bool) |
true | true の場合、代入演算子の前のスペースを削除しない |
||||||||||||||||||||||
SpaceBeforeParens
(SpaceBeforeParensOptions) |
ControlStatements | 開始括弧’(‘ の前のスペース 注釈 設定ファイルでは、設定値のprefix
|
||||||||||||||||||||||
SpaceInEmptyParentheses (bool) |
false | 空括弧()内のスペース
|
||||||||||||||||||||||
SpacesBeforeTrailingComments (unsigned) |
1 | 2 | 2 | 1 | 1 | 1行コメントの前のスペース幅
int n;
ココの幅 //< コメント |
||||||||||||||||||
SpacesInAngles (bool) |
false | 山括弧<>の内側のスペース(
|
||||||||||||||||||||||
SpacesInContainerLiterals (bool) |
true | true の場合、コンテナリテラル(例. ObjC、 Javascript 配列、 dict リテラル)
の内部にスペースを挿入する |
||||||||||||||||||||||
SpacesInCStyleCastParentheses (bool) |
false | Cスタイルのキャストのスペース
|
||||||||||||||||||||||
SpacesInParentheses (bool) |
false | 括弧()の内側のスペース
|
||||||||||||||||||||||
SpacesInSquareBrackets (bool) |
false | 括弧[]の内側のスペース
|
||||||||||||||||||||||
Standard (LanguageStandard) |
Cpp11 | Auto | Auto | Cpp03 | Cpp03 | 規格との互換性 注釈 設定ファイルでは、設定値のprefix
|
||||||||||||||||||
TabWidth (unsigned) |
8 | タブ幅 | ||||||||||||||||||||||
UseTab (UseTabStyle) |
Never | タブの使い方 注釈 設定ファイルでは、設定値のprefix
|
||||||||||||||||||||||
| # BasedOnStyle | LLVM | Chromium | Mozilla | WebKit | 概要 | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
AlignAfterOpenBracket (bool) |
true | true | true | true | false |
丸括弧()、波括弧{}、角括弧[]に適用。
警告 (バージョン3.7まで有効。それ以降のバージョンは、設定値が
|
||||||
AlwaysBreakAfterDefinitionReturnType
(bool) |
false |
警告 (バージョン3.7まで有効。それ以降のバージョンは、設定値が
|
||||||||||
DerivePointerBinding (bool) |
false | true | false | true | false | インプットファイルを解析して最も多い配置に従って、 警告 (バージョン3.4まで有効。それ以降のバージョンは、この項目は削除され、
|
||||||
IndentFunctionDeclarationAfterType (bool) |
false | 警告 バージョン3.4まで有効。 |
||||||||||
PointerBindsToType (bool) |
false | true | true | true | true |
警告 (バージョン3.4まで有効。それ以降のバージョンは、この項目は削除され、
|
||||||
SpaceAfterControlStatementKeyword (bool) |
true | true の場合、括弧のヘッダー(例. if, for, while ...)の後にスペースを挿入する
警告 (バージョン3.4まで有効。それ以降のバージョンは、この項目は削除され、
|
||||||||||