Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/kdoc-to-block-comments' …
Browse files Browse the repository at this point in the history
…into feature/kdoc-to-block-comments
  • Loading branch information
icemachined committed Jun 7, 2022
2 parents 781553e + 969fff0 commit 524acba
Show file tree
Hide file tree
Showing 102 changed files with 1,542 additions and 1,409 deletions.
99 changes: 99 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
[*]
charset = utf-8
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 180
tab_width = 4
trim_trailing_whitespace = true
ij_continuation_indent_size = 8
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = true
ij_smart_tabs = false
ij_visual_guides = 80,120,180
ij_wrap_on_typing = false

[{*.kt,*.kts}]
ij_kotlin_align_in_columns_case_branch = false
ij_kotlin_align_multiline_binary_operation = false
ij_kotlin_align_multiline_extends_list = false
ij_kotlin_align_multiline_method_parentheses = false
ij_kotlin_align_multiline_parameters = true
ij_kotlin_align_multiline_parameters_in_calls = false
ij_kotlin_allow_trailing_comma = false
ij_kotlin_allow_trailing_comma_on_call_site = false
ij_kotlin_assignment_wrap = normal
ij_kotlin_blank_lines_after_class_header = 0
ij_kotlin_blank_lines_around_block_when_branches = 0
ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1
ij_kotlin_block_comment_add_space = false
ij_kotlin_block_comment_at_first_column = true
ij_kotlin_call_parameters_new_line_after_left_paren = true
ij_kotlin_call_parameters_right_paren_on_new_line = true
ij_kotlin_call_parameters_wrap = on_every_item
ij_kotlin_catch_on_new_line = false
ij_kotlin_class_annotation_wrap = split_into_lines
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
ij_kotlin_continuation_indent_for_chained_calls = false
ij_kotlin_continuation_indent_for_expression_bodies = false
ij_kotlin_continuation_indent_in_argument_lists = false
ij_kotlin_continuation_indent_in_elvis = false
ij_kotlin_continuation_indent_in_if_conditions = false
ij_kotlin_continuation_indent_in_parameter_lists = false
ij_kotlin_continuation_indent_in_supertype_lists = false
ij_kotlin_else_on_new_line = false
ij_kotlin_enum_constants_wrap = off
ij_kotlin_extends_list_wrap = normal
ij_kotlin_field_annotation_wrap = split_into_lines
ij_kotlin_finally_on_new_line = false
ij_kotlin_if_rparen_on_new_line = true
ij_kotlin_import_nested_classes = false
ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^
ij_kotlin_insert_whitespaces_in_simple_one_line_method = true
ij_kotlin_keep_blank_lines_before_right_brace = 2
ij_kotlin_keep_blank_lines_in_code = 2
ij_kotlin_keep_blank_lines_in_declarations = 2
ij_kotlin_keep_first_column_comment = true
ij_kotlin_keep_indents_on_empty_lines = false
ij_kotlin_keep_line_breaks = true
ij_kotlin_lbrace_on_next_line = false
ij_kotlin_line_comment_add_space = false
ij_kotlin_line_comment_add_space_on_reformat = false
ij_kotlin_line_comment_at_first_column = true
ij_kotlin_method_annotation_wrap = split_into_lines
ij_kotlin_method_call_chain_wrap = normal
ij_kotlin_method_parameters_new_line_after_left_paren = true
ij_kotlin_method_parameters_right_paren_on_new_line = true
ij_kotlin_method_parameters_wrap = on_every_item
ij_kotlin_name_count_to_use_star_import = 5
ij_kotlin_name_count_to_use_star_import_for_members = 3
ij_kotlin_packages_to_use_import_on_demand = java.util.*,kotlinx.android.synthetic.**,io.ktor.**
ij_kotlin_parameter_annotation_wrap = off
ij_kotlin_space_after_comma = true
ij_kotlin_space_after_extend_colon = true
ij_kotlin_space_after_type_colon = true
ij_kotlin_space_before_catch_parentheses = true
ij_kotlin_space_before_comma = false
ij_kotlin_space_before_extend_colon = true
ij_kotlin_space_before_for_parentheses = true
ij_kotlin_space_before_if_parentheses = true
ij_kotlin_space_before_lambda_arrow = true
ij_kotlin_space_before_type_colon = false
ij_kotlin_space_before_when_parentheses = true
ij_kotlin_space_before_while_parentheses = true
ij_kotlin_spaces_around_additive_operators = true
ij_kotlin_spaces_around_assignment_operators = true
ij_kotlin_spaces_around_equality_operators = true
ij_kotlin_spaces_around_function_type_arrow = true
ij_kotlin_spaces_around_logical_operators = true
ij_kotlin_spaces_around_multiplicative_operators = true
ij_kotlin_spaces_around_range = false
ij_kotlin_spaces_around_relational_operators = true
ij_kotlin_spaces_around_unary_operator = false
ij_kotlin_spaces_around_when_arrow = true
ij_kotlin_variable_annotation_wrap = off
ij_kotlin_while_on_new_line = false
ij_kotlin_wrap_elvis_expressions = 1
ij_kotlin_wrap_expression_body_functions = 1
ij_kotlin_wrap_first_method_in_call_chain = false
4 changes: 2 additions & 2 deletions diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
# If true: if first parameter in parameter list is on the same line as opening parenthesis, then other parameters can be aligned with it
alignedParameters: true
# If true: if expression is split by newline after operator like +/-/`*`, then the next line is indented with two indentations instead of one
extendedIndentAfterOperators: true
extendedIndentAfterOperators: false
# If true: when dot qualified expression starts on a new line, this line will be indented with two indentations instead of one
extendedIndentBeforeDot: false
# The indentation size for each file
Expand Down Expand Up @@ -530,4 +530,4 @@
enabled: true
# Only properties from the primary constructor should be documented in a @property tag in class KDoc
- name: KDOC_NO_CLASS_BODY_PROPERTIES_IN_HEADER
enabled: true
enabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class JsonResourceConfigReader<T> {
* @return [BufferedReader] representing loaded resource
*/
protected open fun getConfigFile(resourceFileName: String): BufferedReader? =
classLoader.getResourceAsStream(resourceFileName)?.bufferedReader()
classLoader.getResourceAsStream(resourceFileName)?.bufferedReader()

/**
* you can specify your own parser, in example for parsing stream as a json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ fun List<RulesConfig>.isRuleEnabled(rule: Rule): Boolean {
* @return true if the code block is marked with annotation that is in `ignored list` in the rule
*/
fun List<RulesConfig>.isAnnotatedWithIgnoredAnnotation(rule: Rule, annotations: Set<String>): Boolean =
getRuleConfig(rule)
?.ignoreAnnotated
?.map { it.trim() }
?.map { it.trim('"') }
?.intersect(annotations)
?.isNotEmpty()
?: false
getRuleConfig(rule)
?.ignoreAnnotated
?.map { it.trim() }
?.map { it.trim('"') }
?.intersect(annotations)
?.isNotEmpty()
?: false

/**
* Parse string into KotlinVersion
Expand Down
2 changes: 1 addition & 1 deletion diktat-common/src/test/resources/test-rules-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
newlineAtEnd: true
extendedIndentOfParameters: false
alignedParameters: true
extendedIndentAfterOperators: true
extendedIndentAfterOperators: false
indentationSize: 4
- name: EMPTY_BLOCK_STRUCTURE_ERROR
enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ open class DiktatJavaExecTaskBase @Inject constructor(

@Suppress("MagicNumber")
private fun isMainClassPropertySupported(gradleVersionString: String) =
GradleVersion.version(gradleVersionString) >= GradleVersion.version("6.4")
GradleVersion.version(gradleVersionString) >= GradleVersion.version("6.4")

private fun MutableList<String>.addInput(file: File) {
add(file.toRelativeString(project.projectDir))
Expand Down Expand Up @@ -226,7 +226,7 @@ open class DiktatJavaExecTaskBase @Inject constructor(
}

private fun getJavaExecJvmVersion(): JavaVersion = if (GradleVersion.version(gradleVersionString) >= GradleVersion.version("6.7") &&
javaLauncher.isPresent
javaLauncher.isPresent
) {
// Java Launchers are available since 6.7, but may not always be configured
javaLauncher.map { it.metadata.jvmVersion }.map(JavaVersion::toVersion).get()
Expand All @@ -247,10 +247,10 @@ fun Project.registerDiktatCheckTask(diktatExtension: DiktatExtension,
diktatConfiguration: Configuration,
patternSet: PatternSet
): TaskProvider<DiktatJavaExecTaskBase> =
tasks.register(
DIKTAT_CHECK_TASK, DiktatJavaExecTaskBase::class.java, gradle.gradleVersion,
diktatExtension, diktatConfiguration, patternSet
)
tasks.register(
DIKTAT_CHECK_TASK, DiktatJavaExecTaskBase::class.java, gradle.gradleVersion,
diktatExtension, diktatConfiguration, patternSet
)

/**
* @param diktatExtension [DiktatExtension] with some values for task configuration
Expand All @@ -262,7 +262,7 @@ fun Project.registerDiktatFixTask(diktatExtension: DiktatExtension,
diktatConfiguration: Configuration,
patternSet: PatternSet
): TaskProvider<DiktatJavaExecTaskBase> =
tasks.register(
DIKTAT_FIX_TASK, DiktatJavaExecTaskBase::class.java, gradle.gradleVersion,
diktatExtension, diktatConfiguration, patternSet, listOf("-F ")
)
tasks.register(
DIKTAT_FIX_TASK, DiktatJavaExecTaskBase::class.java, gradle.gradleVersion,
diktatExtension, diktatConfiguration, patternSet, listOf("-F ")
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ class KotlinClosure1<in T : Any?, V : Any>(
"KDOC_WITHOUT_RETURN_TAG"
)
fun <T> Any.closureOf(action: T.() -> Unit): Closure<Any?> =
KotlinClosure1(action, this, this)
KotlinClosure1(action, this, this)
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ abstract class DiktatBaseMojo : AbstractMojo() {
throw MojoExecutionException("Configuration file $diktatConfigFile doesn't exist")
}
log.info("Running diKTat plugin with configuration file $configFile and inputs $inputs" +
if (excludes.isNotEmpty()) " and excluding $excludes" else ""
if (excludes.isNotEmpty()) " and excluding $excludes" else ""
)

val ruleSets by lazy {
Expand Down Expand Up @@ -236,24 +236,24 @@ abstract class DiktatBaseMojo : AbstractMojo() {
) {
val text = file.readText()
val params =
KtLint.ExperimentalParams(
fileName = file.relativeTo(mavenProject.basedir).path,
text = text,
ruleSets = ruleSets,
userData = mapOf("file_path" to file.path),
script = file.extension.equals("kts", ignoreCase = true),
cb = { lintError, isCorrected ->
if (baselineErrors.none {
// ktlint's BaselineReporter stores only these fields
it.line == lintError.line && it.col == lintError.col &&
it.ruleId == lintError.ruleId
}) {
reporterImpl.onLintError(file.path, lintError, isCorrected)
lintErrors.add(lintError)
}
},
debug = debug
)
KtLint.ExperimentalParams(
fileName = file.relativeTo(mavenProject.basedir).path,
text = text,
ruleSets = ruleSets,
userData = mapOf("file_path" to file.path),
script = file.extension.equals("kts", ignoreCase = true),
cb = { lintError, isCorrected ->
if (baselineErrors.none {
// ktlint's BaselineReporter stores only these fields
it.line == lintError.line && it.col == lintError.col &&
it.ruleId == lintError.ruleId
}) {
reporterImpl.onLintError(file.path, lintError, isCorrected)
lintErrors.add(lintError)
}
},
debug = debug
)
runAction(params)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fun Warnings.isRuleFromActiveChapter(configRules: List<RulesConfig>): Boolean {
fun Warnings.getChapterByWarning() = Chapters.values().find { it.number == this.ruleId.first().toString() }!!

private fun validate(chapter: String) =
require(chapter in Chapters.values().map { it.title }) {
val closestMatch = Chapters.values().minByOrNull { Levenshtein.distance(it.title, chapter) }
"Chapter name <$chapter> in configuration file is invalid, did you mean <$closestMatch>?"
}
require(chapter in Chapters.values().map { it.title }) {
val closestMatch = Chapters.values().minByOrNull { Levenshtein.distance(it.title, chapter) }
"Chapter name <$chapter> in configuration file is invalid, did you mean <$closestMatch>?"
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ enum class Warnings(
NO_BRACES_IN_CONDITIONALS_AND_LOOPS(true, "3.2.1", "in if, else, when, for, do, and while statements braces should be used. Exception: single line if statement."),
WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES(true, "3.1.4", "the declaration part of a class-like code structures (class/interface/etc.) should be in the proper order"),
BLANK_LINE_BETWEEN_PROPERTIES(true, "3.1.4", "there should be no blank lines between properties without comments; comment, KDoc or annotation on property should have blank" +
" line before"),
" line before"),
TOP_LEVEL_ORDER(true, "3.1.5", "the declaration part of a top level elements should be in the proper order"),
BRACES_BLOCK_STRUCTURE_ERROR(true, "3.2.2", "braces should follow 1TBS style"),
WRONG_INDENTATION(true, "3.3.1", "only spaces are allowed for indentation and each indentation should equal to 4 spaces (tabs are not allowed)"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import kotlin.io.path.writeLines
* The comment that will be added to the generated sources file.
*/
private val autoGenerationComment =
"""
| This document was auto generated, please don't modify it.
| This document contains all enum properties from Warnings.kt as Strings.
""".trimMargin()
"""
| This document was auto generated, please don't modify it.
| This document contains all enum properties from Warnings.kt as Strings.
""".trimMargin()

fun main() {
generateWarningNames()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ abstract class DiktatRule(
}

private fun areInspectionsDisabled(): Boolean =
inspections.none { configRules.isRuleEnabled(it) }
inspections.none { configRules.isRuleEnabled(it) }

/**
* Logic of the rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,20 @@ class DiktatRuleSetProvider(private var diktatConfigFile: String = DIKTAT_ANALYS
)
override fun get(): RuleSet {
log.debug("Will run $DIKTAT_RULE_SET_ID with $diktatConfigFile" +
" (it can be placed to the run directory or the default file from resources will be used)")
" (it can be placed to the run directory or the default file from resources will be used)")
val configPath = possibleConfigs
.firstOrNull { it != null && File(it).exists() }
diktatConfigFile = configPath
?: run {
val possibleConfigsList = possibleConfigs.toList()
log.warn(
"Configuration file not found in directory where diktat is run (${possibleConfigsList[0]}) " +
"or in the directory where diktat.jar is stored (${possibleConfigsList[1]}) " +
"or in system property <diktat.config.path> (${possibleConfigsList[2]}), " +
"the default file included in jar will be used. " +
"Some configuration options will be disabled or substituted with defaults. " +
"Custom configuration file should be placed in diktat working directory if run from CLI " +
"or provided as configuration options in plugins."
"or in the directory where diktat.jar is stored (${possibleConfigsList[1]}) " +
"or in system property <diktat.config.path> (${possibleConfigsList[2]}), " +
"the default file included in jar will be used. " +
"Some configuration options will be disabled or substituted with defaults. " +
"Custom configuration file should be placed in diktat working directory if run from CLI " +
"or provided as configuration options in plugins."
)
diktatConfigFile
}
Expand Down Expand Up @@ -241,23 +241,23 @@ class DiktatRuleSetProvider(private var diktatConfigFile: String = DIKTAT_ANALYS
}

private fun validate(config: RulesConfig) =
require(config.name == DIKTAT_COMMON || config.name in Warnings.names) {
val closestMatch = Warnings.names.minByOrNull { Levenshtein.distance(it, config.name) }
"Warning name <${config.name}> in configuration file is invalid, did you mean <$closestMatch>?"
}
require(config.name == DIKTAT_COMMON || config.name in Warnings.names) {
val closestMatch = Warnings.names.minByOrNull { Levenshtein.distance(it, config.name) }
"Warning name <${config.name}> in configuration file is invalid, did you mean <$closestMatch>?"
}

private fun resolveDefaultConfig() = diktatConfigFile

private fun resolveConfigFileFromJarLocation(): String {
// for some aggregators of static analyzers we need to provide configuration for cli
// in this case diktat would take the configuration from the directory where jar file is stored
val ruleSetProviderPath =
DiktatRuleSetProvider::class
.java
.protectionDomain
.codeSource
.location
.toURI()
DiktatRuleSetProvider::class
.java
.protectionDomain
.codeSource
.location
.toURI()

val configPathWithFileName = File(ruleSetProviderPath).absolutePath

Expand Down
Loading

0 comments on commit 524acba

Please sign in to comment.