perl-lint について
perl-lint は Perl 開発者向けのコード検査・整形スキルです。Perl::Critic と perltidy の検出、重大度の選択、設定方法を案内します。
主な機能
- 01Perl::Critic と perltidy の検出
- 02重大度別のコード検査
- 03指摘内容と重大度の説明
- 04perltidy による整形の案内
- 05プロジェクト設定ファイルの解説
活用シーン
- 01Perl スクリプトのポリシー違反の確認
- 02プロジェクト規約に沿った Perl ファイルの整形
- 03コードレビューでの検査レベルの選択
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ jamie-bitflight/ claude_skills --skill perl-lintインストール後、Claude Code で/perl-lintを入力して読み込まれたか確認します。
同梱ファイルreferences/code-examples.md
詳細
Perl のリンティングとフォーマット
ツールを自動検出して、Perl::Critic による解析と perltidy によるフォーマットを実行します。
ワークフロー
- perlcritic/perltidy がインストールされているか確認します
- 指定したファイルを解析します
- 重要度レベルとともに検出結果を報告します
- 修正を提案するか、コードをフォーマットします
ツールの検出
まず、ツールが利用可能であることを確認します。
# Check perlcritic
command -v perlcritic >/dev/null && echo "perlcritic available" || echo "Install: cpanm Perl::Critic"
# Check perltidy
command -v perltidy >/dev/null && echo "perltidy available" || echo "Install: cpanm Perl::Tidy"
Perl::Critic による解析
perlcritic の実行
# Default analysis (severity 5 - gentle)
perlcritic script.pl
# All severities (1 = strictest)
perlcritic --severity 1 script.pl
# Specific severity level
perlcritic --severity 3 script.pl
# With verbose explanations
perlcritic --verbose 11 script.pl
# Single policy
perlcritic --single-policy RequireUseStrict script.pl
# Exclude policies
perlcritic --exclude RequireUseWarnings script.pl
重要度レベル
| レベル | 名称 | 説明 |
|---|---|---|
| 5 | 穏やか | 明白で疑いの余地がない問題 |
| 4 | 厳格 | 通常は悪い慣習 |
| 3 | 厳しい | 議論の余地はあるものの推奨 |
| 2 | 非情 | スタイルをより細かくチェック |
| 1 | 過酷 | 最大限の厳格さ |
よく使われるポリシー
| ポリシー | 重要度 | 問題 |
|---|---|---|
| RequireUseStrict | 5 | use strict がありません |
| RequireUseWarnings | 4 | use warnings がありません |
| ProhibitBarewordFileHandles | 5 | 裸の単語のファイルハンドルを使用しています |
| ProhibitTwoArgOpen | 5 | 2 引数形式の open() |
| ProhibitStringyEval | 5 | 文字列を使った eval |
| RequireTidyCode | 1 | コードがフォーマットされていません |
設定ファイル
プロジェクトのルートに .perlcriticrc を作成します。
# .perlcriticrc
severity = 3
verbose = 8
theme = core
# Exclude specific policies
[-Documentation::RequirePodSections]
[-InputOutput::RequireBriefOpen]
# Configure specific policy
[CodeLayout::RequireTidyCode]
perltidyrc = .perltidyrc
[Variables::ProhibitPackageVars]
packages = Data::Dumper File::Find
[TestingAndDebugging::ProhibitNoStrict]
allow = refs
詳細出力形式
| レベル | 出力形式 |
|---|---|
| 1 | 行のみ |
| 4 | 行 + 列 |
| 8 | 行 + ポリシー + 重要度 |
| 10 | 詳細な説明 |
| 11 | PBP のページ参照を含む |
Perltidy によるフォーマット
基本的な使い方
# Format file (creates .bak backup)
perltidy script.pl
# Format to stdout (no backup)
perltidy -st script.pl
# In-place edit (no backup)
perltidy -b -nst script.pl
# Check if tidy (exit code)
perltidy -st script.pl | diff -q - script.pl
よく使われるオプション
# Basic formatting
perltidy -i=4 -ci=4 -l=100 script.pl
# Full command with common options
perltidy \
--indent-columns=4 \
--continuation-indentation=4 \
--maximum-line-length=100 \
--vertical-tightness=2 \
--paren-tightness=1 \
--brace-tightness=1 \
script.pl
設定ファイル
プロジェクトのルートに .perltidyrc を作成します。
# .perltidyrc
# Indentation
--indent-columns=4
--continuation-indentation=4
# Line length
--maximum-line-length=100
# Blank lines
--blank-lines-before-subs=1
--blank-lines-after-block-opening=0
# Spaces
--paren-tightness=1
--brace-tightness=1
--square-bracket-tightness=1
# Vertical alignment
--no-outdent-long-quotes
--no-outdent-long-comments
# Output
--backup-and-modify-in-place
--backup-file-extension=/
組み合わせたワークフロー
リンティングと修正
結果の解釈
重要度 5(重大)
すぐに修正する必要があります。
Bareword file handle opened at line 10, column 1.
Two-argument "open" used at line 15, column 5.
修正:
# Wrong
open FILE, $filename;
# Correct
open my $fh, '<', $filename;
重要度 4(重要)
修正することを推奨します。
Code before strictures are enabled at line 1.
修正:
# Add at top
use strict;
use warnings;
重要度 3(推奨)
修正を検討してください。
Regular expression without "/x" flag at line 25.
インストール
ツールが見つからない場合:
# Install both tools
cpanm Perl::Critic Perl::Tidy
# Verify installation
perlcritic --version
perltidy --version
クイックコマンド
特定のファイルをリンティング:
perlcritic --severity 4 --verbose 8 path/to/file.pl
ディレクトリ内のすべての Perl ファイルをリンティング:
find . -name '*.pl' -o -name '*.pm' | xargs perlcritic --severity 4
すべてのファイルをフォーマット:
find . -name '*.pl' -o -name '*.pm' | xargs perltidy -b
コメント
Markdown 対応