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

Fix build failures caused by the New Year #1066

Merged
merged 6 commits into from
Jan 5, 2022

Conversation

lutovich
Copy link
Contributor

@lutovich lutovich commented Jan 4, 2022

Bump the default DiKTat version

Use the latest major release - 1.0.1. The previous default version 0.4.0 started causing build failures because of the copyright rule. DiKTat tests started failing after the New Year. It is not entirely clear why the tests started failing, but the error behavior changes when adding a dummy copyright header to Kotlin source files. Example header:

/*
    Copyright (c) My Company, Ltd. 2000-2022. All rights reserved.
*/

Release notes for DiKTat 1.0.1 mention a PR that fixes the copyrights rule: https://github.com/analysis-dev/diktat/releases/tag/v1.0.1

Fix DiKTat tests after a version bump

FIRST_COMMENT_NO_SPACES rule renamed to FIRST_COMMENT_NO_BLANK_LINE in saveourtool/diktat#759.

Update explicit version to 1.0.1.

Remove copyright header rules because we do not want DiKTat tests to fail every New Year.

Fix licence header test

Compute the current year instead of using a fixed year 2021. This test started failing after the New Year.

Fix a few more DiKTat test failures

Use the newest DiKTat version. Change expected messages. They do not look right - probably a bug in DiKTat.

@lutovich
Copy link
Contributor Author

lutovich commented Jan 4, 2022

Example failure with DikTat 0.4.0:

SEVERE: Step 'diktat' found problem in 'src/main/kotlin/Main.kt':
java.lang.NullPointerException: null cannot be cast to non-null type org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement
com.pinterest.ktlint.core.RuleExecutionException: java.lang.NullPointerException: null cannot be cast to non-null type org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement
	at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:285)
	at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:23)
	at com.pinterest.ktlint.core.KtLint$visitor$2$2.invoke(KtLint.kt:212)
	at com.pinterest.ktlint.core.KtLint$visitor$2$2.invoke(KtLint.kt:23)
	at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:224)
	at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:211)
	at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:23)
	at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:264)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.diffplug.spotless.kotlin.DiktatStep$State.lambda$createFormat$1(DiktatStep.java:163)
	at com.diffplug.spotless.FormatterFunc$NeedsFile.apply(FormatterFunc.java:154)
	at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:78)
	at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:88)
	at com.diffplug.spotless.Formatter.compute(Formatter.java:230)
	at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:203)
	at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:190)
	at com.diffplug.spotless.maven.SpotlessApplyMojo.process(SpotlessApplyMojo.java:45)
	at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:190)
...
Caused by: java.lang.NullPointerException: null cannot be cast to non-null type org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement
	at org.cqfn.diktat.ruleset.rules.chapter2.comments.HeaderCommentRule$checkCopyright$2.invoke(HeaderCommentRule.kt:187)
	at org.cqfn.diktat.ruleset.rules.chapter2.comments.HeaderCommentRule$checkCopyright$2.invoke(HeaderCommentRule.kt:43)
	at org.cqfn.diktat.ruleset.constants.Warnings.warnAndFix(Warnings.kt:239)
	at org.cqfn.diktat.ruleset.constants.Warnings.warnAndFix$default(Warnings.kt:189)
	at org.cqfn.diktat.ruleset.rules.chapter2.comments.HeaderCommentRule.checkCopyright(HeaderCommentRule.kt:186)
	at org.cqfn.diktat.ruleset.rules.chapter2.comments.HeaderCommentRule.visit(HeaderCommentRule.kt:54)
	at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:271)
	... 48 more

The error changes when I add a dummy copyright header:

SEVERE: Step 'diktat' found problem in 'src/main/kotlin/Main.kt':
There are 1 unfixed errors:
Error on line: 1, column: 1 cannot be fixed automatically
[WRONG_COPYRIGHT_YEAR] year defined in copyright and current year are different: year should be 2022
java.lang.AssertionError: There are 1 unfixed errors:
Error on line: 1, column: 1 cannot be fixed automatically
[WRONG_COPYRIGHT_YEAR] year defined in copyright and current year are different: year should be 2022

@lutovich lutovich force-pushed the bump-diktat-version branch from 1ef2012 to 28867b6 Compare January 4, 2022 22:34
@lutovich lutovich changed the title Bump the default DiKTat version Fix DiKTat tests that started failing after the New Year Jan 4, 2022
Use the latest major release - 1.0.1. The previous default version 0.4.0
started causing build failures because of the copyright rule. DiKTat
tests started failing after the New Year. It is not entirely clear
why the tests started failing, but the error behaviour changes when
adding a dummy copyright header to Kotlin source files. Example header:

```
/*
    Copyright (c) My Company, Ltd. 2000-2022. All rights reserved.
*/
```

Release notes for DiKTat 1.0.1 mention a PR that fixes the copyrights rule:
https://github.com/analysis-dev/diktat/releases/tag/v1.0.1
FIRST_COMMENT_NO_SPACES rule renamed to FIRST_COMMENT_NO_BLANK_LINE
in saveourtool/diktat#759.

Update explicit version to 1.0.1.

Remove copyright header rules because we do not want DiKTat tests to
fail every New Year.
@lutovich lutovich force-pushed the bump-diktat-version branch from a47192f to 9fb30cd Compare January 4, 2022 23:03
Compute the current year instead of using a fixed year 2021.
This test started failing after the New Year.
Use the newest DiKTat version. Change expected messages. They do not look
right - probably a bug in DiKTat.
@lutovich lutovich changed the title Fix DiKTat tests that started failing after the New Year Fix tests that started failing after the New Year Jan 4, 2022
@lutovich lutovich changed the title Fix tests that started failing after the New Year Fix build failures caused by the New Year Jan 4, 2022
@lutovich lutovich marked this pull request as ready for review January 4, 2022 23:53
@lutovich lutovich requested a review from nedtwigg January 4, 2022 23:53
@nedtwigg
Copy link
Member

nedtwigg commented Jan 5, 2022

Amazing, thanks so much! I tweaked changelog entries a bit and I'll merge a whole bunch of PRs in the next hour or two :)

@orchestr7
Copy link
Contributor

orchestr7 commented Jan 31, 2022

@nedtwigg @lutovich thank you guys!
Btw, this issue with copyright will never appear again after saveourtool/diktat#1151 saveourtool/diktat#1154

Now the current year will properly be calculated automatically

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