Allow skipping targets based on text they contain#1749
Allow skipping targets based on text they contain#1749oldergod wants to merge 2 commits intodiffplug:mainfrom sandboxing:bquenaudon.2023-07-08.filterfileconsuming
Conversation
| private Charset encoding; | ||
| private Path rootDir; | ||
| private List<FormatterStep> steps; | ||
| private List<String> skipIfContentContains; |
There was a problem hiding this comment.
I didn't add it as a step because every steps would then be repeating the same logic. I thought it best to filter files before thinking of computing them or not.
There was a problem hiding this comment.
The approach you took is a bit faster, but it has some downsides
- more code (we already have a mechanism for skipping based on content, now we have two mechanisms)
- functionality spread (formatter was as simple as possible to operate the FormatterStep, now it has one more mechanism that it needs to have)
This is a useful feature to have, but I think it is better to implement it using FormatterStep.filterByContentPattern. Making the fast part of a program a little faster doesn't matter very much.
There was a problem hiding this comment.
Thank you for the feedback. I removed most of the code and left the API in the Gradle extension + the tests.
I don't see how to use FilterByContentPatternFormatterStep so I took it out. This one is opting-in based on a pattern, and I would wanna do the reverse. I don't know how to do that from the existing class.
If this was sorted out, I would probably then, when setting the task, wrap all steps with a filtering one.
Let me know if you have better ideas on how to reuse FilterByContentPatternFormatterStep
There was a problem hiding this comment.
I would
- add a field
boolean formatIfMatchesto - then change this to
if (matcher.find() == formatIfMatches) - Now you can add a
booleanto this methodspotless/lib/src/main/java/com/diffplug/spotless/FormatterStep.java
Lines 56 to 58 in d245b60
Now, in FormatExtension, save the excludeContent, and apply it to each step at the end with steps.replaceAll
There was a problem hiding this comment.
Updated the code @nedtwigg with passing tests.
| for (String skipIfContentContain : skipIfContentContains) { | ||
| if (unix.contains(skipIfContentContain)) | ||
| return unix; | ||
| } |
There was a problem hiding this comment.
The logic might be executed twice across computeLineEndings and compute but they're both public so to guarantee skipIfContentContains are respected, I added it to both.
nedtwigg
left a comment
There was a problem hiding this comment.
Formatter should not change, use FormatterStep.filterByContentPattern.
| public default FormatterStep filterByContentPattern(String contentPattern) { | ||
| return new FilterByContentPatternFormatterStep(this, contentPattern); | ||
| return filterByContentPattern(contentPattern, true); | ||
| } |
There was a problem hiding this comment.
I can update this one directly if you don't mind having an API change.
|
Because I'm not able to push to this PR, I opened a new PR (#1755) where I added a few more commits. Thanks for a great PR, it will be merged shortly. |
|
Thank you |
|
Released in |
…lugin to v2.40.0 (mulk/quarkus-googlecloud-jsonlogging!20) This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [com.diffplug.spotless:spotless-maven-plugin](https://github.com/diffplug/spotless) | build | minor | `2.39.0` -> `2.40.0` | --- ### Release Notes <details> <summary>diffplug/spotless</summary> ### [`v2.40.0`](https://github.com/diffplug/spotless/blob/HEAD/CHANGES.md#​2400---2023-07-17) ##### Added - Added support for Protobuf formatting based on [Buf](https://buf.build/). ([#​1208](diffplug/spotless#1208)) - `enum OnMatch { INCLUDE, EXCLUDE }` so that `FormatterStep.filterByContent` can not only include based on the pattern but also exclude. ([#​1749](diffplug/spotless#1749)) ##### Fixed - Update documented default `semanticSort` to `false`. ([#​1728](diffplug/spotless#1728)) ##### Changes - Bump default `cleanthat` version to latest `2.13` -> `2.17`. ([#​1734](diffplug/spotless#1734)) - Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#​1741](diffplug/spotless#1741)) - Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. - Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property. </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNC4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjQuMCJ9-->
This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [flow-bin](https://github.com/flowtype/flow-bin) ([changelog](https://github.com/facebook/flow/blob/master/Changelog.md)) | devDependencies | minor | [`^0.216.0` -> `^0.217.0`](https://renovatebot.com/diffs/npm/flow-bin/0.216.1/0.217.2) | | [org.liquibase:liquibase-maven-plugin](http://www.liquibase.org/liquibase-maven-plugin) ([source](https://github.com/liquibase/liquibase)) | build | minor | `4.23.2` -> `4.24.0` | | [com.diffplug.spotless:spotless-maven-plugin](https://github.com/diffplug/spotless) | build | minor | `2.39.0` -> `2.40.0` | | [io.quarkus:quarkus-maven-plugin](https://github.com/quarkusio/quarkus) | build | patch | `3.4.1` -> `3.4.2` | | [io.quarkus:quarkus-universe-bom](https://github.com/quarkusio/quarkus-platform) | import | patch | `3.4.1` -> `3.4.2` | --- ### Release Notes <details> <summary>flowtype/flow-bin</summary> ### [`v0.217.2`](flow/flow-bin@15ccd14...dc93913) [Compare Source](flow/flow-bin@15ccd14...dc93913) ### [`v0.217.1`](flow/flow-bin@6af43b3...15ccd14) [Compare Source](flow/flow-bin@6af43b3...15ccd14) ### [`v0.217.0`](flow/flow-bin@f96ca32...6af43b3) [Compare Source](flow/flow-bin@f96ca32...6af43b3) </details> <details> <summary>liquibase/liquibase</summary> ### [`v4.24.0`](https://github.com/liquibase/liquibase/blob/HEAD/changelog.txt#Liquibase-4240-is-a-major-release) [Compare Source](liquibase/liquibase@v4.23.2...v4.24.0) </details> <details> <summary>diffplug/spotless</summary> ### [`v2.40.0`](https://github.com/diffplug/spotless/blob/HEAD/CHANGES.md#​2400---2023-07-17) ##### Added - Added support for Protobuf formatting based on [Buf](https://buf.build/). ([#​1208](diffplug/spotless#1208)) - `enum OnMatch { INCLUDE, EXCLUDE }` so that `FormatterStep.filterByContent` can not only include based on the pattern but also exclude. ([#​1749](diffplug/spotless#1749)) ##### Fixed - Update documented default `semanticSort` to `false`. ([#​1728](diffplug/spotless#1728)) ##### Changes - Bump default `cleanthat` version to latest `2.13` -> `2.17`. ([#​1734](diffplug/spotless#1734)) - Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#​1741](diffplug/spotless#1741)) - Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. - Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property. </details> <details> <summary>quarkusio/quarkus</summary> ### [`v3.4.2`](quarkusio/quarkus@3.4.1...3.4.2) [Compare Source](quarkusio/quarkus@3.4.1...3.4.2) </details> <details> <summary>quarkusio/quarkus-platform</summary> ### [`v3.4.2`](quarkusio/quarkus-platform@3.4.1...3.4.2) [Compare Source](quarkusio/quarkus-platform@3.4.1...3.4.2) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This MR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNC4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjQuMCJ9-->
Follow-up of #1738
Add an field to FormatExtension (Gradle) to accept lists of text which if detected will get a Formatter to skip a file as a whole and will not apply anything.
I didn't touch the
mavenplugin.