LoginSignup
6
5

More than 5 years have passed since last update.

RuboCop | Style/CommentAnnotation

Posted at

RuboCop | Style/CommentAnnotation

概要

RuboCopの「Style/CommentAnnotation」警告について。

TODOなど、アノテーションコメントの記法をチェックします。
アノテーションコメントについては、別途下記の記事を参照

アノテーションコメント(TODO、FIXME、OPTIMIZE、HACK、REVIEW)

具体的には、

# ANNOTATION: comment

のように、
「#」, 半角スペース, キーワード(大文字), 半角コロン, 半角スペース, コメント
のフォーマットになっている必要があります。

設定値一覧

デフォルトでは下記のキーがチェック対象になっています。

  • TODO
  • FIXME
  • OPTIMIZE
  • HACK
  • REVIEW

CommentAnnotation

各設定値での検証結果をまとめます。

検証プログラム

comment_annotation.rb

# TODO: comment
# FIXME: comment
# OPTIMIZE: comment
# HACK!: comment
# REVIEW: comment
# ORIGINAL: comment
# TODO invalid_format_no_colon
# TODO:invalid_format_no_space
# todo: invalid_format_lower_case
# ORIGINAL invalid_format_no_colon
# ORIGINAL:invalid_format_no_space
# original: invalid_format_lower_case

実行結果 デフォルト の場合

.rubocop.yml

※明示的に設定しているが、デフォルト値なので何も設定しなくてもよい

CommentAnnotation:
  Keywords:
    - TODO
    - FIXME
    - OPTIMIZE
    - HACK
    - REVIEW
$ rubocop comment_annotation.rb
Inspecting 1 file
C

Offenses:

comment_annotation.rb:7:3: C: Annotation keywords should be all upper case, followed by a colon and a space, then a note describing the problem.
# TODO invalid_format_no_colon
  ^^^^
comment_annotation.rb:8:3: C: Annotation keywords should be all upper case, followed by a colon and a space, then a note describing the problem.
# TODO:invalid_format_no_space
  ^^^^^
comment_annotation.rb:9:3: C: Annotation keywords should be all upper case, followed by a colon and a space, then a note describing the problem.
# todo: invalid_format_lower_case
  ^^^^^

1 file inspected, 3 offenses detected

実行結果 ORIGINAL をキーワードに追加した場合

.rubocop.yml

CommentAnnotation:
  Keywords:
    - TODO
    - FIXME
    - OPTIMIZE
    - HACK
    - REVIEW
    - ORIGINAL
$ rubocop comment_annotation.rb
Inspecting 1 file
C

Offenses:

comment_annotation.rb:7:3: C: Annotation keywords should be all upper case, followed by a colon and a space, then a note describing the problem.
# TODO invalid_format_no_colon
  ^^^^
comment_annotation.rb:8:3: C: Annotation keywords should be all upper case, followed by a colon and a space, then a note describing the problem.
# TODO:invalid_format_no_space
  ^^^^^
comment_annotation.rb:9:3: C: Annotation keywords should be all upper case, followed by a colon and a space, then a note describing the problem.
# todo: invalid_format_lower_case
  ^^^^^
comment_annotation.rb:10:3: C: Annotation keywords should be all upper case, followed by a colon and a space, then a note describing the problem.
# ORIGINAL invalid_format_no_colon
  ^^^^^^^^
comment_annotation.rb:11:3: C: Annotation keywords should be all upper case, followed by a colon and a space, then a note describing the problem.
# ORIGINAL:invalid_format_no_space
  ^^^^^^^^^
comment_annotation.rb:12:3: C: Annotation keywords should be all upper case, followed by a colon and a space, then a note describing the problem.
# original: invalid_format_lower_case
  ^^^^^^^^^

1 file inspected, 6 offenses detected
6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5