Skip to content

Commit

Permalink
chore: add ktlint in Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
nikit19 committed Oct 14, 2018
1 parent 9a18ba5 commit 478e503
Show file tree
Hide file tree
Showing 30 changed files with 58 additions and 30 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ install:
- echo yes | ${ANDROID_HOME}/tools/bin/sdkmanager "platforms;android-27"
script:
- ./gradlew build
- ./gradlew ktlint
after_success:
- bash scripts/prep-key.sh
- bash scripts/update-apk.sh
21 changes: 21 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ repositories {
mavenCentral()
}

configurations {
ktlint
}

dependencies {
def lifecycle_version = "1.1.1"
def koin_version = "0.9.3"
Expand Down Expand Up @@ -119,9 +123,26 @@ dependencies {
//QR Code
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'

// ktlint
ktlint "com.github.shyiko:ktlint:0.15.0"

testImplementation 'junit:junit:4.12'
testImplementation "io.mockk:mockk:1.8.9"
testImplementation 'org.threeten:threetenbp:1.3.7'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
classpath = configurations.ktlint
main = "com.github.shyiko.ktlint.Main"
args "src/**/*.kt"
}

task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
main = "com.github.shyiko.ktlint.Main"
classpath = configurations.ktlint
args "-F", "src/**/*.kt"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general

import android.content.Context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.attendees

import io.reactivex.Completable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.attendees

import android.app.AlertDialog
Expand Down Expand Up @@ -174,8 +175,7 @@ class AttendeeFragment : Fragment() {
selectedPaymentOption = paymentOptions[p2]
if (selectedPaymentOption == "Stripe")
rootView.stripePayment.visibility = View.VISIBLE
else
rootView.stripePayment.visibility = View.GONE
else rootView.stripePayment.visibility = View.GONE
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class AttendeeService(
return formsSingle.flatMap {
if (it.isNotEmpty())
formsSingle
else
attendeeApi.getCustomFormsForAttendees(id, filter)
else attendeeApi.getCustomFormsForAttendees(id, filter)
.map {
attendeeDao.insertCustomForms(it)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.attendees

import android.support.design.widget.TextInputLayout
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.attendees

import android.arch.lifecycle.MutableLiveData
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.auth

import io.reactivex.Single
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.auth

import android.arch.lifecycle.Observer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.di

import android.arch.persistence.room.Room
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.event

import android.arch.lifecycle.Observer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class EventService(
return eventsFlowable.switchMap {
if (it.isNotEmpty())
eventsFlowable
else
eventApi.getEvents()
else eventApi.getEvents()
.map {
eventDao.insertEvents(it)
eventTopicsDao.insertEventTopics(getEventTopicList(it))
Expand Down Expand Up @@ -97,8 +96,7 @@ class EventService(
return eventsFlowable.switchMap {
if (it.isNotEmpty())
eventsFlowable
else
eventTopicApi.getEventsUnderTopicId(id)
else eventTopicApi.getEventsUnderTopicId(id)
.toFlowable()
.map {
eventDao.insertEvents(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ object EventUtils {
try {
if (startingDate != endingDate)
return "${getFormattedDateShort(startsAt)}, ${getFormattedTime(startsAt)}"
else
return "${getFormattedDateWithoutYear(startsAt)}"
else return "${getFormattedDateWithoutYear(startsAt)}"
} catch (e: IllegalArgumentException) {
Timber.e(e, "Error formatting time")
return ""
Expand All @@ -123,8 +122,7 @@ object EventUtils {
try {
if (startingDate != endingDate)
return "- ${getFormattedDateShort(endsAt)}, ${getFormattedTime(endsAt)} ${getFormattedTimeZone(endsAt)}"
else
return "${getFormattedTime(startsAt)} - ${getFormattedTime(endsAt)} ${getFormattedTimeZone(endsAt)}"
else return "${getFormattedTime(startsAt)} - ${getFormattedTime(endsAt)} ${getFormattedTimeZone(endsAt)}"
} catch (e: IllegalArgumentException) {
Timber.e(e, "Error formatting time")
return ""
Expand All @@ -137,8 +135,7 @@ object EventUtils {
try {
if (startingDate != endingDate)
return "$startingDate at ${getFormattedTime(startsAt)} - $endingDate at ${getFormattedTime(endsAt)} (${getFormattedTimeZone(endsAt)})"
else
return "$startingDate from ${getFormattedTime(startsAt)} to ${getFormattedTime(endsAt)} (${getFormattedTimeZone(endsAt)})"
else return "$startingDate from ${getFormattedTime(startsAt)} to ${getFormattedTime(endsAt)} (${getFormattedTimeZone(endsAt)})"
} catch (e: IllegalArgumentException) {
Timber.e(e, "Error formatting time")
return ""
Expand All @@ -151,8 +148,7 @@ object EventUtils {
try {
if (startingDate != endingDate)
return "$startingDate - $endingDate${getFormattedTime(startsAt)} ${getFormattedTimeZone(startsAt)}"
else
return "$startingDate${getFormattedTime(startsAt)} ${getFormattedTimeZone(startsAt)}"
else return "$startingDate${getFormattedTime(startsAt)} ${getFormattedTimeZone(startsAt)}"
} catch (e: IllegalArgumentException) {
Timber.e(e, "Error formatting time")
return ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.event

import android.support.v7.widget.RecyclerView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.event.topic

import android.arch.lifecycle.Observer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.favorite

import android.support.v7.widget.RecyclerView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.favorite

import android.arch.lifecycle.Observer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.order

import android.arch.lifecycle.Observer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.order

import android.arch.lifecycle.Observer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class OrdersUnderUserVM(

if (idList.size != 0)
eventsUnderUser(query)
else
progress.value = false
else progress.value = false
}, {
message.value = "Failed to list Orders under a user"
Timber.d(it, "Failed to list Orders under a user ")
Expand Down Expand Up @@ -103,13 +102,11 @@ class OrdersUnderUserVM(

val formattedSubQuery = if (subQuery != "")
subQuery.substring(1) // remove "," from the beginning
else
"" // if there are no orders
else "" // if there are no orders

return if (idList.size == 1)
"[{\"name\":\"id\",\"op\":\"eq\",\"val\":\"$eventId\"}]"
else
"[{\"or\":[$formattedSubQuery]}]"
else "[{\"or\":[$formattedSubQuery]}]"
}

override fun onCleared() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.search

import android.arch.lifecycle.Observer
Expand Down Expand Up @@ -130,8 +131,7 @@ class SearchFragment : Fragment() {
rootView.fabSearch.visibility = View.GONE
if (searchViewModel.savedLocation != null && TextUtils.isEmpty(rootView.locationTextView.text.toString()) && rootView.timeTextView.text == "Anytime")
searchViewModel.loadEvents(searchViewModel.savedLocation.nullToEmpty(), searchViewModel.savedDate.nullToEmpty())
else
searchViewModel.loadEvents(rootView.locationTextView.text.toString().nullToEmpty(), rootView.timeTextView.text.toString().nullToEmpty())
else searchViewModel.loadEvents(rootView.locationTextView.text.toString().nullToEmpty(), rootView.timeTextView.text.toString().nullToEmpty())
loadEventsAgain = true
return false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.search

import android.app.DatePickerDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class SearchViewModel(private val eventService: EventService, private val prefer
"[{\"name\":\"name\",\"op\":\"ilike\",\"val\":\"%$searchEvent%\"}]"
else if (time == "Anytime")
"[{\"and\":[{\"name\":\"location-name\",\"op\":\"ilike\",\"val\":\"%$location%\"},{\"name\":\"name\",\"op\":\"ilike\",\"val\":\"%$searchEvent%\"}]}]"
else
"[{\"and\":[{\"name\":\"location-name\",\"op\":\"ilike\",\"val\":\"%$location%\"},{\"name\":\"name\",\"op\":\"ilike\",\"val\":\"%$searchEvent%\"},{\"name\":\"starts-at\",\"op\":\"ge\",\"val\":\"$savedDate%\"},{\"name\":\"starts-at\",\"op\":\"lt\",\"val\":\"$savedNextDate%\"}]}]"
else "[{\"and\":[{\"name\":\"location-name\",\"op\":\"ilike\",\"val\":\"%$location%\"},{\"name\":\"name\",\"op\":\"ilike\",\"val\":\"%$searchEvent%\"},{\"name\":\"starts-at\",\"op\":\"ge\",\"val\":\"$savedDate%\"},{\"name\":\"starts-at\",\"op\":\"lt\",\"val\":\"$savedNextDate%\"}]}]"

compositeDisposable.add(eventService.getSearchEvents(query)
.subscribeOn(Schedulers.io())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.settings

import android.app.AlertDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class SocialLinksService(
return socialFlowable.switchMap {
if (it.isNotEmpty())
socialFlowable
else
socialLinkApi.getSocialLinks(id)
else socialLinkApi.getSocialLinks(id)
.map {
socialLinksDao.insertSocialLinks(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class TicketService(private val ticketApi: TicketApi, private val ticketDao: Tic
return ticketFlowable.switchMap {
if (it.isNotEmpty())
ticketFlowable
else
ticketApi.getTickets(id)
else ticketApi.getTickets(id)
.map {
ticketDao.insertTickets(it)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.ticket

import android.support.v7.widget.RecyclerView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general

import android.app.Application
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* ktlint-disable no-wildcard-imports */
package org.fossasia.openevent.general.event

import io.mockk.MockKAnnotations
Expand Down

0 comments on commit 478e503

Please sign in to comment.