LoginSignup
5
1

More than 5 years have passed since last update.

Perl::Critic(perlcritic)を使用して静的解析、コーディング規約テストを実施(実施編:コマンド)

Last updated at Posted at 2017-02-26

Perlの静的解析、コーディング規約テストを実施する為にPerl::Criticを使用する事になったので、内容を残しておきます。

dockerのubuntuにて実行
「Ubuntu 14.04.3 LTS」
(実行日付:2017/02/26)

コマンド実行

コマンド:
perlcritic 「ファイル名称」

(実行結果)

# perlcritic testCode.pl
Code before strictures are enabled at line 1, column 1.  See page 429 of PBP.  (Severity: 5)
#

(テスト対象ファイル内容)

# cat testCode.pl
print "Hello world";

# 

出力結果を対象外とする場合

オプション:
--exclude

(実行例)

# perlcritic --exclude=stric testCode.pl     
testCode.pl source OK
# 

severity設定

番号(1〜5)を設定して出力する内容を設定します。
2を設定すると、2以上の内容を出力します。
番号と意味は以下の通りです。

SEVERITY NAME   ...is equivalent to...   SEVERITY NUMBER
--------------------------------------------------------
--severity gentle                           --severity 5
--severity stern                            --severity 4
--severity harsh                            --severity 3
--severity cruel                            --severity 2
--severity brutal                           --severity 1

オプション:
--severity

(実行例)

# perlcritic --severity=2 testCode.pl
Module does not end with "1;" at line 1, column 1.  Must end with a recognizable true value.  (Severity: 4)
Code not contained in explicit package at line 1, column 1.  Violates encapsulation.  (Severity: 4)
No package-scoped "$VERSION" variable found at line 1, column 1.  See page 404 of PBP.  (Severity: 2)
Code before strictures are enabled at line 1, column 1.  See page 429 of PBP.  (Severity: 5)
Code before warnings are enabled at line 1, column 1.  See page 431 of PBP.  (Severity: 4)
# 

その他設定

コマンドのhelpを実行する事で、その他の設定内容を確認する事が出来ます。

コマンド:
perlcritic --help

(実行結果)

# perlcritic --help
Usage:
      perlcritic [-12345 | --brutal | --cruel | --harsh | --stern | --gentle]
                 [--severity number | name] [{-p | --profile} file | --noprofile]
                 [--top [ number ]] [--theme expression] [--include pattern]
                 [--exclude pattern] [{-s | --single-policy} pattern]
                 [--only | --noonly] [--profile-strictness {warn|fatal|quiet}]
                 [--force | --noforce] [--statistics] [--statistics-only]
                 [--count | -C] [--verbose {number | format}] [--allow-unsafe]
                 [--color | --nocolor] [--pager pager] [--quiet]
                 [--color-severity-highest color_specification]
                 [--color-severity-high color_specification]
                 [--color-severity-medium color_specification]
                 [--color-severity-low color_specification]
                 [--color-severity-lowest color_specification]
                 [--files-with-violations | -l]
                 [--files-without-violations | -L]
                 [--program-extensions file_name_extension]
                 {FILE | DIRECTORY | STDIN}

      perlcritic --profile-proto

      perlcritic { --list | --list-enabled | --list-themes | --doc pattern [...] }

      perlcritic { --help | --options | --man | --version }

# 

参照サイト:
perlcritic

5
1
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
5
1