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

chore: add ktlint in Travis #640

Closed
wants to merge 4 commits into from
Closed
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
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 "--androidsrc/**/*.kt"
Copy link
Member

Choose a reason for hiding this comment

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

There should be a space after android

Try running this locally

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated. The task keeps running, it never completes

}

task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
main = "com.github.shyiko.ktlint.Main"
classpath = configurations.ktlint
args "-F", "--androidsrc/**/*.kt"
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,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
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
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
Expand Up @@ -130,8 +130,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
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
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