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

How to exclude generated sources from ktlint --relative? #1834

Closed
Kolyall opened this issue Feb 24, 2023 · 6 comments
Closed

How to exclude generated sources from ktlint --relative? #1834

Kolyall opened this issue Feb 24, 2023 · 6 comments

Comments

@Kolyall
Copy link

Kolyall commented Feb 24, 2023

./ktlint --version
0.48.2

After run the command from pre-commit:

git diff --name-only -z --cached --relative -- '*.kt' '*.kts' | ./ktlint --relative --patterns-from-stdin=''

Output is :

...
app/build/generated/source/kapt/debug/....kt:46:1: Unexpected indentation (4) (should be 8) (indent)

Summary error count (descending) by rule:
  indent: 464
  parameter-list-wrapping: 194
  wrapping: 194
  curly-spacing: 27
  no-consecutive-blank-lines: 1

ktlint also include files from folder: app/build/generated/source/kapt/

@mfederczuk
Copy link
Contributor

mfederczuk commented Feb 24, 2023

Duplicate of #1793.
This problem is known and has already been fixed, though the fix is not yet released.
In the meantime, you can refer to the linked issue for a workaround.

@paul-dingemans
Copy link
Collaborator

@Kolyall You can also use the ktlint snapshot (https://pinterest.github.io/ktlint/install/snapshot-build/) to verify that your problem is solved.

@androideveloper
Copy link

Having similar issue with generated code from Kotlin build scripts (under buildSrc folder). Can confirm 0.49-snapshot fixes that. But I run ktlint without githooks, any workaround to exclude paths (buildSrc folder in this case)?

@mfederczuk
Copy link
Contributor

Excluding paths is already a feature.
Something like this should work:

ktlint . '!buildSrc/**'

@androideveloper
Copy link

Thanks! found the docs https://pinterest.github.io/ktlint/install/cli/#globs
Only excluding didn't work, we also need to include smth.
So this worked for me:

    "**/*.{kt,kts}",
    "!**/build/**",

So this will make sure ktlint is running on both kt and kts files (event in buildSrc), but not in the generated build folder

@paul-dingemans
Copy link
Collaborator

Only excluding didn't work, we also need to include smth.

Yes that is correct. The default (include) patters will only be applied whenever no patterns are specified. But that does not make sense when only an exclude pattern is given.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants