Repository: cqfn/diKTat (kotlin)

Issue:
"no newline at the end of file" message points to the first line and first column of the file
## Describe the bug

If there is no new line at the end of file, diKTat points to the first line and first column. I would rather expect to see a pointer to the end of file. It will be more intuitive with IDE highlight.

## Example

```kotlin
package pkg

import kotlin.test.assertEquals
import org.junit.Test

class MainTest {
    @Test fun testAssert() {
        assertEquals("Hello world!", getHelloString())
    }
}
```

## Expected output

```
.../MainTest.kt:10:2 [WRONG_INDENTATION] only spaces are allowed for indentation and each indentation should equal to 4 spaces (tabs are not allowed): no newline at the end of file MainTest.kt
```

## Observed output

```
.../MainTest.kt:1:1 [WRONG_INDENTATION] only spaces are allowed for indentation and each indentation should equal to 4 spaces (tabs are not allowed): no newline at the end of file MainTest.kt
```

## Steps to Reproduce

Check any file without newline at the end of file.

## Environment information

* diktat version: 1.0.0-rc.3
* build tool (maven/gradle): maven
* how is diktat run (CLI, plugin, etc.): plugin
* kotlin version: 1.5.10
* operating system: Windows 10

Pull request description:
### What's done:
* Fix pointing of warning in WRONG_INDENTATION Rule
* Add tests

Patch:
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt
index 5d976b27d8..42f7e6b8dd 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt
@@ -138,7 +138,12 @@ class IndentationRule(configRules: List<RulesConfig>) : DiktatRule(
             if (lastChild.elementType != WHITE_SPACE || numBlankLinesAfter != 1) {
                 val warnText = if (lastChild.elementType != WHITE_SPACE || numBlankLinesAfter == 0) "no newline" else "too many blank lines"
                 val fileName = filePath.substringAfterLast(File.separator)
-                WRONG_INDENTATION.warnAndFix(configRules, emitWarn, isFixMode, "$warnText at the end of file $fileName", node.startOffset + node.textLength, node) {
+                // In case, when last child is newline, visually user will see blank line at the end of file,
+                // however, the text length does not consider it, since it's blank and line appeared only because of `\n`
+                // But ktlint synthetically increase length in aim to have ability to point to this line, so in this case
+                // offset will be `node.textLength`, otherwise we will point to the last symbol, i.e `node.textLength - 1`
+                val offset = if (lastChild.elementType == WHITE_SPACE && lastChild.textContains('\n')) node.textLength else node.textLength - 1
+                WRONG_INDENTATION.warnAndFix(configRules, emitWarn, isFixMode, "$warnText at the end of file $fileName", offset, node) {
                     if (lastChild.elementType != WHITE_SPACE) {
                         node.addChild(PsiWhiteSpaceImpl("\n"), null)
                     } else {


Test patch:
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/IndentationRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/IndentationRuleWarnTest.kt
index 2d1690d0c5..adb26a8052 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/IndentationRuleWarnTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/IndentationRuleWarnTest.kt
@@ -65,6 +65,47 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule) {
         )
     }
 
+    @Test
+    @Tag(WarningNames.WRONG_INDENTATION)
+    fun `should warn if no new line at the end of file`() {
+        lintMethod(
+            """
+                    |class Example {
+                    |    val zero = 0
+                    |}
+                """.trimMargin(),
+            LintError(3, 1, ruleId, "${WRONG_INDENTATION.warnText()} no newline at the end of file TestFileName.kt", true)
+        )
+    }
+
+    @Test
+    @Tag(WarningNames.WRONG_INDENTATION)
+    fun `should warn if no new line at the end of file, last child whitespace`() {
+        lintMethod(
+            """
+                    |class Example {
+                    |    val zero = 0
+                    |} 
+                """.trimMargin(),
+            LintError(3, 2, ruleId, "${WRONG_INDENTATION.warnText()} no newline at the end of file TestFileName.kt", true)
+        )
+    }
+
+    @Test
+    @Tag(WarningNames.WRONG_INDENTATION)
+    fun `should warn if too many blank lines at the end of file`() {
+        lintMethod(
+            """
+                    |class Example {
+                    |    val zero = 0
+                    |}
+                    |
+                    |
+                """.trimMargin(),
+            LintError(5, 1, ruleId, "${WRONG_INDENTATION.warnText()} too many blank lines at the end of file TestFileName.kt", true)
+        )
+    }
+
     @Test
     @Tag(WarningNames.WRONG_INDENTATION)
     fun `valid indentation - example 1`() {