Fix linting warnings

This commit is contained in:
Hubert Van De Walle 2020-08-22 05:11:59 +02:00
parent bad5322abd
commit eeae982a71
19 changed files with 47 additions and 54 deletions

View File

@ -18,7 +18,6 @@ import be.simplenotes.persistance.persistanceModule
import be.simplenotes.search.searchModule
import be.simplenotes.shared.config.DataSourceConfig
import be.simplenotes.shared.config.JwtConfig
import org.http4k.core.Filter
import org.http4k.core.RequestContexts
import org.koin.core.context.startKoin
import org.koin.core.qualifier.named

View File

@ -9,7 +9,6 @@ import be.simplenotes.domain.usecases.NoteService
import be.simplenotes.domain.usecases.markdown.InvalidMeta
import be.simplenotes.domain.usecases.markdown.MissingMeta
import be.simplenotes.domain.usecases.markdown.ValidationError
import be.simplenotes.domain.usecases.search.SearchTerms
import org.http4k.core.Method
import org.http4k.core.Request
import org.http4k.core.Response
@ -36,9 +35,11 @@ class NoteController(
val html = when (it) {
MissingMeta -> view.noteEditor(jwtPayload, error = "Missing note metadata", textarea = markdownForm)
InvalidMeta -> view.noteEditor(jwtPayload, error = "Invalid note metadata", textarea = markdownForm)
is ValidationError -> view.noteEditor(jwtPayload,
is ValidationError -> view.noteEditor(
jwtPayload,
validationErrors = it.validationErrors,
textarea = markdownForm)
textarea = markdownForm
)
}
Response(BAD_REQUEST).html(html)
},
@ -93,9 +94,11 @@ class NoteController(
val html = when (it) {
MissingMeta -> view.noteEditor(jwtPayload, error = "Missing note metadata", textarea = markdownForm)
InvalidMeta -> view.noteEditor(jwtPayload, error = "Invalid note metadata", textarea = markdownForm)
is ValidationError -> view.noteEditor(jwtPayload,
is ValidationError -> view.noteEditor(
jwtPayload,
validationErrors = it.validationErrors,
textarea = markdownForm)
textarea = markdownForm
)
}
Response(BAD_REQUEST).html(html)
},

View File

@ -53,8 +53,10 @@ class SettingsController(
val isDownload = request.form("download") != null
val json = userService.export(jwtPayload.userId)
val res = Response(Status.OK).body(json).header("Content-Type", "application/json")
return if (isDownload) res.header("Content-Disposition",
"attachment; filename=\"simplenotes-export-${sanitizeFilename(jwtPayload.username)}.json\"")
return if (isDownload) res.header(
"Content-Disposition",
"attachment; filename=\"simplenotes-export-${sanitizeFilename(jwtPayload.username)}.json\""
)
else res
}

View File

@ -4,7 +4,6 @@ import be.simplenotes.app.controllers.BaseController
import be.simplenotes.app.controllers.NoteController
import be.simplenotes.app.controllers.SettingsController
import be.simplenotes.app.controllers.UserController
import be.simplenotes.app.filters.ErrorFilter
import be.simplenotes.app.filters.ImmutableFilter
import be.simplenotes.app.filters.SecurityFilter
import be.simplenotes.app.filters.jwtPayload

View File

@ -2,8 +2,10 @@ package be.simplenotes.app.utils
import be.simplenotes.domain.usecases.search.SearchTerms
private fun innerRegex(name: String) = """$name:['"](.*?)['"]""".toRegex()
private fun outerRegex(name: String) = """($name:['"].*?['"])""".toRegex()
private fun innerRegex(name: String) =
"""$name:['"](.*?)['"]""".toRegex()
private fun outerRegex(name: String) =
"""($name:['"].*?['"])""".toRegex()
private val titleRe = innerRegex("title")
private val outerTitleRe = outerRegex("title")

View File

@ -10,7 +10,8 @@ class BaseView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
fun renderHome(jwtPayload: JwtPayload?) = renderPage(
title = "Home",
description = "A fast and simple note taking website",
jwtPayload = jwtPayload) {
jwtPayload = jwtPayload
) {
section("text-center my-2 p-2") {
h1("text-5xl") {
span("text-teal-300") { +"Simplenotes " }
@ -22,7 +23,8 @@ class BaseView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
unsafe {
@Language("html")
val html = """
val html =
"""
<div aria-label="demo" class="md:order-1 order-2 flipped flipped-left p-4 my-10 w-full md:w-1/2">
<div class="flex justify-between mb-4">
<h1 class="text-2xl underline">Notes</h1>
@ -78,13 +80,12 @@ class BaseView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
</table>
</div>
</div>
""".trimIndent()
""".trimIndent()
+html
}
welcome()
}
}

View File

@ -3,7 +3,6 @@ package be.simplenotes.app.views
import be.simplenotes.app.utils.StaticFileResolver
import be.simplenotes.app.views.components.Alert
import be.simplenotes.app.views.components.alert
import kotlinx.html.FlowContent
import kotlinx.html.a
import kotlinx.html.div
@ -18,10 +17,12 @@ class ErrorView(staticFileResolver: StaticFileResolver) : View(staticFileResolve
fun error(errorType: Type) = renderPage(errorType.title, jwtPayload = null) {
div("container mx-auto p-4") {
when (errorType) {
Type.SqlTransientError -> alert(Alert.Warning,
Type.SqlTransientError -> alert(
Alert.Warning,
errorType.title,
"Please try again later",
multiline = true)
multiline = true
)
Type.NotFound -> alert(Alert.Warning, errorType.title, "Page not found", multiline = true)
Type.Other -> alert(Alert.Warning, errorType.title)
}
@ -30,5 +31,4 @@ class ErrorView(staticFileResolver: StaticFileResolver) : View(staticFileResolve
}
}
}
}

View File

@ -101,7 +101,6 @@ class NoteView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
}
}
private fun DIV.pagination(currentPage: Int, numberOfPages: Int, tag: String?) {
val links = mutableListOf<Pair<String, String>>()
// if (currentPage > 1) links += "Previous" to "?page=${currentPage - 1}"
@ -120,7 +119,7 @@ class NoteView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
fun renderedNote(jwtPayload: JwtPayload, note: PersistedNote) = renderPage(
note.meta.title,
jwtPayload = jwtPayload,
scripts = listOf("/highlight.10.1.2.js","/init-highlight.0.0.1.js")
scripts = listOf("/highlight.10.1.2.js", "/init-highlight.0.0.1.js")
) {
div("container mx-auto p-4") {
div("flex items-center justify-between mb-4") {

View File

@ -33,7 +33,9 @@ class SettingView(staticFileResolver: StaticFileResolver) : View(staticFileResol
form(method = FormMethod.post, action = "/export") {
button(name = "display", classes = "btn btn-teal block", type = submit) { +"Display my data" }
button(name = "download", classes = "btn btn-green block mt-2", type = submit) { +"Download my data" }
button(name = "download", classes = "btn btn-green block mt-2", type = submit) {
+"Download my data"
}
}
}
@ -72,7 +74,6 @@ class SettingView(staticFileResolver: StaticFileResolver) : View(staticFileResol
attributes["for"] = "checked"
+" Do you want to proceed ?"
}
}
button(
type = submit,

View File

@ -8,20 +8,21 @@ import be.simplenotes.app.views.components.submitButton
import be.simplenotes.domain.security.JwtPayload
import io.konform.validation.ValidationError
import kotlinx.html.*
import kotlinx.html.ButtonType.submit
class UserView(staticFileResolver: StaticFileResolver) : View(staticFileResolver) {
fun register(
jwtPayload: JwtPayload?,
error: String? = null,
validationErrors: List<ValidationError> = emptyList(),
) = accountForm("Register",
) = accountForm(
"Register",
"Registration page",
jwtPayload,
error,
validationErrors,
"Create an account",
"Register") {
"Register"
) {
+"Already have an account? "
a(href = "/login", classes = "no-underline text-blue-500 font-bold") { +"Sign In" }
}

View File

@ -6,7 +6,7 @@ import be.simplenotes.domain.security.JwtPayload
import kotlinx.html.*
import kotlinx.html.stream.appendHTML
abstract class View(private val staticFileResolver: StaticFileResolver) {
abstract class View(staticFileResolver: StaticFileResolver) {
private val styles = staticFileResolver.resolve("styles.css")!!

View File

@ -28,7 +28,10 @@ internal class SearchTermsParserKtTest {
createResult("blah blah tag:'example' title:'other'", title = "other", tag = "example", all = "blah blah"),
createResult("tag:'example' middle title:'other'", title = "other", tag = "example", all = "middle"),
createResult("tag:'example' title:'other' end", title = "other", tag = "example", all = "end"),
createResult("tag:'example abc' title:'other with words' this is the end ", title = "other with words", tag = "example abc", all = "this is the end"),
createResult(
"tag:'example abc' title:'other with words' this is the end ",
title = "other with words", tag = "example abc", all = "this is the end"
),
)
@ParameterizedTest
@ -36,5 +39,4 @@ internal class SearchTermsParserKtTest {
fun `valid search parser`(case: Pair<String, SearchTerms>) {
assertThat(parseSearchTerms(case.first)).isEqualTo(case.second)
}
}

View File

@ -1,3 +1,5 @@
@file:Suppress("unused")
package be.simplenotes.persistance.notes
import be.simplenotes.domain.model.Note
@ -45,7 +47,8 @@ internal interface NoteEntity : Entity<NoteEntity> {
internal fun NoteEntity.toPersistedMetadata(tags: List<String>) = PersistedNoteMetadata(title, tags, updatedAt, uuid)
internal fun NoteEntity.toPersistedNote(tags: List<String>) = PersistedNote(NoteMetadata(title, tags), markdown, html, updatedAt, uuid)
internal fun NoteEntity.toPersistedNote(tags: List<String>) =
PersistedNote(NoteMetadata(title, tags), markdown, html, updatedAt, uuid)
internal fun Note.toEntity(uuid: UUID, userId: Int): NoteEntity {
val note = this

View File

@ -1,7 +1,6 @@
package be.simplenotes.persistance.users
import be.simplenotes.domain.model.PersistedUser
import be.simplenotes.domain.model.User
import me.liuwj.ktorm.database.*
import me.liuwj.ktorm.entity.*
import me.liuwj.ktorm.schema.*
@ -26,12 +25,4 @@ internal interface UserEntity : Entity<UserEntity> {
internal fun UserEntity.toPersistedUser() = PersistedUser(username, password, id)
internal fun User.toEntity(): UserEntity {
val user = this
return UserEntity {
this.username = user.username
this.password = user.password
}
}
internal val Database.users get() = this.sequenceOf(Users, withReferences = false)

View File

@ -175,7 +175,6 @@ internal class NoteRepositoryImplTest {
assertThat(noteRepo.findAll(user2.id, tag = "c"))
.hasSize(1)
}
}
@Nested
@ -320,8 +319,5 @@ internal class NoteRepositoryImplTest {
assertThat(noteRepo.restore(user1.id, note1.uuid)).isFalse
}
}
}

View File

@ -6,8 +6,6 @@ import org.apache.lucene.document.Document
import org.apache.lucene.document.Field
import org.apache.lucene.document.StringField
import org.apache.lucene.document.TextField
import org.apache.lucene.search.IndexSearcher
import org.apache.lucene.search.TopDocs
internal fun PersistedNote.toDocument(): Document {
val note = this

View File

@ -1,7 +1,6 @@
package be.simplenotes.search
import be.simplenotes.domain.model.PersistedNote
import be.simplenotes.domain.model.PersistedNoteMetadata
import be.simplenotes.domain.usecases.search.NoteSearcher
import be.simplenotes.domain.usecases.search.SearchTerms
import be.simplenotes.search.utils.rmdir
@ -96,5 +95,4 @@ class NoteSearcherImpl(basePath: Path = Path.of("/tmp", "lucene")) : NoteSearche
override fun dropIndex(userId: Int) = rmdir(File(baseFile, userId.toString()).toPath())
override fun dropAll() = rmdir(baseFile.toPath())
}

View File

@ -63,7 +63,7 @@ internal class NoteSearcherImplTest {
* small RAM requirements -- only 1MB heap
* incremental indexing as fast as batch indexing
* index size roughly 20-30% the size of text indexed
""".trimIndent()
""".trimIndent()
// endregion
@Test
@ -85,6 +85,7 @@ internal class NoteSearcherImplTest {
index("second")
index("flip")
@Suppress("SpellCheckingInspection")
assertThat(search("firt"))
.hasSizeGreaterThanOrEqualTo(1)
.anyMatch { it.title == "first" }

View File

@ -10,9 +10,8 @@ data class DataSourceConfig(
val maximumPoolSize: Int,
val connectionTimeout: Long,
) {
override fun toString(): String {
return "DataSourceConfig(jdbcUrl='$jdbcUrl', driverClassName='$driverClassName', username='$username', password='***', maximumPoolSize=$maximumPoolSize, connectionTimeout=$connectionTimeout)"
}
override fun toString() = "DataSourceConfig(jdbcUrl='$jdbcUrl', driverClassName='$driverClassName', " +
"username='$username', password='***', maximumPoolSize=$maximumPoolSize, connectionTimeout=$connectionTimeout)"
}
data class JwtConfig(
@ -20,9 +19,7 @@ data class JwtConfig(
val validity: Long,
val timeUnit: TimeUnit,
) {
override fun toString(): String {
return "JwtConfig(secret='***', validity=$validity, timeUnit=$timeUnit)"
}
override fun toString() = "JwtConfig(secret='***', validity=$validity, timeUnit=$timeUnit)"
}
data class ServerConfig(