mcpField
P
perl-lint

perl-lint

github.com/jamie-bitflightテスト・品質50 回インストール
リポジトリ

perl-lint について

perl-lint は Perl 開発者向けのコード検査・整形スキルです。Perl::Critic と perltidy の検出、重大度の選択、設定方法を案内します。

主な機能

  1. 01Perl::Critic と perltidy の検出
  2. 02重大度別のコード検査
  3. 03指摘内容と重大度の説明
  4. 04perltidy による整形の案内
  5. 05プロジェクト設定ファイルの解説

活用シーン

  1. 01Perl スクリプトのポリシー違反の確認
  2. 02プロジェクト規約に沿った Perl ファイルの整形
  3. 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 によるフォーマットを実行します。

ワークフロー

  1. perlcritic/perltidy がインストールされているか確認します
  2. 指定したファイルを解析します
  3. 重要度レベルとともに検出結果を報告します
  4. 修正を提案するか、コードをフォーマットします

ツールの検出

まず、ツールが利用可能であることを確認します。

# 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過酷最大限の厳格さ
よく使われるポリシー
ポリシー重要度問題
RequireUseStrict5use strict がありません
RequireUseWarnings4use warnings がありません
ProhibitBarewordFileHandles5裸の単語のファイルハンドルを使用しています
ProhibitTwoArgOpen52 引数形式の open()
ProhibitStringyEval5文字列を使った eval
RequireTidyCode1コードがフォーマットされていません
設定ファイル

プロジェクトのルートに .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詳細な説明
11PBP のページ参照を含む

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

コメント