Skip to content

Commit a09e56b

Browse files
author
Prabha Kylasamiyer Sundara Rajan
committed
MTA-5290 Modularized Rule Development Guide
Signed-off-by: Prabha Kylasamiyer Sundara Rajan <[email protected]>
1 parent 927b9e6 commit a09e56b

File tree

57 files changed

+1538
-733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1538
-733
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
:_newdoc-version: 2.18.3
2+
:_template-generated: 2025-05-28
3+
4+
ifdef::context[:parent-context-of-creating-rule: {context}]
5+
6+
:_mod-docs-content-type: ASSEMBLY
7+
8+
ifndef::context[]
9+
[id="creating-rule"]
10+
endif::[]
11+
ifdef::context[]
12+
[id="creating-rule_{context}"]
13+
endif::[]
14+
= Creating custom rules
15+
16+
:context: creating-rule
17+
18+
[role="_abstract"]
19+
You can refer to example rules that describe how to create a YAML rule. This assumes that you already have MTA installed. See the MTA CLI Guide for installation instructions.
20+
21+
//This section describes how to create a {ProductShortName} YAML rule. This assumes that you already have {ProductShortName} installed. See the {ProductShortName} {ProductDocUserGuideURL}[_{UserCLIBookName}_] for installation instructions.//
22+
23+
include::topics/rules-development/create-basic-yaml-rule-template.adoc[leveloffset=+1]
24+
25+
include::topics/rules-development/create-first-yaml-rule.adoc[leveloffset=+1]
26+
27+
include::topics/rules-development/create-go-custom-rule.adoc[leveloffset=+1]
28+
29+
include::topics/rules-development/create-nodejs-custom-rule.adoc[leveloffset=+1]
30+
31+
include::topics/rules-development/create-python-custom-rule.adoc[leveloffset=+1]
32+
33+
34+
ifdef::parent-context-of-creating-rule[:context: {parent-context-of-creating-rule}]
35+
ifndef::parent-context-of-creating-rule[:!context:]
36+
37+
:!creating-rule:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
:_newdoc-version: 2.18.3
2+
:_template-generated: 2025-05-28
3+
4+
ifdef::context[:parent-context-of-java-conditions-capabilities: {context}]
5+
6+
:_mod-docs-content-type: ASSEMBLY
7+
8+
ifndef::context[]
9+
[id="java-conditions-capabilities"]
10+
endif::[]
11+
ifdef::context[]
12+
[id="java-conditions-capabilities_{context}"]
13+
endif::[]
14+
= Java condition and capabilities
15+
16+
:context: java-conditions-capabilities
17+
18+
[role="_abstract"]
19+
The `java.referenced` capability in the when condition for Java rules can define search queries for the following fields in the source code:
20+
21+
* Locations - such as the classes, methods, packages and so on
22+
* Annotations
23+
* Patterns
24+
25+
You can refer to this section for a detailed explanation on the Locations, Annotations, and Patterns.
26+
27+
include::topics/rules-development/yaml-java-locations.adoc[leveloffset=+1]
28+
29+
include::topics/rules-development/yaml-annotation-inspection.adoc[leveloffset=+1]
30+
31+
include::topics/rules-development/yaml-condition-patterns.adoc[leveloffset=+1]
32+
33+
ifdef::parent-context-of-rule-java-conditions-capabilities[:context: {parent-context-of-rule-java-conditions-capabilities}]
34+
ifndef::parent-context-of-rule-java-conditions-capabilities[:!context:]
35+
36+
:!java-conditions-capabilities:
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
:_newdoc-version: 2.18.3
2+
:_template-generated: 2025-05-28
3+
4+
ifdef::context[:parent-context-of-logical-chaining-custom-variables: {context}]
5+
6+
:_mod-docs-content-type: ASSEMBLY
7+
8+
ifndef::context[]
9+
[id="logical-chaining-custom-variables"]
10+
endif::[]
11+
ifdef::context[]
12+
[id="logical-chaining-custom-variables_{context}"]
13+
endif::[]
14+
= Logical conditions, condition chaining, and custom variables
15+
16+
:context: logical-chaining-custom-variables
17+
18+
[role="_abstract"]
19+
You can create complex conditions in rules by using the following:
20+
21+
* Logical conditions inform the provider how to handle more than one condition in a when block. You can aggregate or filter conditions using logical operations.
22+
* Condition chaining uses the output of one condition as the input in another condition of the when block. Assign the output to a variable in one condition and reuse it in other conditions in the when block.
23+
* Nested conditions to create conditions that depend on the evaluation of other conditions.
24+
* Custom variables to capture specific information from the code that is evaluated by a rule. You can use the custom variable in the message displayed for the code if it contains a violation defined by the rule.
25+
26+
include::topics/rules-development/yaml-logical-conditions.adoc[leveloffset=+1]
27+
28+
include::topics/rules-development/yaml-and-condition.adoc[leveloffset=+1]
29+
30+
include::topics/rules-development/yaml-or-condition.adoc[leveloffset=+1]
31+
32+
include::topics/rules-development/yaml-chaining-condition-variables.adoc[leveloffset=+1]
33+
34+
include::topics/rules-development/yaml-chaining-java-provider.adoc[leveloffset=+1]
35+
36+
include::topics/rules-development/yaml-nested-condition.adoc[leveloffset=+1]
37+
38+
include::topics/rules-development/yaml-custom-variables.adoc[leveloffset=+1]
39+
40+
ifdef::parent-context-of-rule-logical-chaining-custom-variables[:context: {parent-context-of-rule-logical-chaining-custom-variables}]
41+
ifndef::parent-context-of-rule-logical-chaining-custom-variables[:!context:]
42+
43+
:!logical-chaining-custom-variables:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
:_newdoc-version: 2.18.3
2+
:_template-generated: 2025-05-28
3+
4+
ifdef::context[:parent-context-of-rule-rulesets: {context}]
5+
6+
:_mod-docs-content-type: ASSEMBLY
7+
8+
ifndef::context[]
9+
[id="rule-rulesets"]
10+
endif::[]
11+
ifdef::context[]
12+
[id="rule-rulesets_{context}"]
13+
endif::[]
14+
= Rulesets
15+
16+
:context: rule-rulesets
17+
18+
[role="_abstract"]
19+
A set of rules forms a ruleset. MTA does not require every rule file to belong to a ruleset, but you can use rulesets to group multiple rules that achieve a common goal and to pass the rules to the rules engine.
20+
21+
To use multiple rule files, you need to place them in a directory and to add a ruleset.yaml file. Then the directory is treated as a ruleset, and you can pass it as input to the `--rules` option.
22+
Note that if you want to use the `--target` or `--source` option in the CLI, the engine will only select rules that match the label for that target. Therefore, make sure that you have added target or source labels on your rules. See xref:reserved-label_rule-yaml-metadata[Reserved labels] for more details.
23+
24+
include::topics/rules-development/yaml-rulesets.adoc[leveloffset=+1]
25+
26+
ifdef::parent-context-of-rule-rulesets[:context: {parent-context-of-rule-rulesets}]
27+
ifndef::parent-context-of-rule-rulesets[:!context:]
28+
29+
:!rule-rulesets:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
:_newdoc-version: 2.18.3
2+
:_template-generated: 2025-05-28
3+
4+
ifdef::context[:parent-context-of-rule-yaml-actions: {context}]
5+
6+
:_mod-docs-content-type: ASSEMBLY
7+
8+
ifndef::context[]
9+
[id="rule-yaml-actions"]
10+
endif::[]
11+
ifdef::context[]
12+
[id="rule-yaml-actions_{context}"]
13+
endif::[]
14+
= Rule actions
15+
16+
:context: rule-yaml-actions
17+
18+
[role="_abstract"]
19+
You can use rule actions to generate information about the source code. The rule action information can be included in a violation or used to categorize the source code.
20+
21+
Rules can include the following types of actions:
22+
23+
* `Message`: use message action to display an informative message in the static report that contains the violation triggered by the rule. See xref:yaml-message-actions_rule-yaml-actions[Message action] for more information.
24+
* `Tag`: use tags to categorize parts of the source code. For example, Backend=Java, where Backend is the key and Java is the value. See xref:yaml-tag-actions_rule-yaml-actions[Tag actions] for more information.
25+
Each rule includes either one of them or both of them.
26+
27+
include::topics/rules-development/yaml-tag-actions.adoc[leveloffset=+1]
28+
29+
include::topics/rules-development/yaml-message-actions.adoc[leveloffset=+1]
30+
31+
include::topics/rules-development/yaml-rule-hyperlinks.adoc[leveloffset=+1]
32+
33+
ifdef::parent-context-of-rule-yaml-actions[:context: {parent-context-of-rule-yaml-actions}]
34+
ifndef::parent-context-of-rule-yaml-actions[:!context:]
35+
36+
:!rule-yaml-actions:
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
:_newdoc-version: 2.18.3
2+
:_template-generated: 2025-05-28
3+
4+
ifdef::context[:parent-context-of-rule-provider-conditions: {context}]
5+
6+
:_mod-docs-content-type: ASSEMBLY
7+
8+
ifndef::context[]
9+
[id="rule-provider-conditions"]
10+
endif::[]
11+
ifdef::context[]
12+
[id="rule-provider-conditions_{context}"]
13+
endif::[]
14+
= Providers and rule conditions
15+
16+
:context: rule-provider-conditions
17+
18+
[role="_abstract"]
19+
The providers are the modular components in charge of analyzing a given language. Providers are able to analyze code by leveraging the Language Server Protocol (LSP). Through the LSP, all code analysis is abstracted away from the analysis engine and left to the specific LSP server to run the search query defined in the rule on the source code.
20+
21+
Additionally, {ProductShortName} provides a built-in provider with abilities such as XML parsing, running regular expressions on files, and so on.
22+
23+
Currently, {ProductShortName} supports the following providers:
24+
25+
* Builtin
26+
* Java
27+
* Go
28+
* External providers (for `Python`, `Dotnet` and `Node.js` applications) initialized by the generic provider binary
29+
30+
[NOTE]
31+
====
32+
You can use the generic provider binary to create an external provider for any language that is compliant with link:https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/[LSP 3.17 specifications].
33+
====
34+
35+
.Using the provider capability in custom rules
36+
37+
In a rule, the when block is where the conditions for matching the rule are specified. Each provider offers a series of capabilities to do matching.. The search query in the rule condition can contain patterns, code locations, specific dependencies to be found, etc, to evaluate the source code and dependencies. The provider sends the LSP server a request to check the search query against the application being analyzed. When the LSP server returns a match for the search in the source code, the analyzer triggers a violation.
38+
39+
The syntax for the when block is as follows: contains one condition, but that condition can have multiple conditions nested under it.
40+
41+
----
42+
when:
43+
<condition>
44+
<nested-condition>
45+
----
46+
47+
include::topics/rules-development/yaml-provider-conditions.adoc[leveloffset=+1]
48+
49+
include::topics/rules-development/yaml-builtin-provider.adoc[leveloffset=+1]
50+
51+
include::topics/rules-development/yaml-java-provider.adoc[leveloffset=+1]
52+
53+
include::topics/rules-development/yaml-go-provider.adoc[leveloffset=+1]
54+
55+
include::topics/rules-development/yaml-dotnet-provider.adoc[leveloffset=+1]
56+
57+
ifdef::parent-context-of-rule-provider-conditions[:context: {parent-context-of-rule-provider-conditions}]
58+
ifndef::parent-context-of-rule-provider-conditions[:!context:]
59+
60+
:!rule-provider-conditions:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
:_newdoc-version: 2.18.3
2+
:_template-generated: 2025-05-28
3+
4+
ifdef::context[:parent-context-of-rule-yaml-metadata: {context}]
5+
6+
:_mod-docs-content-type: ASSEMBLY
7+
8+
ifndef::context[]
9+
[id="rule-yaml-metadata"]
10+
endif::[]
11+
ifdef::context[]
12+
[id="rule-yaml-metadata_{context}"]
13+
endif::[]
14+
= Rule metadata
15+
16+
:context: rule-yaml-metadata
17+
18+
[role="_abstract"]
19+
The rule metadata contains information about the migration defined by the Architect. You can use rule metadata to:
20+
21+
* Estimate the total migration effort
22+
* Prioritize issues that must be resolved based on the effort
23+
* Evaluate if a resolution is mandatory through rule category before migrating the applications to the target technologies or platforms
24+
* Define labels for which {ProductShortName} filters rules to trigger a violation.
25+
26+
27+
include::topics/rules-development/yaml-rule-metadata.adoc[leveloffset=+1]
28+
29+
include::topics/rules-development/yaml-rule-labels.adoc[leveloffset=+1]
30+
31+
include::topics/rules-development/yaml-rule-categories.adoc[leveloffset=+1]
32+
33+
ifdef::parent-context-of-rule-yaml-metadata[:context: {parent-context-of-rule-yaml-metadata}]
34+
ifndef::parent-context-of-rule-yaml-metadata[:!context:]
35+
36+
:!rule-yaml-metadata:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
:_newdoc-version: 2.18.3
2+
:_template-generated: 2025-05-28
3+
4+
ifdef::context[:parent-context-of-rules-introduction: {context}]
5+
6+
:_mod-docs-content-type: ASSEMBLY
7+
8+
ifndef::context[]
9+
[id="rules-introduction"]
10+
endif::[]
11+
ifdef::context[]
12+
[id="rules-introduction_{context}"]
13+
endif::[]
14+
= Introduction to rules
15+
16+
:context: rules-introduction
17+
18+
[role="_abstract"]
19+
This guide is intended for software engineers who want to create custom YAML-based rules for {ProductName} ({ProductShortName}) tools.
20+
21+
See the link:{ProductDocIntroToMTAGuideURL}[_{IntroToMTABookName}_] for an overview and the link:{ProductDocUserGuideURL}[_{UserCLIBookName}_] for details.
22+
23+
include::topics/rules-development/about-rules.adoc[leveloffset=+1]
24+
25+
include::topics/rules-development/yaml-rule-structure-syntax.adoc[leveloffset=+1]
26+
27+
ifdef::parent-context-of-getting-started[:context: {parent-context-of-rules-introduction}]
28+
ifndef::parent-context-of-getting-started[:!context:]
29+
30+
:!rules-introduction:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../docs/topics/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../assemblies/

0 commit comments

Comments
 (0)