diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..590d68372 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,2 @@ +[*.{kt,kts}] +max_line_length=120 diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml index 6f39cae9a..0cfcc74ce 100644 --- a/.idea/checkstyle-idea.xml +++ b/.idea/checkstyle-idea.xml @@ -3,12 +3,14 @@ diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 1bec35e57..63f6cc0b2 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,10 +1,250 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 000000000..9a8b7e5c4 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml index ada92a5ef..97626ba45 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/externalDependencies.xml b/.idea/externalDependencies.xml new file mode 100644 index 000000000..687e9fd1e --- /dev/null +++ b/.idea/externalDependencies.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..d727ff611 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,17 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..3b312839b --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1ddfb..94a25f7f4 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/README.md b/README.md index 5fa6093fc..1abb1e826 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,37 @@ # portkey-android Portkey concept app + +# Code style + +Our code style guidelines are based on the [Android Code Style Guidelines for Contributors](https://source.android.com/source/code-style.html). We only changed a few rules: + +* Line length is 120 characters +* FIXME must not be committed in the repository use TODO instead. FIXME can be used in your own local repository only. + +On top of the Android linter rules (best run for this project using `./gradlew lintRelease`), we use two linters: [Checkstyle](http://checkstyle.sourceforge.net/) (for Java and some language-independent custom project rules), and [ktlint](https://github.com/pinterest/ktlint) (for Kotlin). + +## Checkstyle + +You can run checkstyle via a gradle command: + +``` +$ ./gradlew checkstyle +``` + +It generates an HTML report in `app/build/reports/checkstyle/checkstyle.html`. + +You can also view errors and warnings in realtime with the Checkstyle plugin. When importing the project into Android Studio, Checkstyle should be set up automatically. If it is not, follow the steps below. + +You can install the CheckStyle-IDEA plugin in Android Studio here: + +`Android Studio > Preferences... > Plugins > CheckStyle-IDEA` + +Once installed, you can configure the plugin here: + +`Android Studio > Preferences... > Other Settings > Checkstyle` + +From there, add and enable the custom configuration file, located at [config/checkstyle.xml](https://github.com/automattic/portkey-android/blob/develop/config/checkstyle.xml). + +## ktlint + +You can run ktlint using `./gradlew ktlint`, and you can also run `./gradlew ktlintFormat` for auto-formatting. There is no IDEA plugin (like Checkstyle's) at this time. diff --git a/app/src/androidTest/java/com/automattic/portkey/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/automattic/portkey/ExampleInstrumentedTest.kt index bf64f8ab8..a2cae957c 100644 --- a/app/src/androidTest/java/com/automattic/portkey/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/com/automattic/portkey/ExampleInstrumentedTest.kt @@ -2,12 +2,11 @@ package com.automattic.portkey import androidx.test.InstrumentationRegistry import androidx.test.runner.AndroidJUnit4 +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * diff --git a/app/src/main/java/com/automattic/portkey/MainActivity.kt b/app/src/main/java/com/automattic/portkey/MainActivity.kt index 20039beb9..0605fbcf8 100644 --- a/app/src/main/java/com/automattic/portkey/MainActivity.kt +++ b/app/src/main/java/com/automattic/portkey/MainActivity.kt @@ -2,14 +2,13 @@ package com.automattic.portkey import android.os.Bundle import com.google.android.material.snackbar.Snackbar -import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity import android.view.Menu import android.view.MenuItem import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) diff --git a/app/src/test/java/com/automattic/portkey/ExampleUnitTest.kt b/app/src/test/java/com/automattic/portkey/ExampleUnitTest.kt index bb2a53f66..64674fa84 100644 --- a/app/src/test/java/com/automattic/portkey/ExampleUnitTest.kt +++ b/app/src/test/java/com/automattic/portkey/ExampleUnitTest.kt @@ -1,9 +1,8 @@ package com.automattic.portkey +import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.Assert.* - /** * Example local unit test, which will execute on the development machine (host). * diff --git a/build.gradle b/build.gradle index b39ac1027..0961898e5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,25 +1,65 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.31' + ext.kotlin_version = '1.3.41' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:3.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath 'com.automattic.android:fetchstyle:1.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } +apply plugin: 'com.automattic.android.fetchstyle' + allprojects { + apply plugin: 'checkstyle' + repositories { google() jcenter() - + } + + task checkstyle(type: Checkstyle) { + source 'src' + include '**/*.java' + include '**/*.kt' + exclude '**/gen/**' + + classpath = files() + } + + checkstyle { + toolVersion = '8.3' + configFile file("${project.rootDir}/config/checkstyle.xml") + } +} + +subprojects { + configurations { + ktlint + } + + dependencies { + ktlint 'com.github.shyiko:ktlint:0.31.0' + } + + task ktlint(type: JavaExec) { + main = "com.github.shyiko.ktlint.Main" + classpath = configurations.ktlint + args "src/**/*.kt" + } + + task ktlintFormat(type: JavaExec) { + main = "com.github.shyiko.ktlint.Main" + classpath = configurations.ktlint + args "-F", "src/**/*.kt" } } diff --git a/config/checkstyle.xml b/config/checkstyle.xml new file mode 100644 index 000000000..5d68f337c --- /dev/null +++ b/config/checkstyle.xml @@ -0,0 +1,282 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +