今回はこれを使って iutest のコーディングスタイルをチェックしてみました。
cpplint.py の使い方
cpplint.py は github から取得できます。クローンしてもいいですし、cpplint.py だけダウンロードしても OK です。https://github.com/google/styleguide
iutest の場合
1行の文字数やスペース、改行の入れ方などの報告のほかに、explicit を付けましょうとか const 参照にしましょうなどの報告も出ました。
チェック内容
チェックされる内容は以下のものがあります。| build | class |
| c++11 | |
| deprecated | |
| endif_comment | |
| explicit_make_pair | |
| forward_decl | |
| header_guard | |
| include | |
| include_alpha | |
| include_order | |
| include_what_you_use | |
| namespaces | |
| printf_format | |
| storage_class | |
| legal | copyright |
| readability | alt_tokens |
| braces | |
| casting | |
| check | |
| constructors | |
| fn_size | |
| function | |
| inheritance | |
| multiline_comment | |
| multiline_string | |
| namespace | |
| nolint | |
| nul | |
| strings | |
| todo | |
| utf8 | |
| runtime | arrays |
| casting | |
| explicit | |
| int | |
| init | |
| invalid_increment | |
| member_string_references | |
| memset | |
| indentation_namespace | |
| operator | |
| printf | |
| printf_format | |
| references | |
| string | |
| threadsafe_fn | |
| vlog | |
| whitespace | blank_line |
| braces | |
| comma | |
| comments | |
| empty_conditional_body | |
| empty_loop_body | |
| end_of_line | |
| ending_newline | |
| forcolon | |
| indent | |
| line_length | |
| newline | |
| operators | |
| parens | |
| semicolon | |
| tab | |
| todo |
これらはコマンドラインオプションで有効/無効を設定できます。
警告の除外
該当行にコメントで NOLINT と書いておくと無視してくれます。using namespace matchers; // NOLINT
それか、--filter コマンドライン引数で無視指定ができます。
警告の末尾に [runtime/explicit] とか [whitespace/end_of_line] とかタグが表示されますので、該当のタグの先頭に '-' を付けると無効にできます。複数指定する場合は、カンマ(,) で区切ります。
cpplint.py --filter=-runtime/explicit,-whitespace/end_of_line
行の長さの設定
1行の長さも --linelength コマンドライン引数で指定できます。cpplint.py --linelength=150
まとめ
cpplint.py (Google Style Guides)の規則が必ずしも良い、正しいわけではありませんが、1つの指標として役に立つと思いました。iutest でも一通りチェックしてみて、可読性に対してやポータビリティなどに対して改善できました。というわけで、cpplint を CI で回すようにしています。
来週は cpplint を回している CI サービスの紹介をしたいと思います。
それでは、また来週~
I know this site gives quality dependent posts and extra stuff, is there any other website which presents these information in quality?
返信削除Howdy excellent blog! Does running a blog similar to this take a great deal of work? I have virtually no understanding of coding but I was hoping to start my own blog soon. Anyways, should you have any ideas or tips for new blog owners please share. I know this is off topic however I simply wanted to ask. Cheers!
返信削除