Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

White-paper table generator #568

Merged
merged 12 commits into from
Dec 16, 2020
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ val TABLE_COLUMN_NAMES = Regex("""[A-Za-z ]*""") // used to find column names i
const val REGEX_PLACEHOLDER = "RE_PL_AC_E_ME"
@Suppress("CONSTANT_UPPERCASE")
const val A4_PAPER_WIDTH = 15f
const val AUTO_TABLE = """
\scriptsize
\begin{longtable}{ |l|p{0.8cm}|p{0.8cm}| p{3cm} | }
\hline
\multicolumn{4}{|c|}{Available Rules} \\
\hline
\textbf{diKTat rule} & \textbf{code style} & \textbf{autofix} & \textbf{config} \\
\hline
"""
const val AUTO_END = """
\hline
\end{longtable}
"""

/**
* Writes text on a new line and adds one blank line
Expand Down
216 changes: 108 additions & 108 deletions info/available-rules.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions info/rules-mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
| MISSING_KDOC_CLASS_ELEMENTS | [2.1.1](guide/diktat-coding-convention.md#r2.1.1) | no |
| MISSING_KDOC_ON_FUNCTION | [2.1.1](guide/diktat-coding-convention.md#r2.1.1) | yes |
| KDOC_NO_CONSTRUCTOR_PROPERTY | [2.1.1](guide/diktat-coding-convention.md#r2.1.1) | yes |
| KDOC_EXTRA_PROPERTY | [2.1.1](guide/diktat-coding-convention.md#r2.1.1) | no |
| KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT | [2.1.1](guide/diktat-coding-convention.md#r2.1.1) | yes |
| KDOC_WITHOUT_PARAM_TAG | [2.1.2](guide/diktat-coding-convention.md#r2.1.2) | yes |
| KDOC_WITHOUT_RETURN_TAG | [2.1.2](guide/diktat-coding-convention.md#r2.1.2) | yes |
Expand Down Expand Up @@ -105,3 +106,4 @@
| COMPACT_OBJECT_INITIALIZATION | [6.1.11](guide/diktat-coding-convention.md#r6.1.11) | yes |
| EXTENSION_FUNCTION_SAME_SIGNATURE | [6.2.2](guide/diktat-coding-convention.md#r6.2.2) | no |
| AVOID_USING_UTILITY_CLASS | [6.4.1](guide/diktat-coding-convention.md#r6.4.1) | no |
| OBJECT_IS_PREFERRED | [6.4.2](guide/diktat-coding-convention.md#r6.4.2) | yes |
Binary file added wp/pictures/package.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wp/pictures/sequence.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed wp/pictures/sequence.jpg
Binary file not shown.
Binary file added wp/pictures/useCase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,267 changes: 236 additions & 2,031 deletions wp/sections/appendix.tex

Large diffs are not rendered by default.

33 changes: 21 additions & 12 deletions wp/sections/feature.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
\subsection{Configuration file}
\par
It's worth starting with the configuration file. This is a file in which the user can manually turn rules on and off or configure the rules settings. Below is one of the rules in the configuration file.

kentr0w marked this conversation as resolved.
Show resolved Hide resolved

\begin{center}
\begin{tabular}{@{}l@{}}
name: FILE\underline{ }IS\underline{ }TOO\underline{ }LONG\\
\hspace{1cm}enabled: true\\
\hspace{1cm}configuration:\\
\hspace{2 cm}maxSize: '2000'\\
\hspace{2 cm}ignoreFolders: ' '\\
\end{tabular}
\end{center}

\\
\begin{lstlisting}[caption={Part of configuration file.},
label={lst:example1}, language=Kotlin]
- name: DIKTAT_COMMON
configuration:
# put your package name here - it will be autofixed and checked
domainName: your.name.here
- name: COMMENTED_OUT_CODE
enabled: true
- name: HEADER_MISSING_OR_WRONG_COPYRIGHT
enabled: true
configuration:
isCopyrightMandatory: true
copyrightText: 'Copyright (c) Your Company Name Here. 2010-2020'
testDirs: test
- name: FILE_IS_TOO_LONG
enabled: true
configuration:
maxSize: '2000'
ignoreFolders: ' '
\end{lstlisting}
Each rule in this file has 3 fields: name - the name of the rule, enabled - whether the rule is enabled or disabled (all rules are enabled by default), configuration - parameters for the rule. With the first two, everything is obvious. The third parameter is less obvious. The configuration is a set of "properties" to configure this rule. For example, for a rule "FILE\underline{ }IS\underline{ }TOO\underline{ }LONG", that checks the number of lines in a Kotlin file, the user can configure the maximum number of lines allowed in the file - by changing the "maxSize" in the configuration, or the user can specify paths to folders that do not need to be checked - by writing the path in "ignoreFolders". \\

\subsection{Create ASTNode}
Expand Down
1 change: 1 addition & 0 deletions wp/wp.tex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
\usepackage{verbatim}
\usepackage{cleveref}
\usepackage{datetime}
\usepackage{longtable}

\crefname{figure}{Figure}{Figures}
\usetikzlibrary{trees}
Expand Down