Skip to content

Instantly share code, notes, and snippets.

@hglattergotz
Last active January 24, 2024 17:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hglattergotz/82801f37ef78e8816cea7f9e3229998b to your computer and use it in GitHub Desktop.
Save hglattergotz/82801f37ef78e8816cea7f9e3229998b to your computer and use it in GitHub Desktop.
Example of how to customize the ShortVariable rule in PHP Mess Detector
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Custom Naming Rules"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
Customizations for the naming rule sets. Do not include the naming ruleset in the options.
This customization pulls all naming rules in and overrides some properties.
</description>
<rule ref="rulesets/naming.xml">
<!-- To be able to customize a property on the ShortVariable rule it must first be excluded.
Does not really make sense, but see https://github.com/phpmd/phpmd/issues/33 for details. -->
<exclude name="ShortVariable"/>
</rule>
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<!-- Add common variable names that should be excepted from the default minimum property value of 3 -->
<property name="exceptions" description="Comma-separated list of exceptions" value="id"/>
</properties>
</rule>
</ruleset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment