-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* White-paper table generator ### What's done: Wrote parser
- Loading branch information
Showing
11 changed files
with
447 additions
and
2,151 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/GenerationAvailableRules.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* This script paste available.rules.md and rules-mapping.md files to automatically generate table for White paper | ||
*/ | ||
|
||
@file:Suppress("FILE_NAME_MATCH_CLASS") | ||
|
||
package org.cqfn.diktat.ruleset.generation | ||
|
||
import org.cqfn.diktat.ruleset.utils.AUTO_END | ||
import org.cqfn.diktat.ruleset.utils.AUTO_TABLE | ||
|
||
import java.io.File | ||
|
||
fun main() { | ||
generateAvailableRules() | ||
} | ||
|
||
@Suppress("MagicNumber", "UnsafeCallOnNullableType") | ||
private fun generateAvailableRules() { | ||
val ruleMap = File("info/rules-mapping.md").readLines() | ||
.drop(2) | ||
.map { it.drop(1).dropLast(1).split("|") } | ||
.map { RuleDescription(it[0].replace("\\s+".toRegex(), ""), it[1], it[2]) } | ||
.associateBy { it.ruleName } | ||
File("info/available-rules.md").readLines() | ||
.drop(2) | ||
.map { it.drop(1).dropLast(1).split("|") } | ||
.map { it[2].replace("\\s+".toRegex(), "") to it[5] } | ||
.forEach { ruleMap[it.first]!!.config = it.second} | ||
val newText = File("wp/sections/appendix.tex").readLines().toMutableList() | ||
newText.removeAll(newText.subList(newText.indexOf("\\section*{available-rules}") + 1, newText.indexOf("\\section*{\\textbf{Diktat Coding Convention}}"))) | ||
var index = newText.indexOf("\\section*{available-rules}") + 1 | ||
AUTO_TABLE.trimIndent().lines().forEach { newText.add(index++, it) } | ||
ruleMap.map { it.value } | ||
.map { "${it.correctRuleName} & ${it.correctCodeStyle} & ${it.autoFix} & ${it.config.replace("<br>", " ")}\\\\" } | ||
.forEach { newText.add(index++, it) } | ||
AUTO_END.trimIndent().split("\n").forEach { newText.add(index++, it) } | ||
File("wp/sections/appendix.tex").writeText(newText.joinToString(separator = "\n")) | ||
} | ||
|
||
/** | ||
* Data class for rule and it's description | ||
* | ||
* @property ruleName rule's name | ||
* @property codeStyle rule's description | ||
* @property autoFix is rule can fix | ||
*/ | ||
@Suppress("UnsafeCallOnNullableType") | ||
data class RuleDescription(val ruleName: String, | ||
val codeStyle: String, | ||
val autoFix: String) { | ||
/** | ||
* Remove square brackets from code style | ||
*/ | ||
val correctCodeStyle = codeStyle.substring(codeStyle.indexOf("[") + 1, codeStyle.indexOf("]")) | ||
|
||
/** | ||
* Replace space between words with underline for Latex | ||
*/ | ||
val correctRuleName = ruleName.replace("_", "\\underline{ }") | ||
|
||
/** | ||
* Parse correctly configuration for Latex | ||
*/ | ||
lateinit var config: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e37b89b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:
Please, copy and paste this stack trace to GitHub: