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

Support org.jetbrains.kotlin.js plugin, bump dependencies #300

Merged
merged 3 commits into from Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions build.gradle.kts
Expand Up @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.7.20"
kotlin("jvm") version "1.7.22"
id("com.gradle.plugin-publish") version "0.21.0"
`java-gradle-plugin`
`maven-publish`
Expand All @@ -25,10 +25,10 @@ group = "org.jmailen.gradle"
description = projectDescription

object Versions {
const val androidTools = "7.3.0"
const val androidTools = "7.3.1"
const val junit = "5.9.1"
const val ktlint = "0.47.1"
const val mockitoKotlin = "4.0.0"
const val mockitoKotlin = "4.1.0"
}

configurations {
Expand Down Expand Up @@ -115,7 +115,7 @@ tasks {
}

wrapper {
gradleVersion = "7.5.1"
gradleVersion = "7.6"
}
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 8 additions & 4 deletions gradlew
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,10 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
Expand Down Expand Up @@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down
Expand Up @@ -5,8 +5,7 @@ import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.tasks.TaskProvider
import org.jmailen.gradle.kotlinter.pluginapplier.AndroidSourceSetApplier
import org.jmailen.gradle.kotlinter.pluginapplier.KotlinJvmSourceSetApplier
import org.jmailen.gradle.kotlinter.pluginapplier.KotlinMultiplatformSourceSetApplier
import org.jmailen.gradle.kotlinter.pluginapplier.KotlinSourceSetApplier
import org.jmailen.gradle.kotlinter.support.reporterFileExtension
import org.jmailen.gradle.kotlinter.tasks.FormatTask
import org.jmailen.gradle.kotlinter.tasks.InstallPreCommitHookTask
Expand All @@ -17,8 +16,9 @@ import java.io.File
class KotlinterPlugin : Plugin<Project> {

private val extendablePlugins = mapOf(
"org.jetbrains.kotlin.jvm" to KotlinJvmSourceSetApplier,
"org.jetbrains.kotlin.multiplatform" to KotlinMultiplatformSourceSetApplier,
"org.jetbrains.kotlin.jvm" to KotlinSourceSetApplier,
"org.jetbrains.kotlin.multiplatform" to KotlinSourceSetApplier,
"org.jetbrains.kotlin.js" to KotlinSourceSetApplier,
"kotlin-android" to AndroidSourceSetApplier,
)

Expand Down

This file was deleted.

@@ -1,15 +1,12 @@
package org.jmailen.gradle.kotlinter.pluginapplier

import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jmailen.gradle.kotlinter.SourceSetAction
import org.jmailen.gradle.kotlinter.SourceSetApplier
import org.jmailen.gradle.kotlinter.id

internal object KotlinJvmSourceSetApplier : SourceSetApplier {

internal object KotlinSourceSetApplier : SourceSetApplier {
override fun applyToAll(project: Project, action: SourceSetAction) {
getSourceSets(project).configureEach { sourceSet ->
sourceSet.kotlin.let { directorySet ->
Expand All @@ -18,6 +15,6 @@ internal object KotlinJvmSourceSetApplier : SourceSetApplier {
}
}

private fun getSourceSets(project: Project): NamedDomainObjectContainer<KotlinSourceSet> =
project.extensions.findByType(KotlinJvmProjectExtension::class.java)!!.sourceSets
private fun getSourceSets(project: Project) =
project.extensions.getByType(KotlinProjectExtension::class.java).sourceSets
Comment on lines +18 to +19
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I started wondering if this might also work for android project 👀 Theoretically it should, but I'd have to do a bit more research if AGP doesn't do some additional magic

}
@@ -0,0 +1,115 @@
package org.jmailen.gradle.kotlinter.functional

import org.gradle.testkit.runner.TaskOutcome
import org.jmailen.gradle.kotlinter.functional.utils.kotlinClass
import org.jmailen.gradle.kotlinter.functional.utils.resolve
import org.jmailen.gradle.kotlinter.functional.utils.settingsFile
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.io.File

class KotlinJsProjectTest : WithGradleTest.Kotlin() {

lateinit var projectRoot: File

@BeforeEach
fun setup() {
projectRoot = testProjectDir.apply {
resolve("settings.gradle") { writeText(settingsFile) }
resolve("build.gradle") {
// language=groovy
writeText(
"""
plugins {
id 'org.jetbrains.kotlin.js'
id 'org.jmailen.kotlinter'
}

repositories.mavenCentral()

kotlin {
js {
browser()
binaries.executable()
}
}
Comment on lines +32 to +37
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have literally zero experience with JS, so the test environment only follows the official documentation

""".trimIndent(),
)
}
}
}

@Test
fun `lintKotlin passes when on valid kotlin files`() {
projectRoot.resolve("src/main/kotlin/FixtureFileName.kt") {
writeText(kotlinClass("FixtureFileName"))
}
projectRoot.resolve("src/test/kotlin/TestFileName.kt") {
writeText(kotlinClass("TestFileName"))
}

build("lintKotlin").apply {
assertEquals(TaskOutcome.SUCCESS, task(":lintKotlinMain")?.outcome)
assertEquals(TaskOutcome.SUCCESS, task(":lintKotlinTest")?.outcome)
}
}

@Test
fun `lintKotlin fails when lint errors detected`() {
projectRoot.resolve("src/main/kotlin/FixtureFileName.kt") {
writeText(kotlinClass("DifferentClassName"))
}
projectRoot.resolve("src/test/kotlin/FixtureTestFileName.kt") {
writeText(kotlinClass("DifferentTestClassName"))
}

buildAndFail("lintKotlin", "--continue").apply {
assertEquals(TaskOutcome.FAILED, task(":lintKotlinMain")?.outcome)
assertTrue(output.contains("Lint error > [filename] File 'FixtureFileName.kt' contains a single top level declaration"))
assertEquals(TaskOutcome.FAILED, task(":lintKotlinTest")?.outcome)
assertTrue(output.contains("Lint error > [filename] File 'FixtureTestFileName.kt' contains a single top level declaration"))
}
}

@Test
fun `formatKotlin reports formatted and unformatted files`() {
projectRoot.resolve("src/main/kotlin/FixtureClass.kt") {
// language=kotlin
val kotlinClass =
"""
import System.*

class FixtureClass{
private fun hi() {
out.println("Hello")
}
}
""".trimIndent()
writeText(kotlinClass)
}
projectRoot.resolve("src/test/kotlin/FixtureTestClass.kt") {
// language=kotlin
val kotlinClass =
"""
import System.*

class FixtureTestClass{
private fun hi() {
out.println("Hello")
}
}
""".trimIndent()
writeText(kotlinClass)
}
build("formatKotlin").apply {
assertEquals(TaskOutcome.SUCCESS, task(":formatKotlinMain")?.outcome)
assertTrue(output.contains("FixtureClass.kt:3:19: Format fixed > [curly-spacing] Missing spacing before \"{\""))
assertTrue(output.contains("FixtureClass.kt:1:1: Format could not fix > [no-wildcard-imports] Wildcard import"))
assertEquals(TaskOutcome.SUCCESS, task(":formatKotlinTest")?.outcome)
assertTrue(output.contains("FixtureTestClass.kt:3:23: Format fixed > [curly-spacing] Missing spacing before \"{\""))
assertTrue(output.contains("FixtureTestClass.kt:1:1: Format could not fix > [no-wildcard-imports] Wildcard import"))
}
}
}
2 changes: 1 addition & 1 deletion test-project-android/build.gradle.kts
@@ -1,5 +1,5 @@
plugins {
kotlin("android") version "1.7.20"
kotlin("android") version "1.7.22"
id("com.android.library")
id("org.jmailen.kotlinter")
}
Expand Down
2 changes: 1 addition & 1 deletion test-project/build.gradle.kts
@@ -1,4 +1,4 @@
plugins {
kotlin("jvm") version "1.7.20"
kotlin("jvm") version "1.7.22"
id("org.jmailen.kotlinter")
}