Skip to content

Fix licenseHeader for Kotlin code starting with @file:... #139

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

Merged
merged 3 commits into from
Sep 5, 2017
Merged

Fix licenseHeader for Kotlin code starting with @file:... #139

merged 3 commits into from
Sep 5, 2017

Conversation

JLLeitschuh
Copy link
Member

Closes #136

@nedtwigg
Copy link
Member

nedtwigg commented Sep 2, 2017

Can you add a changelog entry under 3.6.0-SNAPSHOT for plugin-gradle/CHANGES.md. Otherwise LGTM, thanks!

@JLLeitschuh
Copy link
Member Author

Done!

Copy link
Member

@jbduncan jbduncan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @JLLeitschuh. I have a couple of comments, but otherwise this LGTM! :)

@@ -25,18 +25,20 @@
import com.diffplug.spotless.kotlin.KtLintStep;

public class KotlinExtension extends FormatExtension {
// The delimiter has the '^' prepended to the regex where the pattern is compiled.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to understand what this comment was saying, so I wonder if it would be clearer if it was worded something like this:

// '^' is prepended to the regex in LICENSE_HEADER_DELIMITER later in FormatExtension.licenseHeader(String, String)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, sounds good.

// Make sure the header gets added.
Assertions.assertThat(result).startsWith(HEADER);
// Make sure that the rest of the file is still there with nothing removed.
Assertions.assertThat(result).endsWith(original);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, these two assertions don't guard against the case where unrelated text gets inserted in between the header and the rest of the original file contents, accidentally or otherwise.

Thus I wonder if it's worth testing that original directly follows HEADER.

(If so, one might be able to do this using String character indexes somehow, or alternatively checking that the file contains exactly as many lines as HEADER + original...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting thought. I'll add something to assert that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've expanded this test.

@JLLeitschuh
Copy link
Member Author

Should be all cleaned up now!

@jbduncan
Copy link
Member

jbduncan commented Sep 5, 2017

Looks great to me now @JLLeitschuh. Thanks!

@nedtwigg nedtwigg merged commit 169a072 into diffplug:master Sep 5, 2017
@nedtwigg
Copy link
Member

nedtwigg commented Sep 5, 2017

I'll release as a bugfix later today.

@JLLeitschuh JLLeitschuh deleted the bug/JLL/kotlin_licenseHeader_file_annotation_delimiter branch September 5, 2017 17:53
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

Successfully merging this pull request may close these issues.

3 participants