forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a checker for
ktfmt
for kotlin files (project-chip#27658)
* Add a kotlin format workflow * Update formatting to be bad, to validate we format properly * Undo format change * Make a generic kotlin style yaml * Add format check to kotlin-style * Update naming for changes when to run kotlin validators * Add ktfmt download and execution * Switch ktfmt to google style * Switch to kotlinlang-style * Revert files to master, to validate that our kotlin formatter validates format * Switch to google-style (to have 2 char indents) and apply formatting to all kt files * Add more exceptions now that code is formatted (some methods became longer) --------- Co-authored-by: Andrei Litvin <[email protected]>
- Loading branch information
1 parent
ddf4db4
commit e532537
Showing
97 changed files
with
2,950 additions
and
2,119 deletions.
There are no files selected for viewing
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: Kotlin | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- "**/*.kt" | ||
- ".github/workflows/kotlin-style.yaml" | ||
- "kotlin-detect-config.yaml" | ||
|
||
concurrency: | ||
group: ${{ github.ref }}-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }} | ||
cancel-in-progress: true | ||
|
||
|
||
jobs: | ||
detekt: | ||
name: Static code analysis | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: "checkout" | ||
uses: actions/checkout@v2 | ||
|
||
- name: "detekt" | ||
uses: natiginfo/[email protected] | ||
# Detekt seems not to like circular symlinks, so we set up | ||
# explicit paths below | ||
with: | ||
args: --parallel --build-upon-default-config --config kotlin-detect-config.yaml --input examples/android/CHIPTest,examples/android/CHIPTool,examples/java-matter-controller/java,src/controller/java | ||
|
||
ktlint: | ||
name: "Format check" | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'adopt' | ||
java-version: '17' | ||
|
||
- name: Download ktfmt | ||
run: | | ||
cd /tmp | ||
wget "https://repo1.maven.org/maven2/com/facebook/ktfmt/0.44/ktfmt-0.44-jar-with-dependencies.jar" | ||
- name: Format kotlin files | ||
run: | | ||
find src examples -name '*.kt' \ | ||
| xargs java -jar /tmp/ktfmt-0.44-jar-with-dependencies.jar --google-style | ||
- name: Ensure git works in current working directory | ||
run: git config --global --add safe.directory `pwd` | ||
|
||
- name: Check for uncommited changes | ||
run: | | ||
git add . | ||
# Show the full diff | ||
git diff-index -p HEAD -- | ||
# Also show just the files that are different, to make it easy | ||
# to tell at a glance what might be going on. And throw in | ||
# --exit-code to make this job fail if there is a difference. | ||
git diff-index --exit-code HEAD -- |
20 changes: 9 additions & 11 deletions
20
...ndroid/CHIPTest/app/src/androidTest/java/com/tcl/chip/chiptest/ExampleInstrumentedTest.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 |
---|---|---|
@@ -1,24 +1,22 @@ | ||
package com.tcl.chip.chiptest | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import org.junit.Assert.* | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.tcl.chip.chiptest", appContext.packageName) | ||
} | ||
} | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.tcl.chip.chiptest", appContext.packageName) | ||
} | ||
} |
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
13 changes: 6 additions & 7 deletions
13
examples/android/CHIPTest/app/src/test/java/com/tcl/chip/chiptest/ExampleUnitTest.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 |
---|---|---|
@@ -1,17 +1,16 @@ | ||
package com.tcl.chip.chiptest | ||
|
||
import org.junit.Test | ||
|
||
import org.junit.Assert.* | ||
import org.junit.Test | ||
|
||
/** | ||
* Example local unit test, which will execute on the development machine (host). | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
class ExampleUnitTest { | ||
@Test | ||
fun addition_isCorrect() { | ||
assertEquals(4, 2 + 2) | ||
} | ||
} | ||
@Test | ||
fun addition_isCorrect() { | ||
assertEquals(4, 2 + 2) | ||
} | ||
} |
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
Oops, something went wrong.