@@ -6,7 +6,6 @@ plugins {
6
6
id(" io.codemodder.java" )
7
7
}
8
8
9
-
10
9
/* *
11
10
* This task generates markdown documentation for all codemods in the core-codemods project.
12
11
*
@@ -19,17 +18,17 @@ val generateDocs by tasks.registering {
19
18
group = " custom"
20
19
description = " generate markdown docs for all codemods"
21
20
22
- if (! project.properties.containsKey(" codemodDocsDir" )) {
21
+ if (! project.properties.containsKey(" codemodDocsDir" )) {
23
22
throw IllegalArgumentException (" codemodDocsDir property is required" )
24
23
}
25
24
26
25
val codemodDocsDir = file(project.properties[" codemodDocsDir" ]!! )
27
26
println (" Using docs directory: $codemodDocsDir " )
28
- if (! codemodDocsDir.exists()) {
27
+ if (! codemodDocsDir.exists()) {
29
28
throw IllegalArgumentException (" codemodDocsDir does not exist" )
30
29
}
31
30
32
- if (codemodDocsDir.list().isEmpty()) {
31
+ if (codemodDocsDir.list().isEmpty()) {
33
32
println (" Docs directory was empty" )
34
33
}
35
34
@@ -43,7 +42,7 @@ val generateDocs by tasks.registering {
43
42
val codemodName = codemodFile.nameWithoutExtension
44
43
45
44
// check if it's in the DefaultCodemods list -- we don't do docs for the others
46
- if (! defaultCodemodSource.contains(codemodName)) {
45
+ if (! defaultCodemodSource.contains(codemodName)) {
47
46
println (" Skipping $codemodName " )
48
47
continue
49
48
} else {
@@ -70,15 +69,15 @@ val generateDocs by tasks.registering {
70
69
.asStringLiteralExpr()
71
70
.value
72
71
73
- val fileName = id.replace(" :" ," _" ).replace(" /" , " _" ) + " .md"
72
+ val fileName = id.replace(" :" , " _" ).replace(" /" , " _" ) + " .md"
74
73
75
74
val importance = annotationParameters.stream()
76
- .filter { it.nameAsString == " importance" }
77
- .findFirst()
78
- .get()
79
- .value
80
- .asFieldAccessExpr()
81
- .nameAsString
75
+ .filter { it.nameAsString == " importance" }
76
+ .findFirst()
77
+ .get()
78
+ .value
79
+ .asFieldAccessExpr()
80
+ .nameAsString
82
81
83
82
val mergeGuidance = annotationParameters.stream()
84
83
.filter { it.nameAsString == " reviewGuidance" }
@@ -98,19 +97,19 @@ val generateDocs by tasks.registering {
98
97
99
98
// add the scanning tool to the summary
100
99
var needsScanningTool = " No"
101
- if (id.startsWith(" sonar" )) {
100
+ if (id.startsWith(" sonar" )) {
102
101
needsScanningTool = " Yes (Sonar)"
103
- } else if (id.startsWith(" codeql" )) {
102
+ } else if (id.startsWith(" codeql" )) {
104
103
needsScanningTool = " Yes (CodeQL)"
105
- } else if (id.startsWith(" semgrep" )) {
104
+ } else if (id.startsWith(" semgrep" )) {
106
105
needsScanningTool = " Yes (Semgrep)"
107
106
}
108
107
109
108
// get the merge advice
110
109
var mergeGuidanceStr = " Merge After Review"
111
- if (mergeGuidance == " ReviewGuidance.MERGE_WITHOUT_REVIEW" ) {
110
+ if (mergeGuidance == " ReviewGuidance.MERGE_WITHOUT_REVIEW" ) {
112
111
mergeGuidanceStr = " Merge Without Review"
113
- } else if (mergeGuidance == " ReviewGuidance.MERGE_AFTER_CURSORY_REVIEW" ) {
112
+ } else if (mergeGuidance == " ReviewGuidance.MERGE_AFTER_CURSORY_REVIEW" ) {
114
113
mergeGuidanceStr = " Merge After Cursory Review"
115
114
}
116
115
@@ -137,35 +136,35 @@ val generateDocs by tasks.registering {
137
136
|-------------|----------------------|------------------------|
138
137
| $importance | $mergeGuidanceStr | $needsScanningTool |
139
138
140
- """ .trimIndent()
139
+ """ .trimIndent()
141
140
142
141
doc + = " \n $description \n "
143
142
144
143
val hasFaq = mergeGuidanceJustification != null || faqs != null
145
144
146
- if (hasFaq) {
145
+ if (hasFaq) {
147
146
doc + = " ## F.A.Q.\n\n "
148
147
}
149
148
150
- if (mergeGuidanceJustification != null ) {
149
+ if (mergeGuidanceJustification != null ) {
151
150
doc + = " ### Why is this codemod marked as $mergeGuidanceStr ?\n\n "
152
151
doc + = " $mergeGuidanceJustification \n\n "
153
152
}
154
153
155
- if (faqs != null ) {
154
+ if (faqs != null ) {
156
155
faqs as List <Map <String , String >>
157
- for (faq in faqs) {
156
+ for (faq in faqs) {
158
157
doc + = """
159
158
### ${faq[" question" ]}
160
159
161
160
${faq[" answer" ]}
162
161
163
- """ .trimIndent()
162
+ """ .trimIndent()
164
163
doc + = " \n "
165
164
}
166
165
}
167
166
168
- doc + = " \n ## References\n "
167
+ doc + = " \n ## References\n "
169
168
doc + = referencesStr
170
169
doc + = " \n " // file editors like a trailing newline
171
170
codemodDocsFile.writeText(doc)
0 commit comments