Skip to content

Commit

Permalink
Merge branch 'feature/ktlint' into 'develop'
Browse files Browse the repository at this point in the history
Use ktlint for ensuring code quality

See merge request pika-lab/tuprolog/2p-in-kotlin!92
  • Loading branch information
gciatto committed Sep 15, 2020
2 parents 488790b + 1af78ac commit a56f737
Show file tree
Hide file tree
Showing 815 changed files with 3,710 additions and 3,133 deletions.
5 changes: 5 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ variables:
AFTER_TASK: ""
GCMD: "gradle"
BUILD_TASK: "clean assemble"
CHECK_CODE_TASK: "ktlintCheck"
TEST_TASK: "check -x dokka"
TEST_JVM_TASK: "jvmTest -x dokka"
TEST_JS_TASK: "clean jsTest -x dokka"
Expand All @@ -33,6 +34,10 @@ Compile:
stage: build
script: $GCMD $BEFORE_TASK $BUILD_TASK $AFTER_TASK $GOPTS

Check Format:
stage: test
script: $GCMD $BEFORE_TASK $CHECK_CODE_TASK $AFTER_TASK $GOPTS

Test JVM:
stage: test
script: $GCMD $BEFORE_TASK $TEST_JVM_TASK $AFTER_TASK $GOPTS
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Some quick links:
* [GitHub Repository](https://github.com/tuProlog/2p-kt) (where JVM releases are hosted)
* [NPM Repository](https://www.npmjs.com/org/tuprolog) (where JS releases are hosted)
* [Maven Repository](https://bintray.com/pika-lab/tuprolog) (where all releases are hosted)
* [Documentation](http://pika-lab.gitlab.io/tuprolog/2p-in-kotlin/)

## Intro

Expand Down
43 changes: 31 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ plugins {
id("org.danilopianini.git-sensitive-semantic-versioning") version Versions.org_danilopianini_git_sensitive_semantic_versioning_gradle_plugin
id("de.fayard.buildSrcVersions") version Versions.de_fayard_buildsrcversions_gradle_plugin
id("com.github.breadmoirai.github-release") version Versions.com_github_breadmoirai_github_release_gradle_plugin
id("org.jlleitschuh.gradle.ktlint") version "9.4.0"
}

repositories {
Expand Down Expand Up @@ -141,7 +142,7 @@ ktSubprojects.forEachProject {
tasks.withType<KotlinJsCompile> {
kotlinOptions {
moduleKind = "umd"
//noStdlib = true
// noStdlib = true
metaInfo = true
sourceMap = true
sourceMapEmbedSources = "always"
Expand All @@ -163,7 +164,6 @@ ktSubprojects.forEachProject {
}
}
}

}

tasks.withType<KotlinJvmCompile> {
Expand All @@ -175,6 +175,7 @@ ktSubprojects.forEachProject {
}
}

configureKtLint()
configureDokka("jvm", "js")
configureMavenPublications("packDokka")
configureUploadToMavenCentral()
Expand All @@ -192,6 +193,7 @@ jvmSubprojects.forEachProject {
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "com.jfrog.bintray")

configureKtLint()
configureDokka()
createMavenPublications("jvm", "java", docArtifact = "packDokka")
configureUploadToMavenCentral()
Expand All @@ -207,14 +209,15 @@ jsSubprojects.forEachProject {
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "com.jfrog.bintray")

configureKtLint()
configureDokka()
createMavenPublications("js", "kotlin", docArtifact = "packDokka")
configureUploadToMavenCentral()
configureUploadToBintray()
configureSigning()
}

configure<GithubReleaseExtension> {
githubRelease {
if (githubToken != null) {
token(githubToken)
owner(githubOwner)
Expand All @@ -237,6 +240,20 @@ configure<GithubReleaseExtension> {
}
}

fun Project.configureKtLint() {
apply(plugin = "org.jlleitschuh.gradle.ktlint")

ktlint {
debug.set(false)
ignoreFailures.set(false)
enableExperimentalRules.set(true)
filter {
exclude("**/generated/**")
include("**/kotlin/**")
}
}
}

fun Project.configureUploadToGithub(
jarTaskPositiveFilter: (String) -> Boolean = { "jar" in it },
jarTaskNegativeFilter: (String) -> Boolean = { "dokka" in it || "source" in it }
Expand Down Expand Up @@ -327,8 +344,10 @@ fun Project.configureUploadToBintray(vararg publicationNames: String) {
user = bintrayUser
key = bintrayKey
if (publicationNames.isEmpty()) {
setPublications(*project.publishing.publications.withType<MavenPublication>().map { it.name }
.toTypedArray())
setPublications(
*project.publishing.publications.withType<MavenPublication>().map { it.name }
.toTypedArray()
)
} else {
setPublications(*publicationNames)
}
Expand Down Expand Up @@ -382,7 +401,7 @@ fun Project.configureMavenPublications(docArtifactBaseName: String) {
} else if (!docArtifact.endsWith("KotlinMultiplatform")) {
log(
"no javadoc artifact for publication $name in project ${project.name}: " +
"no such a task: $docArtifact"
"no such a task: $docArtifact"
)
}

Expand All @@ -392,7 +411,6 @@ fun Project.configureMavenPublications(docArtifactBaseName: String) {
}

fun Project.createMavenPublications(name: String, vararg componentsStrings: String, docArtifact: String? = null) {

val sourcesJar by tasks.creating(Jar::class) {
archiveBaseName.set(project.name)
archiveVersion.set(project.version.toString())
Expand All @@ -405,8 +423,9 @@ fun Project.createMavenPublications(name: String, vararg componentsStrings: Stri
version = project.version.toString()

for (component in componentsStrings) {
if (component in components.names)
if (component in components.names) {
from(components[component])
}
}

if (docArtifact != null && docArtifact in tasks.names) {
Expand All @@ -416,7 +435,7 @@ fun Project.createMavenPublications(name: String, vararg componentsStrings: Stri
} else if (docArtifact == null || !docArtifact.endsWith("KotlinMultiplatform")) {
log(
"no javadoc artifact for publication $name in project ${project.name}: " +
"no such a task: $docArtifact"
"no such a task: $docArtifact"
)
}

Expand All @@ -430,9 +449,9 @@ fun Project.createMavenPublications(name: String, vararg componentsStrings: Stri
fun Set<String>.forEachProject(f: Project.() -> Unit) = allprojects.filter { it.name in this }.forEach(f)

fun NamedDomainObjectContainerScope<GradlePassConfigurationImpl>.registerPlatform(
platform: String, configuration: Action<in GradlePassConfigurationImpl>
platform: String,
configuration: Action<in GradlePassConfigurationImpl>
) {

val low = platform.toLowerCase()
val up = platform.toUpperCase()

Expand Down Expand Up @@ -487,4 +506,4 @@ fun Project.configureJsPackage(packageJsonTask: String = "jsPackageJson", compil
.replace("\"2p", "\"@tuprolog/2p")
}
}
}
}
8 changes: 5 additions & 3 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ kotlin {

val createInfoKt by tasks.creating {
doLast {
infoKtFile.writeText("""
infoKtFile.writeText(
"""
|package $tuPrologPackage
|
|object Info {
| const val VERSION = "${rootProject.version}"
|}
""".trimMargin())
|""".trimMargin()
)
}
outputs.file(infoKtFile)
}
Expand All @@ -32,4 +34,4 @@ kotlin {
}
}
}
}
}
1 change: 0 additions & 1 deletion core/src/commonMain/kotlin/it/unibo/tuprolog/core/Atom.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ interface Atom : Struct, Constant {
override val isTrue: Boolean
get() = Truth.TRUE_FUNCTOR == value


override val isFail: Boolean
get() = Truth.FAIL_FUNCTOR == value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,4 @@ interface Clause : Struct {
*/
internal val defaultPreparationForExecutionVisitor = preparationForExecutionVisitor()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ package it.unibo.tuprolog.core
import kotlin.js.JsName
import kotlin.jvm.JvmName



/**
* Prepares the receiver Clause for execution, using the provided visitor
*
Expand All @@ -19,4 +17,4 @@ fun Clause.prepareForExecution(): Clause =

@JsName("prepareForExecutionWithUnifier")
fun Clause.prepareForExecution(unifier: Substitution.Unifier): Clause =
accept(Clause.preparationForExecutionVisitor(unifier)) as Clause
accept(Clause.preparationForExecutionVisitor(unifier)) as Clause
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ interface Collection : Struct {

@JsName("unfold")
fun unfold(): Sequence<Term>
}
}
1 change: 0 additions & 1 deletion core/src/commonMain/kotlin/it/unibo/tuprolog/core/Cons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package it.unibo.tuprolog.core

import it.unibo.tuprolog.core.impl.ConsImpl
import kotlin.js.JsName
import kotlin.jvm.JvmField
import kotlin.jvm.JvmStatic
import it.unibo.tuprolog.core.List as LogicList

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ interface Constant : Term {
* Empty companion aimed at letting extensions be injected through extension methods
*/
companion object
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ fun Sequence<Term>.toTerm(): List = this.asIterable().toTerm()
fun Iterable<Term>.toTerm(): List = List.of(this)

@JsName("arrayToTerm")
fun Array<out Term>.toTerm(): List = List.of(*this)
fun Array<out Term>.toTerm(): List = List.of(*this)
1 change: 0 additions & 1 deletion core/src/commonMain/kotlin/it/unibo/tuprolog/core/Empty.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package it.unibo.tuprolog.core

import kotlin.js.JsName
import kotlin.jvm.JvmField
import kotlin.jvm.JvmStatic

interface Empty : Atom {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ interface Formatter<T> {
@JsName("format")
fun format(value: T): String
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ import kotlin.jvm.JvmName
fun <T> T.format(formatter: Formatter<T>): String {
return formatter.format(this)
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ interface Indicator : Struct {
@JsName("isWellFormed")
val isWellFormed: Boolean
get() = nameTerm is Atom &&
arityTerm is Integer &&
arityTerm.`as`<Integer>().intValue.signum >= 0
arityTerm is Integer &&
arityTerm.`as`<Integer>().intValue.signum >= 0

/** The indicated functor name, if well-formed */
@JsName("indicatedName")
Expand Down Expand Up @@ -86,4 +86,4 @@ interface Indicator : Struct {
@JsName("ofString")
fun of(name: String, arity: Int): Indicator = of(Atom.of(name), Integer.of(arity))
}
}
}
3 changes: 2 additions & 1 deletion core/src/commonMain/kotlin/it/unibo/tuprolog/core/Integer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ interface Integer : Numeric {
companion object {

@JvmField
val INTEGER_REGEX_PATTERN = """^[+\-]?(0[xXbBoO])?[0-9A-Fa-f]+$""".toRegex()
val INTEGER_REGEX_PATTERN =
"""^[+\-]?(0[xXbBoO])?[0-9A-Fa-f]+$""".toRegex()

@JvmStatic
@JsName("ofBigInteger")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ sealed class ListIterator(list: List) : Iterator<Term> {
return item
}
}
}
}
1 change: 0 additions & 1 deletion core/src/commonMain/kotlin/it/unibo/tuprolog/core/Real.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ interface Real : Numeric {
fun of(real: String): Real = of(BigDecimal.of(real))
}
}

11 changes: 7 additions & 4 deletions core/src/commonMain/kotlin/it/unibo/tuprolog/core/RegexUtils.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package it.unibo.tuprolog.core

internal object RegexUtils {
const val INT = """([0-9]+)"""
const val INT =
"""([0-9]+)"""

const val DEC = """(\.[0-9]+)"""
const val DEC =
"""(\.[0-9]+)"""

const val EXP = """([eE][+\-]?[0-9]+)"""
}
const val EXP =
"""([eE][+\-]?[0-9]+)"""
}
3 changes: 1 addition & 2 deletions core/src/commonMain/kotlin/it/unibo/tuprolog/core/Rule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package it.unibo.tuprolog.core

import it.unibo.tuprolog.core.impl.RuleImpl
import kotlin.js.JsName
import kotlin.jvm.JvmField
import kotlin.jvm.JvmStatic

interface Rule : Clause {
Expand Down Expand Up @@ -40,4 +39,4 @@ interface Rule : Clause {
return of(Struct.template(functor, arity), Var.anonymous())
}
}
}
}
2 changes: 1 addition & 1 deletion core/src/commonMain/kotlin/it/unibo/tuprolog/core/Scope.kt
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,4 @@ interface Scope {
@JsName("ofVarAndThen")
fun <R> of(vararg vars: Var, lambda: Scope.() -> R): R = of(*vars).with(lambda)
}
}
}
1 change: 0 additions & 1 deletion core/src/commonMain/kotlin/it/unibo/tuprolog/core/Set.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ interface Set : Collection {
fun of(terms: Sequence<Term>): Set = of(terms.toList())
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ class SetIterator(Set: Set) : Iterator<Term> {
}
}
}

}
}
5 changes: 2 additions & 3 deletions core/src/commonMain/kotlin/it/unibo/tuprolog/core/Struct.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ interface Struct : Term {

/** The pattern of a well-formed functor for a Struct */
@JvmField
val STRUCT_FUNCTOR_REGEX_PATTERN = """^[a-z][A-Za-z_0-9]*$""".toRegex()
val STRUCT_FUNCTOR_REGEX_PATTERN =
"""^[a-z][A-Za-z_0-9]*$""".toRegex()

@JvmStatic
@JsName("escapeFunctor")
Expand Down Expand Up @@ -176,7 +177,6 @@ interface Struct : Term {
}
}


@JvmStatic
@JsName("foldSequence")
fun fold(operator: String, terms: Sequence<Term>, terminal: Term?): Struct =
Expand Down Expand Up @@ -206,6 +206,5 @@ interface Struct : Term {
@JsName("foldNullTerminated")
fun fold(operator: String, vararg terms: Term): Struct =
fold(operator, listOf(*terms))

}
}
Loading

0 comments on commit a56f737

Please sign in to comment.