-
Notifications
You must be signed in to change notification settings - Fork 461
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
Additional Tests for SpecificFilesTest #529
Comments
I wasn't aware that Spotless, when |
And another one: The tests only cover the case of absolute path specified in |
Spotless always looks exclusively at the field I would focus more tightly on this: spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java Lines 181 to 255 in c007dba
|
I think we found the bug / our error! Look at this line: spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java Lines 201 to 202 in c007dba
So the path gets compiled as a regex (so This matches the documentation
I think that's probably the whole bug. I agree this is not obvious, but it looks like throughout this whole ordeal neither I nor you really looked at the code or its documentation very carefully. Which is why I put such an emphasis on good defaults, and why I'm hesitant to let too many escape hatches for one-off behaviors into the code. |
I'm open to any changes to documentation to make it less likely for others to bump into this. Probably the examples in the documentation are misleading, since they seem to be relative path. If you want a behavior change, that's tricky, because current users are counting on this behavior. |
I didn't want to do NxM, I just wanted to have one test case that makes sure that cases similar to the one I'm having trouble with are covered, though I've since discovered that making that change in my dummy project didn't solve the issue. i.e., I moved my I guess what I'm really testing is that, if the files specified in Rather than writing tests based on the code, I prefer to write tests based on expected behavior. Tests based on code are more likely to be brittle and less likely to test the thing you really want to verify. Hmm, I swear I tried using absolute paths before, but I'll try again. I know I haven't tried them since I simplified my build script.
Why would it be a problem to match absolute or relative paths? As long as absolute continues working, would there be a problem? I could be mistaken, but my initial thought is that it shouldn't be hard at all to match either the absolute or relative path. Thank you for finding this! |
Because of common prefixes. |
Nah, I get that. I was thinking something more along the lines of: shouldInclude = file -> compiledIncludePatterns
.stream()
.anyMatch(filePattern ->
filePattern.matcher(file.getAbsolutePath()).matches() ||
filePattern.matcher(file.getRelativePath()).matches()); I feel like these particular comments probably would make more sense in #528 |
What is In a different issue you mentioned that your experience with this makes you wary of |
I think it's pretty fair to make the assumption that a relative path is relative to the working directory from which the command is run. In IDEs this might not be as clear, but most other tools allow it and people who want to use relative paths from their IDE are aware of this and configure their IDE appropriately. If not, they can just specify absolute paths when in their IDE and use relative paths only on the command line. Not only are relative paths easier to specify, they're also easier to read in cases like this one. The only possible exception is those odd cases where someone sets up their Gradle to run from a non-root directory, but I personally think this should be viewed as misuse of the tool and, in most cases, should not be designed for. Even so, those people could just prefix their relative paths with
I remember in #527 saying I was was wary of piggybacking the CLI off of Gradle, but I definitely didn't mean that supporting custom formatter steps was a problem. Custom formatter steps is absolutely a great feature. Was it the following quote that gave you that impression?
"That just sounds like ______ with extra steps" is a Rick and Morty reference :P. It seems wrong to build a CLI that calls a build system directly in order to do its actual work. Part of the motivation for the CLI is to provide the option for independence from build systems. I'm not sure I can fully articulate why I feel this way, but it just seems cleaner and more resilient to build an actual CLI than to configure your CLI in Gradle then run it independently. At that point, why doesn't the user just install Gradle? They're going to have to learn all about it anyway. If you avoid this problem by generating a Gradle config from another configuration like YAML, then why not just run Spotless directly? Anyway, if/when I end up adding stuff that you feel comfortable with, absolutely feel free to include me on any issues with or changes to that functionality. I think a notion of fine-grained code owners is great, allowing much better support from true SMEs on that part of the code. After all this, I wouldn't mind helping support the I'm going to link to this comment in #527 because it seems relevant. |
Question: What is the expected behavior when an invalid pattern is passed to |
That is the comprehensive, exhaustive documentation for the feature currently. One of the things I like about it is that I think it answers your question. If you want to add validation for the argument, or add relative paths, I'm okay with it, but make sure the documentation explains what the paths are relative to, and make sure that it doesn't have the common-prefix problem. e.g. relative to the root project (e.g. If the documentation can answer those questions in a fairly concise way, then I'll merge whatever you want. My recommendation is to write the docs first, get those signed off, and then proceed with the implementation. My opinionated recommendation is to pass absolute paths, because it takes all these questions off the table. But I'm out of time on this - if your docs are good, I'll merge what you want. |
So, this ticket is actually not really about adding relative path support; or specifically related to the relative paths question. This is legitimately about tests. The empty string case, the invalid pattern case, and the Kotlin case, at least. I think I would be satisfied with those three, and I'm almost done implementing them. I just need to know how you would like it to behave with an invalid pattern and I need to implement the Kotlin test. If you assume that Kotlin Gradle functions identically to Groovy Gradle, this is trivial, but, in my experience this has not been the case. Then again, I guess one could make the argument that adding such a test here is actually testing functionality within Gradle, on some level; which is inappropriate. I would argue otherwise.
The question of invalid pattern behavior? I'm still not sure what that should look like. My thoughts are that it should either fail in error or not match any files. I am assuming based on one of your previous comments that empty string should cause Spotless to target 0 files. If left up to me, I would make the invalid pattern fail in error, so that it is easier to debug. |
From this comment onward the discussion has been about ways to implement relative path matching, and the pros and cons of it. If you want to organize the issues differently, you have my blessing to close any issues you want and open/reopen whatever other issues you want. You have my blessing copy-paste any discussion you feel is relevant. A pattern that matches no files is not necessarily an error. For example, you could pipe If you add things to a test, I'll merge it 99%+ of the time, whether there's an issue or not. If you want to change or add functionality, I strongly recommend starting with the documentation. |
Yeah, there's been a lot of back and forth on different tickets about different things. I think since the initial description of this one is about tests, it would be best to leave this as the one about tests. For now, I'm just going to update the tests.
Yeah, I guessed this, and that makes sense if you pass an empty string. The part I'm not as sure of is when an invalid regex pattern is passed to
Is this the behavior you want here? I think it makes sense to return in error, but it shouldn't be hard to change. |
I agree. |
Should the empty pattern case format no files? This is not the current behavior; Spotless runs against all files when Otherwise, I'm done with the test additions. I know it's minor, but I think it's worth it. I'll put up the PR shortly. |
I think so. How are you using this feature? My assumption has been that anyone using this feature was connecting it to some other tooling, and probably that tooling might sometimes want to apply to nothing. |
FYI, |
SpecificFilesTest
is missing a few test cases:build.gradle
withapply from: spotless_config_file.gradle
. This should be tested.[asdf\\.)?
or another invalid pattern.The text was updated successfully, but these errors were encountered: