How to add a new dialect.
Table of Contents What is a dialect?A dialect is a particular form of another supported language. For example, an XSLT is a particular form of an XML. Even though the dialect has its own semantics and uses, the contents are still readable by any tool capable of understanding the base language.
In PMD, a dialect allows to set up completely custom rules, XPath functions, properties and metrics for these files; while retaining the full support of the underlying language. That means:
- All rules applicable to the base language are automatically applicable to all files processed as a dialect.
- All XPath functions existing in the base language are available when creating new rules.
- All metrics supported by the base language are available when creating new rules.
- All properties (ie: support to suppress literals in CPD) supported by the base language are supported by the dialect.
net.sourceforge.pmd.lang.impl.SimpleDialectLanguageModuleBase
, see XSL as an example: XslDialectModule
.LanguageMetadata.withId
name
extensions
addVersion
in your language moduleâs constructor. Use addDefaultVersion
for defining the default version.asDialectOf
to reference the base language by id.src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language
. Add your fully qualified class name as a single line into it.ViolationDecorator
s, to add additional dialect specific information to the created violations. The Java language module uses this to provide the method name or class name, where the violation occurred.BasePmdDialectLanguageVersionHandler
, and override the getter corresponding to what you want to extend. You donât need to worry about including anything from the base language, only include your extensions. PMD will take care of merging everything together.super
.AbstractXmlRule
. Note, that all rule classes should be suffixed with Rule
and should be placed in a package the corresponds to their dialect and category.externalInfoUrl
attribute of a rule. E.g. we use ${pmd.website.baseurl}
to point to the correct webpage (depending on the PMD version).PmdRuleTst
(see UnavailableFunctionTest
for example)category/swift/bestpractices.xml
for example)UnavailableFunction.xml
for example)To verify the validity of all the created rulesets, create a subclass of AbstractRuleSetFactoryTest
(see RuleSetFactoryTest
in pmd-swift for example). This will load all rulesets and verify, that all required attributes are provided.
Note: Youâll need to add your ruleset to categories.properties
, so that it can be found.
Finishing up your new dialect by adding a page in the documentation. Create a new markdown file <langId>.md
in docs/pages/pmd/languages/
. This file should have the following frontmatter:
---
title: <Language Name>
permalink: pmd_languages_<langId>.html
last_updated: <Month> <Year> (<PMD Version>)
tags: [languages, PmdCapableLanguage, CpdCapableLanguage]
---
On this page, language specifics can be documented, e.g. when the language was first supported by PMD. There is also the following Jekyll Include, that creates summary box for the language:
{% include language_info.html name='<Language Name>' id='<langId>' implementation='<langId>::lang.<langId>.<langId>LanguageModule' supports_cpd=true supports_pmd=true since='<PMD Version>' %}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4