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

Add support for creating tasks to format .gradle.kts files #337

Open
1 of 2 tasks
cortinico opened this issue Aug 13, 2024 · 4 comments
Open
1 of 2 tasks

Add support for creating tasks to format .gradle.kts files #337

cortinico opened this issue Aug 13, 2024 · 4 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@cortinico
Copy link
Owner

⚠️ Is your feature request related to a problem? Please describe

We should create tasks that format the gradle.kts files (like ktfmtFormatKotlinScript and ktfmtCheckKotlinScript) and hook them inside the ktfmtFormat and ktfmtCheck tasks.

💡 Describe the solution you'd like

Could be implemented in a number of ways. Happy to discuss any approach

🤚 Do you want to develop this feature yourself?

  • Yes
  • No

This is up for grab :)

@cortinico cortinico added help wanted Extra attention is needed good first issue Good for newcomers labels Aug 13, 2024
@simonhauck
Copy link
Collaborator

I think this is a great idea.
One easy way to implement this, would be to take the project directory and only collect the top level .kts. files. That would probably solve most use cases.

If we searched recursively for all .kts files, it would be a bit weird for nested multi-module projects. Because the parent project would also format the gradle scripts of subprojects. What do you think?

@cortinico
Copy link
Owner Author

If we searched recursively for all .kts files, it would be a bit weird for nested multi-module projects. Because the parent project would also format the gradle scripts of subprojects. What do you think?

Yeah that's a good point, so we get the top level .gradle.kts and .settings.kts file and we're good to go 👍 Each project will inspect its own kts file

@jessestricker
Copy link
Contributor

For an ad-hoc solution, I've implented this in my build.gradle.kts like the following and it works really well for now:

val scriptFiles = fileTree(projectDir) { include("*.kts") }

val ktfmtFormatScript by
    tasks.registering(KtfmtFormatTask::class) {
        description = "Run Ktfmt formatter for script files on project '${project.name}'."
        source = scriptFiles
    }

tasks.ktfmtFormat { dependsOn(ktfmtFormatScript) }

val ktfmtCheckScript by
    tasks.registering(KtfmtCheckTask::class) {
        description =
            "Run Ktfmt formatter validation for script files on project '${project.name}'."
        source = scriptFiles
    }

tasks.ktfmtCheck { dependsOn(ktfmtCheckScript) }

@cortinico
Copy link
Owner Author

For an ad-hoc solution, I've implented this in my build.gradle.kts like the following and it works really well for now:

I know but I think we can add support for ktfmtFormatScript and ktfmtCheckScript out of the box for ktfmt-gradle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants