PMDバージョン: 7.0.0-rc4
Best Practices
AvoidInlineStyles
公式ドキュメント: AvoidInlineStyles
Since: PMD 6.45.0
Priority: Medium (3)
Description:
コンテンツとスタイルを混在させない。スタイルと導入クラスには別々のCSSファイル使用する。
これにより、共通のスタイルを再利用することができる。
Configuration:
<rule ref="category/html/bestpractices.xml/AvoidInlineStyles" />
Example:
<!-- HTMLファイル内にstyleタグを記載しない。スタイルはCSSファイルで定義するべき --> <div style="font-size: 12pt;"></div>
UnnecessaryTypeAttribute
公式ドキュメント: UnnecessaryTypeAttribute
Since: PMD 6.45.0
Priority: Medium (3)
Description:
HTML5では、linkとscript要素に対する明示的なtype属性は必要ない。
最近のブラウザは、スタイルシートはCSSで、スクリプトはJavaScriptを使うことを想定している。
Configuration:
<rule ref="category/html/bestpractices.xml/UnnecessaryTypeAttribute" />
Example:
<!-- 以下の書き方はあまり良くない --> <link type="text/css" rel="stylesheet" href="css/styles.css" /> <script type="text/javascript" src="js/scripts.js"></script> <!-- 以下のように記載するべき --> <link rel="stylesheet" href="css/styles.css" /> <script src="js/scripts.js"></script>
UseAltAttributeForImages
公式ドキュメント: UseAltAttributeForImages
Since: PMD 6.45.0
Priority: Medium (3)
Description:
画像には必ず alt
属性をつける。
代替テキストを提供し、スクリーンリーダーで広く使用される。
Configuration:
<rule ref="category/html/bestpractices.xml/UseAltAttributeForImages"/>
Example:
<!-- 以下の書き方はあまり良くない --> <img src="house.jpeg"> <!-- 以下のように記載するべき --> <img src="house.jpeg" alt="A house from the 18th century">