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 path with --android flag? #602

Closed
mrleolink opened this issue Oct 3, 2019 · 4 comments

Comments

@mrleolink
Copy link

commented Oct 3, 2019

As the title says, how do I exclude some certain locations while using --android flag?

I have tried different ways like:

ktlint '!*/build/generated/*' --android
This apparently doesn't really scan anything

ktlint '*.kt' '!*/build/generated/*' --android
This doesn't respect the exclude pattern

ktlint '*.kt' '!*/build/generated/*'
This works but it doesn't apply android style.


Also, what do single asterisk and double asterisk mean in the pattern?
I tried both:
ktlint '*.kt' '!**/build/generated/*'
ktlint '*.kt' '!*/build/generated/*'
They gave same result.

@Tapchicoma Tapchicoma added the question label Oct 3, 2019
@Tapchicoma

This comment has been minimized.

Copy link
Collaborator

commented Oct 3, 2019

You should have --android flag first:

$ ./ktlint --android '*.kt' '!*/build/generated/*'
@Tapchicoma Tapchicoma added the cli label Oct 3, 2019
@mrleolink

This comment has been minimized.

Copy link
Author

commented Oct 4, 2019

Thanks for the suggestion @Tapchicoma , putting --android first doesn't help.

Yet I have figured out just by trial-and-error.

Either of this works:
ktlint '*.kt' '!**/build/generated/*' --android
ktlint --android '*.kt' '!**/build/generated/*'

The key is to use ** for my negate pattern. I guess ** matches any directory, and * matches any file.
That's just my guess, I would like to hear some confirmation from someone though.

@Tapchicoma

This comment has been minimized.

Copy link
Collaborator

commented Oct 7, 2019

Ktlint uses klob library for path matching, that implements .gitignore pattern style syntax: https://git-scm.com/docs/gitignore#_pattern_format

@mrleolink

This comment has been minimized.

Copy link
Author

commented Oct 7, 2019

That explains everything.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.