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

Minor infrastructure improvements #700

Merged
merged 4 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ jobs:
key: ${{ runner.os }}-maven-build-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-build-
- name: Maven Package
run: mvn -B clean package -DskipTests
- name: Maven Install
run: mvn -B install
run: mvn -B clean install
- name: Code coverage report
uses: codecov/codecov-action@v1
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ jobs:
sed -i "s/$PREVIOUS_VERSION/$RELEASE_VERSION/g" $file || echo "File $file hasn't been updated!"
cp diktat-rules/src/main/resources/diktat-analysis.yml $(dirname $file)
done
next_snapshot_version=$(printf 'VERSION=${project.version}\n0\n' | mvn help:evaluate | grep '^VERSION' | cut -d= -f2)
echo "version=$next_snapshot_version" > info/buildSrc/gradle.properties
- name: Create pull request
uses: peter-evans/create-pull-request@v3
with:
Expand Down
3 changes: 2 additions & 1 deletion diktat-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repositories {

// default value is needed for correct gradle loading in IDEA; actual value from maven is used during build
val ktlintVersion = project.properties.getOrDefault("ktlintVersion", "0.39.0") as String
val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "0.2.0"
val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "0.3.0"
val junitVersion = project.properties.getOrDefault("junitVersion", "5.7.0") as String
val jacocoVersion = project.properties.getOrDefault("jacocoVersion", "0.8.6") as String
dependencies {
Expand Down Expand Up @@ -98,6 +98,7 @@ tasks.getByName<Test>("functionalTest") {
dependsOn("test")
testClassesDirs = functionalTest.output.classesDirs
classpath = functionalTest.runtimeClasspath
maxParallelForks = Runtime.getRuntime().availableProcessors()
doLast {
if (getCurrentOperatingSystem().isWindows) {
// workaround for https://github.com/koral--/jacoco-gradle-testkit-plugin/issues/9
Expand Down
1 change: 1 addition & 0 deletions diktat-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
</goals>
<configuration>
<sourceDirs>
<!-- For some weird reason if main sourceset is removed from here, syntax highlighting in idea an ability to launch tests is broken -->
<source>src/main/kotlin</source>
<source>src/test/kotlin</source>
<source>${project.basedir}/src/main/kotlin</source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class LocalVariablesRule(private val configRules: List<RulesConfig>) : Rule("loc
val declarationScope = property.getDeclarationScope()

val firstUsageStatementLine = getFirstUsageStatementOrBlock(usages, declarationScope).node.getLineNumber()
val firstUsage = usages.minBy { it.node.getLineNumber() }!!
val firstUsage = usages.minByOrNull { it.node.getLineNumber() }!!

// should skip val and var before it's statement
val offset = property
Expand Down Expand Up @@ -184,7 +184,7 @@ class LocalVariablesRule(private val configRules: List<RulesConfig>) : Rule("loc
*/
@Suppress("UnsafeCallOnNullableType", "GENERIC_VARIABLE_WRONG_DECLARATION")
private fun getFirstUsageStatementOrBlock(usages: List<KtNameReferenceExpression>, declarationScope: KtBlockExpression?): PsiElement {
val firstUsage = usages.minBy { it.node.getLineNumber() }!!
val firstUsage = usages.minByOrNull { it.node.getLineNumber() }!!
val firstUsageScope = firstUsage.getParentOfType<KtBlockExpression>(true)
Comment on lines +187 to 188
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it gonna cause NPE if it returns null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

min returns nullable too, they've just changed function names. We already had !! there, because we should always be able to sort by line number


return if (firstUsageScope == declarationScope) {
Expand All @@ -194,7 +194,7 @@ class LocalVariablesRule(private val configRules: List<RulesConfig>) : Rule("loc
.find { it.parent == declarationScope }!!
} else {
// first usage is in deeper block compared to declaration, need to check how close is declaration to the first line of the block
usages.minBy { it.node.getLineNumber() }!!
usages.minByOrNull { it.node.getLineNumber() }!!
.parentsWithSelf
.find { it.parent == declarationScope }!!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ fun ASTNode.isChildAfterAnother(child: ASTNode, afterChild: ASTNode): Boolean =
* @return boolean result
*/
fun ASTNode.isChildAfterGroup(child: ASTNode, group: List<ASTNode>): Boolean =
getChildren(null).indexOf(child) > (group.map { getChildren(null).indexOf(it) }.max() ?: 0)
getChildren(null).indexOf(child) > (group.map { getChildren(null).indexOf(it) }.maxOrNull() ?: 0)

/**
* Checks whether [child] is before [beforeChild] among the children of [this] node
Expand Down Expand Up @@ -637,7 +637,7 @@ fun ASTNode.areChildrenBeforeChild(children: List<ASTNode>, beforeChild: ASTNode
@Suppress("UnsafeCallOnNullableType")
fun ASTNode.areChildrenBeforeGroup(children: List<ASTNode>, group: List<ASTNode>): Boolean {
require(children.isNotEmpty() && group.isNotEmpty()) { "no sense to operate on empty lists" }
return children.map { getChildren(null).indexOf(it) }.max()!! < group.map { getChildren(null).indexOf(it) }.min()!!
return children.map { getChildren(null).indexOf(it) }.maxOrNull()!! < group.map { getChildren(null).indexOf(it) }.minOrNull()!!
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,5 @@ abstract class VariablesSearch(val node: ASTNode, private val filterForVariables
*
* @param node an [ASTNode]
*/
@SuppressWarnings("FunctionOnlyReturningConstant")
@Suppress("UNUSED_PARAMETER", "FunctionOnlyReturningConstant")
fun default(node: KtProperty) = true
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) {

@Test
@Tag(WarningNames.WRONG_WHITESPACE)
fun `there should be no space before ? in nullable types`() {
fun `there should be no space before question mark in nullable types`() {
lintMethod(
"""
|class Example {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ class VariablesWithUsagesSearchTest {
val var1 = keys.elementAt(0)
val var2 = keys.elementAt(1)
val var3 = keys.elementAt(2)
val var4 = keys.elementAt(3)
assertEquals("var v = 0", var1)
assertEquals(0, vars[var1]?.size)
assertEquals("var v = 1", var2)
Expand Down