From bebd25837bb6fe36a9cf207e54d765f3c19af032 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Fri, 7 Jan 2022 19:00:30 +0200 Subject: [PATCH] Added spotless plugin. --- build.gradle.kts | 12 ++++++++++++ .../Solution.kt | 1 - .../Solution.kt | 2 +- .../s0006_zigzag_conversion/Solution.kt | 2 +- .../s0009_palindrome_number/Solution.kt | 19 +++++++++---------- .../Solution.kt | 2 +- .../s0012_integer_to_roman/Solution.kt | 2 +- .../s0013_roman_to_integer/Solution.kt | 2 +- .../Solution.kt | 7 ++++--- .../SolutionTest.kt | 2 +- .../s0012_integer_to_roman/SolutionTest.kt | 3 +-- .../s0013_roman_to_integer/SolutionTest.kt | 4 +--- .../SolutionTest.kt | 1 - 13 files changed, 33 insertions(+), 26 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 857092e4c..4ee52388d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,7 @@ plugins { kotlin("jvm") version "1.6.10" jacoco id("org.sonarqube") version "3.3" + id("com.diffplug.spotless") version "6.1.2" `maven-publish` } @@ -38,6 +39,17 @@ tasks.withType() { options.encoding = "UTF-8" } +spotless { + kotlin { + encoding("UTF-8") + target("**/*.kt") + ktlint("0.43.0") + toggleOffOn() + trimTrailingWhitespace() + endWithNewline() + } +} + tasks { jacocoTestReport { reports { diff --git a/src/main/kotlin/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.kt b/src/main/kotlin/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.kt index 66d538875..83e186149 100644 --- a/src/main/kotlin/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.kt +++ b/src/main/kotlin/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.kt @@ -22,4 +22,3 @@ class Solution { return f } } - diff --git a/src/main/kotlin/g0001_0100/s0005_longest_palindromic_substring/Solution.kt b/src/main/kotlin/g0001_0100/s0005_longest_palindromic_substring/Solution.kt index 5ede46082..f1929efda 100644 --- a/src/main/kotlin/g0001_0100/s0005_longest_palindromic_substring/Solution.kt +++ b/src/main/kotlin/g0001_0100/s0005_longest_palindromic_substring/Solution.kt @@ -32,4 +32,4 @@ class Solution { } return s.substring((lpsCenter - lpsRadius + 1) / 2, (lpsCenter + lpsRadius - 1) / 2) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/g0001_0100/s0006_zigzag_conversion/Solution.kt b/src/main/kotlin/g0001_0100/s0006_zigzag_conversion/Solution.kt index a93cea9d6..4566c880e 100644 --- a/src/main/kotlin/g0001_0100/s0006_zigzag_conversion/Solution.kt +++ b/src/main/kotlin/g0001_0100/s0006_zigzag_conversion/Solution.kt @@ -29,4 +29,4 @@ class Solution { } return buf.toString() } -} \ No newline at end of file +} diff --git a/src/main/kotlin/g0001_0100/s0009_palindrome_number/Solution.kt b/src/main/kotlin/g0001_0100/s0009_palindrome_number/Solution.kt index 47e27d5c7..2040fc914 100644 --- a/src/main/kotlin/g0001_0100/s0009_palindrome_number/Solution.kt +++ b/src/main/kotlin/g0001_0100/s0009_palindrome_number/Solution.kt @@ -2,15 +2,14 @@ package g0001_0100.s0009_palindrome_number class Solution { fun isPalindrome(x: Int): Boolean { - if (x < 0) return false - var rev = 0 - var localX = x - while (localX > 0) - { - rev *= 10 - rev += localX % 10 - localX /= 10 - } - return rev == x + if (x < 0) return false + var rev = 0 + var localX = x + while (localX > 0) { + rev *= 10 + rev += localX % 10 + localX /= 10 + } + return rev == x } } diff --git a/src/main/kotlin/g0001_0100/s0010_regular_expression_matching/Solution.kt b/src/main/kotlin/g0001_0100/s0010_regular_expression_matching/Solution.kt index 3ff5df7bc..f41a8f799 100644 --- a/src/main/kotlin/g0001_0100/s0010_regular_expression_matching/Solution.kt +++ b/src/main/kotlin/g0001_0100/s0010_regular_expression_matching/Solution.kt @@ -25,4 +25,4 @@ class Solution { cache[i][j] = result return result } -} \ No newline at end of file +} diff --git a/src/main/kotlin/g0001_0100/s0012_integer_to_roman/Solution.kt b/src/main/kotlin/g0001_0100/s0012_integer_to_roman/Solution.kt index 865e00a8c..d9c94df11 100644 --- a/src/main/kotlin/g0001_0100/s0012_integer_to_roman/Solution.kt +++ b/src/main/kotlin/g0001_0100/s0012_integer_to_roman/Solution.kt @@ -55,4 +55,4 @@ class Solution { } return num - div * one } -} \ No newline at end of file +} diff --git a/src/main/kotlin/g0001_0100/s0013_roman_to_integer/Solution.kt b/src/main/kotlin/g0001_0100/s0013_roman_to_integer/Solution.kt index a81087762..2b1280087 100644 --- a/src/main/kotlin/g0001_0100/s0013_roman_to_integer/Solution.kt +++ b/src/main/kotlin/g0001_0100/s0013_roman_to_integer/Solution.kt @@ -32,4 +32,4 @@ class Solution { } return localX } -} \ No newline at end of file +} diff --git a/src/main/kotlin/g0801_0900/s0864_shortest_path_to_get_all_keys/Solution.kt b/src/main/kotlin/g0801_0900/s0864_shortest_path_to_get_all_keys/Solution.kt index e48ad502f..7254fd6d8 100644 --- a/src/main/kotlin/g0801_0900/s0864_shortest_path_to_get_all_keys/Solution.kt +++ b/src/main/kotlin/g0801_0900/s0864_shortest_path_to_get_all_keys/Solution.kt @@ -1,6 +1,7 @@ package g0801_0900.s0864_shortest_path_to_get_all_keys -import java.util.* +import java.util.LinkedList +import java.util.Queue class Solution { private var m = 0 @@ -75,8 +76,8 @@ class Solution { // use & to see if we have the key // 0 means that the digit we are looking at is 0 // need a 1 at the digit spot which means there is a key there - if (('A' > grid[nx][ny] || grid[nx][ny] > 'F' || nState and (1 shl grid[nx][ny] - 'A') != 0) - && !visited[nx][ny][nState] + if (('A' > grid[nx][ny] || grid[nx][ny] > 'F' || nState and (1 shl grid[nx][ny] - 'A') != 0) && + !visited[nx][ny][nState] ) { q.add(intArrayOf(nx, ny, nState)) visited[nx][ny][nState] = true diff --git a/src/test/kotlin/g0001_0100/s0011_container_with_most_water/SolutionTest.kt b/src/test/kotlin/g0001_0100/s0011_container_with_most_water/SolutionTest.kt index 3d4b9eec1..2c8c52da4 100644 --- a/src/test/kotlin/g0001_0100/s0011_container_with_most_water/SolutionTest.kt +++ b/src/test/kotlin/g0001_0100/s0011_container_with_most_water/SolutionTest.kt @@ -7,6 +7,6 @@ import org.junit.jupiter.api.Test class SolutionTest { @Test fun isPalindrome() { - assertThat(Solution().maxArea(intArrayOf(1,8,6,2,5,4,8,3,7)), equalTo(49)) + assertThat(Solution().maxArea(intArrayOf(1, 8, 6, 2, 5, 4, 8, 3, 7)), equalTo(49)) } } diff --git a/src/test/kotlin/g0001_0100/s0012_integer_to_roman/SolutionTest.kt b/src/test/kotlin/g0001_0100/s0012_integer_to_roman/SolutionTest.kt index ae54cd146..c550f7f59 100644 --- a/src/test/kotlin/g0001_0100/s0012_integer_to_roman/SolutionTest.kt +++ b/src/test/kotlin/g0001_0100/s0012_integer_to_roman/SolutionTest.kt @@ -2,7 +2,6 @@ package g0001_0100.s0012_integer_to_roman import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.MatcherAssert.assertThat - import org.junit.jupiter.api.Test class SolutionTest { @@ -15,4 +14,4 @@ class SolutionTest { assertThat(solution.intToRoman(58), equalTo("LVIII")) assertThat(solution.intToRoman(1994), equalTo("MCMXCIV")) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/g0001_0100/s0013_roman_to_integer/SolutionTest.kt b/src/test/kotlin/g0001_0100/s0013_roman_to_integer/SolutionTest.kt index bce4a701c..f13c56505 100644 --- a/src/test/kotlin/g0001_0100/s0013_roman_to_integer/SolutionTest.kt +++ b/src/test/kotlin/g0001_0100/s0013_roman_to_integer/SolutionTest.kt @@ -2,7 +2,6 @@ package g0001_0100.s0013_roman_to_integer import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.MatcherAssert.assertThat - import org.junit.jupiter.api.Test class SolutionTest { @@ -15,5 +14,4 @@ class SolutionTest { assertThat(solution.romanToInt("LVIII"), equalTo(58)) assertThat(solution.romanToInt("MCMXCIV"), equalTo(1994)) } - -} \ No newline at end of file +} diff --git a/src/test/kotlin/g0801_0900/s0864_shortest_path_to_get_all_keys/SolutionTest.kt b/src/test/kotlin/g0801_0900/s0864_shortest_path_to_get_all_keys/SolutionTest.kt index 79cc9e0b1..055870d34 100644 --- a/src/test/kotlin/g0801_0900/s0864_shortest_path_to_get_all_keys/SolutionTest.kt +++ b/src/test/kotlin/g0801_0900/s0864_shortest_path_to_get_all_keys/SolutionTest.kt @@ -2,7 +2,6 @@ package g0801_0900.s0864_shortest_path_to_get_all_keys import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.MatcherAssert.assertThat - import org.junit.jupiter.api.Test internal class SolutionTest {